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,
|
|
|
|
PageHeaderToolsGroup,
|
2021-07-21 09:30:18 +00:00
|
|
|
PageHeaderToolsItem,
|
2020-09-01 14:51:59 +00:00
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import { HelpIcon } from "@patternfly/react-icons";
|
2021-07-21 09:30:18 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2021-01-15 01:44:16 +00:00
|
|
|
import { Link, useHistory } from "react-router-dom";
|
2021-07-21 09:30:18 +00:00
|
|
|
import { HelpHeader, useHelp } from "./components/help-enabler/HelpHeader";
|
2020-11-12 12:55:52 +00:00
|
|
|
import { useAdminClient } from "./context/auth/AdminClient";
|
2021-07-21 09:30:18 +00:00
|
|
|
import { useWhoAmI } from "./context/whoami/WhoAmI";
|
2021-07-15 09:50:01 +00:00
|
|
|
import environment from "./environment";
|
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"
|
2021-01-21 12:09:50 +00:00
|
|
|
id="manage-account"
|
2020-12-02 13:37:40 +00:00
|
|
|
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
|
2021-01-21 12:09:50 +00:00
|
|
|
id="sign-out"
|
2020-12-02 13:37:40 +00:00
|
|
|
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();
|
2021-01-15 01:44:16 +00:00
|
|
|
const history = useHistory();
|
|
|
|
return (
|
|
|
|
<DropdownItem
|
|
|
|
key="server info"
|
|
|
|
onClick={() => {
|
|
|
|
history.push("/master/");
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t("realmInfo")}
|
|
|
|
</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 HelpDropdownItem = () => {
|
|
|
|
const { t } = useTranslation();
|
2021-07-21 09:30:18 +00:00
|
|
|
const { enabled, toggleHelp } = useHelp();
|
2021-02-08 20:35:38 +00:00
|
|
|
return (
|
|
|
|
<DropdownItem icon={<HelpIcon />} onClick={toggleHelp}>
|
|
|
|
{enabled ? t("helpEnabled") : t("helpDisabled")}
|
|
|
|
</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 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>
|
2021-07-15 09:50:01 +00:00
|
|
|
<Avatar
|
|
|
|
src={environment.resourceUrl + "/img_avatar.svg"}
|
|
|
|
alt="Avatar image"
|
|
|
|
/>
|
2020-11-12 12:55:52 +00:00
|
|
|
</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
|
2021-01-21 12:09:50 +00:00
|
|
|
id="user-dropdown-kebab"
|
2020-11-12 12:55:52 +00:00
|
|
|
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 = () => {
|
2021-07-21 09:30:18 +00:00
|
|
|
const { whoAmI } = useWhoAmI();
|
2020-11-12 12:55:52 +00:00
|
|
|
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"
|
2021-01-21 12:09:50 +00:00
|
|
|
id="user-dropdown"
|
2020-11-12 12:55:52 +00:00
|
|
|
isOpen={isDropdownOpen}
|
|
|
|
toggle={
|
|
|
|
<DropdownToggle onToggle={onDropdownToggle}>
|
2021-01-12 12:39:37 +00:00
|
|
|
{whoAmI.getDisplayName()}
|
2020-11-12 12:55:52 +00:00
|
|
|
</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="/">
|
2021-01-15 01:44:16 +00:00
|
|
|
<Brand
|
2021-07-15 09:50:01 +00:00
|
|
|
src={environment.resourceUrl + "/logo.svg"}
|
2021-01-21 12:09:50 +00:00
|
|
|
id="masthead-logo"
|
2021-01-15 01:44:16 +00:00
|
|
|
alt="Logo"
|
|
|
|
className="keycloak__pageheader_brand"
|
|
|
|
/>
|
2020-11-12 12:55:52 +00:00
|
|
|
</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
|
|
|
};
|