fix(stacks): conditionally hide node and namespace stacks [EE-6949] (#11527)

Co-authored-by: testa113 <testa113>
pull/11646/head
Ali 2024-04-19 17:33:22 +12:00 committed by GitHub
parent 7e9dd01265
commit 3ccbd40232
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 74 additions and 49 deletions

View File

@ -1,5 +1,5 @@
import { Badge } from '@@/Badge';
export function ExternalBadge() {
return <Badge type="info">external</Badge>;
return <Badge type="info">External</Badge>;
}

View File

@ -24,7 +24,6 @@ export function NodeApplicationsDatatable({
onRefresh: () => void;
isLoading: boolean;
}) {
const columns = useColumns(true);
const tableState = useTableStateWithStorage<TableSettings>(
'kube-node-apps',
'Name',
@ -34,6 +33,8 @@ export function NodeApplicationsDatatable({
);
useRepeater(tableState.autoRefreshRate, onRefresh);
const columns = useColumns();
return (
<Datatable
dataset={dataset}

View File

@ -1,19 +1,25 @@
import { useMemo } from 'react';
import _ from 'lodash';
import { useMemo } from 'react';
import { humanize, truncate } from '@/portainer/filters/filters';
import { usePublicSettings } from '@/react/portainer/settings/queries';
import { Link } from '@@/Link';
import { helper } from './columns.helper';
import { name } from './columns.name';
export function useColumns(areStacksVisible: boolean) {
export function useColumns() {
const hideStacksQuery = usePublicSettings<boolean>({
select: (settings) =>
settings.GlobalDeploymentOptions.hideStacksFunctionality,
});
return useMemo(
() =>
_.compact([
name,
areStacksVisible &&
!hideStacksQuery.data &&
helper.accessor('StackName', {
header: 'Stack',
cell: ({ getValue }) => getValue() || '-',
@ -53,6 +59,6 @@ export function useColumns(areStacksVisible: boolean) {
cell: ({ getValue }) => humanize(getValue()),
}),
]),
[areStacksVisible]
[hideStacksQuery.data]
);
}

View File

@ -11,7 +11,7 @@ import {
} from '@@/datatables/types';
import { NamespaceApp } from './types';
import { columns } from './columns';
import { useColumns } from './columns';
interface TableSettings extends BasicTableSettings, RefreshableTableSettings {}
@ -32,6 +32,7 @@ export function NamespaceAppsDatatable({
})
);
useRepeater(tableState.autoRefreshRate, onRefresh);
const columns = useColumns();
return (
<Datatable

View File

@ -1,6 +1,9 @@
import { createColumnHelper } from '@tanstack/react-table';
import _ from 'lodash';
import { useMemo } from 'react';
import { humanize, truncate } from '@/portainer/filters/filters';
import { usePublicSettings } from '@/react/portainer/settings/queries';
import { Link } from '@@/Link';
import { ExternalBadge } from '@@/Badge/ExternalBadge';
@ -12,45 +15,59 @@ import { NamespaceApp } from './types';
const columnHelper = createColumnHelper<NamespaceApp>();
export const columns = [
columnHelper.accessor('Name', {
header: 'Name',
cell: ({ row: { original: item } }) => (
<>
<Link
to="kubernetes.applications.application"
params={{ name: item.Name, namespace: item.ResourcePool }}
data-cy={`application-link-${item.Name}`}
>
{item.Name}
</Link>
{isExternalApplication({ metadata: item.Metadata }) && (
<div className="ml-2">
<ExternalBadge />
</div>
)}
</>
),
}),
columnHelper.accessor('StackName', {
header: 'Stack',
cell: ({ getValue }) => getValue() || '-',
}),
columnHelper.accessor('Image', {
header: 'Image',
cell: ({ row: { original: item } }) => (
<>
{truncate(item.Image, 64)}
{item.Containers?.length > 1 && <>+ {item.Containers.length - 1}</>}
</>
),
}),
columnHelper.accessor('CPU', {
header: 'CPU',
cell: ({ getValue }) => cpuHumanValue(getValue()),
}),
columnHelper.accessor('Memory', {
header: 'Memory',
cell: ({ getValue }) => humanize(getValue()),
}),
];
export function useColumns() {
const hideStacksQuery = usePublicSettings<boolean>({
select: (settings) =>
settings.GlobalDeploymentOptions.hideStacksFunctionality,
});
return useMemo(
() =>
_.compact([
columnHelper.accessor('Name', {
header: 'Name',
cell: ({ row: { original: item } }) => (
<>
<Link
to="kubernetes.applications.application"
params={{ name: item.Name, namespace: item.ResourcePool }}
data-cy={`application-link-${item.Name}`}
>
{item.Name}
</Link>
{isExternalApplication({ metadata: item.Metadata }) && (
<div className="ml-2">
<ExternalBadge />
</div>
)}
</>
),
}),
!hideStacksQuery.data &&
columnHelper.accessor('StackName', {
header: 'Stack',
cell: ({ getValue }) => getValue() || '-',
}),
columnHelper.accessor('Image', {
header: 'Image',
cell: ({ row: { original: item } }) => (
<>
{truncate(item.Image, 64)}
{item.Containers?.length > 1 && (
<>+ {item.Containers.length - 1}</>
)}
</>
),
}),
columnHelper.accessor('CPU', {
header: 'CPU',
cell: ({ getValue }) => cpuHumanValue(getValue()),
}),
columnHelper.accessor('Memory', {
header: 'Memory',
cell: ({ getValue }) => humanize(getValue()),
}),
]),
[hideStacksQuery.data]
);
}