From f4f58409a2e5614b206e1bfb93e7fe36c9a1d712 Mon Sep 17 00:00:00 2001 From: Richy HBM Date: Thu, 27 Apr 2023 19:21:57 +0100 Subject: [PATCH] Add Whats Up Docker widget (#1150) Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> --- public/locales/en/common.json | 4 ++++ src/widgets/components.js | 1 + src/widgets/whatsupdocker/component.jsx | 32 +++++++++++++++++++++++++ src/widgets/whatsupdocker/widget.js | 14 +++++++++++ src/widgets/widgets.js | 2 ++ 5 files changed, 53 insertions(+) create mode 100644 src/widgets/whatsupdocker/component.jsx create mode 100644 src/widgets/whatsupdocker/widget.js diff --git a/public/locales/en/common.json b/public/locales/en/common.json index d3eb43cc8..9dd10d047 100755 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -587,5 +587,9 @@ "people_home": "People Home", "lights_on": "Lights On", "switches_on": "Switches On" + }, + "whatsupdocker": { + "monitoring": "Monitoring", + "updates": "Updates" } } diff --git a/src/widgets/components.js b/src/widgets/components.js index 673383322..f8828f3bd 100644 --- a/src/widgets/components.js +++ b/src/widgets/components.js @@ -81,6 +81,7 @@ const components = { unmanic: dynamic(() => import("./unmanic/component")), uptimekuma: dynamic(() => import("./uptimekuma/component")), watchtower: dynamic(() => import("./watchtower/component")), + whatsupdocker: dynamic(() => import("./whatsupdocker/component")), xteve: dynamic(() => import("./xteve/component")), }; diff --git a/src/widgets/whatsupdocker/component.jsx b/src/widgets/whatsupdocker/component.jsx new file mode 100644 index 000000000..26b38dee6 --- /dev/null +++ b/src/widgets/whatsupdocker/component.jsx @@ -0,0 +1,32 @@ +import Container from "components/services/widget/container"; +import Block from "components/services/widget/block"; +import useWidgetAPI from "utils/proxy/use-widget-api"; + +export default function Component({ service }) { + const { widget } = service; + + const { data: containersData, error: containersError } = useWidgetAPI(widget, "containers"); + + if (containersError) { + return ; + } + + if (!containersData) { + return ( + + + + + ); + } + + const totalCount = containersData.length; + const updatesAvailable = containersData.filter(container => container.updateAvailable).length; + + return ( + + + + + ); +} diff --git a/src/widgets/whatsupdocker/widget.js b/src/widgets/whatsupdocker/widget.js new file mode 100644 index 000000000..6c2423a05 --- /dev/null +++ b/src/widgets/whatsupdocker/widget.js @@ -0,0 +1,14 @@ +import genericProxyHandler from "utils/proxy/handlers/generic"; + +const widget = { + api: "{url}/{endpoint}", + proxyHandler: genericProxyHandler, + + mappings: { + containers: { + endpoint: "api/containers" + }, + }, +}; + +export default widget; diff --git a/src/widgets/widgets.js b/src/widgets/widgets.js index 9878d50dd..9e1553831 100644 --- a/src/widgets/widgets.js +++ b/src/widgets/widgets.js @@ -75,6 +75,7 @@ import unifi from "./unifi/widget"; import unmanic from "./unmanic/widget"; import uptimekuma from "./uptimekuma/widget"; import watchtower from "./watchtower/widget"; +import whatsupdocker from "./whatsupdocker/widget"; import xteve from "./xteve/widget"; const widgets = { @@ -157,6 +158,7 @@ const widgets = { unmanic, uptimekuma, watchtower, + whatsupdocker, xteve, };