From cdeb3911c48a36f4746241de728b97290a9d9ce3 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 29 Apr 2023 21:46:46 -0400 Subject: [PATCH] Make widget clickable + cleanup helperrs --- src/components/widgets/glances/glances.jsx | 8 ++++++-- src/utils/config/widget-helpers.js | 24 +++++++++++----------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/components/widgets/glances/glances.jsx b/src/components/widgets/glances/glances.jsx index d3da7200..ddf14188 100644 --- a/src/components/widgets/glances/glances.jsx +++ b/src/components/widgets/glances/glances.jsx @@ -1,4 +1,5 @@ import useSWR from "swr"; +import { useContext } from "react"; import { BiError } from "react-icons/bi"; import { FaMemory, FaRegClock, FaThermometerHalf } from "react-icons/fa"; import { FiCpu, FiHardDrive } from "react-icons/fi"; @@ -6,6 +7,8 @@ import { useTranslation } from "next-i18next"; import UsageBar from "../resources/usage-bar"; +import { SettingsContext } from "utils/contexts/settings"; + const cpuSensorLabels = ["cpu_thermal", "Core", "Tctl"]; function convertToFahrenheit(t) { @@ -14,6 +17,7 @@ function convertToFahrenheit(t) { export default function Widget({ options }) { const { t, i18n } = useTranslation(); + const { settings } = useContext(SettingsContext); const { data, error } = useSWR( `/api/widgets/glances?${new URLSearchParams({ lang: i18n.language, ...options }).toString()}`, { @@ -93,7 +97,7 @@ export default function Widget({ options }) { : [data.fs.find((d) => d.mnt_point === options.disk)].filter((d) => d); return ( -
+
@@ -218,6 +222,6 @@ export default function Widget({ options }) { {options.label && (
{options.label}
)} -
+
); } diff --git a/src/utils/config/widget-helpers.js b/src/utils/config/widget-helpers.js index c03bd906..6f61b7e2 100644 --- a/src/utils/config/widget-helpers.js +++ b/src/utils/config/widget-helpers.js @@ -5,8 +5,6 @@ import yaml from "js-yaml"; import checkAndCopyConfig, { substituteEnvironmentVars } from "utils/config/config"; -const exemptWidgets = ["search"]; - export async function widgetsFromConfig() { checkAndCopyConfig("widgets.yaml"); @@ -32,15 +30,17 @@ export async function cleanWidgetGroups(widgets) { return widgets.map((widget, index) => { const sanitizedOptions = widget.options; const optionKeys = Object.keys(sanitizedOptions); - if (!exemptWidgets.includes(widget.type)) { - ["url", "username", "password", "key"].forEach((pO) => { - if (optionKeys.includes(pO)) { - // allow URL in search - if (widget.type !== "search" && pO !== "key") { - delete sanitizedOptions[pO]; - } - } - }); + + // delete private options from the sanitized options + ["username", "password", "key"].forEach((pO) => { + if (optionKeys.includes(pO)) { + delete sanitizedOptions[pO]; + } + }); + + // delete url from the sanitized options if the widget is not a search or glances widgeth + if (widget.type !== "search" && widget.type !== "glances" && optionKeys.includes("url")) { + delete sanitizedOptions.url; } return { @@ -78,4 +78,4 @@ export async function getPrivateWidgetOptions(type, widgetIndex) { }); return (type !== undefined && widgetIndex !== undefined) ? privateOptions.find(o => o.type === type && o.options.index === parseInt(widgetIndex, 10))?.options : privateOptions; -} \ No newline at end of file +}