From 4697cff511af802bc262057def9cc8eaae09be9a Mon Sep 17 00:00:00 2001 From: testA113 Date: Fri, 4 Oct 2024 14:50:06 +1300 Subject: [PATCH] sync CE and EE service account codebases --- .../ServiceAccountsDatatable.tsx | 51 +++++++++++++------ .../columns/index.tsx | 2 +- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/app/react/kubernetes/more-resources/ServiceAccountsView/ServiceAccountsDatatable/ServiceAccountsDatatable.tsx b/app/react/kubernetes/more-resources/ServiceAccountsView/ServiceAccountsDatatable/ServiceAccountsDatatable.tsx index 20ddfce56..f16ff83cb 100644 --- a/app/react/kubernetes/more-resources/ServiceAccountsView/ServiceAccountsDatatable/ServiceAccountsDatatable.tsx +++ b/app/react/kubernetes/more-resources/ServiceAccountsView/ServiceAccountsDatatable/ServiceAccountsDatatable.tsx @@ -1,29 +1,38 @@ import { User } from 'lucide-react'; import { useRouter } from '@uirouter/react'; +import { useMemo } from 'react'; import { useEnvironmentId } from '@/react/hooks/useEnvironmentId'; import { Authorized } from '@/react/hooks/useUser'; import { notifyError, notifySuccess } from '@/portainer/services/notifications'; import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription'; import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery'; -import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store'; +import { + DefaultDatatableSettings, + TableSettings as KubeTableSettings, +} from '@/react/kubernetes/datatables/DefaultDatatableSettings'; import { CreateFromManifestButton } from '@/react/kubernetes/components/CreateFromManifestButton'; import { useUnauthorizedRedirect } from '@/react/hooks/useUnauthorizedRedirect'; import { isSystemNamespace } from '@/react/kubernetes/namespaces/queries/useIsSystemNamespace'; +import { useKubeStore } from '@/react/kubernetes/datatables/default-kube-datatable-store'; import { Datatable, TableSettingsMenu } from '@@/datatables'; -import { useTableState } from '@@/datatables/useTableState'; import { DeleteButton } from '@@/buttons/DeleteButton'; +import { + type FilteredColumnsTableSettings, + filteredColumnsSettings, +} from '@@/datatables/types'; import { ServiceAccount } from '../types'; -import { DefaultDatatableSettings } from '../../../datatables/DefaultDatatableSettings'; -import { useColumns } from './columns'; +import { getColumns } from './columns'; import { useDeleteServiceAccountsMutation } from './queries/useDeleteServiceAccountsMutation'; import { useGetAllServiceAccountsQuery } from './queries/useGetAllServiceAccountsQuery'; const storageKey = 'serviceAccounts'; -const settingsStore = createStore(storageKey); +interface TableSettings + extends KubeTableSettings, + FilteredColumnsTableSettings {} export function ServiceAccountsDatatable() { useUnauthorizedRedirect( @@ -32,20 +41,30 @@ export function ServiceAccountsDatatable() { ); const environmentId = useEnvironmentId(); - const tableState = useTableState(settingsStore, storageKey); + const tableState = useKubeStore( + storageKey, + undefined, + (set) => ({ + ...filteredColumnsSettings(set), + }) + ); const namespacesQuery = useNamespacesQuery(environmentId); + const namespaces = namespacesQuery.data; const serviceAccountsQuery = useGetAllServiceAccountsQuery(environmentId, { refetchInterval: tableState.autoRefreshRate * 1000, enabled: namespacesQuery.isSuccess, }); - const columns = useColumns(); - - const filteredServiceAccounts = tableState.showSystemResources - ? serviceAccountsQuery.data - : serviceAccountsQuery.data?.filter( - (sa) => !isSystemNamespace(sa.namespace, namespacesQuery.data) - ); + const columns = getColumns(namespaces); + const filteredServiceAccounts = useMemo( + () => + tableState.showSystemResources + ? serviceAccountsQuery.data + : serviceAccountsQuery.data?.filter( + (sa) => !isSystemNamespace(sa.namespace, namespaces) + ), + [namespaces, serviceAccountsQuery.data, tableState.showSystemResources] + ); return ( row.uid} - isRowSelectable={(row) => !row.original.isSystem} + getRowId={(row) => `${row.namespace}-${row.name}`} + isRowSelectable={(row) => + !isSystemNamespace(row.original.namespace, namespaces) + } renderTableActions={(selectedRows) => ( )} diff --git a/app/react/kubernetes/more-resources/ServiceAccountsView/ServiceAccountsDatatable/columns/index.tsx b/app/react/kubernetes/more-resources/ServiceAccountsView/ServiceAccountsDatatable/columns/index.tsx index 3d5808bd5..2ac51596b 100644 --- a/app/react/kubernetes/more-resources/ServiceAccountsView/ServiceAccountsDatatable/columns/index.tsx +++ b/app/react/kubernetes/more-resources/ServiceAccountsView/ServiceAccountsDatatable/columns/index.tsx @@ -4,6 +4,6 @@ import { name } from './name'; import { namespace } from './namespace'; import { created } from './created'; -export function useColumns(namespaces?: PortainerNamespace[]) { +export function getColumns(namespaces?: PortainerNamespace[]) { return [name(namespaces), namespace, created]; }