2020-08-21 00:09:05 +00:00
|
|
|
import React, { useContext, useState } from 'react';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import {
|
2020-08-24 18:11:17 +00:00
|
|
|
Avatar,
|
|
|
|
Button,
|
|
|
|
ButtonVariant,
|
|
|
|
Brand,
|
|
|
|
Dropdown,
|
|
|
|
DropdownItem,
|
|
|
|
DropdownSeparator,
|
|
|
|
DropdownToggle,
|
|
|
|
KebabToggle,
|
|
|
|
PageHeader,
|
|
|
|
PageHeaderTools,
|
|
|
|
PageHeaderToolsItem,
|
|
|
|
PageHeaderToolsGroup,
|
|
|
|
} from '@patternfly/react-core';
|
2020-08-21 00:09:05 +00:00
|
|
|
import { HelpIcon } from '@patternfly/react-icons';
|
2020-08-04 12:59:41 +00:00
|
|
|
import { KeycloakContext } from './auth/KeycloakContext';
|
2020-08-27 12:09:36 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
2020-08-04 12:59:41 +00:00
|
|
|
|
|
|
|
export const Header = () => {
|
|
|
|
return (
|
|
|
|
<PageHeader
|
2020-08-21 00:09:05 +00:00
|
|
|
showNavToggle
|
2020-08-27 12:09:36 +00:00
|
|
|
logo={
|
|
|
|
<Link to="/">
|
|
|
|
<Brand src="/logo.svg" alt="Logo" />
|
|
|
|
</Link>
|
|
|
|
}
|
|
|
|
logoComponent="div"
|
2020-08-21 00:09:05 +00:00
|
|
|
headerTools={headerTools()}
|
2020-08-04 12:59:41 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
|
|
|
const ManageAccountDropdownItem = () => {
|
|
|
|
const keycloak = useContext(KeycloakContext);
|
|
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
2020-08-24 18:11:17 +00:00
|
|
|
<DropdownItem key="manage account" onClick={() => keycloak?.account()}>
|
|
|
|
{t('Manage account')}
|
|
|
|
</DropdownItem>
|
2020-08-21 00:09:05 +00:00
|
|
|
);
|
2020-08-24 18:11:17 +00:00
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
|
|
|
const SignOutDropdownItem = () => {
|
|
|
|
const keycloak = useContext(KeycloakContext);
|
|
|
|
const { t } = useTranslation();
|
|
|
|
return (
|
2020-08-24 18:11:17 +00:00
|
|
|
<DropdownItem key="sign out" onClick={() => keycloak?.logout()}>
|
|
|
|
{t('Sign out')}
|
|
|
|
</DropdownItem>
|
2020-08-21 00:09:05 +00:00
|
|
|
);
|
2020-08-24 18:11:17 +00:00
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
|
|
|
const ServerInfoDropdownItem = () => {
|
|
|
|
const { t } = useTranslation();
|
2020-08-24 18:11:17 +00:00
|
|
|
return <DropdownItem key="server info">{t('Server info')}</DropdownItem>;
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
|
|
|
const HelpDropdownItem = () => {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const help = t('Help');
|
|
|
|
return (
|
2020-08-24 18:11:17 +00:00
|
|
|
<DropdownItem>
|
|
|
|
<HelpIcon />
|
|
|
|
{` ${help}`}
|
|
|
|
</DropdownItem>
|
|
|
|
);
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
|
|
|
const kebabDropdownItems = [
|
2020-08-24 18:11:17 +00:00
|
|
|
<ManageAccountDropdownItem key="kebab Manage Account" />,
|
|
|
|
<ServerInfoDropdownItem key="kebab Server Info" />,
|
|
|
|
<HelpDropdownItem key="kebab Help" />,
|
2020-08-21 00:09:05 +00:00
|
|
|
<DropdownSeparator key="kebab sign out seperator" />,
|
2020-08-24 18:11:17 +00:00
|
|
|
<SignOutDropdownItem key="kebab Sign out" />,
|
2020-08-21 00:09:05 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const userDropdownItems = [
|
2020-08-24 18:11:17 +00:00
|
|
|
<ManageAccountDropdownItem key="Manage Account" />,
|
|
|
|
<ServerInfoDropdownItem key="Server info" />,
|
|
|
|
<DropdownSeparator key="sign out seperator" />,
|
|
|
|
<SignOutDropdownItem key="Sign out" />,
|
2020-08-21 00:09:05 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const headerTools = () => {
|
|
|
|
return (
|
|
|
|
<PageHeaderTools>
|
|
|
|
<PageHeaderToolsGroup
|
|
|
|
visibility={{
|
|
|
|
default: 'hidden',
|
2020-08-24 18:11:17 +00:00
|
|
|
md: 'visible',
|
2020-08-21 00:09:05 +00:00
|
|
|
}} /** the settings and help icon buttons are only visible on desktop sizes and replaced by a kebab dropdown for other sizes */
|
|
|
|
>
|
|
|
|
<PageHeaderToolsItem>
|
|
|
|
<Button aria-label="Help actions" variant={ButtonVariant.plain}>
|
|
|
|
<HelpIcon />
|
|
|
|
</Button>
|
|
|
|
</PageHeaderToolsItem>
|
|
|
|
</PageHeaderToolsGroup>
|
|
|
|
|
|
|
|
<PageHeaderToolsGroup>
|
|
|
|
<PageHeaderToolsItem
|
|
|
|
visibility={{
|
2020-08-24 18:11:17 +00:00
|
|
|
md: 'hidden',
|
2020-08-21 00:09:05 +00:00
|
|
|
}} /** this kebab dropdown replaces the icon buttons and is hidden for desktop sizes */
|
|
|
|
>
|
2020-08-24 18:11:17 +00:00
|
|
|
<KebabDropdown />
|
2020-08-21 00:09:05 +00:00
|
|
|
</PageHeaderToolsItem>
|
|
|
|
<PageHeaderToolsItem
|
|
|
|
visibility={{
|
|
|
|
default: 'hidden',
|
2020-08-24 18:11:17 +00:00
|
|
|
md: 'visible',
|
2020-08-21 00:09:05 +00:00
|
|
|
}} /** this user dropdown is hidden on mobile sizes */
|
|
|
|
>
|
2020-08-24 18:11:17 +00:00
|
|
|
<UserDropdown />
|
2020-08-21 00:09:05 +00:00
|
|
|
</PageHeaderToolsItem>
|
|
|
|
</PageHeaderToolsGroup>
|
|
|
|
<Avatar src="/img_avatar.svg" alt="Avatar image" />
|
|
|
|
</PageHeaderTools>
|
|
|
|
);
|
2020-08-24 18:11:17 +00:00
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
|
|
|
const KebabDropdown = () => {
|
|
|
|
const [isDropdownOpen, setDropdownOpen] = useState(false);
|
|
|
|
|
|
|
|
const onDropdownToggle = () => {
|
|
|
|
setDropdownOpen(!isDropdownOpen);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dropdown
|
|
|
|
isPlain
|
|
|
|
position="right"
|
|
|
|
toggle={<KebabToggle onToggle={onDropdownToggle} />}
|
|
|
|
isOpen={isDropdownOpen}
|
|
|
|
dropdownItems={kebabDropdownItems}
|
|
|
|
/>
|
2020-08-24 18:11:17 +00:00
|
|
|
);
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
|
|
|
const UserDropdown = () => {
|
|
|
|
const keycloak = useContext(KeycloakContext);
|
|
|
|
const [isDropdownOpen, setDropdownOpen] = useState(false);
|
|
|
|
|
|
|
|
const onDropdownToggle = () => {
|
|
|
|
setDropdownOpen(!isDropdownOpen);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dropdown
|
|
|
|
isPlain
|
|
|
|
position="right"
|
|
|
|
isOpen={isDropdownOpen}
|
2020-08-24 18:11:17 +00:00
|
|
|
toggle={
|
|
|
|
<DropdownToggle onToggle={onDropdownToggle}>
|
|
|
|
{keycloak?.loggedInUser}
|
|
|
|
</DropdownToggle>
|
|
|
|
}
|
2020-08-21 00:09:05 +00:00
|
|
|
dropdownItems={userDropdownItems}
|
|
|
|
/>
|
|
|
|
);
|
2020-08-24 18:11:17 +00:00
|
|
|
};
|