diff --git a/src/components/organisms/HeaderSecond/organisms/Selector/Selector.tsx b/src/components/organisms/HeaderSecond/organisms/Selector/Selector.tsx index 9fdfeda..782f2d2 100644 --- a/src/components/organisms/HeaderSecond/organisms/Selector/Selector.tsx +++ b/src/components/organisms/HeaderSecond/organisms/Selector/Selector.tsx @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom' import { // useDirectUnknownResource, useK8sSmartResource, + TNavigationResource, } from '@prorobotech/openapi-k8s-toolkit' import { useNavSelector } from 'hooks/useNavSelector' import { useMountEffect } from 'hooks/useMountEffect' @@ -44,7 +45,7 @@ export const Selector: FC = ({ clusterName, projectName, instanc // }) const { data: navigationDataArr } = useK8sSmartResource<{ - items: { spec: { projects: { clear: string; change: string }; instances: { clear: string; change: string } } }[] + items: TNavigationResource[] }>({ cluster: clusterName || '', group: BASE_API_GROUP, @@ -66,13 +67,13 @@ export const Selector: FC = ({ clusterName, projectName, instanc if (value && value !== 'all') { setSelectedProjectName(value) const changeUrl = - navigationData?.spec.projects.change + navigationData?.spec?.projects?.change .replace('{selectedCluster}', selectedClusterName || 'no-cluster') .replace('{value}', value) || 'no navigation data' navigate(changeUrl) } else { const clearUrl = - navigationData?.spec.projects.clear.replace('{selectedCluster}', selectedClusterName || 'no-cluster') || + navigationData?.spec?.projects?.clear.replace('{selectedCluster}', selectedClusterName || 'no-cluster') || 'no navigation data' navigate(clearUrl) } @@ -82,14 +83,14 @@ export const Selector: FC = ({ clusterName, projectName, instanc if (value && value !== 'all') { setSelectedInstanceName(value) const changeUrl = - navigationData?.spec.instances.change + navigationData?.spec?.instances?.change .replace('{selectedCluster}', selectedClusterName || 'no-cluster') .replace('{selectedProject}', selectedProjectName || 'no-project') .replace('{value}', value) || 'no navigation data' navigate(changeUrl) } else { const clearUrl = - navigationData?.spec.instances.clear + navigationData?.spec?.instances?.clear .replace('{selectedCluster}', selectedClusterName || 'no-cluster') .replace('{selectedProject}', selectedProjectName || 'no-project') || 'no navigation data' navigate(clearUrl) diff --git a/src/components/organisms/HeaderSecond/organisms/SelectorNamespace/SelectorNamespace.tsx b/src/components/organisms/HeaderSecond/organisms/SelectorNamespace/SelectorNamespace.tsx index 46c9ce5..a3c2db5 100644 --- a/src/components/organisms/HeaderSecond/organisms/SelectorNamespace/SelectorNamespace.tsx +++ b/src/components/organisms/HeaderSecond/organisms/SelectorNamespace/SelectorNamespace.tsx @@ -4,6 +4,7 @@ import { useLocation, useNavigate } from 'react-router-dom' import { // useDirectUnknownResource, useK8sSmartResource, + TNavigationResource, } from '@prorobotech/openapi-k8s-toolkit' import { useSelector } from 'react-redux' import type { RootState } from 'store/store' @@ -44,9 +45,7 @@ export const SelectorNamespace: FC = ({ clusterName, na // }) const { data: navigationDataArr } = useK8sSmartResource<{ - items: { - spec: { namespaces: { clear: string; change: string } } - }[] + items: TNavigationResource[] }>({ cluster: clusterName || '', group: BASE_API_GROUP, @@ -101,13 +100,13 @@ export const SelectorNamespace: FC = ({ clusterName, na if (value && value !== 'all') { setSelectedNamespace(value) const changeUrl = - navigationData?.spec.namespaces.change + navigationData?.spec?.namespaces?.change .replace('{selectedCluster}', selectedClusterName || 'no-cluster') .replace('{value}', value) || 'no navigation data' navigate(changeUrl) } else { const clearUrl = - navigationData?.spec.namespaces.clear.replace('{selectedCluster}', selectedClusterName || 'no-cluster') || + navigationData?.spec?.namespaces?.clear.replace('{selectedCluster}', selectedClusterName || 'no-cluster') || 'no navigation data' navigate(clearUrl) } diff --git a/src/hooks/useNavSelector/useNavSelector.ts b/src/hooks/useNavSelector/useNavSelector.ts index 1ae504e..a54da43 100644 --- a/src/hooks/useNavSelector/useNavSelector.ts +++ b/src/hooks/useNavSelector/useNavSelector.ts @@ -4,6 +4,7 @@ import { TSingleResource, // useDirectUnknownResource, useK8sSmartResource, + TNavigationResource, } from '@prorobotech/openapi-k8s-toolkit' import { useSelector } from 'react-redux' import { RootState } from 'store/store' @@ -61,9 +62,7 @@ export const useNavSelector = (clusterName?: string, projectName?: string) => { // }) const { data: navigationDataArr } = useK8sSmartResource<{ - items: { - spec: { instances: { mapOptionsPattern: string } } - }[] + items: TNavigationResource[] }>({ cluster: clusterName || '', group: BASE_API_GROUP, @@ -133,7 +132,7 @@ export const useNavSelector = (clusterName?: string, projectName?: string) => { .map(item => mappedInstanceToOptionInSidebar({ instance: item, - templateString: navigationData?.spec.instances.mapOptionsPattern, + templateString: navigationData?.spec?.instances?.mapOptionsPattern, }), ) : []