import { createColumnHelper } from '@tanstack/react-table'; import { Trash2 } from 'lucide-react'; import { Authorized } from '@/react/hooks/useUser'; import { formatDate } from '@/portainer/filters/filters'; import { pluralize } from '@/react/common/string-utils'; import { Badge } from '@@/Badge'; import { Tooltip } from '@@/Tip/Tooltip'; import { Link } from '@@/Link'; import { Icon } from '@@/Icon'; import { TooltipWithChildren } from '@@/Tip/TooltipWithChildren'; import { LoadingButton } from '@@/buttons'; import { confirmDelete } from '@@/modals/confirm'; import { PodRowData } from '../types'; const columnHelper = createColumnHelper(); const pod = columnHelper.accessor('podName', { header: 'Pod', id: 'podName', cell: ({ row: { original: podRow } }) => { const statusData = podRow.status; return (
{podRow.podName} {statusData.status} {statusData.restartCount ? ` (Restarted ${statusData.restartCount} ${pluralize( statusData.restartCount, 'time' )})` : ''} {statusData.message && }
); }, }); const node = columnHelper.accessor('nodeName', { header: 'Node', cell: ({ getValue }) => { const nodeName = getValue(); return (
{nodeName}
); }, }); const podIp = columnHelper.accessor('podIp', { header: 'Pod IP', id: 'podIp', }); const containers = columnHelper.accessor( (row) => `${row.readyContainers}/${row.totalContainers}`, { id: 'containers', header: 'Containers', enableSorting: false, } ); const creationDate = columnHelper.accessor( (row) => formatDate(row.creationDate), { header: 'Creation Date', cell: ({ getValue }) => getValue(), } ); export const podColumns = [pod, node, podIp, containers, creationDate]; interface PodColumnsOptions { supportsRestartStrategy: boolean; onDelete: (podName: string) => void; isDeleting: boolean; isLoading: boolean; } export function getPodColumns({ supportsRestartStrategy, onDelete, isDeleting, isLoading, }: PodColumnsOptions) { const deleteTooltip = supportsRestartStrategy ? 'Delete pod. If this pod is configured with the RestartAllContainers restart strategy, containers will restart in-place automatically.' : 'Delete pod'; const actions = columnHelper.display({ id: 'actions', header: 'Actions', cell: ({ row: { original: podRow } }) => (
{ const confirmed = await confirmDelete( `Are you sure you want to delete pod '${podRow.podName}'? Kubernetes will reschedule a new pod to replace it.` ); if (!confirmed) { return; } onDelete(podRow.podName); }} >
), }); return [pod, node, podIp, containers, creationDate, actions]; }