-
-
Notifications
You must be signed in to change notification settings - Fork 972
/
component.jsx
39 lines (31 loc) · 1.1 KB
/
component.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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: infoData, error: infoError } = useWidgetAPI(widget, "nginx/proxy-hosts");
if (infoError || infoData?.error) {
return <Container error={t("widget.api_error")} />;
}
if (!infoData) {
return (
<Container service={service}>
<Block label="npm.enabled" />
<Block label="npm.disabled" />
<Block label="npm.total" />
</Container>
);
}
const enabled = infoData.filter((c) => c.enabled === 1).length;
const disabled = infoData.filter((c) => c.enabled === 0).length;
const total = infoData.length;
return (
<Container service={service}>
<Block label="npm.enabled" value={enabled} />
<Block label="npm.disabled" value={disabled} />
<Block label="npm.total" value={total} />
</Container>
);
}