From ec89848d558ba44a1701a9e12eaccd3f2e8f8ecc Mon Sep 17 00:00:00 2001 From: kratosmy Date: Sat, 30 Nov 2024 16:18:10 +0800 Subject: [PATCH] fix(ui): Same filter can be applied multiple times --- ui/src/components/filter/KestraFilter.vue | 28 +++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/ui/src/components/filter/KestraFilter.vue b/ui/src/components/filter/KestraFilter.vue index 06136b30d81..25750ee99b8 100644 --- a/ui/src/components/filter/KestraFilter.vue +++ b/ui/src/components/filter/KestraFilter.vue @@ -244,11 +244,20 @@ }; const valueCallback = (filter, isDate = false) => { if (!isDate) { - const values = current.value[dropdowns.value.third.index].value; - const index = values.indexOf(filter.value); - - if (index === -1) values.push(filter.value); - else values.splice(index, 1); + const currentFilter = current.value[dropdowns.value.third.index]; + const label = currentFilter.label; + const existingIndex = current.value.findIndex(i => i.label === label); + + if (existingIndex !== -1 && existingIndex !== dropdowns.value.third.index) { + current.value[existingIndex].value = [filter.value]; + current.value.splice(dropdowns.value.third.index, 1); + dropdowns.value.third.index = existingIndex; + } else { + const values = currentFilter.value; + const index = values.indexOf(filter.value); + if (index === -1) values.push(filter.value); + else values.splice(index, 1); + } // Update the hover index for better UX const hoverIndex = valueOptions.value.findIndex( @@ -411,7 +420,12 @@ if (typeof v.at(-1) === "string") { if (v.at(-2)?.label === "labels") { // Adding labels to proper filter - v.at(-2).value?.push(v.at(-1)); + const existingIndex = current.value.findIndex(i => i.label === "labels"); + if (existingIndex !== -1) { + current.value[existingIndex].value.push(v.at(-1)); + } else { + current.value.push({label: "labels", value: [v.at(-1)]}); + } closeDropdown(); triggerSearch(); } else { @@ -566,4 +580,4 @@ bottom: -0.15rem; } } - + \ No newline at end of file