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

View File

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

View File

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

View File

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