2022-09-26 15:25:10 +03:00
|
|
|
import Container from "components/services/widget/container";
|
|
|
|
import Block from "components/services/widget/block";
|
2022-09-27 22:59:14 +03:00
|
|
|
import useWidgetAPI from "utils/proxy/use-widget-api";
|
2022-09-26 00:35:54 +03:00
|
|
|
|
|
|
|
export default function Component({ service }) {
|
2022-09-27 22:59:14 +03:00
|
|
|
const { widget } = service;
|
2022-09-26 00:35:54 +03:00
|
|
|
|
2022-09-27 22:59:14 +03:00
|
|
|
const { data: containersData, error: containersError } = useWidgetAPI(widget, "docker/containers/json", {
|
|
|
|
all: 1,
|
|
|
|
});
|
2022-09-26 00:35:54 +03:00
|
|
|
|
2022-11-07 09:24:15 -08:00
|
|
|
if (containersError) {
|
2023-04-30 19:09:37 -04:00
|
|
|
return <Container service={service} error={containersError} />;
|
2022-09-26 00:35:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!containersData) {
|
|
|
|
return (
|
2022-09-29 21:15:25 -07:00
|
|
|
<Container service={service}>
|
|
|
|
<Block label="portainer.running" />
|
|
|
|
<Block label="portainer.stopped" />
|
|
|
|
<Block label="portainer.total" />
|
2022-09-26 15:25:10 +03:00
|
|
|
</Container>
|
2022-09-26 00:35:54 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-08 09:40:20 -07:00
|
|
|
if (containersData.error || containersData.message) {
|
|
|
|
// containersData can be itself an error object e.g. if environment fails
|
2023-10-17 23:26:55 -07:00
|
|
|
return <Container service={service} error={containersData?.error ?? containersData} />;
|
2022-09-26 00:35:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const running = containersData.filter((c) => c.State === "running").length;
|
|
|
|
const stopped = containersData.filter((c) => c.State === "exited").length;
|
|
|
|
const total = containersData.length;
|
|
|
|
|
|
|
|
return (
|
2022-09-29 21:15:25 -07:00
|
|
|
<Container service={service}>
|
|
|
|
<Block label="portainer.running" value={running} />
|
|
|
|
<Block label="portainer.stopped" value={stopped} />
|
|
|
|
<Block label="portainer.total" value={total} />
|
2022-09-26 15:25:10 +03:00
|
|
|
</Container>
|
2022-09-26 00:35:54 +03:00
|
|
|
);
|
|
|
|
}
|