From 3e6ef6d5fbce4e6e476a01ada35486bff3a65611 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 17 Feb 2023 21:52:04 +0100 Subject: [PATCH] fix app select --- .../components/selectInputs/AppSelect.svelte | 24 ++++++++++++------- .../components/apps/editor/Component.svelte | 5 ---- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/frontend/src/lib/components/apps/components/selectInputs/AppSelect.svelte b/frontend/src/lib/components/apps/components/selectInputs/AppSelect.svelte index 70e4d39b24..9e69abac25 100644 --- a/frontend/src/lib/components/apps/components/selectInputs/AppSelect.svelte +++ b/frontend/src/lib/components/apps/components/selectInputs/AppSelect.svelte @@ -15,9 +15,7 @@ const { worldStore, connectingInput, selectedComponent } = getContext('AppEditorContext') - let label: string - let items: string[] - let itemKey: string + let items: { label: string; value: any }[] let multiple: boolean = false let placeholder: string = 'Select an item' @@ -25,13 +23,23 @@ result: Output } - let value = undefined + let value: string | undefined = undefined $: items && handleItems() + let listItems: { label: string; value: string }[] = [] + function handleItems() { + listItems = Array.isArray(items) + ? items.map((item) => { + return { + label: item.label, + value: JSON.stringify(item.value) + } + }) + : [] if (items?.[0]?.['value'] != value) { - value = items?.[0]?.['value'] + value = JSON.stringify(items?.[0]?.['value']) outputs?.result.set(value) } } @@ -39,13 +47,11 @@ function onChange(e: CustomEvent) { e?.stopPropagation() window.dispatchEvent(new Event('pointerup')) - outputs?.result.set(e.detail?.[itemKey] || undefined) + outputs?.result.set(JSON.parse(e.detail?.['value']) || undefined) } - - @@ -56,7 +62,7 @@ {multiple} on:clear={onChange} on:change={onChange} - items={Array.isArray(items) ? items : []} + items={listItems} {value} {placeholder} on:click={() => { diff --git a/frontend/src/lib/components/apps/editor/Component.svelte b/frontend/src/lib/components/apps/editor/Component.svelte index 4a899d0026..370cabe7fa 100644 --- a/frontend/src/lib/components/apps/editor/Component.svelte +++ b/frontend/src/lib/components/apps/editor/Component.svelte @@ -687,11 +687,6 @@ { value: 'bar', label: 'Bar' } ] }, - itemKey: { - type: 'static', - fieldType: 'text', - value: 'value' - }, multiple: { type: 'static', fieldType: 'boolean',