From eff44b8d4e3bcc8efd0dacd9d4ba10287d75f3a7 Mon Sep 17 00:00:00 2001 From: jonathancrangle <94425204+joncrangle@users.noreply.github.com> Date: Sat, 24 Aug 2024 12:29:49 -0400 Subject: [PATCH 1/8] fix: mealie api change --- src/widgets/mealie/component.jsx | 9 ++++++--- src/widgets/mealie/widget.js | 14 +++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/widgets/mealie/component.jsx b/src/widgets/mealie/component.jsx index 7a42bc7d04c..0bacbf5d87b 100644 --- a/src/widgets/mealie/component.jsx +++ b/src/widgets/mealie/component.jsx @@ -5,10 +5,13 @@ import useWidgetAPI from "utils/proxy/use-widget-api"; export default function Component({ service }) { const { widget } = service; - const { data: mealieData, error: mealieError } = useWidgetAPI(widget); + const { data: versionData, error: versionError } = useWidgetAPI(widget, "version"); + const endpoint = versionData?.version.major >= 2 || versionData?.version === "nightly" ? "households" : "groups"; - if (mealieError || mealieData?.statusCode === 401) { - return ; + const { data: mealieData, error: mealieError } = useWidgetAPI(widget, endpoint); + + if (versionError || mealieError || mealieData?.statusCode === 401) { + return ; } if (!mealieData) { diff --git a/src/widgets/mealie/widget.js b/src/widgets/mealie/widget.js index 3ec8ff24d3c..daa635d9729 100644 --- a/src/widgets/mealie/widget.js +++ b/src/widgets/mealie/widget.js @@ -1,8 +1,20 @@ import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; const widget = { - api: "{url}/api/groups/statistics", + api: "{url}/api/{endpoint}", proxyHandler: credentialedProxyHandler, + + mappings: { + version: { + endpoint: "app/about", + }, + groups: { + endpoint: "groups/statistics", + }, + households: { + endpoint: "households/statistics", + }, + } }; export default widget; From 56f75381dde968d939cf200a5f80248055731a01 Mon Sep 17 00:00:00 2001 From: jonathancrangle <94425204+joncrangle@users.noreply.github.com> Date: Sat, 24 Aug 2024 12:39:13 -0400 Subject: [PATCH 2/8] update version comparison --- src/widgets/mealie/component.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/mealie/component.jsx b/src/widgets/mealie/component.jsx index 0bacbf5d87b..ca58fb0f80a 100644 --- a/src/widgets/mealie/component.jsx +++ b/src/widgets/mealie/component.jsx @@ -6,7 +6,7 @@ export default function Component({ service }) { const { widget } = service; const { data: versionData, error: versionError } = useWidgetAPI(widget, "version"); - const endpoint = versionData?.version.major >= 2 || versionData?.version === "nightly" ? "households" : "groups"; + const endpoint = parseInt(versionData?.version) >= 2 || versionData?.version === "nightly" ? "households" : "groups"; const { data: mealieData, error: mealieError } = useWidgetAPI(widget, endpoint); From 26d8267c4fe4539a9e7da19131c7cbc8c05e1962 Mon Sep 17 00:00:00 2001 From: jonathancrangle <94425204+joncrangle@users.noreply.github.com> Date: Sat, 24 Aug 2024 12:46:28 -0400 Subject: [PATCH 3/8] fix linting error --- src/widgets/mealie/component.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/mealie/component.jsx b/src/widgets/mealie/component.jsx index ca58fb0f80a..47cfe354874 100644 --- a/src/widgets/mealie/component.jsx +++ b/src/widgets/mealie/component.jsx @@ -6,7 +6,7 @@ export default function Component({ service }) { const { widget } = service; const { data: versionData, error: versionError } = useWidgetAPI(widget, "version"); - const endpoint = parseInt(versionData?.version) >= 2 || versionData?.version === "nightly" ? "households" : "groups"; + const endpoint = parseInt(versionData?.version, 10) >= 2 || versionData?.version === "nightly" ? "households" : "groups"; const { data: mealieData, error: mealieError } = useWidgetAPI(widget, endpoint); From fc4ca116028d43f2564b0390e324434f3f576288 Mon Sep 17 00:00:00 2001 From: jonathancrangle <94425204+joncrangle@users.noreply.github.com> Date: Sat, 24 Aug 2024 17:47:27 -0400 Subject: [PATCH 4/8] fix version check --- src/widgets/mealie/component.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/mealie/component.jsx b/src/widgets/mealie/component.jsx index 47cfe354874..1ef5beb37bc 100644 --- a/src/widgets/mealie/component.jsx +++ b/src/widgets/mealie/component.jsx @@ -6,7 +6,7 @@ export default function Component({ service }) { const { widget } = service; const { data: versionData, error: versionError } = useWidgetAPI(widget, "version"); - const endpoint = parseInt(versionData?.version, 10) >= 2 || versionData?.version === "nightly" ? "households" : "groups"; + const endpoint = versionData?.version?.startsWith("v2") || versionData?.version === "nightly" ? "households" : "groups"; const { data: mealieData, error: mealieError } = useWidgetAPI(widget, endpoint); From e8dac6999ac721c2e01db5c386c2a4cd735277d6 Mon Sep 17 00:00:00 2001 From: jonathancrangle <94425204+joncrangle@users.noreply.github.com> Date: Sat, 24 Aug 2024 17:52:37 -0400 Subject: [PATCH 5/8] prettier --- src/widgets/mealie/component.jsx | 3 ++- src/widgets/mealie/widget.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/widgets/mealie/component.jsx b/src/widgets/mealie/component.jsx index 1ef5beb37bc..9cb3eefd455 100644 --- a/src/widgets/mealie/component.jsx +++ b/src/widgets/mealie/component.jsx @@ -6,7 +6,8 @@ export default function Component({ service }) { const { widget } = service; const { data: versionData, error: versionError } = useWidgetAPI(widget, "version"); - const endpoint = versionData?.version?.startsWith("v2") || versionData?.version === "nightly" ? "households" : "groups"; + const endpoint = + versionData?.version?.startsWith("v2") || versionData?.version === "nightly" ? "households" : "groups"; const { data: mealieData, error: mealieError } = useWidgetAPI(widget, endpoint); diff --git a/src/widgets/mealie/widget.js b/src/widgets/mealie/widget.js index daa635d9729..303b067cba6 100644 --- a/src/widgets/mealie/widget.js +++ b/src/widgets/mealie/widget.js @@ -14,7 +14,7 @@ const widget = { households: { endpoint: "households/statistics", }, - } + }, }; export default widget; From 4e28ce832ef4bbf81de0bd438ec8f1b2efd690ce Mon Sep 17 00:00:00 2001 From: jonathancrangle <94425204+joncrangle@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:20:14 -0400 Subject: [PATCH 6/8] update for version key --- docs/widgets/services/mealie.md | 1 + src/widgets/mealie/component.jsx | 26 ++++++++++++-------------- src/widgets/mealie/widget.js | 7 ++----- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/docs/widgets/services/mealie.md b/docs/widgets/services/mealie.md index b1cf117bea9..213ae3127a7 100644 --- a/docs/widgets/services/mealie.md +++ b/docs/widgets/services/mealie.md @@ -14,4 +14,5 @@ widget: type: mealie url: http://mealie-frontend.host.or.ip key: mealieapitoken + version: 1 # optional, defaults to 1 ``` diff --git a/src/widgets/mealie/component.jsx b/src/widgets/mealie/component.jsx index 9cb3eefd455..a4dd1bf164f 100644 --- a/src/widgets/mealie/component.jsx +++ b/src/widgets/mealie/component.jsx @@ -1,21 +1,20 @@ +import { useTranslation } from "next-i18next"; + 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 { t } = useTranslation(); const { widget } = service; + const version = widget.version ?? 1; + const { data, error } = useWidgetAPI(widget, version === 1 ? "statisticsv1" : "statisticsv2"); - const { data: versionData, error: versionError } = useWidgetAPI(widget, "version"); - const endpoint = - versionData?.version?.startsWith("v2") || versionData?.version === "nightly" ? "households" : "groups"; - - const { data: mealieData, error: mealieError } = useWidgetAPI(widget, endpoint); - - if (versionError || mealieError || mealieData?.statusCode === 401) { - return ; + if (error) { + return ; } - if (!mealieData) { + if (!data) { return ( @@ -25,13 +24,12 @@ export default function Component({ service }) { ); } - return ( - - - - + + + + ); } diff --git a/src/widgets/mealie/widget.js b/src/widgets/mealie/widget.js index 303b067cba6..8a706923915 100644 --- a/src/widgets/mealie/widget.js +++ b/src/widgets/mealie/widget.js @@ -5,13 +5,10 @@ const widget = { proxyHandler: credentialedProxyHandler, mappings: { - version: { - endpoint: "app/about", - }, - groups: { + statisticsv1: { endpoint: "groups/statistics", }, - households: { + statisticsv2: { endpoint: "households/statistics", }, }, From 5fde0913a181fa06ef3a24650218985c56afa82a Mon Sep 17 00:00:00 2001 From: joncrangle <94425204+joncrangle@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:24:45 -0400 Subject: [PATCH 7/8] Update docs/widgets/services/mealie.md Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> --- docs/widgets/services/mealie.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/widgets/services/mealie.md b/docs/widgets/services/mealie.md index 213ae3127a7..7fb335036ef 100644 --- a/docs/widgets/services/mealie.md +++ b/docs/widgets/services/mealie.md @@ -14,5 +14,5 @@ widget: type: mealie url: http://mealie-frontend.host.or.ip key: mealieapitoken - version: 1 # optional, defaults to 1 + version: 2 # only required if version > 1, defaults to 1 ``` From 125bcd90d147a3b68bf75a085f760469cb623f54 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:00:35 -0700 Subject: [PATCH 8/8] Include version for mealie in service-helpers --- src/utils/config/service-helpers.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index 03b4507ea23..3dde943d7c5 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -402,7 +402,7 @@ export function cleanServiceGroups(groups) { // frigate enableRecentEvents, - // glances, pihole, pfsense + // glances, mealie, pihole, pfsense version, // glances @@ -512,9 +512,6 @@ export function cleanServiceGroups(groups) { if (type === "unifi") { if (site) cleanedService.widget.site = site; } - if (type === "pfsense") { - if (version) cleanedService.widget.version = version; - } if (type === "proxmox") { if (node) cleanedService.widget.node = node; } @@ -561,7 +558,7 @@ export function cleanServiceGroups(groups) { if (snapshotHost) cleanedService.widget.snapshotHost = snapshotHost; if (snapshotPath) cleanedService.widget.snapshotPath = snapshotPath; } - if (["glances", "pihole"].includes(type)) { + if (["glances", "mealie", "pfsense", "pihole"].includes(type)) { if (version) cleanedService.widget.version = version; } if (type === "glances") {