2020-09-01 14:51:59 +00:00
|
|
|
import React, { useContext, useState } from "react";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2020-08-21 00:09:05 +00:00
|
|
|
import {
|
2020-08-24 18:11:17 +00:00
|
|
|
Avatar,
|
|
|
|
Brand,
|
|
|
|
Dropdown,
|
|
|
|
DropdownItem,
|
|
|
|
DropdownSeparator,
|
|
|
|
DropdownToggle,
|
|
|
|
KebabToggle,
|
|
|
|
PageHeader,
|
|
|
|
PageHeaderTools,
|
|
|
|
PageHeaderToolsItem,
|
|
|
|
PageHeaderToolsGroup,
|
2020-09-01 14:51:59 +00:00
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import { HelpIcon } from "@patternfly/react-icons";
|
2020-10-06 08:25:38 +00:00
|
|
|
import { WhoAmIContext } from "./context/whoami/WhoAmI";
|
2020-09-02 07:51:42 +00:00
|
|
|
import { HelpHeader } from "./components/help-enabler/HelpHeader";
|
2020-09-01 14:51:59 +00:00
|
|
|
import { Link } from "react-router-dom";
|
2020-11-12 12:55:52 +00:00
|
|
|
import { useAdminClient } from "./context/auth/AdminClient";
|
2020-08-04 12:59:41 +00:00
|
|
|
|
|
|
|
export const Header = () => {
|
2020-11-12 12:55:52 +00:00
|
|
|
const adminClient = useAdminClient();
|
2020-08-21 00:09:05 +00:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const ManageAccountDropdownItem = () => {
|
|
|
|
return (
|
2020-12-02 13:37:40 +00:00
|
|
|
<>
|
|
|
|
{adminClient.keycloak && (
|
|
|
|
<DropdownItem
|
|
|
|
key="manage account"
|
|
|
|
onClick={() => adminClient.keycloak.accountManagement()}
|
|
|
|
>
|
|
|
|
{t("manageAccount")}
|
|
|
|
</DropdownItem>
|
|
|
|
)}
|
|
|
|
</>
|
2020-11-12 12:55:52 +00:00
|
|
|
);
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const SignOutDropdownItem = () => {
|
|
|
|
return (
|
2020-12-02 13:37:40 +00:00
|
|
|
<>
|
|
|
|
{adminClient.keycloak && (
|
|
|
|
<DropdownItem
|
|
|
|
key="sign out"
|
|
|
|
onClick={() => adminClient.keycloak.logout({ redirectUri: "" })}
|
|
|
|
>
|
|
|
|
{t("signOut")}
|
|
|
|
</DropdownItem>
|
|
|
|
)}
|
|
|
|
</>
|
2020-11-12 12:55:52 +00:00
|
|
|
);
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const ServerInfoDropdownItem = () => {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
return <DropdownItem key="server info">{t("serverInfo")}</DropdownItem>;
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const HelpDropdownItem = () => {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
return <DropdownItem icon={<HelpIcon />}>{t("help")}</DropdownItem>;
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const kebabDropdownItems = [
|
|
|
|
<ManageAccountDropdownItem key="kebab Manage Account" />,
|
|
|
|
<ServerInfoDropdownItem key="kebab Server Info" />,
|
|
|
|
<HelpDropdownItem key="kebab Help" />,
|
|
|
|
<DropdownSeparator key="kebab sign out separator" />,
|
|
|
|
<SignOutDropdownItem key="kebab Sign out" />,
|
|
|
|
];
|
|
|
|
|
|
|
|
const userDropdownItems = [
|
|
|
|
<ManageAccountDropdownItem key="Manage Account" />,
|
|
|
|
<ServerInfoDropdownItem key="Server info" />,
|
|
|
|
<DropdownSeparator key="sign out separator" />,
|
|
|
|
<SignOutDropdownItem key="Sign out" />,
|
|
|
|
];
|
|
|
|
|
|
|
|
const headerTools = () => {
|
|
|
|
return (
|
|
|
|
<PageHeaderTools>
|
|
|
|
<PageHeaderToolsGroup
|
2020-08-21 00:09:05 +00:00
|
|
|
visibility={{
|
2020-09-01 14:51:59 +00:00
|
|
|
default: "hidden",
|
|
|
|
md: "visible",
|
2020-11-12 12:55:52 +00:00
|
|
|
}} /** the settings and help icon buttons are only visible on desktop sizes and replaced by a kebab dropdown for other sizes */
|
2020-08-21 00:09:05 +00:00
|
|
|
>
|
2020-11-12 12:55:52 +00:00
|
|
|
<PageHeaderToolsItem>
|
|
|
|
<HelpHeader />
|
|
|
|
</PageHeaderToolsItem>
|
|
|
|
</PageHeaderToolsGroup>
|
|
|
|
|
|
|
|
<PageHeaderToolsGroup>
|
|
|
|
<PageHeaderToolsItem
|
|
|
|
visibility={{
|
|
|
|
md: "hidden",
|
|
|
|
}} /** this kebab dropdown replaces the icon buttons and is hidden for desktop sizes */
|
|
|
|
>
|
|
|
|
<KebabDropdown />
|
|
|
|
</PageHeaderToolsItem>
|
|
|
|
<PageHeaderToolsItem
|
|
|
|
visibility={{
|
|
|
|
default: "hidden",
|
|
|
|
md: "visible",
|
|
|
|
}} /** this user dropdown is hidden on mobile sizes */
|
|
|
|
>
|
|
|
|
<UserDropdown />
|
|
|
|
</PageHeaderToolsItem>
|
|
|
|
</PageHeaderToolsGroup>
|
|
|
|
<Avatar src="/img_avatar.svg" alt="Avatar image" />
|
|
|
|
</PageHeaderTools>
|
|
|
|
);
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const KebabDropdown = () => {
|
|
|
|
const [isDropdownOpen, setDropdownOpen] = useState(false);
|
2020-08-21 00:09:05 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const onDropdownToggle = () => {
|
|
|
|
setDropdownOpen(!isDropdownOpen);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dropdown
|
|
|
|
isPlain
|
|
|
|
position="right"
|
|
|
|
toggle={<KebabToggle onToggle={onDropdownToggle} />}
|
|
|
|
isOpen={isDropdownOpen}
|
|
|
|
dropdownItems={kebabDropdownItems}
|
|
|
|
/>
|
|
|
|
);
|
2020-08-21 00:09:05 +00:00
|
|
|
};
|
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const UserDropdown = () => {
|
|
|
|
const whoami = useContext(WhoAmIContext);
|
|
|
|
const [isDropdownOpen, setDropdownOpen] = useState(false);
|
2020-08-21 00:09:05 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
const onDropdownToggle = () => {
|
|
|
|
setDropdownOpen(!isDropdownOpen);
|
|
|
|
};
|
2020-08-21 00:09:05 +00:00
|
|
|
|
2020-11-12 12:55:52 +00:00
|
|
|
return (
|
|
|
|
<Dropdown
|
|
|
|
isPlain
|
|
|
|
position="right"
|
|
|
|
isOpen={isDropdownOpen}
|
|
|
|
toggle={
|
|
|
|
<DropdownToggle onToggle={onDropdownToggle}>
|
|
|
|
{whoami.getDisplayName()}
|
|
|
|
</DropdownToggle>
|
|
|
|
}
|
|
|
|
dropdownItems={userDropdownItems}
|
|
|
|
/>
|
|
|
|
);
|
2020-08-21 00:09:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2020-11-12 12:55:52 +00:00
|
|
|
<PageHeader
|
|
|
|
showNavToggle
|
|
|
|
logo={
|
|
|
|
<Link to="/">
|
|
|
|
<Brand src="/logo.svg" alt="Logo" />
|
|
|
|
</Link>
|
2020-08-24 18:11:17 +00:00
|
|
|
}
|
2020-11-12 12:55:52 +00:00
|
|
|
logoComponent="div"
|
|
|
|
headerTools={headerTools()}
|
2020-08-21 00:09:05 +00:00
|
|
|
/>
|
|
|
|
);
|
2020-08-24 18:11:17 +00:00
|
|
|
};
|