Skip to content
Snippets Groups Projects
Unverified Commit 56c5a533 authored by Sebastian Civarolo's avatar Sebastian Civarolo Committed by GitHub
Browse files

Fix false positives for duplicate filters error when saving a new filter (#2970)

* update conditionExists function to compare filter options

* rename method

* array.some instead of for loop

* release note

* refactor the condition search
parent 7e3ff1ad
No related branches found
No related tags found
No related merge requests found
...@@ -56,50 +56,58 @@ async function filterNameExists(name, filterId, newItem) { ...@@ -56,50 +56,58 @@ async function filterNameExists(name, filterId, newItem) {
return true; return true;
} }
//TODO: Possible to simplify this?
//use filters and maps
function conditionExists(item, filters, newItem) { function conditionExists(item, filters, newItem) {
const { conditions, conditionsOp } = item; const { conditions, conditionsOp } = item;
let condCheck = []; let fConditionFound = null;
let fCondCheck = false;
let fCondFound;
filters.map(filter => { filters.some(filter => {
if ( if (
!fCondCheck && (conditions.length === 1 || filter.conditionsOp === conditionsOp) &&
//If conditions.length equals 1 then ignore conditionsOp
(conditions.length === 1 ? true : filter.conditionsOp === conditionsOp) &&
!filter.tombstone && !filter.tombstone &&
filter.conditions.length === conditions.length filter.conditions.length === conditions.length
) { ) {
fCondCheck = false; const allConditionsMatch = !conditions.some(
conditions.map((cond, i) => { cond =>
condCheck[i] = !filter.conditions.some(
filter.conditions.filter(fcond => { fcond =>
return (
cond.value === fcond.value && cond.value === fcond.value &&
cond.op === fcond.op && cond.op === fcond.op &&
cond.field === fcond.field cond.field === fcond.field &&
); filterOptionsMatch(cond.options, fcond.options),
}).length > 0; ),
fCondCheck = (i === 0 ? true : fCondCheck) && condCheck[i]; );
if (allConditionsMatch) {
fConditionFound = filter;
return true; return true;
}); }
fCondFound = fCondCheck && condCheck[conditions.length - 1] && filter;
} }
return true; return false;
}); });
condCheck = [];
if (!newItem) { if (!newItem) {
return fCondFound return fConditionFound
? fCondFound.id !== item.id ? fConditionFound.id !== item.id
? fCondFound.name ? fConditionFound.name
: false : false
: false; : false;
} }
return fCondFound ? fCondFound.name : false;
return fConditionFound ? fConditionFound.name : false;
}
function filterOptionsMatch(options1, options2) {
const opt1 = options1 ?? {};
const opt2 = options2 ?? {};
const keys1 = Object.keys(opt1);
const keys2 = Object.keys(opt2);
if (keys1.length !== keys2.length) {
return false;
}
return keys1.every(key => opt1[key] === opt2[key]);
} }
async function createFilter(filter) { async function createFilter(filter) {
......
---
category: Bugfix
authors: [scivarolo]
---
Fix false positives for duplicate filters error when saving a new filter.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment