2022-11-28 02:00:28 +00:00
|
|
|
import { Heart, Power } from 'lucide-react';
|
2022-08-05 02:17:31 +00:00
|
|
|
|
|
|
|
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">
|
2022-11-28 02:00:28 +00:00
|
|
|
<Icon icon={Power} mode="success" size="sm" />
|
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">
|
2022-11-28 02:00:28 +00:00
|
|
|
<Icon icon={Power} mode="danger" size="sm" />
|
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">
|
2022-11-28 02:00:28 +00:00
|
|
|
<Icon icon={Heart} mode="success" size="sm" />
|
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">
|
2022-11-28 02:00:28 +00:00
|
|
|
<Icon icon={Heart} mode="danger" size="sm" />
|
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;
|
|
|
|
}
|