From 71badb959d298e76802aebd47acc03f685e8f498 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Mon, 29 Jul 2024 20:21:39 +0200 Subject: [PATCH] fix(frontend): Fix how new items are processed in App select (#4109) * fix(frontend): Fix how new items are procesed * fix(frontend): Fix regex Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> * fix(frontend): avoid duplicates * fix(frontend): simplify code --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- .../apps/components/inputs/AppSelect.svelte | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/frontend/src/lib/components/apps/components/inputs/AppSelect.svelte b/frontend/src/lib/components/apps/components/inputs/AppSelect.svelte index 8cc19b9edb..136e06517b 100644 --- a/frontend/src/lib/components/apps/components/inputs/AppSelect.svelte +++ b/frontend/src/lib/components/apps/components/inputs/AppSelect.svelte @@ -164,14 +164,23 @@ let css = initCss($app.css?.selectcomponent, customCss) + let previsousFilter = '' + function handleFilter(e) { - if (resolvedConfig.create) { - if (e.detail.length === 0 && filterText.length > 0) { - const prev = listItems.filter((i) => !i.created) - listItems = [ - ...prev, - { value: JSON.stringify(filterText), label: filterText, created: true } - ] + if (resolvedConfig.create && filterText !== previsousFilter) { + previsousFilter = filterText + if (filterText.length > 0) { + const prev = listItems?.filter((i) => !i.created) + + const exists = listItems?.some( + (item) => item.label.toLowerCase() === filterText.toLowerCase() + ) + if (!exists) { + listItems = [ + ...prev, + { value: JSON.stringify(filterText), label: filterText, created: true } + ] + } } } }