diff --git a/public/locales/en/common.json b/public/locales/en/common.json index d53d480c7..63b597644 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -36,6 +36,11 @@ "uptime": "System Uptime", "days": "Days", "wan": "WAN", + "lan": "LAN", + "wlan": "WLAN", + "devices": "Devices", + "lan_devices": "LAN Devices", + "wlan_devices": "WLAN Devices", "lan_users": "LAN Users", "wlan_users": "WLAN Users", "up": "UP", diff --git a/src/components/services/widget/container.jsx b/src/components/services/widget/container.jsx index ef2ddcfd2..60536e86b 100644 --- a/src/components/services/widget/container.jsx +++ b/src/components/services/widget/container.jsx @@ -11,7 +11,7 @@ export default function Container({ error = false, children, service }) { const fields = service?.widget?.fields; const type = service?.widget?.type; if (fields && type) { - visibleChildren = children.filter(child => fields.some(field => `${type}.${field}` === child.props?.label)); + visibleChildren = children.filter(child => fields.some(field => `${type}.${field}` === child?.props?.label)); } return
{visibleChildren}
; diff --git a/src/components/widgets/unifi_console/unifi_console.jsx b/src/components/widgets/unifi_console/unifi_console.jsx index 889a517f1..15d0665ed 100644 --- a/src/components/widgets/unifi_console/unifi_console.jsx +++ b/src/components/widgets/unifi_console/unifi_console.jsx @@ -1,4 +1,4 @@ -import { BiError, BiWifi, BiCheckCircle, BiXCircle } from "react-icons/bi"; +import { BiError, BiWifi, BiCheckCircle, BiXCircle, BiNetworkChart } from "react-icons/bi"; import { MdSettingsEthernet } from "react-icons/md"; import { useTranslation } from "next-i18next"; import { SiUbiquiti } from "react-icons/si"; @@ -48,19 +48,12 @@ export default function Widget({ options }) { const wan = defaultSite.health.find(h => h.subsystem === "wan"); const lan = defaultSite.health.find(h => h.subsystem === "lan"); const wlan = defaultSite.health.find(h => h.subsystem === "wlan"); - const data = { - name: wan.gw_name, - uptime: wan["gw_system-stats"].uptime, - up: wan.status === 'ok', - wlan: { - users: wlan.num_user, - status: wlan.status - }, - lan: { - users: lan.num_user, - status: lan.status - } - }; + [wan, lan, wlan].forEach(s => { + s.up = s.status === "ok" // eslint-disable-line no-param-reassign + s.show = s.status !== "unknown" // eslint-disable-line no-param-reassign + }); + const name = wan.gw_name ?? defaultSite.desc; + const uptime = wan["gw_system-stats"] ? wan["gw_system-stats"].uptime : null; return (
@@ -68,51 +61,76 @@ export default function Widget({ options }) {
- {data.name} + {name}
-
+ {uptime &&
{t("common.number", { - value: data.uptime / 86400, + value: uptime / 86400, maximumFractionDigits: 1, })}
{t("unifi.days")}
-
-
+
} + {wan.show &&
{t("unifi.wan")}
- { data.up + {wan.up ? : } -
+
} + {!wan.show && !lan.show && wlan.show &&
+
{t("unifi.wlan")}
+ {wlan.up + ? + : + } +
} + {!wan.show && !wlan.show && lan.show &&
+
{t("unifi.lan")}
+ {lan.up + ? + : + } +
}
-
+ {wlan.show &&
{t("common.number", { - value: data.wlan.users, + value: wlan.num_user, maximumFractionDigits: 0, })}
-
-
+
} + {lan.show &&
{t("common.number", { - value: data.lan.users, + value: lan.num_user, maximumFractionDigits: 0, })}
-
+
} + {(wlan.show && !lan.show || !wlan.show && lan.show) &&
+ +
+
+ {t("common.number", { + value: wlan.show ? wlan.num_adopted : lan.num_adopted, + maximumFractionDigits: 0, + })} +
+
+
}
); diff --git a/src/widgets/unifi/component.jsx b/src/widgets/unifi/component.jsx index e2db8e77f..b24d7b5aa 100644 --- a/src/widgets/unifi/component.jsx +++ b/src/widgets/unifi/component.jsx @@ -31,28 +31,25 @@ export default function Component({ service }) { const wan = defaultSite.health.find(h => h.subsystem === "wan"); const lan = defaultSite.health.find(h => h.subsystem === "lan"); const wlan = defaultSite.health.find(h => h.subsystem === "wlan"); - const data = { - name: wan.gw_name, - uptime: wan["gw_system-stats"].uptime, - up: wan.status === 'ok', - wlan: { - users: wlan.num_user, - status: wlan.status - }, - lan: { - users: lan.num_user, - status: lan.status - }, - }; - - const uptime = `${t("common.number", { value: data.uptime / 86400, maximumFractionDigits: 1 })} ${t("unifi.days")}`; + [wan, lan, wlan].forEach(s => { + s.up = s.status === "ok" // eslint-disable-line no-param-reassign + s.show = s.status !== "unknown" // eslint-disable-line no-param-reassign + }); + + const uptime = wan["gw_system-stats"] ? `${t("common.number", { value: wan["gw_system-stats"].uptime / 86400, maximumFractionDigits: 1 })} ${t("unifi.days")}` : null; return ( - - - - + {uptime && } + {wan.show && } + + {lan.show && } + {lan.show && !wlan.show && } + {lan.show && !wlan.show && } + + {wlan.show && } + {wlan.show && !lan.show && } + {wlan.show && !lan.show && } ); }