mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 15:35:55 +01:00
✨ 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:
@@ -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 { useConfig } from '../../tools/state';
|
||||||
import { IModule } from './modules';
|
import { IModule } from './modules';
|
||||||
|
|
||||||
function getItems(module: IModule) {
|
function getItems(module: IModule) {
|
||||||
const { config, setConfig } = useConfig();
|
const { config, setConfig } = useConfig();
|
||||||
const enabledModules = config.modules ?? {};
|
|
||||||
const items: JSX.Element[] = [];
|
const items: JSX.Element[] = [];
|
||||||
if (module.options) {
|
if (module.options) {
|
||||||
const keys = Object.keys(module.options);
|
const keys = Object.keys(module.options);
|
||||||
@@ -15,6 +23,35 @@ function getItems(module: IModule) {
|
|||||||
types.forEach((type, index) => {
|
types.forEach((type, index) => {
|
||||||
const optionName = `${module.title}.${keys[index]}`;
|
const optionName = `${module.title}.${keys[index]}`;
|
||||||
const moduleInConfig = config.modules?.[module.title];
|
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') {
|
if (type === 'string') {
|
||||||
items.push(
|
items.push(
|
||||||
<form
|
<form
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ interface Option {
|
|||||||
|
|
||||||
export interface OptionValues {
|
export interface OptionValues {
|
||||||
name: string;
|
name: string;
|
||||||
value: boolean | string;
|
value: boolean | string | string[];
|
||||||
|
options?: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user