import { createColumnHelper } from '@tanstack/react-table'; import _ from 'lodash'; import { useMemo } from 'react'; import { usePublicSettings } from '@/react/portainer/settings/queries'; import { humanize } from '@/portainer/filters/filters'; import { Link } from '@@/Link'; import { ExternalBadge } from '@@/Badge/ExternalBadge'; import { isExternalApplication } from '../../applications/utils'; import { cpuHumanValue } from '../../applications/utils/cpuHumanValue'; import { Application } from '../../applications/ListView/ApplicationsDatatable/types'; const columnHelper = createColumnHelper(); export function useColumns() { const hideStacksQuery = usePublicSettings({ select: (settings) => settings.GlobalDeploymentOptions.hideStacksFunctionality, }); return useMemo( () => _.compact([ columnHelper.accessor('Name', { header: 'Name', cell: ({ row: { original: item } }) => (
{item.Name} {isExternalApplication({ metadata: item.Metadata }) && (
)}
), }), !hideStacksQuery.data && columnHelper.accessor('StackName', { header: 'Stack', cell: ({ getValue }) => getValue() || '-', }), columnHelper.accessor('Image', { header: 'Image', cell: ({ getValue }) => (
{getValue()}
), }), columnHelper.accessor( (row) => row.Resource?.CpuRequest ? cpuHumanValue(row.Resource?.CpuRequest) : '-', { header: 'CPU', cell: ({ getValue }) => getValue(), } ), columnHelper.accessor( (row) => row.Resource?.MemoryRequest ? row.Resource?.MemoryRequest : '-', { header: 'Memory', cell: ({ getValue }) => { const value = getValue(); if (value === '-') { return value; } return humanize(value); }, } ), ]), [hideStacksQuery.data] ); }