From 132b8c32e51fe305aa3ab497a58fe316e9612400 Mon Sep 17 00:00:00 2001 From: InsertDisc <31751462+InsertDisc@users.noreply.github.com> Date: Fri, 23 Aug 2024 22:28:37 -0400 Subject: [PATCH] Refactor: update RomM widget (#3886) --------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com> --- docs/widgets/services/romm.md | 4 +++- public/locales/en/common.json | 6 +++++- src/widgets/romm/component.jsx | 35 ++++++++++++++++++++++++---------- src/widgets/romm/widget.js | 2 +- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/docs/widgets/services/romm.md b/docs/widgets/services/romm.md index 9d26b70f5..6bde13777 100644 --- a/docs/widgets/services/romm.md +++ b/docs/widgets/services/romm.md @@ -3,7 +3,8 @@ title: Romm description: Romm Widget Configuration --- -Allowed fields: `["platforms", "totalRoms"]`. +Allowed fields: `["platforms", "totalRoms", "saves", "states", "screenshots", "totalfilesize"]`. +If more than (4) fields are provided, only the first (4) will be used. ```yaml widget: @@ -11,4 +12,5 @@ widget: url: http://romm.host.or.ip username: username # optional password: password # optional + fields: ["platforms", "totalRoms", "saves", "states"] # optional - default fields shown ``` diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 1ac41f901..fabf5d84d 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -831,7 +831,11 @@ }, "romm": { "platforms": "Platforms", - "totalRoms": "Total ROMs" + "totalRoms": "Games", + "saves": "Saves", + "states": "States", + "screenshots": "Screenshots", + "totalfilesize": "Total Size" }, "netdata": { "warnings": "Warnings", diff --git a/src/widgets/romm/component.jsx b/src/widgets/romm/component.jsx index 44b114b03..ea9549f73 100644 --- a/src/widgets/romm/component.jsx +++ b/src/widgets/romm/component.jsx @@ -4,31 +4,46 @@ import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; +const ROMM_DEFAULT_FIELDS = ["platforms", "totalRoms", "saves", "states"]; +const MAX_ALLOWED_FIELDS = 4; + export default function Component({ service }) { const { widget } = service; const { t } = useTranslation(); - const { data: response, error: responseError } = useWidgetAPI(widget, "statistics"); if (responseError) { + return ; + } + + if (!widget.fields?.length > 0) { + widget.fields = ROMM_DEFAULT_FIELDS; + } else if (widget.fields.length > MAX_ALLOWED_FIELDS) { + widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS); + } + + if (!response) { return ( - + + + + + + ); } - if (responseError) { - return ; - } - if (response) { - const platforms = response.filter((x) => x.rom_count !== 0).length; - const totalRoms = response.reduce((total, stat) => total + stat.rom_count, 0); return ( - - + + + + + + ); } diff --git a/src/widgets/romm/widget.js b/src/widgets/romm/widget.js index a7bb60fd6..84fe47f85 100644 --- a/src/widgets/romm/widget.js +++ b/src/widgets/romm/widget.js @@ -6,7 +6,7 @@ const widget = { mappings: { statistics: { - endpoint: "platforms", + endpoint: "stats", }, }, };