Add support for lists in module option

This feature allows a module maker to use a list as the different possible values for a module integration.
This commit is contained in:
Thomas Camlong
2022-06-28 11:27:23 +02:00
parent 9945ef892e
commit e93a3a3b5f
2 changed files with 41 additions and 3 deletions

View File

@@ -1,10 +1,18 @@
import { Button, Card, Group, Menu, Switch, TextInput, useMantineColorScheme } from '@mantine/core';
import {
Button,
Card,
Group,
Menu,
MultiSelect,
Switch,
TextInput,
useMantineColorScheme,
} from '@mantine/core';
import { useConfig } from '../../tools/state';
import { IModule } from './modules';
function getItems(module: IModule) {
const { config, setConfig } = useConfig();
const enabledModules = config.modules ?? {};
const items: JSX.Element[] = [];
if (module.options) {
const keys = Object.keys(module.options);
@@ -15,6 +23,35 @@ function getItems(module: IModule) {
types.forEach((type, index) => {
const optionName = `${module.title}.${keys[index]}`;
const moduleInConfig = config.modules?.[module.title];
if (type === 'object') {
items.push(
<MultiSelect
label={module.options?.[keys[index]].name}
data={module.options?.[keys[index]].options ?? []}
defaultValue={(moduleInConfig?.options?.[keys[index]]?.value as string[]) ?? []}
clearable
searchable
onChange={(value) => {
setConfig({
...config,
modules: {
...config.modules,
[module.title]: {
...moduleInConfig,
options: {
...moduleInConfig?.options,
[keys[index]]: {
...moduleInConfig?.options?.[keys[index]],
value,
},
},
},
},
});
}}
/>
);
}
if (type === 'string') {
items.push(
<form

View File

@@ -16,5 +16,6 @@ interface Option {
export interface OptionValues {
name: string;
value: boolean | string;
value: boolean | string | string[];
options?: string[];
}