1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

fix(ui): mark resources system correctly [EE-6558] (#10996)

* fix(ui): mark resources system correctly [EE-6558]

* address review comments
This commit is contained in:
Prabhat Khera 2024-01-23 13:49:25 +13:00 committed by GitHub
parent 85ae705833
commit f7840e0407
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 110 additions and 75 deletions

View file

@ -6,12 +6,12 @@ import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
import { Authorized, useAuthorizations } from '@/react/hooks/useUser';
import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings';
import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription';
import { useApplicationsQuery } from '@/react/kubernetes/applications/application.queries';
import { Application } from '@/react/kubernetes/applications/types';
import { pluralize } from '@/portainer/helpers/strings';
import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery';
import { Namespaces } from '@/react/kubernetes/namespaces/types';
import { Datatable, TableSettingsMenu } from '@@/datatables';
import { confirmDelete } from '@@/modals/confirm';
@ -64,14 +64,15 @@ export function ConfigMapsDatatable() {
configMaps?.filter(
(configMap) =>
(canAccessSystemResources && tableState.showSystemResources) ||
!isSystemNamespace(configMap.metadata?.namespace ?? '')
!namespaces?.[configMap.metadata?.namespace ?? '']?.IsSystem
) || [],
[configMaps, tableState, canAccessSystemResources]
[configMaps, tableState, canAccessSystemResources, namespaces]
);
const configMapRowData = useConfigMapRowData(
filteredConfigMaps,
applications ?? [],
applicationsQuery.isLoading
applicationsQuery.isLoading,
namespaces
);
return (
@ -85,7 +86,7 @@ export function ConfigMapsDatatable() {
titleIcon={FileCode}
getRowId={(row) => row.metadata?.uid ?? ''}
isRowSelectable={(row) =>
!isSystemNamespace(row.original.metadata?.namespace ?? '')
!namespaces?.[row.original.metadata?.namespace ?? ''].IsSystem
}
disableSelect={readOnly}
renderTableActions={(selectedRows) => (
@ -110,7 +111,8 @@ export function ConfigMapsDatatable() {
function useConfigMapRowData(
configMaps: ConfigMap[],
applications: Application[],
applicationsLoading: boolean
applicationsLoading: boolean,
namespaces?: Namespaces
): ConfigMapRowData[] {
return useMemo(
() =>
@ -119,8 +121,11 @@ function useConfigMapRowData(
inUse:
// if the apps are loading, set inUse to true to hide the 'unused' badge
applicationsLoading || getIsConfigMapInUse(configMap, applications),
isSystem: namespaces
? namespaces?.[configMap.metadata?.namespace ?? '']?.IsSystem
: false,
})),
[configMaps, applicationsLoading, applications]
[configMaps, applicationsLoading, applications, namespaces]
);
}

View file

@ -1,6 +1,5 @@
import { CellContext } from '@tanstack/react-table';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
import { Authorized } from '@/react/hooks/useUser';
import { Link } from '@@/Link';
@ -13,13 +12,9 @@ import { columnHelper } from './helper';
export const name = columnHelper.accessor(
(row) => {
const name = row.metadata?.name;
const namespace = row.metadata?.namespace;
const isSystemToken = name?.includes('default-token-');
const isInSystemNamespace = namespace
? isSystemNamespace(namespace)
: false;
const isSystemConfigMap = isSystemToken || isInSystemNamespace;
const isSystemConfigMap = isSystemToken || row.isSystem;
const hasConfigurationOwner =
!!row.metadata?.labels?.['io.portainer.kubernetes.configuration.owner'];
@ -36,11 +31,9 @@ export const name = columnHelper.accessor(
function Cell({ row }: CellContext<ConfigMapRowData, string>) {
const name = row.original.metadata?.name;
const namespace = row.original.metadata?.namespace;
const isSystemToken = name?.includes('default-token-');
const isInSystemNamespace = namespace ? isSystemNamespace(namespace) : false;
const isSystemConfigMap = isSystemToken || isInSystemNamespace;
const isSystemConfigMap = isSystemToken || row.original.isSystem;
const hasConfigurationOwner =
!!row.original.metadata?.labels?.[

View file

@ -2,4 +2,5 @@ import { ConfigMap } from 'kubernetes-types/core/v1';
export interface ConfigMapRowData extends ConfigMap {
inUse: boolean;
isSystem: boolean;
}