2022-11-23 15:27:04 +01:00
|
|
|
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 }) {
|
2022-12-04 19:33:15 +01:00
|
|
|
|
|
|
|
// @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/shared/device-status.pipe.ts
|
|
|
|
const DeviceStatus = {
|
|
|
|
passed: 0,
|
|
|
|
failed_smart: 1,
|
|
|
|
failed_scrutiny: 2,
|
|
|
|
failed_both: 3
|
|
|
|
}
|
|
|
|
|
|
|
|
// @see https://github.com/AnalogJ/scrutiny/blob/d8d56f77f9e868127c4849dac74d65512db658e8/webapp/frontend/src/app/core/config/app.config.ts
|
|
|
|
const DeviceStatusThreshold = {
|
2022-12-04 15:33:51 -08:00
|
|
|
smart: 1,
|
2022-12-04 19:33:15 +01:00
|
|
|
scrutiny: 2,
|
|
|
|
both: 3
|
|
|
|
}
|
|
|
|
|
2022-11-23 15:27:04 +01:00
|
|
|
const { widget } = service;
|
|
|
|
|
2022-12-04 19:33:15 +01:00
|
|
|
const { data: scrutinySettings, error: scrutinySettingsError } = useWidgetAPI(widget, "settings");
|
2022-11-23 15:27:04 +01:00
|
|
|
const { data: scrutinyData, error: scrutinyError } = useWidgetAPI(widget, "summary");
|
|
|
|
|
2022-12-04 19:33:15 +01:00
|
|
|
if (scrutinyError || scrutinySettingsError) {
|
|
|
|
const finalError = scrutinyError ?? scrutinySettingsError;
|
|
|
|
return <Container error={finalError} />;
|
2022-11-23 15:27:04 +01:00
|
|
|
}
|
|
|
|
|
2022-12-04 19:33:15 +01:00
|
|
|
if (!scrutinyData || !scrutinySettings) {
|
2022-11-23 15:27:04 +01:00
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="scrutiny.passed" />
|
|
|
|
<Block label="scrutiny.failed" />
|
|
|
|
<Block label="scrutiny.unknown" />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const deviceIds = Object.values(scrutinyData.data.summary);
|
2022-12-04 19:33:15 +01:00
|
|
|
const statusThreshold = scrutinySettings.settings.metrics.status_threshold;
|
2022-11-23 15:27:04 +01:00
|
|
|
|
2022-12-04 15:33:51 -08:00
|
|
|
const failed = deviceIds.filter(deviceId => (deviceId.device.device_status > 0 && statusThreshold === DeviceStatusThreshold.both) || [statusThreshold, DeviceStatus.failed_both].includes(deviceId.device.device_status))?.length || 0;
|
2022-12-04 19:33:15 +01:00
|
|
|
const unknown = deviceIds.filter(deviceId => deviceId.device.device_status < DeviceStatus.passed || deviceId.device.device_status > DeviceStatus.failed_both)?.length || 0;
|
2022-12-04 15:33:51 -08:00
|
|
|
const passed = deviceIds.filter(deviceId => deviceId.device.device_status === 0 || (deviceId.device.device_status > statusThreshold && deviceId.device.device_status < DeviceStatus.failed_both))?.length || 0;
|
2022-11-23 15:27:04 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Container service={service}>
|
|
|
|
<Block label="scrutiny.passed" value={passed} />
|
|
|
|
<Block label="scrutiny.failed" value={failed} />
|
|
|
|
<Block label="scrutiny.unknown" value={unknown} />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
2022-12-04 19:33:15 +01:00
|
|
|
|
|
|
|
|