mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 16:20:04 +00:00
Cast plugin config values in frontend
This commit is contained in:
@@ -8,7 +8,7 @@ import {PluginEndpoint} from "Frontend/generated/endpoints";
|
|||||||
import PluginDto from "Frontend/generated/de/grimsi/gameyfin/core/plugins/dto/PluginDto";
|
import PluginDto from "Frontend/generated/de/grimsi/gameyfin/core/plugins/dto/PluginDto";
|
||||||
import {ArrowClockwise} from "@phosphor-icons/react";
|
import {ArrowClockwise} from "@phosphor-icons/react";
|
||||||
import PluginConfigMetadataDto from "Frontend/generated/de/grimsi/gameyfin/core/plugins/dto/PluginConfigMetadataDto";
|
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 {
|
interface PluginDetailsModalProps {
|
||||||
plugin: PluginDto;
|
plugin: PluginDto;
|
||||||
@@ -35,18 +35,26 @@ export default function PluginDetailsModal({plugin, isOpen, onOpenChange}: Plugi
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEffectiveConfig(): Record<string, string> {
|
function getEffectiveConfig(): Record<string, any> {
|
||||||
const effectiveConfig: Record<string, string> = {};
|
const effectiveConfig: Record<string, any> = {};
|
||||||
if (!plugin.configMetadata) return effectiveConfig;
|
if (!plugin.configMetadata) return effectiveConfig;
|
||||||
|
|
||||||
for (const meta of plugin.configMetadata) {
|
for (const meta of plugin.configMetadata) {
|
||||||
const key = meta.key;
|
const key = meta.key;
|
||||||
let value = plugin.config?.[key]?.toString();
|
let value = plugin.config?.[key] ?? meta.default;
|
||||||
if (value == null && meta.default != null) {
|
|
||||||
value = meta.default.toString();
|
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();
|
||||||
}
|
}
|
||||||
if (value) {
|
|
||||||
effectiveConfig[key] = value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return effectiveConfig;
|
return effectiveConfig;
|
||||||
@@ -55,14 +63,18 @@ export default function PluginDetailsModal({plugin, isOpen, onOpenChange}: Plugi
|
|||||||
return (
|
return (
|
||||||
<Modal isOpen={isOpen} onOpenChange={onOpenChange} backdrop="opaque" size="lg">
|
<Modal isOpen={isOpen} onOpenChange={onOpenChange} backdrop="opaque" size="lg">
|
||||||
<ModalContent>
|
<ModalContent>
|
||||||
{(onClose) => (
|
{(onClose) => {
|
||||||
|
|
||||||
|
async function handleSubmit(values: Record<string, string>): Promise<void> {
|
||||||
|
await saveConfig(values);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
<Formik initialValues={getEffectiveConfig()}
|
<Formik initialValues={getEffectiveConfig()}
|
||||||
initialErrors={plugin.configValidation?.errors}
|
initialErrors={plugin.configValidation?.errors}
|
||||||
enableReinitialize={true}
|
enableReinitialize={true}
|
||||||
onSubmit={async (values: any) => {
|
onSubmit={handleSubmit}
|
||||||
await saveConfig(values);
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{(formik: any) => (
|
{(formik: any) => (
|
||||||
<Form>
|
<Form>
|
||||||
@@ -178,9 +190,11 @@ export default function PluginDetailsModal({plugin, isOpen, onOpenChange}: Plugi
|
|||||||
</Button> : ""}
|
</Button> : ""}
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)
|
||||||
|
}
|
||||||
</Formik>
|
</Formik>
|
||||||
)}
|
)
|
||||||
|
}}
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user