diff --git a/src/widgets/glances/components/container.jsx b/src/widgets/glances/components/container.jsx index df9e9bdb..8a72a1b3 100644 --- a/src/widgets/glances/components/container.jsx +++ b/src/widgets/glances/components/container.jsx @@ -1,19 +1,10 @@ -import { useContext } from "react"; -import { useTranslation } from "next-i18next"; -import { SettingsContext } from "utils/contexts/settings"; -import Error from "./error" - -export default function Container({ service, children, chart = true, error = false, className = "" }) { - const { t } = useTranslation(); - const { settings } = useContext(SettingsContext); - const hideErrors = (settings.hideErrors || service.widget.hide_errors) +export default function Container({ children, chart = true, className = "" }) { return (
{children}
{chart &&
} {!chart &&
} - {error && !hideErrors && }
); } diff --git a/src/widgets/glances/components/error.jsx b/src/widgets/glances/components/error.jsx index b0c21e96..1ee1ebcb 100644 --- a/src/widgets/glances/components/error.jsx +++ b/src/widgets/glances/components/error.jsx @@ -1,7 +1,17 @@ import { useTranslation } from "next-i18next"; +import { useContext } from "react"; -export default function Error() { +import { SettingsContext } from "utils/contexts/settings"; + +export default function Error({ service, error }) { const { t } = useTranslation(); + const { settings } = useContext(SettingsContext); - return
{t("widget.api_error")}
; -} \ No newline at end of file + if (error) { + if (settings.hideErrors || service?.widget.hide_errors) { + return null; + } + + return
{t("widget.api_error")}
; + } +} diff --git a/src/widgets/glances/metrics/cpu.jsx b/src/widgets/glances/metrics/cpu.jsx index fbf8e1ae..9c5bf6e6 100644 --- a/src/widgets/glances/metrics/cpu.jsx +++ b/src/widgets/glances/metrics/cpu.jsx @@ -4,6 +4,7 @@ import { useTranslation } from "next-i18next"; import Container from "../components/container"; import Block from "../components/block"; +import Error from "../components/error"; import useWidgetAPI from "utils/proxy/use-widget-api"; @@ -39,22 +40,22 @@ export default function Component({ service }) { if (error) { return ( - - + + ); } if (!data) { return ( - + - ); } return ( - + {chart && ( { - if (data) { + if (data && !data.error) { const diskData = data.find((item) => item.disk_name === diskName); setDataPoints((prevDataPoints) => { @@ -51,16 +52,18 @@ export default function Component({ service }) { setRatePoints(calculateRates(dataPoints)); }, [dataPoints]); - if (error) { + if (error || (data && data.error)) { + const finalError = error || data.error; return ( - + + ); } if (!data) { return ( - + - ); @@ -70,7 +73,7 @@ export default function Component({ service }) { if (!diskData) { return ( - + - ); @@ -80,7 +83,7 @@ export default function Component({ service }) { const currentRate = diskRates[diskRates.length - 1]; return ( - + {chart && ( + + ); } if (!data) { return ( - + - ); @@ -37,14 +39,14 @@ export default function Component({ service }) { if (!fsData) { return ( - + - ); } return ( - + {chart && (
{ - if (data) { + if (data && !data.error) { + // eslint-disable-next-line eqeqeq + const gpuData = data.find((item) => item[item.key] == gpuName); - if (data.hasOwnProperty("error")) { - return ( - - - ) + if (gpuData) { + setDataPoints((prevDataPoints) => { + const newDataPoints = [...prevDataPoints, { a: gpuData.mem, b: gpuData.proc }]; + if (newDataPoints.length > pointsLimit) { + newDataPoints.shift(); + } + return newDataPoints; + }); } - - else { - // eslint-disable-next-line eqeqeq - const gpuData = data.find((item) => item[item.key] == gpuName); - - if (gpuData) { - setDataPoints((prevDataPoints) => { - const newDataPoints = [...prevDataPoints, { a: gpuData.mem, b: gpuData.proc }]; - if (newDataPoints.length > pointsLimit) { - newDataPoints.shift(); - } - return newDataPoints; - }); - } - } - } }, [data, gpuName, pointsLimit]); - if (error) { + if (error || (data && data.error)) { + const finalError = error || data.error; return ( - + + ); } if (!data) { return ( - + - ); @@ -72,14 +64,14 @@ export default function Component({ service }) { if (!gpuData) { return ( - + - ); } return ( - + {chart && ( + + ); } if (systemError) { return ( - + + ); } const dataCharts = []; - if (quicklookData) { - if (quicklookData.hasOwnProperty("error")) { - const quicklookError = true; - return ( - - - ); - } - else { - quicklookData.percpu.forEach((cpu, index) => { - dataCharts.push({ - name: `CPU ${index}`, - cpu: cpu.total, - mem: quicklookData.mem, - swap: quicklookData.swap, - proc: quicklookData.cpu, - }); + quicklookData.percpu.forEach((cpu, index) => { + dataCharts.push({ + name: `CPU ${index}`, + cpu: cpu.total, + mem: quicklookData.mem, + swap: quicklookData.swap, + proc: quicklookData.cpu, }); - } - + }); } return ( - + {quicklookData && quicklookData.cpu_name && chart && (
{quicklookData.cpu_name}
diff --git a/src/widgets/glances/metrics/memory.jsx b/src/widgets/glances/metrics/memory.jsx index d3f3e2f8..87782120 100644 --- a/src/widgets/glances/metrics/memory.jsx +++ b/src/widgets/glances/metrics/memory.jsx @@ -2,6 +2,7 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; +import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -38,21 +39,22 @@ export default function Component({ service }) { if (error) { return ( - + + ); } if (!data) { return ( - + - ); } return ( - + {chart && ( { - if (data) { + if (data && !data.error) { const interfaceData = data.find((item) => item[item.key] === interfaceName); if (interfaceData) { @@ -51,16 +52,18 @@ export default function Component({ service }) { } }, [data, interfaceName, pointsLimit, rxKey, txKey]); - if (error) { + if (error || (data && data.error)) { + const finalError = error || data.error; return ( - + + ); } if (!data) { return ( - + - ); @@ -70,14 +73,14 @@ export default function Component({ service }) { if (!interfaceData) { return ( - + - ); } return ( - + {chart && ( + + ); } if (!data) { return ( - + - ); @@ -47,7 +49,7 @@ export default function Component({ service }) { data.splice(chart ? 5 : 1); return ( - +
diff --git a/src/widgets/glances/metrics/sensor.jsx b/src/widgets/glances/metrics/sensor.jsx index df23ce99..0b42e3d6 100644 --- a/src/widgets/glances/metrics/sensor.jsx +++ b/src/widgets/glances/metrics/sensor.jsx @@ -2,6 +2,7 @@ import dynamic from "next/dynamic"; import { useState, useEffect } from "react"; import { useTranslation } from "next-i18next"; +import Error from "../components/error"; import Container from "../components/container"; import Block from "../components/block"; @@ -25,7 +26,7 @@ export default function Component({ service }) { }); useEffect(() => { - if (data) { + if (data && !data.error) { const sensorData = data.find((item) => item.label === sensorName); setDataPoints((prevDataPoints) => { const newDataPoints = [...prevDataPoints, { value: sensorData.value }]; @@ -37,16 +38,18 @@ export default function Component({ service }) { } }, [data, sensorName, pointsLimit]); - if (error) { + if (error || (data && data.error)) { + const finalError = error || data.error; return ( - + + ); } if (!data) { return ( - + - ); @@ -56,14 +59,14 @@ export default function Component({ service }) { if (!sensorData) { return ( - + - ); } return ( - + {chart && (