From 608aa06b2e9861a478087b592dbef18e91aafabc Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 26 Aug 2025 09:59:38 -0500 Subject: [PATCH 1/3] minor change --- .../instruction-components/instruction-agent.svelte | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/routes/page/instruction/instruction-components/instruction-agent.svelte b/src/routes/page/instruction/instruction-components/instruction-agent.svelte index 4d3559c9..b535f66a 100644 --- a/src/routes/page/instruction/instruction-components/instruction-agent.svelte +++ b/src/routes/page/instruction/instruction-components/instruction-agent.svelte @@ -22,13 +22,18 @@ let selectedTemplate = null; $: { - collectAgentOptions(agents); + initAgentOptions(agents); } /** * @param {import('$agentTypes').AgentModel[]} agents */ - function collectAgentOptions(agents) { + function initAgentOptions(agents) { + agentOptions = []; + templateOptions = []; + selectedAgent = null; + selectedTemplate = null; + agentOptions = agents?.map(x => ({ label: x.name, value: x.id From e1bea0a06cfcbe15c9bab5f414810b2d3d4c80c9 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 26 Aug 2025 11:09:08 -0500 Subject: [PATCH 2/3] refine select component --- src/lib/common/Select.svelte | 48 ++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/lib/common/Select.svelte b/src/lib/common/Select.svelte index f98a1278..47083a01 100644 --- a/src/lib/common/Select.svelte +++ b/src/lib/common/Select.svelte @@ -72,6 +72,11 @@ /** @type {boolean} */ let loading = false; + /** + * @type {number | undefined} + */ + let timer; + onMount(() => { initOptions(); }); @@ -79,8 +84,6 @@ $: { innerOptions = verifySelectedOptions(innerOptions, selectedValues); refOptions = verifySelectedOptions(innerOptions, selectedValues); - applySearchFilter(); - changeDisplayText(); } $: { @@ -105,22 +108,22 @@ ...newOptions ]; - changeDisplayText(); - } else { - applySearchFilter(); - changeDisplayText(); } } else { innerOptions = verifySelectedOptions(options, selectedValues); refOptions = verifySelectedOptions(options, selectedValues); + } + } + + $: { + if (innerOptions && refOptions) { applySearchFilter(); changeDisplayText(); } } - function initOptions() { - innerOptions = options.map(x => { + const newInnerOptions = options.map(x => { return { label: x.label, value: x.value, @@ -128,13 +131,16 @@ } }); - refOptions = options.map(x => { + const newRefOptions = options.map(x => { return { label: x.label, value: x.value, checked: false } }); + + innerOptions = newInnerOptions; + refOptions = newRefOptions; } /** @@ -167,8 +173,11 @@ /** @param {any} e */ function changeSearchValue(e) { searchValue = e.target.value || ''; - applySearchFilter(); - verifySelectAll(); + clearTimeout(timer); + timer = setTimeout(() => { + applySearchFilter(); + verifySelectAll(); + }, 500); } function applySearchFilter() { @@ -186,7 +195,7 @@ * @param {any} option */ function checkOption(e, option) { - innerOptions = innerOptions.map(x => { + const newInnerOptions = innerOptions.map(x => { const item = { ...x }; if (item.value == option.value) { item.checked = e == null ? !item.checked : e.target.checked; @@ -196,7 +205,7 @@ return item; }); - refOptions = refOptions.map(x => { + const newRefOptions = refOptions.map(x => { const item = { ...x }; if (item.value == option.value) { item.checked = e == null ? !item.checked : e.target.checked; @@ -206,7 +215,9 @@ return item; }); - changeDisplayText(); + innerOptions = newInnerOptions; + refOptions = newRefOptions; + sendEvent(); hideOptionList(); } @@ -219,7 +230,6 @@ }); syncChangesToRef(selectAllChecked); - changeDisplayText(); sendEvent(); } @@ -320,15 +330,17 @@ } function clearSelection() { - innerOptions = innerOptions.map(x => { + const newInnerOptions = innerOptions.map(x => { return { ...x, checked: false } }); - refOptions = refOptions.map(x => { + const newRefOptions = refOptions.map(x => { return { ...x, checked: false } }); - changeDisplayText(); + innerOptions = newInnerOptions; + refOptions = newRefOptions; + sendEvent(); hideOptionList(); } From 9ff2c838b6628e75e1de28d1b2f5b46d6f576a4a Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 26 Aug 2025 11:10:41 -0500 Subject: [PATCH 3/3] minor change --- src/lib/common/Select.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/common/Select.svelte b/src/lib/common/Select.svelte index 47083a01..10089280 100644 --- a/src/lib/common/Select.svelte +++ b/src/lib/common/Select.svelte @@ -173,7 +173,11 @@ /** @param {any} e */ function changeSearchValue(e) { searchValue = e.target.value || ''; - clearTimeout(timer); + + if (timer) { + clearTimeout(timer); + } + timer = setTimeout(() => { applySearchFilter(); verifySelectAll();