diff --git a/src/components/organisms/Factory/Factory.tsx b/src/components/organisms/Factory/Factory.tsx index 2da5374..6ed21ae 100644 --- a/src/components/organisms/Factory/Factory.tsx +++ b/src/components/organisms/Factory/Factory.tsx @@ -4,7 +4,8 @@ import { DynamicComponents, DynamicRendererWithProviders, TDynamicComponentsAppTypeMap, - useDirectUnknownResource, + // useDirectUnknownResource, + useK8sSmartResource, TFactoryResponse, ContentCard, } from '@prorobotech/openapi-k8s-toolkit' @@ -44,11 +45,17 @@ export const Factory: FC = ({ setSidebarTags }) => { } }, []) - const { data: factoryData } = useDirectUnknownResource>({ - uri: `/api/clusters/${cluster}/k8s/apis/${BASE_API_GROUP}/${BASE_API_VERSION}/factories/`, - refetchInterval: false, - queryKey: ['factories', cluster || 'no-cluster'], - isEnabled: cluster !== undefined, + // const { data: factoryData } = useDirectUnknownResource>({ + // uri: `/api/clusters/${cluster}/k8s/apis/${BASE_API_GROUP}/${BASE_API_VERSION}/factories/`, + // refetchInterval: false, + // queryKey: ['factories', cluster || 'no-cluster'], + // isEnabled: cluster !== undefined, + // }) + const { data: factoryData } = useK8sSmartResource>({ + cluster, + group: BASE_API_GROUP, + version: BASE_API_VERSION, + plural: 'factories', }) const { spec } = factoryData?.items.find(({ spec }) => spec.key === key) ?? { spec: undefined } diff --git a/src/components/organisms/HeaderSecond/organisms/Selector/Selector.tsx b/src/components/organisms/HeaderSecond/organisms/Selector/Selector.tsx index a7c0cdb..9fdfeda 100644 --- a/src/components/organisms/HeaderSecond/organisms/Selector/Selector.tsx +++ b/src/components/organisms/HeaderSecond/organisms/Selector/Selector.tsx @@ -1,7 +1,10 @@ import React, { FC, useState } from 'react' import { Flex, Typography } from 'antd' import { useNavigate } from 'react-router-dom' -import { useDirectUnknownResource } from '@prorobotech/openapi-k8s-toolkit' +import { + // useDirectUnknownResource, + useK8sSmartResource, +} from '@prorobotech/openapi-k8s-toolkit' import { useNavSelector } from 'hooks/useNavSelector' import { useMountEffect } from 'hooks/useMountEffect' import { EntrySelect } from 'components/atoms' @@ -31,15 +34,29 @@ export const Selector: FC = ({ clusterName, projectName, instanc projectName, ) - const { data: navigationData } = useDirectUnknownResource<{ - spec: { projects: { clear: string; change: string }; instances: { clear: string; change: string } } + // const { data: navigationData } = useDirectUnknownResource<{ + // spec: { projects: { clear: string; change: string }; instances: { clear: string; change: string } } + // }>({ + // uri: `/api/clusters/${clusterName}/k8s/apis/${BASE_API_GROUP}/${BASE_API_VERSION}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, + // refetchInterval: false, + // queryKey: ['navigation', clusterName || 'no-cluster'], + // isEnabled: clusterName !== undefined, + // }) + + const { data: navigationDataArr } = useK8sSmartResource<{ + items: { spec: { projects: { clear: string; change: string }; instances: { clear: string; change: string } } }[] }>({ - uri: `/api/clusters/${clusterName}/k8s/apis/${BASE_API_GROUP}/${BASE_API_VERSION}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, - refetchInterval: false, - queryKey: ['navigation', clusterName || 'no-cluster'], + cluster: clusterName || '', + group: BASE_API_GROUP, + version: BASE_API_VERSION, + plural: BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME, + fieldSelector: `metadata.name=${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, isEnabled: clusterName !== undefined, }) + const navigationData = + navigationDataArr?.items && navigationDataArr.items.length > 0 ? navigationDataArr.items[0] : undefined + // const handleClusterChange = (value: string) => { // setSelectedClusterName(value) // navigate(`${baseprefix}/clusters/${value}`) diff --git a/src/components/organisms/HeaderSecond/organisms/SelectorNamespace/SelectorNamespace.tsx b/src/components/organisms/HeaderSecond/organisms/SelectorNamespace/SelectorNamespace.tsx index c3bf2a1..46c9ce5 100644 --- a/src/components/organisms/HeaderSecond/organisms/SelectorNamespace/SelectorNamespace.tsx +++ b/src/components/organisms/HeaderSecond/organisms/SelectorNamespace/SelectorNamespace.tsx @@ -1,7 +1,10 @@ import React, { FC, useState } from 'react' import { Flex, Typography } from 'antd' import { useLocation, useNavigate } from 'react-router-dom' -import { useDirectUnknownResource } from '@prorobotech/openapi-k8s-toolkit' +import { + // useDirectUnknownResource, + useK8sSmartResource, +} from '@prorobotech/openapi-k8s-toolkit' import { useSelector } from 'react-redux' import type { RootState } from 'store/store' import { useNavSelectorInside } from 'hooks/useNavSelectorInside' @@ -31,15 +34,31 @@ export const SelectorNamespace: FC = ({ clusterName, na const { namespacesInSidebar } = useNavSelectorInside(selectedClusterName) - const { data: navigationData } = useDirectUnknownResource<{ - spec: { namespaces: { clear: string; change: string } } + // const { data: navigationData } = useDirectUnknownResource<{ + // spec: { namespaces: { clear: string; change: string } } + // }>({ + // uri: `/api/clusters/${clusterName}/k8s/apis/${BASE_API_GROUP}/${BASE_API_VERSION}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, + // refetchInterval: false, + // queryKey: ['navigation', clusterName || 'no-cluster'], + // isEnabled: clusterName !== undefined, + // }) + + const { data: navigationDataArr } = useK8sSmartResource<{ + items: { + spec: { namespaces: { clear: string; change: string } } + }[] }>({ - uri: `/api/clusters/${clusterName}/k8s/apis/${BASE_API_GROUP}/${BASE_API_VERSION}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, - refetchInterval: false, - queryKey: ['navigation', clusterName || 'no-cluster'], + cluster: clusterName || '', + group: BASE_API_GROUP, + version: BASE_API_VERSION, + plural: BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME, + fieldSelector: `metadata.name=${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, isEnabled: clusterName !== undefined, }) + const navigationData = + navigationDataArr?.items && navigationDataArr.items.length > 0 ? navigationDataArr.items[0] : undefined + const isSearchPage = useIsSearchPage(baseprefix || '') const handleNamepsaceChange = (value?: string) => { diff --git a/src/hooks/useNavSelector/useNavSelector.ts b/src/hooks/useNavSelector/useNavSelector.ts index 4bc12ef..e338a32 100644 --- a/src/hooks/useNavSelector/useNavSelector.ts +++ b/src/hooks/useNavSelector/useNavSelector.ts @@ -2,7 +2,8 @@ import { useApiResources, TClusterList, TSingleResource, - useDirectUnknownResource, + // useDirectUnknownResource, + useK8sSmartResource, } from '@prorobotech/openapi-k8s-toolkit' import { useSelector } from 'react-redux' import { RootState } from 'store/store' @@ -50,15 +51,31 @@ const mappedInstanceToOptionInSidebar = ({ export const useNavSelector = (clusterName?: string, projectName?: string) => { const clusterList = useSelector((state: RootState) => state.clusterList.clusterList) - const { data: navigationData } = useDirectUnknownResource<{ - spec: { instances: { mapOptionsPattern: string } } + // const { data: navigationData } = useDirectUnknownResource<{ + // spec: { instances: { mapOptionsPattern: string } } + // }>({ + // uri: `/api/clusters/${clusterName}/k8s/apis/${BASE_API_GROUP}/${BASE_API_VERSION}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, + // refetchInterval: false, + // queryKey: ['navigation', clusterName || 'no-cluster'], + // isEnabled: clusterName !== undefined, + // }) + + const { data: navigationDataArr } = useK8sSmartResource<{ + items: { + spec: { instances: { mapOptionsPattern: string } } + }[] }>({ - uri: `/api/clusters/${clusterName}/k8s/apis/${BASE_API_GROUP}/${BASE_API_VERSION}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME}/${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, - refetchInterval: false, - queryKey: ['navigation', clusterName || 'no-cluster'], + cluster: clusterName || '', + group: BASE_API_GROUP, + version: BASE_API_VERSION, + plural: BASE_CUSTOMIZATION_NAVIGATION_RESOURCE_NAME, + fieldSelector: `metadata.name=${BASE_CUSTOMIZATION_NAVIGATION_RESOURCE}`, isEnabled: clusterName !== undefined, }) + const navigationData = + navigationDataArr?.items && navigationDataArr.items.length > 0 ? navigationDataArr.items[0] : undefined + const { data: projects } = useApiResources({ clusterName: clusterName || '', namespace: '',