import {
Box,
Clock,
Layers,
List,
Lock,
Share2,
Shuffle,
Trello,
Clipboard,
Edit,
} from 'lucide-react';
import {
type Environment,
type EnvironmentId,
} from '@/react/portainer/environments/types';
import { Authorized, useUser, isEnvironmentAdmin } from '@/react/hooks/useUser';
import { useInfo } from '@/react/docker/proxy/queries/useInfo';
import { useApiVersion } from '@/react/docker/proxy/queries/useVersion';
import { SidebarItem } from './SidebarItem';
import { DashboardLink } from './items/DashboardLink';
import { VolumesLink } from './items/VolumesLink';
import { SidebarParent } from './SidebarItem/SidebarParent';
interface Props {
environmentId: EnvironmentId;
environment: Environment;
}
export function DockerSidebar({ environmentId, environment }: Props) {
const { user } = useUser();
const isAdmin = isEnvironmentAdmin(user, environmentId);
const areStacksVisible =
isAdmin || environment.SecuritySettings.allowStackManagementForRegularUsers;
const envInfoQuery = useInfo(
environmentId,
(info) => !!info.Swarm?.NodeID && !!info.Swarm?.ControlAvailable
);
const apiVersion = useApiVersion(environmentId);
const isSwarmManager = envInfoQuery.data;
const setupSubMenuProps = isSwarmManager
? {
label: 'Swarm',
icon: Trello,
to: 'docker.swarm',
dataCy: 'portainerSidebar-swarm',
}
: {
label: 'Host',
icon: Trello,
to: 'docker.host',
dataCy: 'portainerSidebar-host',
};
const featSubMenuTo = isSwarmManager
? 'docker.swarm.featuresConfiguration'
: 'docker.host.featuresConfiguration';
const registrySubMenuTo = isSwarmManager
? 'docker.swarm.registries'
: 'docker.host.registries';
return (
<>
{areStacksVisible && (
)}
{isSwarmManager && (
)}
{apiVersion >= 1.3 && isSwarmManager && (
)}
{apiVersion >= 1.25 && isSwarmManager && (
)}
{!isSwarmManager && isAdmin && (
)}
>
);
}