From 0ae0321e4b2d551ac7b5cf2af7ff0ab8a0a2655a Mon Sep 17 00:00:00 2001 From: Clement Zhang Date: Mon, 4 Nov 2024 17:35:21 +0100 Subject: [PATCH] fix default items --- .../components/inputs/AppMultiSelectV2.svelte | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/frontend/src/lib/components/apps/components/inputs/AppMultiSelectV2.svelte b/frontend/src/lib/components/apps/components/inputs/AppMultiSelectV2.svelte index 356d9cafb7..c72f341ac2 100644 --- a/frontend/src/lib/components/apps/components/inputs/AppMultiSelectV2.svelte +++ b/frontend/src/lib/components/apps/components/inputs/AppMultiSelectV2.svelte @@ -81,19 +81,12 @@ if (!Array.isArray(resolvedConfig.defaultItems)) { nvalue = [] } else { - nvalue = resolvedConfig.defaultItems?.map((item) => { - if (!item || typeof item !== 'object') { - console.error('Select component items should be an array of objects') - return { - label: 'not object', - value: 'not object' - } - } - return { - label: item?.label ?? 'undefined', - value: item?.value != undefined ? JSON.stringify(item.value) : 'undefined' - } - }) + let rawNvalue = new Set( + resolvedConfig.defaultItems?.map((value) => { + return typeof value === 'string' ? value : `NOT_STRING` + }) + ) + nvalue = items?.filter((item) => rawNvalue.has(item.value)) } value = [...new Set(nvalue)] outputs?.result.set([...(value ?? [])])