diff --git a/frontend/src/routes/config-overview/+page.svelte b/frontend/src/routes/config-overview/+page.svelte index 196e9a09..d6682f10 100644 --- a/frontend/src/routes/config-overview/+page.svelte +++ b/frontend/src/routes/config-overview/+page.svelte @@ -19,19 +19,13 @@ $: modules = getModules(tag, device); $: modulesAnywhere = getModulesInstalledAnywhere(); - const getOrigin = (tag: Tag | undefined, device: Device | undefined) => { - if (tag) { - return tag.displayName; - } - - if (device) { - return device.displayName; - } + const getOrigin = (target: Tag | Device) => { + return target.displayName; }; const getModuleSettings = (tag: Tag | undefined, device: Device | undefined) => { if (tag) { - return tag.modules.map((m) => ({ origin: getOrigin(tag, undefined), ...m })); + return tag.modules.map((m) => ({ origin: getOrigin(tag), ...m })); } if (device) { @@ -39,10 +33,8 @@ (t) => data.state.tags.find((tag) => tag.displayName === t) ?? [] ); return [ - ...device.modules.map((m) => ({ origin: getOrigin(undefined, device), ...m })), - ...usedTags.flatMap((t) => - t.modules.map((m) => ({ origin: getOrigin(t, undefined), ...m })) - ) + ...device.modules.map((m) => ({ origin: getOrigin(device), ...m })), + ...usedTags.flatMap((t) => t.modules.map((m) => ({ origin: getOrigin(t), ...m }))) ]; } }; diff --git a/frontend/src/routes/config/+page.svelte b/frontend/src/routes/config/+page.svelte index 0f9d0e3a..3202f583 100644 --- a/frontend/src/routes/config/+page.svelte +++ b/frontend/src/routes/config/+page.svelte @@ -25,26 +25,18 @@ const deviceParam = queryParam('device'); const moduleParam = queryParam('module'); - let modules: Module[]; - $: tag = data.state.tags.find((t) => t.identifier === $tagParam); $: device = data.state.devices.find((d) => d.identifier === $deviceParam); $: modules = getModules(tag, device); $: selectedModule = data.availableModules.find((m) => m.type === $moduleParam); - const getOrigin = (tag: Tag | undefined, device: Device | undefined) => { - if (tag) { - return tag.displayName; - } - - if (device) { - return device.displayName; - } + const getOrigin = (target: Tag | Device | undefined) => { + return target?.displayName; }; const getModuleSettings = (tag: Tag | undefined, device: Device | undefined) => { if (tag) { - return tag.modules.map((m) => ({ origin: getOrigin(tag, undefined), ...m })); + return tag.modules.map((m) => ({ origin: getOrigin(tag), ...m })); } if (device) { @@ -52,10 +44,8 @@ (t) => data.state.tags.find((tag) => tag.displayName === t) ?? [] ); return [ - ...device.modules.map((m) => ({ origin: getOrigin(undefined, device), ...m })), - ...usedTags.flatMap((t) => - t.modules.map((m) => ({ origin: getOrigin(t, undefined), ...m })) - ) + ...device.modules.map((m) => ({ origin: getOrigin(device), ...m })), + ...usedTags.flatMap((t) => t.modules.map((m) => ({ origin: getOrigin(t), ...m }))) ]; } }; @@ -251,7 +241,7 @@
{effectingSetting.origin}: {effectingSetting.settings[settingKey].value}
{/each} - {#if effectingSettings.reverse()[0].origin == getOrigin(tag, device)} + {#if effectingSettings.reverse()[0].origin == getOrigin(tag ?? device)}