added initial version of the "help system" (#26)
* added initial version of the "help system" fixes: #25 * fix merge error * fix format
This commit is contained in:
parent
8e664659b7
commit
bc041cd44e
7 changed files with 174 additions and 45 deletions
3
.prettierrc.json
Normal file
3
.prettierrc.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"singleQuote": false
|
||||||
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"singleQuote": true
|
|
||||||
}
|
|
21
src/App.tsx
21
src/App.tsx
|
@ -9,6 +9,7 @@ import { PageNav } from "./PageNav";
|
||||||
import { KeycloakContext } from "./auth/KeycloakContext";
|
import { KeycloakContext } from "./auth/KeycloakContext";
|
||||||
import { TableToolbar } from "./components/table-toolbar/TableToolbar";
|
import { TableToolbar } from "./components/table-toolbar/TableToolbar";
|
||||||
|
|
||||||
|
import { Help } from "./components/help-enabler/HelpHeader";
|
||||||
import {
|
import {
|
||||||
BrowserRouter as Router,
|
BrowserRouter as Router,
|
||||||
Route,
|
Route,
|
||||||
|
@ -65,15 +66,17 @@ export const App = () => {
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Router>
|
<Router>
|
||||||
<Page header={<Header />} isManagedSidebar sidebar={<PageNav />}>
|
<Help>
|
||||||
<PageSection variant="light">
|
<Page header={<Header />} isManagedSidebar sidebar={<PageNav />}>
|
||||||
<Switch>
|
<PageSection variant="light">
|
||||||
<Route exact path="/add-realm" component={NewRealmForm}></Route>
|
<Switch>
|
||||||
<Route exact path="/add-client" component={NewClientForm}></Route>
|
<Route exact path="/add-realm" component={NewRealmForm}></Route>
|
||||||
<Route exact path="/" component={Clients}></Route>
|
<Route exact path="/add-client" component={NewClientForm}></Route>
|
||||||
</Switch>
|
<Route exact path="/" component={Clients}></Route>
|
||||||
</PageSection>
|
</Switch>
|
||||||
</Page>
|
</PageSection>
|
||||||
|
</Page>
|
||||||
|
</Help>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,8 +2,6 @@ import React, { useContext, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
Button,
|
|
||||||
ButtonVariant,
|
|
||||||
Brand,
|
Brand,
|
||||||
Dropdown,
|
Dropdown,
|
||||||
DropdownItem,
|
DropdownItem,
|
||||||
|
@ -17,6 +15,7 @@ import {
|
||||||
} from "@patternfly/react-core";
|
} from "@patternfly/react-core";
|
||||||
import { HelpIcon } from "@patternfly/react-icons";
|
import { HelpIcon } from "@patternfly/react-icons";
|
||||||
import { KeycloakContext } from "./auth/KeycloakContext";
|
import { KeycloakContext } from "./auth/KeycloakContext";
|
||||||
|
import { HelpHeader } from "./components/help-enabler/HelpHeader";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
export const Header = () => {
|
export const Header = () => {
|
||||||
|
@ -95,9 +94,7 @@ const headerTools = () => {
|
||||||
}} /** the settings and help icon buttons are only visible on desktop sizes and replaced by a kebab dropdown for other sizes */
|
}} /** the settings and help icon buttons are only visible on desktop sizes and replaced by a kebab dropdown for other sizes */
|
||||||
>
|
>
|
||||||
<PageHeaderToolsItem>
|
<PageHeaderToolsItem>
|
||||||
<Button aria-label="Help actions" variant={ButtonVariant.plain}>
|
<HelpHeader />
|
||||||
<HelpIcon />
|
|
||||||
</Button>
|
|
||||||
</PageHeaderToolsItem>
|
</PageHeaderToolsItem>
|
||||||
</PageHeaderToolsGroup>
|
</PageHeaderToolsGroup>
|
||||||
|
|
||||||
|
|
93
src/components/help-enabler/HelpHeader.tsx
Normal file
93
src/components/help-enabler/HelpHeader.tsx
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
import React, { useState, useContext, ReactNode, createContext } from "react";
|
||||||
|
import {
|
||||||
|
Dropdown,
|
||||||
|
DropdownItem,
|
||||||
|
DropdownToggle,
|
||||||
|
Switch,
|
||||||
|
Text,
|
||||||
|
TextVariants,
|
||||||
|
} from "@patternfly/react-core";
|
||||||
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
|
import { HelpIcon, ExternalLinkAltIcon } from "@patternfly/react-icons";
|
||||||
|
|
||||||
|
import style from "./help-header.module.css";
|
||||||
|
|
||||||
|
type HelpProps = {
|
||||||
|
children: ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
type HelpContextProps = {
|
||||||
|
enabled: boolean;
|
||||||
|
toggleHelp: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const HelpContext = createContext<HelpContextProps>({
|
||||||
|
enabled: true,
|
||||||
|
toggleHelp: () => {},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const Help = ({ children }: HelpProps) => {
|
||||||
|
const [enabled, setHelp] = useState(true);
|
||||||
|
|
||||||
|
function toggleHelp() {
|
||||||
|
setHelp((help) => !help);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<HelpContext.Provider value={{ enabled, toggleHelp }}>
|
||||||
|
{children}
|
||||||
|
</HelpContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const HelpHeader = () => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const help = useContext(HelpContext);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const dropdownItems = [
|
||||||
|
<DropdownItem key="link" id="link">
|
||||||
|
{t("Documentation") + " "}
|
||||||
|
<ExternalLinkAltIcon />
|
||||||
|
</DropdownItem>,
|
||||||
|
<DropdownItem
|
||||||
|
key="enable"
|
||||||
|
id="enable"
|
||||||
|
component="div"
|
||||||
|
className={style.helpDropdownItem}
|
||||||
|
>
|
||||||
|
{t("Enable help mode") + " "}
|
||||||
|
<Switch
|
||||||
|
id="enableHelp"
|
||||||
|
aria-label="Help is enabled"
|
||||||
|
isChecked={help.enabled}
|
||||||
|
onChange={() => help.toggleHelp()}
|
||||||
|
/>
|
||||||
|
<div>
|
||||||
|
<Text component={TextVariants.small} className={style.helpText}>
|
||||||
|
<Trans>
|
||||||
|
This toggle will enable / disable part of the help info in the
|
||||||
|
console. Includes any help text, links and popovers.
|
||||||
|
</Trans>
|
||||||
|
</Text>
|
||||||
|
</div>
|
||||||
|
</DropdownItem>,
|
||||||
|
];
|
||||||
|
return (
|
||||||
|
<Dropdown
|
||||||
|
position="right"
|
||||||
|
isPlain
|
||||||
|
isOpen={open}
|
||||||
|
toggle={
|
||||||
|
<DropdownToggle
|
||||||
|
toggleIndicator={null}
|
||||||
|
onToggle={() => setOpen(!open)}
|
||||||
|
aria-label="Help"
|
||||||
|
id="help"
|
||||||
|
>
|
||||||
|
<HelpIcon />
|
||||||
|
</DropdownToggle>
|
||||||
|
}
|
||||||
|
dropdownItems={dropdownItems}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
9
src/components/help-enabler/help-header.module.css
Normal file
9
src/components/help-enabler/help-header.module.css
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
.helpDropdownItem {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.helpText {
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
white-space: normal;
|
||||||
|
}
|
|
@ -1,33 +1,60 @@
|
||||||
import React from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Nav, NavItem, NavList, PageSidebar, Page } from '@patternfly/react-core';
|
import { storiesOf } from '@storybook/react';
|
||||||
|
import { Nav, NavItem, NavList, PageSidebar, Page, PageHeader, PageHeaderTools, PageHeaderToolsItem } from '@patternfly/react-core';
|
||||||
|
|
||||||
import { RealmSelector } from '../src/components/realm-selector/RealmSelector';
|
import { RealmSelector } from '../src/components/realm-selector/RealmSelector';
|
||||||
|
import { Help, HelpContext, HelpHeader } from '../src/components/help-enabler/HelpHeader';
|
||||||
|
|
||||||
export default {
|
storiesOf('Toolbar')
|
||||||
title: 'Toolbar'
|
.add('realm selector', () => {
|
||||||
};
|
return (
|
||||||
|
<Page sidebar={
|
||||||
|
<PageSidebar nav={
|
||||||
|
<Nav>
|
||||||
|
<NavList>
|
||||||
|
<RealmSelector realm="Master" realmList={["Master", "Photoz"]} />
|
||||||
|
|
||||||
export const RealmSelect = () => (
|
<NavItem id="default-link1" to="#default-link1" itemId={0}>
|
||||||
<Page sidebar={
|
Link 1
|
||||||
<PageSidebar nav={
|
</NavItem>
|
||||||
<Nav>
|
<NavItem id="default-link2" to="#default-link2" itemId={1} isActive>
|
||||||
<NavList>
|
Current link
|
||||||
<RealmSelector realm="Master" realmList={["Master", "Photoz"]} />
|
</NavItem>
|
||||||
|
<NavItem id="default-link3" to="#default-link3" itemId={2}>
|
||||||
|
Link 3
|
||||||
|
</NavItem>
|
||||||
|
<NavItem id="default-link4" to="#default-link4" itemId={3}>
|
||||||
|
Link 4
|
||||||
|
</NavItem>
|
||||||
|
</NavList>
|
||||||
|
</Nav>
|
||||||
|
} />
|
||||||
|
} />
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.add('help system', () => {
|
||||||
|
return (
|
||||||
|
<Help>
|
||||||
|
<HelpSystemTest />
|
||||||
|
</Help>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
<NavItem id="default-link1" to="#default-link1" itemId={0}>
|
const HelpSystemTest = () => {
|
||||||
Link 1
|
const { enabled } = useContext(HelpContext);
|
||||||
</NavItem>
|
return (
|
||||||
<NavItem id="default-link2" to="#default-link2" itemId={1} isActive>
|
<Page header={<PageHeader
|
||||||
Current link
|
headerTools={
|
||||||
</NavItem>
|
<PageHeaderTools>
|
||||||
<NavItem id="default-link3" to="#default-link3" itemId={2}>
|
<PageHeaderToolsItem>
|
||||||
Link 3
|
<HelpHeader />
|
||||||
</NavItem>
|
</PageHeaderToolsItem>
|
||||||
<NavItem id="default-link4" to="#default-link4" itemId={3}>
|
<PageHeaderToolsItem>
|
||||||
Link 4
|
dummy user...
|
||||||
</NavItem>
|
</PageHeaderToolsItem>
|
||||||
</NavList>
|
</PageHeaderTools>}
|
||||||
</Nav>
|
/>}>
|
||||||
} />
|
Help system is {enabled ? 'enabled' : "not on, guess you don't need help"}
|
||||||
} />
|
</Page>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue