2022-08-05 02:17:31 +00:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
|
|
|
import { Icon } from '@/react/components/Icon';
|
|
|
|
|
2022-07-06 08:23:53 +00:00
|
|
|
import { DockerContainer } from '../containers/types';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
containers: DockerContainer[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useContainerStatusComponent(containers: DockerContainer[]) {
|
|
|
|
return <ContainerStatus containers={containers} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function ContainerStatus({ containers }: Props) {
|
|
|
|
return (
|
2022-08-05 02:17:31 +00:00
|
|
|
<div className="pull-right">
|
|
|
|
<div>
|
|
|
|
<div className="vertical-center space-right pr-5">
|
|
|
|
<Icon
|
|
|
|
icon="power"
|
|
|
|
className={clsx('icon icon-sm icon-success')}
|
|
|
|
feather
|
|
|
|
/>
|
2022-07-06 08:23:53 +00:00
|
|
|
{runningContainersFilter(containers)} running
|
|
|
|
</div>
|
2022-08-05 02:17:31 +00:00
|
|
|
<div className="vertical-center space-right">
|
|
|
|
<Icon
|
|
|
|
icon="power"
|
|
|
|
className={clsx('icon icon-sm icon-danger')}
|
|
|
|
feather
|
|
|
|
/>
|
2022-07-06 08:23:53 +00:00
|
|
|
{stoppedContainersFilter(containers)} stopped
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-05 02:17:31 +00:00
|
|
|
<div>
|
|
|
|
<div className="vertical-center space-right pr-5">
|
|
|
|
<Icon
|
|
|
|
icon="heart"
|
|
|
|
className={clsx('icon icon-sm icon-success')}
|
|
|
|
feather
|
|
|
|
/>
|
2022-07-06 08:23:53 +00:00
|
|
|
{healthyContainersFilter(containers)} healthy
|
|
|
|
</div>
|
2022-08-05 02:17:31 +00:00
|
|
|
<div className="vertical-center space-right">
|
|
|
|
<Icon
|
|
|
|
icon="heart"
|
|
|
|
className={clsx('icon icon-sm icon-danger')}
|
|
|
|
feather
|
|
|
|
/>
|
2022-07-06 08:23:53 +00:00
|
|
|
{unhealthyContainersFilter(containers)} unhealthy
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-05 02:17:31 +00:00
|
|
|
</div>
|
2022-07-06 08:23:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function runningContainersFilter(containers: DockerContainer[]) {
|
|
|
|
return containers.filter((container) => container.Status === 'running')
|
|
|
|
.length;
|
|
|
|
}
|
|
|
|
function stoppedContainersFilter(containers: DockerContainer[]) {
|
2022-10-20 07:10:39 +00:00
|
|
|
return containers.filter(
|
|
|
|
(container) =>
|
|
|
|
container.Status === 'exited' || container.Status === 'stopped'
|
|
|
|
).length;
|
2022-07-06 08:23:53 +00:00
|
|
|
}
|
|
|
|
function healthyContainersFilter(containers: DockerContainer[]) {
|
|
|
|
return containers.filter((container) => container.Status === 'healthy')
|
|
|
|
.length;
|
|
|
|
}
|
|
|
|
function unhealthyContainersFilter(containers: DockerContainer[]) {
|
|
|
|
return containers.filter((container) => container.Status === 'unhealthy')
|
|
|
|
.length;
|
|
|
|
}
|