From 268e80a8d15c173fac985ff5394f2dc82823b79e Mon Sep 17 00:00:00 2001 From: sgrtye Date: Thu, 8 Feb 2024 16:02:42 +0000 Subject: [PATCH] add vertical config for custom API widget --- src/utils/config/service-helpers.js | 2 ++ src/widgets/customapi/component.jsx | 56 ++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index fb6757b6..e28c8d50 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -378,6 +378,7 @@ export function cleanServiceGroups(groups) { // customapi mappings, + vertical, // diskstation volume, @@ -539,6 +540,7 @@ export function cleanServiceGroups(groups) { } if (type === "customapi") { if (mappings) cleanedService.widget.mappings = mappings; + if (vertical) cleanedService.widget.vertical = vertical; if (refreshInterval) cleanedService.widget.refreshInterval = refreshInterval; } if (type === "calendar") { diff --git a/src/widgets/customapi/component.jsx b/src/widgets/customapi/component.jsx index 7e6ad4d7..6639bf7d 100644 --- a/src/widgets/customapi/component.jsx +++ b/src/widgets/customapi/component.jsx @@ -104,7 +104,7 @@ export default function Component({ service }) { const { widget } = service; - const { mappings = [], refreshInterval = 10000 } = widget; + const { mappings = [], refreshInterval = 10000, vertical = false } = widget; const { data: customData, error: customError } = useWidgetAPI(widget, null, { refreshInterval: Math.max(1000, refreshInterval), }); @@ -123,15 +123,55 @@ export default function Component({ service }) { ); } + if (!vertical) { + return ( + + {mappings.slice(0, 4).map((mapping) => ( + + ))} + + ); + } + return ( - {mappings.slice(0, 4).map((mapping) => ( - - ))} +
+ {mappings.map((mapping) => ( +
+
{mapping.label}
+
+
+ {mapping.currency ? + t("common.number", { + value: formatValue(t, mapping, getValue(mapping.field, customData)), + style: "currency", + currency: mapping.currency, + }) : + formatValue(t, mapping, getValue(mapping.field, customData)) + } +
+ {mapping.trend && ( +
0 ? "text-emerald-300" : "text-rose-300" + }`} + > + {!Number.isNaN(parseFloat(getValue(mapping.trend, customData))) ? + Number(parseFloat(getValue(mapping.trend, customData)).toFixed(2)) : + getValue(mapping.trend, customData) + }% +
+ )} +
+
+ ))} +
); }