2022-09-02 12:13:15 +02:00
|
|
|
import useSWR from "swr";
|
2022-09-08 11:48:16 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-09-02 12:13:15 +02:00
|
|
|
|
|
|
|
import Widget from "../widget";
|
|
|
|
import Block from "../block";
|
|
|
|
|
2022-09-04 21:58:42 +03:00
|
|
|
import { formatApiUrl } from "utils/api-helpers";
|
|
|
|
|
2022-09-02 12:13:15 +02:00
|
|
|
export default function Npm({ service }) {
|
2022-09-08 11:48:16 +03:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
2022-09-02 12:13:15 +02:00
|
|
|
const config = service.widget;
|
|
|
|
|
2022-09-04 21:58:42 +03:00
|
|
|
const { data: infoData, error: infoError } = useSWR(formatApiUrl(config, "nginx/proxy-hosts"));
|
2022-09-02 12:13:15 +02:00
|
|
|
|
|
|
|
if (infoError) {
|
2022-09-08 11:48:16 +03:00
|
|
|
return <Widget error={t("widget.api_error")} />;
|
2022-09-02 12:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!infoData) {
|
|
|
|
return (
|
|
|
|
<Widget>
|
2022-09-08 11:48:16 +03:00
|
|
|
<Block label={t("npm.enabled")} />
|
|
|
|
<Block label={t("npm.disabled")} />
|
|
|
|
<Block label={t("npm.total")} />
|
2022-09-02 12:13:15 +02:00
|
|
|
</Widget>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const enabled = infoData.filter((c) => c.enabled === 1).length;
|
|
|
|
const disabled = infoData.filter((c) => c.enabled === 0).length;
|
|
|
|
const total = infoData.length;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Widget>
|
2022-09-08 11:48:16 +03:00
|
|
|
<Block label={t("npm.enabled")} value={enabled} />
|
|
|
|
<Block label={t("npm.disabled")} value={disabled} />
|
|
|
|
<Block label={t("npm.total")} value={total} />
|
2022-09-02 12:13:15 +02:00
|
|
|
</Widget>
|
|
|
|
);
|
|
|
|
}
|