mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-12 07:58:49 +00:00
Add scrutiny widget
This commit is contained in:
parent
c8d0b5ac4b
commit
16561bac79
5 changed files with 62 additions and 0 deletions
37
src/widgets/scrutiny/component.jsx
Normal file
37
src/widgets/scrutiny/component.jsx
Normal file
|
@ -0,0 +1,37 @@
|
|||
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 { widget } = service;
|
||||
|
||||
const { data: scrutinyData, error: scrutinyError } = useWidgetAPI(widget, "summary");
|
||||
|
||||
if (scrutinyError) {
|
||||
return <Container error={scrutinyError} />;
|
||||
}
|
||||
|
||||
if (!scrutinyData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="scrutiny.passed" />
|
||||
<Block label="scrutiny.failed" />
|
||||
<Block label="scrutiny.unknown" />
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
const deviceIds = Object.values(scrutinyData.data.summary);
|
||||
|
||||
const passed = deviceIds.filter(deviceId => deviceId.device.device_status === 0)?.length || 0;
|
||||
const failed = deviceIds.filter(deviceId => deviceId.device.device_status > 0 && deviceId.device.device_status <= 3)?.length || 0;
|
||||
const unknown = deviceIds.length - (passed + failed) || 0;
|
||||
|
||||
return (
|
||||
<Container service={service}>
|
||||
<Block label="scrutiny.passed" value={passed} />
|
||||
<Block label="scrutiny.failed" value={failed} />
|
||||
<Block label="scrutiny.unknown" value={unknown} />
|
||||
</Container>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue