2022-06-28 07:42:42 +00:00
|
|
|
import clsx from 'clsx';
|
2022-11-28 02:00:28 +00:00
|
|
|
import { Home } from 'lucide-react';
|
2022-06-28 07:42:42 +00:00
|
|
|
|
2022-11-13 08:10:18 +00:00
|
|
|
import { useUser } from '@/react/hooks/useUser';
|
2022-06-23 07:25:56 +00:00
|
|
|
import { useIsTeamLeader } from '@/portainer/users/queries';
|
2022-09-21 06:14:29 +00:00
|
|
|
import { usePublicSettings } from '@/react/portainer/settings/queries';
|
2022-06-23 07:25:56 +00:00
|
|
|
|
|
|
|
import styles from './Sidebar.module.css';
|
|
|
|
import { EdgeComputeSidebar } from './EdgeComputeSidebar';
|
|
|
|
import { EnvironmentSidebar } from './EnvironmentSidebar';
|
|
|
|
import { SettingsSidebar } from './SettingsSidebar';
|
|
|
|
import { SidebarItem } from './SidebarItem';
|
|
|
|
import { Footer } from './Footer';
|
|
|
|
import { Header } from './Header';
|
2023-10-09 18:23:12 +00:00
|
|
|
import { SidebarProvider, useSidebarState } from './useSidebarState';
|
2022-12-11 06:58:22 +00:00
|
|
|
import { UpgradeBEBannerWrapper } from './UpgradeBEBanner';
|
2022-06-23 07:25:56 +00:00
|
|
|
|
|
|
|
export function Sidebar() {
|
2023-10-09 18:23:12 +00:00
|
|
|
return (
|
|
|
|
/* in the future (when we remove r2a) this should wrap the whole app - to change root styles */
|
|
|
|
<SidebarProvider>
|
|
|
|
<InnerSidebar />
|
|
|
|
</SidebarProvider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function InnerSidebar() {
|
2022-06-23 07:25:56 +00:00
|
|
|
const { isAdmin, user } = useUser();
|
2022-08-03 21:23:38 +00:00
|
|
|
const isTeamLeader = useIsTeamLeader(user) as boolean;
|
2023-10-09 18:23:12 +00:00
|
|
|
const { isOpen } = useSidebarState();
|
2022-06-23 07:25:56 +00:00
|
|
|
|
|
|
|
const settingsQuery = usePublicSettings();
|
|
|
|
|
|
|
|
if (!settingsQuery.data) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-10-05 07:31:08 +00:00
|
|
|
const { LogoURL } = settingsQuery.data;
|
2022-06-23 07:25:56 +00:00
|
|
|
|
|
|
|
return (
|
2023-10-09 18:23:12 +00:00
|
|
|
<div className={clsx(styles.root, 'sidebar flex flex-col')}>
|
|
|
|
<UpgradeBEBannerWrapper />
|
|
|
|
<nav
|
|
|
|
className={clsx(
|
|
|
|
styles.nav,
|
|
|
|
'flex flex-1 flex-col overflow-y-auto py-5 pl-5',
|
|
|
|
{ 'pr-5': isOpen }
|
|
|
|
)}
|
|
|
|
aria-label="Main"
|
|
|
|
>
|
|
|
|
<Header logo={LogoURL} />
|
|
|
|
{/* negative margin + padding -> scrollbar won't hide the content */}
|
|
|
|
<div
|
2022-11-16 16:38:39 +00:00
|
|
|
className={clsx(
|
2023-10-09 18:23:12 +00:00
|
|
|
styles.navListContainer,
|
|
|
|
'mt-6 flex-1 overflow-y-auto [color-scheme:light] be:[color-scheme:dark] th-dark:[color-scheme:dark] th-highcontrast:[color-scheme:dark]',
|
|
|
|
{ 'pr-5 -mr-5': isOpen }
|
2022-11-16 16:38:39 +00:00
|
|
|
)}
|
|
|
|
>
|
2023-10-09 18:23:12 +00:00
|
|
|
<ul className={clsx('space-y-5', { 'w-[32px]': !isOpen })}>
|
|
|
|
<SidebarItem
|
|
|
|
to="portainer.home"
|
|
|
|
icon={Home}
|
|
|
|
label="Home"
|
|
|
|
data-cy="portainerSidebar-home"
|
|
|
|
/>
|
|
|
|
<EnvironmentSidebar />
|
|
|
|
{isAdmin && <EdgeComputeSidebar />}
|
|
|
|
<SettingsSidebar isAdmin={isAdmin} isTeamLeader={isTeamLeader} />
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div className="mt-auto pt-8">
|
|
|
|
<Footer />
|
|
|
|
</div>
|
|
|
|
</nav>
|
|
|
|
</div>
|
2022-06-23 07:25:56 +00:00
|
|
|
);
|
|
|
|
}
|