From a7d98362dd135548599354583ab402fdfc3aacd5 Mon Sep 17 00:00:00 2001 From: typescreep Date: Tue, 11 Nov 2025 02:32:11 +0300 Subject: [PATCH] crds sockets --- .../molecules/TableCrdInfo/TableCrdInfo.tsx | 36 ++++++++++++--- .../molecules/ResourceInfo/ResourceInfo.tsx | 29 +++++++++--- .../Forms/CrdsForms/UpdateCrdsForm.tsx | 46 +++++++++++++++---- 3 files changed, 89 insertions(+), 22 deletions(-) diff --git a/src/components/molecules/TableCrdInfo/TableCrdInfo.tsx b/src/components/molecules/TableCrdInfo/TableCrdInfo.tsx index fbd8519..72cc1bc 100644 --- a/src/components/molecules/TableCrdInfo/TableCrdInfo.tsx +++ b/src/components/molecules/TableCrdInfo/TableCrdInfo.tsx @@ -1,6 +1,12 @@ import React, { FC, useState, useEffect } from 'react' import { Spin, Alert } from 'antd' -import { usePermissions, checkIfApiInstanceNamespaceScoped, useCrdData } from '@prorobotech/openapi-k8s-toolkit' +import { + usePermissions, + checkIfApiInstanceNamespaceScoped, + // useCrdData, + useK8sSmartResource, + TCRD, +} from '@prorobotech/openapi-k8s-toolkit' import { useSelector } from 'react-redux' import { RootState } from 'store/store' import { ResourceInfo } from './molecules' @@ -28,12 +34,28 @@ export const TableCrdInfo: FC = ({ const [isNamespaced, setIsNamespaced] = useState() - const { isPending, error, data } = useCrdData({ - clusterName: cluster, - crdName, - apiExtensionVersion, + // const { isPending, error, data } = useCrdData({ + // clusterName: cluster, + // crdName, + // apiExtensionVersion, + // }) + + const { + data: dataArr, + isLoading: isPending, + error, + } = useK8sSmartResource<{ + items: TCRD[] + }>({ + cluster, + group: 'apiextensions.k8s.io', + version: apiExtensionVersion, + plural: 'customresourcedefinitions', + fieldSelector: `metadata.name=${crdName}`, }) + const data = dataArr?.items && dataArr.items.length > 0 ? dataArr.items[0] : undefined + useEffect(() => { if (data && !isPending && !error) { checkIfApiInstanceNamespaceScoped({ @@ -79,7 +101,9 @@ export const TableCrdInfo: FC = ({ return ( <> {isPending && } - {error && } + {error && ( + + )} {!error && data && data.spec && ( = ({ } }, []) - const { isPending, error, data } = useCrdResources({ - clusterName, - namespace, - apiGroup, - apiVersion, - crdName: crdPluralName, + // const { isPending, error, data } = useCrdResources({ + // clusterName, + // namespace, + // apiGroup, + // apiVersion, + // crdName: crdPluralName, + // }) + + const { + data, + isLoading: isPending, + error, + } = useK8sSmartResource<{ + items: TJSON[] + }>({ + cluster: clusterName, + group: apiGroup, + version: apiVersion, + plural: crdPluralName, }) let resourceSchema = {} diff --git a/src/components/organisms/Forms/CrdsForms/UpdateCrdsForm.tsx b/src/components/organisms/Forms/CrdsForms/UpdateCrdsForm.tsx index 35714cb..7f4cb5d 100644 --- a/src/components/organisms/Forms/CrdsForms/UpdateCrdsForm.tsx +++ b/src/components/organisms/Forms/CrdsForms/UpdateCrdsForm.tsx @@ -1,6 +1,11 @@ import React, { FC, useState } from 'react' import { Spin, Alert, Segmented } from 'antd' -import { useCrdResourceSingle, Spacer } from '@prorobotech/openapi-k8s-toolkit' +import { + // useCrdResourceSingle, + useK8sSmartResource, + TSingleResource, + Spacer, +} from '@prorobotech/openapi-k8s-toolkit' import { useSelector } from 'react-redux' import { RootState } from 'store/store' import { BlackholeForm } from 'components' @@ -41,22 +46,45 @@ export const UpdateCrdsForm: FC = ({ onDisabled: onCurrentModeDisabled, } - const { data, isPending, error } = useCrdResourceSingle({ - clusterName: cluster, + // const { data, isPending, error } = useCrdResourceSingle({ + // clusterName: cluster, + // namespace, + // apiGroup, + // apiVersion, + // crdName: typeName, + // entryName, + // refetchInterval: false, + // }) + + const { + data: dataArr, + isLoading: isPending, + error, + } = useK8sSmartResource<{ + items: TSingleResource[] + }>({ + cluster, namespace, - apiGroup, - apiVersion, - crdName: typeName, - entryName, - refetchInterval: false, + group: apiGroup, + version: apiVersion, + plural: typeName, + fieldSelector: `metadata.name=${entryName}`, }) + const data = dataArr?.items && dataArr.items.length > 0 ? dataArr.items[0] : undefined + if (isPending) { return } if (error) { - return + return ( + + ) + } + + if (!data) { + return } /* eslint-disable-next-line @typescript-eslint/no-unused-vars */