From c2983197a0bba473b46c2b2789fe98347b6d99e0 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 3 Feb 2023 01:01:30 -0800 Subject: [PATCH 1/2] Unifi widgets show warning with no data --- public/locales/en/common.json | 3 ++- src/components/widgets/unifi_console/unifi_console.jsx | 10 ++++++++++ src/widgets/unifi/component.jsx | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index f144182f6..953e9fbd2 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -51,7 +51,8 @@ "wlan_users": "WLAN Users", "up": "UP", "down": "DOWN", - "wait": "Please wait" + "wait": "Please wait", + "empty_data": "Subsystem status unknown" }, "docker": { "rx": "RX", diff --git a/src/components/widgets/unifi_console/unifi_console.jsx b/src/components/widgets/unifi_console/unifi_console.jsx index af8fd4586..156e2866f 100644 --- a/src/components/widgets/unifi_console/unifi_console.jsx +++ b/src/components/widgets/unifi_console/unifi_console.jsx @@ -55,6 +55,8 @@ export default function Widget({ options }) { const name = wan.gw_name ?? defaultSite.desc; const uptime = wan["gw_system-stats"] ? wan["gw_system-stats"].uptime : null; + const dataEmpty = !(wan.show || lan.show || wlan.show || uptime); + return (
@@ -64,6 +66,14 @@ export default function Widget({ options }) { {name}
+ {dataEmpty &&
+
+
+ + {t("unifi.empty_data")} +
+
+
}
{uptime &&
diff --git a/src/widgets/unifi/component.jsx b/src/widgets/unifi/component.jsx index 6df43dfdb..25ba8ea21 100644 --- a/src/widgets/unifi/component.jsx +++ b/src/widgets/unifi/component.jsx @@ -38,6 +38,14 @@ export default function Component({ service }) { const uptime = wan["gw_system-stats"] ? `${t("common.number", { value: wan["gw_system-stats"].uptime / 86400, maximumFractionDigits: 1 })} ${t("unifi.days")}` : null; + if (!(wan.show || lan.show || wlan.show || uptime)) { + return ( + + + + ) + } + return ( {uptime && } From 17ebdd8226ecaff930b666b7a16682805358fd31 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 3 Feb 2023 01:12:52 -0800 Subject: [PATCH 2/2] Unifi widgets support sites other than default --- src/components/widgets/unifi_console/unifi_console.jsx | 3 +-- src/utils/config/service-helpers.js | 4 ++++ src/widgets/unifi/component.jsx | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/widgets/unifi_console/unifi_console.jsx b/src/components/widgets/unifi_console/unifi_console.jsx index 156e2866f..13c90bd42 100644 --- a/src/components/widgets/unifi_console/unifi_console.jsx +++ b/src/components/widgets/unifi_console/unifi_console.jsx @@ -20,7 +20,6 @@ export default function Widget({ options }) {
{t("widget.api_error")} - -
@@ -28,7 +27,7 @@ export default function Widget({ options }) { ); } - const defaultSite = statsData?.data?.find(s => s.name === "default"); + const defaultSite = options.site ? statsData?.data.find(s => s.desc === options.site) : statsData?.data?.find(s => s.name === "default"); if (!defaultSite) { return ( diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index 352367d2e..e2e3055e0 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -233,6 +233,7 @@ export function cleanServiceGroups(groups) { currency, // coinmarketcap widget symbols, defaultinterval, + site, // unifi widget namespace, // kubernetes widget app, podSelector, @@ -256,6 +257,9 @@ export function cleanServiceGroups(groups) { if (server) cleanedService.widget.server = server; if (container) cleanedService.widget.container = container; } + if (type === "unifi") { + if (site) cleanedService.widget.site = site; + } if (type === "kubernetes") { if (namespace) cleanedService.widget.namespace = namespace; if (app) cleanedService.widget.app = app; diff --git a/src/widgets/unifi/component.jsx b/src/widgets/unifi/component.jsx index 25ba8ea21..ff3185169 100644 --- a/src/widgets/unifi/component.jsx +++ b/src/widgets/unifi/component.jsx @@ -15,7 +15,7 @@ export default function Component({ service }) { return ; } - const defaultSite = statsData?.data?.find(s => s.name === "default"); + const defaultSite = widget.site ? statsData?.data.find(s => s.desc === widget.site) : statsData?.data?.find(s => s.name === "default"); if (!defaultSite) { return (