You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
homepage/src/widgets/portainer/component.jsx

46 lines
1.3 KiB

import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: containersData, error: containersError } = useWidgetAPI(widget, "docker/containers/json", {
all: 1,
});
if (containersError) {
return <Container service={service} error={containersError} />;
}
if (!containersData) {
return (
<Container service={service}>
<Block label="portainer.running" />
<Block label="portainer.stopped" />
<Block label="portainer.total" />
</Container>
);
}
if (containersData.error) {
return <Container service={service} error={t("widget.api_error")} />;
}
const running = containersData.filter((c) => c.State === "running").length;
const stopped = containersData.filter((c) => c.State === "exited").length;
const total = containersData.length;
return (
<Container service={service}>
<Block label="portainer.running" value={running} />
<Block label="portainer.stopped" value={stopped} />
<Block label="portainer.total" value={total} />
</Container>
);
}