navigations ts

This commit is contained in:
typescreep
2025-11-17 09:44:38 +03:00
parent 7a95d58e36
commit fe7380ba11
3 changed files with 13 additions and 14 deletions

View File

@@ -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<TSelectorProps> = ({ 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<TSelectorProps> = ({ 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<TSelectorProps> = ({ 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)

View File

@@ -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<TSelectorNamespaceProps> = ({ 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<TSelectorNamespaceProps> = ({ 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)
}

View File

@@ -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,
}),
)
: []