From a4f9667329c060186b519c6fba02253653bc4ade Mon Sep 17 00:00:00 2001 From: Stephen Donchez Date: Sat, 29 Jul 2023 16:57:17 -0400 Subject: [PATCH] add support for "fields" from services.yaml --- src/widgets/urbackup/component.jsx | 23 +++++++++++++++++++---- src/widgets/urbackup/proxy.js | 4 +--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/widgets/urbackup/component.jsx b/src/widgets/urbackup/component.jsx index c42efc3e..e3079a19 100644 --- a/src/widgets/urbackup/component.jsx +++ b/src/widgets/urbackup/component.jsx @@ -6,6 +6,19 @@ import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; +function determineFields(widget){ + + // don't include diskUsage by default, since it requires a second API call + if (!widget.fields) return [true, true, true, false] + + return [ + widget.fields?.includes('ok'), + widget.fields?.includes('errored'), + widget.fields?.includes('noRecent'), + widget.fields?.includes('totalUsed') + ]; +} + export default function Component({ service }) { const { t } = useTranslation(); @@ -13,6 +26,8 @@ export default function Component({ service }) { const { data: urbackupData, error: urbackupError } = useWidgetAPI(widget, "status"); + const [showOk, showErrored, showNoRecent, showDiskUsage] = determineFields(widget); + if (urbackupError) { return ; } @@ -31,10 +46,10 @@ export default function Component({ service }) { return ( - - - - {urbackupData.diskUsage && } + {showOk && } + {showErrored && } + {showNoRecent && } + {showDiskUsage && } ); } diff --git a/src/widgets/urbackup/proxy.js b/src/widgets/urbackup/proxy.js index ce08b514..e81e24b0 100644 --- a/src/widgets/urbackup/proxy.js +++ b/src/widgets/urbackup/proxy.js @@ -1,5 +1,3 @@ -// suppress a false positive - this is in package.json -// eslint-disable-next-line import/no-extraneous-dependencies import {UrbackupServer} from "urbackup-server-api"; import getServiceWidget from "utils/config/service-helpers"; @@ -18,7 +16,7 @@ await (async () => { try { const allClients = await server.getStatus({includeRemoved: false}); let diskUsage = false - if(serviceWidget.diskUsage) + if(serviceWidget.fields?.includes("totalUsed")) { diskUsage = await server.getUsage(); }