mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
refactor(containers): replace containers datatable with react component [EE-1815] (#6059)
This commit is contained in:
parent
65821aaccc
commit
07e7fbd270
80 changed files with 3614 additions and 1084 deletions
|
@ -0,0 +1,60 @@
|
|||
import { Column } from 'react-table';
|
||||
import clsx from 'clsx';
|
||||
import _ from 'lodash-es';
|
||||
|
||||
import { DefaultFilter } from '@/portainer/components/datatables/components/Filter';
|
||||
import type {
|
||||
DockerContainer,
|
||||
DockerContainerStatus,
|
||||
} from '@/docker/containers/types';
|
||||
|
||||
export const state: Column<DockerContainer> = {
|
||||
Header: 'State',
|
||||
accessor: 'Status',
|
||||
id: 'state',
|
||||
Cell: StatusCell,
|
||||
sortType: 'string',
|
||||
filter: 'multiple',
|
||||
Filter: DefaultFilter,
|
||||
canHide: true,
|
||||
};
|
||||
|
||||
function StatusCell({ value: status }: { value: DockerContainerStatus }) {
|
||||
const statusNormalized = _.toLower(status);
|
||||
const hasHealthCheck = ['starting', 'healthy', 'unhealthy'].includes(
|
||||
statusNormalized
|
||||
);
|
||||
|
||||
const statusClassName = getClassName();
|
||||
|
||||
return (
|
||||
<span
|
||||
className={clsx('label', `label-${statusClassName}`, {
|
||||
interactive: hasHealthCheck,
|
||||
})}
|
||||
title={hasHealthCheck ? 'This container has a health check' : ''}
|
||||
>
|
||||
{status}
|
||||
</span>
|
||||
);
|
||||
|
||||
function getClassName() {
|
||||
if (includeString(['paused', 'starting', 'unhealthy'])) {
|
||||
return 'warning';
|
||||
}
|
||||
|
||||
if (includeString(['created'])) {
|
||||
return 'info';
|
||||
}
|
||||
|
||||
if (includeString(['stopped', 'dead', 'exited'])) {
|
||||
return 'danger';
|
||||
}
|
||||
|
||||
return 'success';
|
||||
|
||||
function includeString(values: DockerContainerStatus[]) {
|
||||
return values.some((val) => statusNormalized.includes(val));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue