mirror of
https://github.com/outbackdingo/openapi-ui.git
synced 2026-01-27 18:19:50 +00:00
factories, navigation resource via hooks
This commit is contained in:
@@ -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<TFactoryProps> = ({ setSidebarTags }) => {
|
||||
}
|
||||
}, [])
|
||||
|
||||
const { data: factoryData } = useDirectUnknownResource<TFactoryResponse<TDynamicComponentsAppTypeMap>>({
|
||||
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<TFactoryResponse<TDynamicComponentsAppTypeMap>>({
|
||||
// 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<TFactoryResponse<TDynamicComponentsAppTypeMap>>({
|
||||
cluster,
|
||||
group: BASE_API_GROUP,
|
||||
version: BASE_API_VERSION,
|
||||
plural: 'factories',
|
||||
})
|
||||
|
||||
const { spec } = factoryData?.items.find(({ spec }) => spec.key === key) ?? { spec: undefined }
|
||||
|
||||
@@ -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<TSelectorProps> = ({ 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}`)
|
||||
|
||||
@@ -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<TSelectorNamespaceProps> = ({ 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) => {
|
||||
|
||||
@@ -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: '',
|
||||
|
||||
Reference in New Issue
Block a user