From c4e451347c426f0aed695a298a7a68ecf09c77f4 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Tue, 22 Aug 2023 16:46:24 +0200 Subject: [PATCH] Fix app list (#2152) * fix(frontend): Fix app list pagination * fix(frontend): make minimal changes * fix(frontend): make minimal changes * fix(frontend): make minimal changes * fix(frontend): revert unecessary changes * fix(frontend): done * fix(frontend): revert unnecessary changes * fix(frontend): remove code duplication * fix(frontend): remove code duplication --- .../lib/components/apps/editor/appUtils.ts | 35 ++++++++++++------- .../OneOfInputSpecsEditor.svelte | 11 ++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/frontend/src/lib/components/apps/editor/appUtils.ts b/frontend/src/lib/components/apps/editor/appUtils.ts index bb748a3714..9a8f85f292 100644 --- a/frontend/src/lib/components/apps/editor/appUtils.ts +++ b/frontend/src/lib/components/apps/editor/appUtils.ts @@ -4,6 +4,7 @@ import type { ConnectingInput, EditorBreakpoint, FocusedGrid, + GeneralAppInput, GridItem } from '../types' import { @@ -215,6 +216,18 @@ function cleanseValue(key: string, value: { type: 'eval' | 'static'; value?: any return [key, { type: value.type, expr: value.expr }] } } + +export function cleanseOneOfConfiguration( + configuration: Record> +) { + return Object.fromEntries( + Object.entries(configuration).map(([key, val]) => [ + key, + Object.fromEntries(Object.entries(val).map(([key, val]) => cleanseValue(key, val))) + ]) + ) +} + export function appComponentFromType( type: T, overrideConfiguration?: Partial @@ -232,14 +245,7 @@ export function appComponentFromType( { type: value.type, selected: value.selected, - configuration: Object.fromEntries( - Object.entries(value.configuration).map(([key, val]) => [ - key, - Object.fromEntries( - Object.entries(val).map(([key, val]) => cleanseValue(key, val)) - ) - ]) - ) + configuration: cleanseOneOfConfiguration(value.configuration) } ] } @@ -521,10 +527,15 @@ export function initConfig< selected: value.selected, type: 'oneOf', configuration: Object.fromEntries( - Object.entries(value.configuration).map(([choice, config]) => [ - choice, - initConfig(config, configuration?.[key]?.configuration?.[choice]) - ]) + Object.entries(value.configuration).map(([choice, config]) => { + const conf = initConfig(config, configuration?.[key]?.configuration?.[choice]) + Object.entries(config).forEach(([innerKey, innerValue]) => { + if (innerValue.type === 'static' && !(innerKey in conf)) { + conf[innerKey] = innerValue.value + } + }) + return [choice, conf] + }) ) } ] diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/OneOfInputSpecsEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/OneOfInputSpecsEditor.svelte index 7894ed7b95..f7c0eb8d96 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/OneOfInputSpecsEditor.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/OneOfInputSpecsEditor.svelte @@ -2,6 +2,7 @@ import Tooltip from '$lib/components/Tooltip.svelte' import { addWhitespaceBeforeCapitals, capitalize } from '$lib/utils' import type { RichConfiguration } from '../../types' + import { cleanseOneOfConfiguration } from '../appUtils' import InputsSpecEditor from './InputsSpecEditor.svelte' export let key: string @@ -26,6 +27,16 @@ if (oneOf?.configuration[oneOf?.selected] == undefined) { oneOf.configuration[oneOf.selected] = {} } + + // If the configuration is empty, we set the first one as selected. + // It happens when the configuration was added after the component was created + if (oneOf.selected === '') { + oneOf = { + configuration: cleanseOneOfConfiguration(inputSpecsConfiguration), + selected: Object.keys(inputSpecsConfiguration ?? {})[0], + type: 'oneOf' + } + } }