import {
Box,
Clock,
Layers,
List,
Lock,
Share2,
Shuffle,
Trello,
Clipboard,
Edit,
} from 'react-feather';
import {
type Environment,
type EnvironmentId,
EnvironmentStatus,
} from '@/react/portainer/environments/types';
import {
Authorized,
useUser,
isEnvironmentAdmin,
} from '@/portainer/hooks/useUser';
import { useInfo, useVersion } from '@/docker/services/system.service';
import { SidebarItem } from './SidebarItem';
import { DashboardLink } from './items/DashboardLink';
import { VolumesLink } from './items/VolumesLink';
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 envVersionQuery = useVersion(environmentId, (version) =>
parseFloat(version.ApiVersion)
);
const isSwarmManager = envInfoQuery.data;
const apiVersion = envVersionQuery.data || 0;
const offlineMode = environment.Status === EnvironmentStatus.Down;
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 && !offlineMode && (
)}
>
);
}