38 lines
1009 B
React
Raw Normal View History

2022-08-27 11:23:04 +03:00
import useSWR from "swr";
2022-09-25 19:43:00 +03:00
import { useTranslation } from "next-i18next";
2022-08-27 11:23:04 +03:00
import Widget from "../widget";
import Block from "../block";
import { formatApiUrl } from "utils/api-helpers";
2022-08-27 11:23:04 +03:00
export default function Traefik({ service }) {
2022-09-08 11:48:16 +03:00
const { t } = useTranslation();
2022-08-27 11:23:04 +03:00
const config = service.widget;
const { data: traefikData, error: traefikError } = useSWR(formatApiUrl(config, "overview"));
2022-08-27 11:23:04 +03:00
if (traefikError) {
2022-09-08 11:48:16 +03:00
return <Widget error={t("widget.api_error")} />;
2022-08-27 11:23:04 +03:00
}
if (!traefikData) {
return (
<Widget>
2022-09-08 11:48:16 +03:00
<Block label={t("traefik.routers")} />
<Block label={t("traefik.services")} />
<Block label={t("traefik.middleware")} />
2022-08-27 11:23:04 +03:00
</Widget>
);
}
return (
<Widget>
2022-09-08 11:48:16 +03:00
<Block label={t("traefik.routers")} value={traefikData.http.routers.total} />
<Block label={t("traefik.services")} value={traefikData.http.services.total} />
<Block label={t("traefik.middleware")} value={traefikData.http.middlewares.total} />
2022-08-27 11:23:04 +03:00
</Widget>
);
}