From bb99c597d3632c9e6f6280552200be5168e80084 Mon Sep 17 00:00:00 2001 From: typescreep Date: Thu, 17 Jul 2025 14:43:13 +0300 Subject: [PATCH] fix reqs for namespaces-mode --- src/components/organisms/Sidebar/Sidebar.tsx | 10 ++-------- .../Sidebar/organisms/Selector/Selector.tsx | 7 +++---- src/hooks/useNavSelectorClusters.ts | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 src/hooks/useNavSelectorClusters.ts diff --git a/src/components/organisms/Sidebar/Sidebar.tsx b/src/components/organisms/Sidebar/Sidebar.tsx index 0173486..2289d4a 100644 --- a/src/components/organisms/Sidebar/Sidebar.tsx +++ b/src/components/organisms/Sidebar/Sidebar.tsx @@ -10,19 +10,13 @@ type TSidebarProps = { } export const Sidebar: FC = ({ inside, sidebar }) => { - const { projectName, clusterName, namespace, syntheticProject } = useParams() + const { clusterName } = useParams() const { token } = theme.useToken() - const possibleProject = syntheticProject && namespace ? syntheticProject : namespace - return ( - {inside ? ( - - ) : ( - - )} + {inside ? : } {sidebar} diff --git a/src/components/organisms/Sidebar/organisms/Selector/Selector.tsx b/src/components/organisms/Sidebar/organisms/Selector/Selector.tsx index 367c98d..df32812 100644 --- a/src/components/organisms/Sidebar/organisms/Selector/Selector.tsx +++ b/src/components/organisms/Sidebar/organisms/Selector/Selector.tsx @@ -2,22 +2,21 @@ import React, { FC, useState } from 'react' import { useNavigate } from 'react-router-dom' import { useSelector } from 'react-redux' import { RootState } from 'store/store' -import { useNavSelector } from 'hooks/useNavSelector' +import { useNavSelectorClusters } from 'hooks/useNavSelectorClusters' import { useMountEffect } from 'hooks/useMountEffect' import { EntrySelect } from 'components/atoms' type TSelectorProps = { clusterName?: string - projectName?: string } -export const Selector: FC = ({ clusterName, projectName }) => { +export const Selector: FC = ({ clusterName }) => { const navigate = useNavigate() const baseprefix = useSelector((state: RootState) => state.baseprefix.baseprefix) const [selectedClusterName, setSelectedClusterName] = useState(clusterName) - const { clustersInSidebar } = useNavSelector(selectedClusterName, projectName) + const { clustersInSidebar } = useNavSelectorClusters() const handleClusterChange = (value?: string) => { if (value) { diff --git a/src/hooks/useNavSelectorClusters.ts b/src/hooks/useNavSelectorClusters.ts new file mode 100644 index 0000000..dee9be2 --- /dev/null +++ b/src/hooks/useNavSelectorClusters.ts @@ -0,0 +1,16 @@ +import { TClusterList } from '@prorobotech/openapi-k8s-toolkit' +import { useSelector } from 'react-redux' +import { RootState } from 'store/store' + +const mappedClusterToOptionInSidebar = ({ name }: TClusterList[number]): { value: string; label: string } => ({ + value: name, + label: name, +}) + +export const useNavSelectorClusters = () => { + const clusterList = useSelector((state: RootState) => state.clusterList.clusterList) + + const clustersInSidebar = clusterList ? clusterList.map(mappedClusterToOptionInSidebar) : [] + + return { clustersInSidebar } +}