From 59a9458ca842d15e2eb35cddd75ae1b181a08b67 Mon Sep 17 00:00:00 2001 From: Clement Zhang Date: Thu, 7 Nov 2024 12:19:50 +0100 Subject: [PATCH] eval preserves labeled objects --- .../ArrayStaticInputEditor.svelte | 22 +++++++++---------- .../inputEditor/EvalV2InputEditor.svelte | 6 ++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/ArrayStaticInputEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/ArrayStaticInputEditor.svelte index cf8ad48b7a..9fb0741075 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/ArrayStaticInputEditor.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/ArrayStaticInputEditor.svelte @@ -11,7 +11,7 @@ import RefreshDatabaseStudioTable from './RefreshDatabaseStudioTable.svelte' import { isObjectOptionArray, isStringArray } from '$lib/components/multiselect/types' - export let componentInput: StaticInput & { loading?: boolean } + export let componentInput: StaticInput & { loading?: boolean; expr?: string } export let subFieldType: InputType | undefined = undefined export let selectOptions: StaticOptions['selectOptions'] | undefined = undefined export let id: string | undefined @@ -20,6 +20,15 @@ const dispatch = createEventDispatcher() const flipDurationMs = 200 + let items = getItems(componentInput) + let raw: boolean = false + let labeled: boolean = subFieldType === 'labeledselect' + + $: subFieldType === 'db-explorer' && clearTableOnComponentReset(componentInput?.value) + + $: labeled !== undefined && handleLabeledChange() + $: items !== undefined && handleItemsChange() + function addElementByType() { if (!Array.isArray(componentInput.value)) { componentInput.value = [] @@ -196,8 +205,6 @@ componentInput.value = reorderedValues } - let items = getItems(componentInput) - function getItems(componentInput: StaticInput & { loading?: boolean }) { return (Array.isArray(componentInput.value) ? componentInput.value : []) .filter((x) => x != undefined) @@ -212,14 +219,10 @@ } } - $: subFieldType === 'db-explorer' && clearTableOnComponentReset(componentInput?.value) - - let raw: boolean = false - let labeled: boolean = subFieldType === 'labeledselect' - function handleItemsChange() { const newComponentInput = { ...componentInput } newComponentInput.value = items.map((item) => item.value).filter((item) => item != undefined) + newComponentInput.expr = JSON.stringify(newComponentInput.value) const newSubFieldType = labeled ? 'labeledselect' : 'simplestringselect' @@ -241,9 +244,6 @@ } } - $: labeled !== undefined && handleLabeledChange() - $: items !== undefined && handleItemsChange() - // let mounted = false // $: if (componentInput.value && mounted) { diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/EvalV2InputEditor.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/EvalV2InputEditor.svelte index 5296fbc21c..ea99f0d08d 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/EvalV2InputEditor.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/inputEditor/EvalV2InputEditor.svelte @@ -30,6 +30,9 @@ editor?.setCode(code) } + let fullscreen = false + let focus = false + $: extraLib = componentInput?.expr && $worldStore ? buildExtraLib($worldStore?.outputsById ?? {}, acceptSelf ? '' : id, $state, false) @@ -52,9 +55,6 @@ inferDeps(code, $worldStore.outputsById, componentInput, app) } } - - let fullscreen = false - let focus = false {#if componentInput?.type === 'evalv2'}