From 2717c4deda79b02a3e4a35dc2ca7073ca0d12364 Mon Sep 17 00:00:00 2001 From: grimsi <9295182+grimsi@users.noreply.github.com> Date: Thu, 5 Jun 2025 22:53:41 +0200 Subject: [PATCH] Cast plugin config values in frontend --- .../general/modals/PluginDetailsModal.tsx | 282 +++++++++--------- 1 file changed, 148 insertions(+), 134 deletions(-) diff --git a/gameyfin/src/main/frontend/components/general/modals/PluginDetailsModal.tsx b/gameyfin/src/main/frontend/components/general/modals/PluginDetailsModal.tsx index f99993b..f0c7c6d 100644 --- a/gameyfin/src/main/frontend/components/general/modals/PluginDetailsModal.tsx +++ b/gameyfin/src/main/frontend/components/general/modals/PluginDetailsModal.tsx @@ -8,7 +8,7 @@ import {PluginEndpoint} from "Frontend/generated/endpoints"; import PluginDto from "Frontend/generated/de/grimsi/gameyfin/core/plugins/dto/PluginDto"; import {ArrowClockwise} from "@phosphor-icons/react"; import PluginConfigMetadataDto from "Frontend/generated/de/grimsi/gameyfin/core/plugins/dto/PluginConfigMetadataDto"; -import PluginConfigFormField from "Frontend/components/general/input/PluginConfigFormField"; +import PluginConfigFormField from "Frontend/components/general/plugin/PluginConfigFormField"; interface PluginDetailsModalProps { plugin: PluginDto; @@ -35,18 +35,26 @@ export default function PluginDetailsModal({plugin, isOpen, onOpenChange}: Plugi }); } - function getEffectiveConfig(): Record { - const effectiveConfig: Record = {}; + function getEffectiveConfig(): Record { + const effectiveConfig: Record = {}; if (!plugin.configMetadata) return effectiveConfig; for (const meta of plugin.configMetadata) { const key = meta.key; - let value = plugin.config?.[key]?.toString(); - if (value == null && meta.default != null) { - value = meta.default.toString(); - } - if (value) { - effectiveConfig[key] = value; + let value = plugin.config?.[key] ?? meta.default; + + if (value != null) { + switch (meta.type.toLowerCase()) { + case "float": + case "int": + effectiveConfig[key] = Number(value); + break; + case "boolean": + effectiveConfig[key] = value === true || value === "true"; + break; + default: + effectiveConfig[key] = value.toString(); + } } } return effectiveConfig; @@ -55,132 +63,138 @@ export default function PluginDetailsModal({plugin, isOpen, onOpenChange}: Plugi return ( - {(onClose) => ( - { - await saveConfig(values); - onClose(); - }} - > - {(formik: any) => ( -
- - Plugin configuration for {plugin.name} - - -
-
- - - - {Object.entries({ - "Author": plugin.author, - "Version": plugin.version, - "License": plugin.license, - "URL": - {plugin.url} - , - }).map(([key, value]) => { - if (!value) return; - return ( - - - - - ) - })} - -
{key}{value}
-
-

Description

- - {props.children} - - } - }} - >{plugin.description} -
+ {(onClose) => { -
-

Configuration

- {(plugin.configMetadata && plugin.configMetadata.length > 0) && <> -
- {(() => { - switch (configValidated) { - case ValidationState.VALID: - return

- Configuration valid -

; - case ValidationState.INVALID: - return

- Configuration invalid -

; - default: - return null; - } - })()} - - - - } -
- {(plugin.configMetadata && plugin.configMetadata.length > 0) ? - plugin.configMetadata.map((entry: PluginConfigMetadataDto) => ( - - )) : "This plugin has no configuration options." - } - - - - {(plugin.configMetadata && plugin.configMetadata?.length > 0) ? - : ""} - - - )} - - )} + async function handleSubmit(values: Record): Promise { + await saveConfig(values); + onClose(); + } + + return ( + + {(formik: any) => ( +
+ + Plugin configuration for {plugin.name} + + +
+
+ + + + {Object.entries({ + "Author": plugin.author, + "Version": plugin.version, + "License": plugin.license, + "URL": + {plugin.url} + , + }).map(([key, value]) => { + if (!value) return; + return ( + + + + + ) + })} + +
{key}{value}
+
+

Description

+ + {props.children} + + } + }} + >{plugin.description} +
+ +
+

Configuration

+ {(plugin.configMetadata && plugin.configMetadata.length > 0) && <> +
+ {(() => { + switch (configValidated) { + case ValidationState.VALID: + return

+ Configuration valid +

; + case ValidationState.INVALID: + return

+ Configuration invalid +

; + default: + return null; + } + })()} + + + + } +
+ {(plugin.configMetadata && plugin.configMetadata.length > 0) ? + plugin.configMetadata.map((entry: PluginConfigMetadataDto) => ( + + )) : "This plugin has no configuration options." + } + + + + {(plugin.configMetadata && plugin.configMetadata?.length > 0) ? + : ""} + + + ) + } + + ) + }} );