diff --git a/src/components/organisms/ListInsideClusterAndNs/ListInsideClusterAndNs.tsx b/src/components/organisms/ListInsideClusterAndNs/ListInsideClusterAndNs.tsx index ac56e5f..4f52a36 100644 --- a/src/components/organisms/ListInsideClusterAndNs/ListInsideClusterAndNs.tsx +++ b/src/components/organisms/ListInsideClusterAndNs/ListInsideClusterAndNs.tsx @@ -37,7 +37,7 @@ export const ListInsideClusterAndNs: FC = () => { clusterName: selectedCluster || '', typeName: 'namespaces', limit: null, - isEnabled: selectedCluster !== undefined && !isCustomNamespaceResource, + isEnabled: Boolean(selectedCluster !== undefined && !isCustomNamespaceResource), }) const namespacesDataCustom = useApiResources({ @@ -46,7 +46,7 @@ export const ListInsideClusterAndNs: FC = () => { apiVersion: CUSTOM_NAMESPACE_API_RESOURCE_API_VERSION, typeName: CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME, limit: null, - isEnabled: selectedCluster !== undefined && isCustomNamespaceResource, + isEnabled: Boolean(selectedCluster !== undefined && isCustomNamespaceResource), }) return ( diff --git a/src/hooks/useNavSelectorInside.ts b/src/hooks/useNavSelectorInside.ts index 5736e2b..7358170 100644 --- a/src/hooks/useNavSelectorInside.ts +++ b/src/hooks/useNavSelectorInside.ts @@ -1,6 +1,11 @@ -import { TClusterList, TSingleResource, useBuiltinResources } from '@prorobotech/openapi-k8s-toolkit' +import { TClusterList, TSingleResource, useBuiltinResources, useApiResources } from '@prorobotech/openapi-k8s-toolkit' import { useSelector } from 'react-redux' import { RootState } from 'store/store' +import { + CUSTOM_NAMESPACE_API_RESOURCE_API_GROUP, + CUSTOM_NAMESPACE_API_RESOURCE_API_VERSION, + CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME, +} from 'constants/customizationApiGroupAndVersion' const mappedClusterToOptionInSidebar = ({ name }: TClusterList[number]): { value: string; label: string } => ({ value: name, @@ -15,15 +20,40 @@ const mappedNamespaceToOptionInSidebar = ({ metadata }: TSingleResource): { valu export const useNavSelectorInside = (clusterName?: string) => { const clusterList = useSelector((state: RootState) => state.clusterList.clusterList) + const isCustomNamespaceResource = + CUSTOM_NAMESPACE_API_RESOURCE_API_GROUP && + typeof CUSTOM_NAMESPACE_API_RESOURCE_API_GROUP === 'string' && + CUSTOM_NAMESPACE_API_RESOURCE_API_GROUP.length > 0 && + CUSTOM_NAMESPACE_API_RESOURCE_API_VERSION && + typeof CUSTOM_NAMESPACE_API_RESOURCE_API_VERSION === 'string' && + CUSTOM_NAMESPACE_API_RESOURCE_API_VERSION.length > 0 && + CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME && + typeof CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME === 'string' && + CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME.length > 0 + const { data: namespaces } = useBuiltinResources({ clusterName: clusterName || '', typeName: 'namespaces', limit: null, - isEnabled: Boolean(clusterName), + isEnabled: Boolean(clusterName !== undefined && !isCustomNamespaceResource), + }) + + const { data: namespacesCustom } = useApiResources({ + clusterName: clusterName || '', + apiGroup: CUSTOM_NAMESPACE_API_RESOURCE_API_GROUP, + apiVersion: CUSTOM_NAMESPACE_API_RESOURCE_API_VERSION, + typeName: CUSTOM_NAMESPACE_API_RESOURCE_RESOURCE_NAME, + limit: null, + isEnabled: Boolean(clusterName !== undefined && isCustomNamespaceResource), }) const clustersInSidebar = clusterList ? clusterList.map(mappedClusterToOptionInSidebar) : [] const namespacesInSidebar = clusterName && namespaces ? namespaces.items.map(mappedNamespaceToOptionInSidebar) : [] + const namespacesInSidebarCustom = + clusterName && namespacesCustom ? namespacesCustom.items.map(mappedNamespaceToOptionInSidebar) : [] - return { clustersInSidebar, namespacesInSidebar } + return { + clustersInSidebar, + namespacesInSidebar: isCustomNamespaceResource ? namespacesInSidebarCustom : namespacesInSidebar, + } }