2021-12-14 19:14:53 +00:00
|
|
|
import { PropsWithChildren } from 'react';
|
2022-06-28 07:42:42 +00:00
|
|
|
import {
|
|
|
|
Menu,
|
|
|
|
MenuButton,
|
|
|
|
MenuList,
|
|
|
|
MenuLink as ReachMenuLink,
|
|
|
|
} from '@reach/menu-button';
|
2022-06-23 06:32:18 +00:00
|
|
|
import clsx from 'clsx';
|
|
|
|
import { User, ChevronDown } from 'react-feather';
|
2022-07-04 09:20:46 +00:00
|
|
|
import { UISrefProps, useSref } from '@uirouter/react';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
|
|
|
import { useUser } from '@/portainer/hooks/useUser';
|
2022-07-04 09:20:46 +00:00
|
|
|
import { AutomationTestingProps } from '@/types';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
2021-12-30 15:46:12 +00:00
|
|
|
import { useHeaderContext } from './HeaderContainer';
|
2022-06-23 06:32:18 +00:00
|
|
|
import styles from './HeaderTitle.module.css';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
title: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function HeaderTitle({ title, children }: PropsWithChildren<Props>) {
|
|
|
|
useHeaderContext();
|
|
|
|
const { user } = useUser();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="page white-space-normal">
|
|
|
|
{title}
|
|
|
|
<span className="header_title_content">{children}</span>
|
2022-06-23 06:32:18 +00:00
|
|
|
<Menu>
|
2022-07-03 23:21:25 +00:00
|
|
|
<MenuButton
|
|
|
|
className={clsx(
|
|
|
|
'pull-right flex items-center gap-1',
|
|
|
|
styles.menuButton
|
|
|
|
)}
|
2022-07-04 09:20:46 +00:00
|
|
|
data-cy="userMenu-button"
|
|
|
|
aria-label="User menu toggle"
|
2022-07-03 23:21:25 +00:00
|
|
|
>
|
2022-08-10 04:12:20 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'icon-badge text-lg !p-2 mr-1',
|
|
|
|
'bg-gray-4 text-gray-8',
|
|
|
|
'th-dark:bg-gray-warm-10 th-dark:text-gray-warm-7'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<User className="feather" />
|
|
|
|
</div>
|
2022-06-23 06:32:18 +00:00
|
|
|
{user && <span>{user.Username}</span>}
|
2022-07-01 01:14:22 +00:00
|
|
|
<ChevronDown className={styles.arrowDown} />
|
2022-06-23 06:32:18 +00:00
|
|
|
</MenuButton>
|
2022-06-28 07:42:42 +00:00
|
|
|
|
2022-07-04 09:20:46 +00:00
|
|
|
<MenuList
|
|
|
|
className={styles.menuList}
|
|
|
|
aria-label="User Menu"
|
|
|
|
data-cy="userMenu"
|
|
|
|
>
|
2022-06-28 07:42:42 +00:00
|
|
|
{!window.ddExtension && (
|
2022-07-04 09:20:46 +00:00
|
|
|
<MenuLink
|
|
|
|
to="portainer.account"
|
|
|
|
label="My account"
|
|
|
|
data-cy="userMenu-myAccount"
|
|
|
|
/>
|
2022-06-28 07:42:42 +00:00
|
|
|
)}
|
|
|
|
|
2022-07-04 09:20:46 +00:00
|
|
|
<MenuLink
|
|
|
|
to="portainer.logout"
|
|
|
|
label="Log out"
|
|
|
|
data-cy="userMenu-logOut"
|
|
|
|
params={{ performApiLogout: true }}
|
|
|
|
/>
|
2022-06-23 06:32:18 +00:00
|
|
|
</MenuList>
|
|
|
|
</Menu>
|
2021-12-14 19:14:53 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-06-28 07:42:42 +00:00
|
|
|
|
2022-07-04 09:20:46 +00:00
|
|
|
interface MenuLinkProps extends AutomationTestingProps, UISrefProps {
|
2022-06-28 07:42:42 +00:00
|
|
|
label: string;
|
|
|
|
}
|
|
|
|
|
2022-07-04 09:20:46 +00:00
|
|
|
function MenuLink({
|
|
|
|
to,
|
|
|
|
label,
|
|
|
|
params,
|
|
|
|
options,
|
|
|
|
'data-cy': dataCy,
|
|
|
|
}: MenuLinkProps) {
|
|
|
|
const anchorProps = useSref(to, params, options);
|
2022-06-28 07:42:42 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ReachMenuLink
|
|
|
|
href={anchorProps.href}
|
|
|
|
onClick={anchorProps.onClick}
|
|
|
|
className={styles.menuLink}
|
2022-07-04 09:20:46 +00:00
|
|
|
aria-label={label}
|
|
|
|
data-cy={dataCy}
|
2022-06-28 07:42:42 +00:00
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</ReachMenuLink>
|
|
|
|
);
|
|
|
|
}
|