From 4f3e52d0569ddde321995648556e288eed18c55b Mon Sep 17 00:00:00 2001 From: typescreep Date: Thu, 18 Sep 2025 15:36:04 +0300 Subject: [PATCH] search by name/labels --- package-lock.json | 8 +++--- package.json | 2 +- .../TableApiBuiltin/TableApiBuiltin.tsx | 12 +++++++-- .../molecules/TableApiBuiltin/utils.ts | 25 +++++++++++++++++++ src/components/organisms/Search/Search.tsx | 6 ++--- .../molecules/SearchEntry/SearchEntry.tsx | 12 ++++++--- 6 files changed, 52 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index a954b87..b56ac1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "@ant-design/icons": "5.6.0", "@monaco-editor/react": "4.6.0", "@originjs/vite-plugin-federation": "1.3.6", - "@prorobotech/openapi-k8s-toolkit": "^0.0.1-alpha.119", + "@prorobotech/openapi-k8s-toolkit": "^0.0.1-alpha.120", "@readme/openapi-parser": "4.0.0", "@reduxjs/toolkit": "2.2.5", "@tanstack/react-query": "5.62.2", @@ -2802,9 +2802,9 @@ } }, "node_modules/@prorobotech/openapi-k8s-toolkit": { - "version": "0.0.1-alpha.119", - "resolved": "https://registry.npmjs.org/@prorobotech/openapi-k8s-toolkit/-/openapi-k8s-toolkit-0.0.1-alpha.119.tgz", - "integrity": "sha512-e0AwwmMBAyjrpTPWMC9eSiyUimTzxskaNhAzs/+7DV7u0MqjJLOPehsko/AIpm/RkOoU6qOYjAHTjWZHV1hLhA==", + "version": "0.0.1-alpha.120", + "resolved": "https://registry.npmjs.org/@prorobotech/openapi-k8s-toolkit/-/openapi-k8s-toolkit-0.0.1-alpha.120.tgz", + "integrity": "sha512-mykTMrnI4Fxsj4wrkFISZJTIYWqKFAxPd11Lkn+LPUsoOoeRCZRpDC6iRnxyxTw2jnBjLEPJ4eTS2A6bagTWyw==", "license": "MIT", "dependencies": { "@monaco-editor/react": "4.6.0", diff --git a/package.json b/package.json index cd91b3a..9429efe 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "@ant-design/icons": "5.6.0", "@monaco-editor/react": "4.6.0", "@originjs/vite-plugin-federation": "1.3.6", - "@prorobotech/openapi-k8s-toolkit": "0.0.1-alpha.119", + "@prorobotech/openapi-k8s-toolkit": "0.0.1-alpha.120", "@readme/openapi-parser": "4.0.0", "@reduxjs/toolkit": "2.2.5", "@tanstack/react-query": "5.62.2", diff --git a/src/components/molecules/TableApiBuiltin/TableApiBuiltin.tsx b/src/components/molecules/TableApiBuiltin/TableApiBuiltin.tsx index ccf0771..601482a 100644 --- a/src/components/molecules/TableApiBuiltin/TableApiBuiltin.tsx +++ b/src/components/molecules/TableApiBuiltin/TableApiBuiltin.tsx @@ -26,7 +26,7 @@ import { TABLE_ADD_BUTTON_HEIGHT, } from 'constants/blocksSizes' import { OverflowContainer } from './atoms' -import { getBackLinkToTable, getLinkToForm } from './utils' +import { getDataItems, getBackLinkToTable, getLinkToForm } from './utils' type TTableApiBuiltinProps = { namespace?: string @@ -34,6 +34,8 @@ type TTableApiBuiltinProps = { apiGroup?: string // api apiVersion?: string // api typeName: string + specificName?: string + labels?: string[] limit: string | null inside?: boolean customizationIdPrefix: string @@ -46,6 +48,8 @@ export const TableApiBuiltin: FC = ({ apiGroup, apiVersion, typeName, + specificName, + labels, limit, inside, customizationIdPrefix, @@ -150,6 +154,8 @@ export const TableApiBuiltin: FC = ({ clusterName: cluster, namespace, typeName, + specificName, + labels, limit, isEnabled: resourceType === 'builtin', }) @@ -164,6 +170,8 @@ export const TableApiBuiltin: FC = ({ apiGroup: apiGroup || '', apiVersion: apiVersion || '', typeName, + specificName, + labels, limit, isEnabled: resourceType === 'api' && !!apiGroup && !!apiVersion, }) @@ -222,7 +230,7 @@ export const TableApiBuiltin: FC = ({ cluster={cluster} theme={theme} baseprefix={inside ? `${baseprefix}/inside` : baseprefix} - dataItems={resourceType === 'builtin' ? dataBuiltin?.items || [] : dataApi?.items || []} + dataItems={getDataItems({ resourceType, dataBuiltin, dataApi, isSingle: !!specificName })} dataForControls={{ cluster, syntheticProject: params.syntheticProject, diff --git a/src/components/molecules/TableApiBuiltin/utils.ts b/src/components/molecules/TableApiBuiltin/utils.ts index a7b2340..b387124 100644 --- a/src/components/molecules/TableApiBuiltin/utils.ts +++ b/src/components/molecules/TableApiBuiltin/utils.ts @@ -1,3 +1,28 @@ +import { TBuiltinResources, TApiResources, TJSON } from '@prorobotech/openapi-k8s-toolkit' + +export const getDataItems = ({ + resourceType, + dataBuiltin, + dataApi, + isSingle, +}: { + resourceType: 'builtin' | 'api' + dataBuiltin?: TBuiltinResources + dataApi?: TApiResources + isSingle?: boolean +}): TJSON[] => { + if (isSingle) { + if (resourceType === 'builtin') { + return dataBuiltin ? [dataBuiltin] : [] + } + + if (resourceType === 'api') { + return dataApi ? [dataApi] : [] + } + } + return resourceType === 'builtin' ? dataBuiltin?.items || [] : dataApi?.items || [] +} + export const getBackLinkToBuiltinTable = ({ cluster, baseprefix, diff --git a/src/components/organisms/Search/Search.tsx b/src/components/organisms/Search/Search.tsx index 064a124..35c24b1 100644 --- a/src/components/organisms/Search/Search.tsx +++ b/src/components/organisms/Search/Search.tsx @@ -8,14 +8,14 @@ import { SearchEntry } from './molecules' export const Search: FC = () => { const cluster = useSelector((state: RootState) => state.cluster.cluster) - const [currentSearch, setCurrentSearch] = useState() + const [currentSearch, setCurrentSearch] = useState<{ resources?: string[]; name?: string; labels?: string[] }>() return ( <> setCurrentSearch(value)} /> - {currentSearch?.map(item => ( + {currentSearch?.resources?.map(item => ( - + ))} diff --git a/src/components/organisms/Search/molecules/SearchEntry/SearchEntry.tsx b/src/components/organisms/Search/molecules/SearchEntry/SearchEntry.tsx index 677e95e..52464a4 100644 --- a/src/components/organisms/Search/molecules/SearchEntry/SearchEntry.tsx +++ b/src/components/organisms/Search/molecules/SearchEntry/SearchEntry.tsx @@ -7,9 +7,11 @@ import { BASE_USE_NAMESPACE_NAV } from 'constants/customizationApiGroupAndVersio type TSearchEntryProps = { resource: string + name?: string + labels?: string[] } -export const SearchEntry: FC = ({ resource }) => { +export const SearchEntry: FC = ({ resource, name, labels }) => { const { namespace, syntheticProject } = useParams() const [searchParams] = useSearchParams() @@ -27,14 +29,18 @@ export const SearchEntry: FC = ({ resource }) => { {apiGroup.length > 0 ? `${apiGroup}/${apiVersion}/` : 'v1/'} {typeName} + {name ? ` & name=${name}` : ''} + {labels ? ` & labels=${labels.join('+')}` : ''} - {typeName && apiGroup && apiVersion && ( + {typeName && ( 0 ? 'api' : 'builtin'} namespace={namespace} apiGroup={apiGroup.length > 0 ? apiGroup : undefined} apiVersion={apiGroup.length > 0 ? apiVersion : undefined} typeName={typeName} + specificName={name?.length ? name : undefined} + labels={labels?.length ? labels : undefined} limit={searchParams.get('limit')} customizationIdPrefix={tableCustomizationIdPrefix} searchMount