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:
parent
85ae705833
commit
f7840e0407
17 changed files with 110 additions and 75 deletions
|
@ -7,7 +7,6 @@ import { useAuthorizations, Authorized } from '@/react/hooks/useUser';
|
|||
import Route from '@/assets/ico/route.svg?c';
|
||||
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 { confirmDelete } from '@@/modals/confirm';
|
||||
|
@ -19,6 +18,7 @@ import { useTableState } from '@@/datatables/useTableState';
|
|||
import { DeleteIngressesRequest, Ingress } from '../types';
|
||||
import { useDeleteIngresses, useIngresses } from '../queries';
|
||||
import { useNamespacesQuery } from '../../namespaces/queries/useNamespacesQuery';
|
||||
import { Namespaces } from '../../namespaces/types';
|
||||
|
||||
import { columns } from './columns';
|
||||
|
||||
|
@ -54,9 +54,14 @@ export function IngressDatatable() {
|
|||
ingresses?.filter(
|
||||
(ingress) =>
|
||||
(canAccessSystemResources && tableState.showSystemResources) ||
|
||||
!isSystemNamespace(ingress.Namespace ?? '')
|
||||
!namespaces?.[ingress.Namespace].IsSystem
|
||||
) || [],
|
||||
[ingresses, tableState, canAccessSystemResources]
|
||||
[ingresses, tableState, canAccessSystemResources, namespaces]
|
||||
);
|
||||
|
||||
const ingressesWithIsSystem = useIngressesRowData(
|
||||
filteredIngresses || [],
|
||||
namespaces
|
||||
);
|
||||
|
||||
const deleteIngressesMutation = useDeleteIngresses();
|
||||
|
@ -66,13 +71,14 @@ export function IngressDatatable() {
|
|||
return (
|
||||
<Datatable
|
||||
settingsManager={tableState}
|
||||
dataset={filteredIngresses}
|
||||
dataset={ingressesWithIsSystem}
|
||||
columns={columns}
|
||||
isLoading={ingressesQuery.isLoading || namespacesQuery.isLoading}
|
||||
emptyContentLabel="No supported ingresses found"
|
||||
title="Ingresses"
|
||||
titleIcon={Route}
|
||||
getRowId={(row) => row.Name + row.Type + row.Namespace}
|
||||
isRowSelectable={(row) => !namespaces?.[row.original.Namespace].IsSystem}
|
||||
renderTableActions={tableActions}
|
||||
renderTableSettings={() => (
|
||||
<TableSettingsMenu>
|
||||
|
@ -88,6 +94,21 @@ export function IngressDatatable() {
|
|||
/>
|
||||
);
|
||||
|
||||
// useIngressesRowData appends the `isSyetem` property to the service data
|
||||
function useIngressesRowData(
|
||||
ingresses: Ingress[],
|
||||
namespaces?: Namespaces
|
||||
): Ingress[] {
|
||||
return useMemo(
|
||||
() =>
|
||||
ingresses.map((r) => ({
|
||||
...r,
|
||||
IsSystem: namespaces ? namespaces?.[r.Namespace].IsSystem : false,
|
||||
})),
|
||||
[ingresses, namespaces]
|
||||
);
|
||||
}
|
||||
|
||||
function tableActions(selectedFlatRows: Ingress[]) {
|
||||
return (
|
||||
<div className="ingressDatatable-actions">
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { CellContext } from '@tanstack/react-table';
|
||||
|
||||
import { Authorized } from '@/react/hooks/useUser';
|
||||
import { isSystemNamespace } from '@/react/kubernetes/namespaces/utils';
|
||||
|
||||
import { Link } from '@@/Link';
|
||||
import { Badge } from '@@/Badge';
|
||||
|
@ -19,7 +18,6 @@ export const name = columnHelper.accessor('Name', {
|
|||
function Cell({ row, getValue }: CellContext<Ingress, string>) {
|
||||
const name = getValue();
|
||||
const namespace = row.original.Namespace;
|
||||
const isSystemIngress = isSystemNamespace(namespace);
|
||||
|
||||
return (
|
||||
<div className="flex flex-nowrap whitespace-nowrap">
|
||||
|
@ -36,7 +34,7 @@ function Cell({ row, getValue }: CellContext<Ingress, string>) {
|
|||
{name}
|
||||
</Link>
|
||||
</Authorized>
|
||||
{isSystemIngress && (
|
||||
{row.original.IsSystem && (
|
||||
<Badge type="success" className="ml-2">
|
||||
System
|
||||
</Badge>
|
||||
|
|
|
@ -35,6 +35,8 @@ export type Ingress = {
|
|||
Type?: string;
|
||||
Labels?: Record<string, string>;
|
||||
CreationDate?: string;
|
||||
|
||||
IsSystem?: boolean;
|
||||
};
|
||||
|
||||
export interface DeleteIngressesRequest {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue