From 1eb4939cf1fb28b9a819c0e4cdfa1305c6fef25c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sat, 29 Jul 2023 21:59:16 -0700 Subject: [PATCH] fix field filtering, syntax --- src/widgets/urbackup/component.jsx | 24 ++++++------------------ src/widgets/urbackup/proxy.js | 3 +-- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/widgets/urbackup/component.jsx b/src/widgets/urbackup/component.jsx index e3079a19..c4b77751 100644 --- a/src/widgets/urbackup/component.jsx +++ b/src/widgets/urbackup/component.jsx @@ -6,27 +6,14 @@ 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(); const { widget } = service; - const { data: urbackupData, error: urbackupError } = useWidgetAPI(widget, "status"); + const showDiskUsage = widget.fields?.includes('totalUsed') - const [showOk, showErrored, showNoRecent, showDiskUsage] = determineFields(widget); + const { data: urbackupData, error: urbackupError } = useWidgetAPI(widget, "status"); if (urbackupError) { return ; @@ -38,6 +25,7 @@ export default function Component({ service }) { + {showDiskUsage && } ); } @@ -46,9 +34,9 @@ export default function Component({ service }) { return ( - {showOk && } - {showErrored && } - {showNoRecent && } + + + {showDiskUsage && } ); diff --git a/src/widgets/urbackup/proxy.js b/src/widgets/urbackup/proxy.js index e81e24b0..3075afd0 100644 --- a/src/widgets/urbackup/proxy.js +++ b/src/widgets/urbackup/proxy.js @@ -16,8 +16,7 @@ await (async () => { try { const allClients = await server.getStatus({includeRemoved: false}); let diskUsage = false - if(serviceWidget.fields?.includes("totalUsed")) - { + if (serviceWidget.fields?.includes("totalUsed")) { diskUsage = await server.getUsage(); } res.status(200).send({