diff --git a/src/widgets/glances/components/container.jsx b/src/widgets/glances/components/container.jsx index 8a72a1b31..f023dc856 100644 --- a/src/widgets/glances/components/container.jsx +++ b/src/widgets/glances/components/container.jsx @@ -1,10 +1,19 @@ -export default function Container({ children, chart = true, className = "" }) { +import { useContext } from "react"; +import { useTranslation } from "next-i18next"; +import { SettingsContext } from "utils/contexts/settings"; +import { Settings } from "luxon"; + +export default function Container({ service, children, chart = true, error = false, className = "" }) { + const { t } = useTranslation(); + const { settings } = useContext(SettingsContext); + const hideErrors = (service.widget.hide_errors || settings.hideErrors) return (
{children}
{chart &&
} {!chart &&
} + {error && !hideErrors &&
{t("widget.api_error")}
}
); } diff --git a/src/widgets/glances/components/error.jsx b/src/widgets/glances/components/error.jsx deleted file mode 100644 index d88a17c0e..000000000 --- a/src/widgets/glances/components/error.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import { useTranslation } from "next-i18next"; - -export default function Error() { - const { t } = useTranslation(); - - return
{t("widget.api_error")}
; -} diff --git a/src/widgets/glances/metrics/cpu.jsx b/src/widgets/glances/metrics/cpu.jsx index 553517bac..fbf8e1ae6 100644 --- a/src/widgets/glances/metrics/cpu.jsx +++ b/src/widgets/glances/metrics/cpu.jsx @@ -2,7 +2,6 @@ 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"; @@ -40,7 +39,7 @@ export default function Component({ service }) { if (error) { return ( - + ); @@ -48,14 +47,14 @@ export default function Component({ service }) { if (!data) { return ( - + - ); } return ( - + {chart && ( - + ); } if (!data) { return ( - + - ); @@ -72,7 +70,7 @@ export default function Component({ service }) { if (!diskData) { return ( - + - ); @@ -82,7 +80,7 @@ export default function Component({ service }) { const currentRate = diskRates[diskRates.length - 1]; return ( - + {chart && ( - + ); } if (!data) { return ( - + - ); @@ -39,14 +37,14 @@ export default function Component({ service }) { if (!fsData) { return ( - + - ); } return ( - + {chart && (
{ if (data) { - // 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; - }); + if (data.hasOwnProperty("error")) { + return ( + + + ) } + + 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) { return ( - - + ); } if (!data) { return ( - + - ); @@ -63,14 +72,14 @@ export default function Component({ service }) { if (!gpuData) { return ( - + - ); } return ( - + {chart && ( - + ); } if (systemError) { return ( - - + ); } const dataCharts = []; + if (quicklookData) { - quicklookData.percpu.forEach((cpu, index) => { - dataCharts.push({ - name: `CPU ${index}`, - cpu: cpu.total, - mem: quicklookData.mem, - swap: quicklookData.swap, - proc: quicklookData.cpu, + 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, + }); }); - }); + } + } 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 49046a5fc..d3f3e2f8d 100644 --- a/src/widgets/glances/metrics/memory.jsx +++ b/src/widgets/glances/metrics/memory.jsx @@ -2,7 +2,6 @@ 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"; @@ -39,22 +38,21 @@ export default function Component({ service }) { if (error) { return ( - - + ); } if (!data) { return ( - + - ); } return ( - + {chart && ( - + ); } if (!data) { return ( - + - ); @@ -72,14 +70,14 @@ export default function Component({ service }) { if (!interfaceData) { return ( - + - ); } return ( - + {chart && ( - + ); } if (!data) { return ( - + - ); @@ -49,7 +47,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 e0f679c13..df23ce99f 100644 --- a/src/widgets/glances/metrics/sensor.jsx +++ b/src/widgets/glances/metrics/sensor.jsx @@ -2,7 +2,6 @@ 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"; @@ -40,15 +39,14 @@ export default function Component({ service }) { if (error) { return ( - - + ); } if (!data) { return ( - + - ); @@ -58,14 +56,14 @@ export default function Component({ service }) { if (!sensorData) { return ( - + - ); } return ( - + {chart && (