Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): Same filter can be applied multiple times #6219

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions ui/src/components/filter/KestraFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,23 @@
};
const valueCallback = (filter, isDate = false) => {
if (!isDate) {
const values = current.value[dropdowns.value.third.index].value;
const currentFilter = current.value[dropdowns.value.third.index];
const values = currentFilter.value;
const isDuplicateInOtherFilters = current.value.some((item, index) => {
return index !== dropdowns.value.third.index &&
item.label === currentFilter.label &&
item.value.includes(filter.value);
});

if (isDuplicateInOtherFilters) {
store.dispatch("core/showMessage", {
variant: "error",
title: t("duplicate filter"),
message: t("duplicate filter message", {filterName: currentFilter.label}),
});
return;
}

const index = values.indexOf(filter.value);

if (index === -1) values.push(filter.value);
Expand Down Expand Up @@ -376,17 +392,49 @@

if (typeof v.at(-1) === "string") {
if (v.at(-2)?.label === "labels") {
const labelValue = v.at(-1);
const isDuplicateInOtherFilters = current.value.some((item) => {
return item.label === "labels" &&
item !== v.at(-2) &&
item.value.includes(labelValue);
});

if (isDuplicateInOtherFilters) {
store.dispatch("core/showMessage", {
variant: "error",
title: t("duplicate filter"),
message: t("duplicate filter message", {filterName: labelValue}),
});
return;
}

// Adding labels to proper filter
v.at(-2).value?.push(v.at(-1));
closeDropdown();
triggerSearch();
} else {
// Adding text search string
const label = t("filters.options.text");
const index = current.value.findIndex((i) => i.label === label);
const newValue = v.at(-1);

// Check if this text already exists in any other filter
const isDuplicateInOtherFilters = current.value.some(item =>
item.label === label &&
item.value.includes(newValue)
);

if (isDuplicateInOtherFilters) {
store.dispatch("core/showMessage", {
variant: "error",
title: t("duplicate filter"),
message: t("duplicate filter message", {filterName: label}),
});
return;
}

if (index !== -1) current.value[index].value = [v.at(-1)];
else current.value.push({label, value: [v.at(-1)]});
const index = current.value.findIndex((i) => i.label === label);
if (index !== -1) current.value[index].value = [newValue];
else current.value.push({label, value: [newValue]});

triggerSearch();
}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@
"delete task confirm": "Do you want to delete the task <code>{taskId}</code>?",
"can not save": "Can not save",
"flow must have id and namespace": "Flow must have an id and a namespace.",
"duplicate filter": "Duplicate filter not allowed",
"duplicate filter message": "Duplicate filter `{filterName}` found, please remove it and choose another one.",
"readonly property": "Read-only property",
"namespace and id readonly": "The properties `namespace` and `id` cannot be changed — they are now set to their initial values. If you want to rename a flow or change its namespace, you can create a new flow and remove the old one.",
"avg": "Average",
Expand Down
Loading