mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-29 02:54:09 -05:00
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
This commit is contained in:
committed by
GitHub
parent
7e3ff1ad03
commit
56c5a533e7
@@ -56,50 +56,58 @@ async function filterNameExists(name, filterId, newItem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO: Possible to simplify this?
|
||||
//use filters and maps
|
||||
function conditionExists(item, filters, newItem) {
|
||||
const { conditions, conditionsOp } = item;
|
||||
let condCheck = [];
|
||||
let fCondCheck = false;
|
||||
let fCondFound;
|
||||
let fConditionFound = null;
|
||||
|
||||
filters.map(filter => {
|
||||
filters.some(filter => {
|
||||
if (
|
||||
!fCondCheck &&
|
||||
//If conditions.length equals 1 then ignore conditionsOp
|
||||
(conditions.length === 1 ? true : filter.conditionsOp === conditionsOp) &&
|
||||
(conditions.length === 1 || filter.conditionsOp === conditionsOp) &&
|
||||
!filter.tombstone &&
|
||||
filter.conditions.length === conditions.length
|
||||
) {
|
||||
fCondCheck = false;
|
||||
conditions.map((cond, i) => {
|
||||
condCheck[i] =
|
||||
filter.conditions.filter(fcond => {
|
||||
return (
|
||||
const allConditionsMatch = !conditions.some(
|
||||
cond =>
|
||||
!filter.conditions.some(
|
||||
fcond =>
|
||||
cond.value === fcond.value &&
|
||||
cond.op === fcond.op &&
|
||||
cond.field === fcond.field
|
||||
);
|
||||
}).length > 0;
|
||||
fCondCheck = (i === 0 ? true : fCondCheck) && condCheck[i];
|
||||
cond.field === fcond.field &&
|
||||
filterOptionsMatch(cond.options, fcond.options),
|
||||
),
|
||||
);
|
||||
|
||||
if (allConditionsMatch) {
|
||||
fConditionFound = filter;
|
||||
return true;
|
||||
});
|
||||
fCondFound = fCondCheck && condCheck[conditions.length - 1] && filter;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
|
||||
condCheck = [];
|
||||
|
||||
if (!newItem) {
|
||||
return fCondFound
|
||||
? fCondFound.id !== item.id
|
||||
? fCondFound.name
|
||||
return fConditionFound
|
||||
? fConditionFound.id !== item.id
|
||||
? fConditionFound.name
|
||||
: 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) {
|
||||
|
||||
6
upcoming-release-notes/2970.md
Normal file
6
upcoming-release-notes/2970.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Bugfix
|
||||
authors: [scivarolo]
|
||||
---
|
||||
|
||||
Fix false positives for duplicate filters error when saving a new filter.
|
||||
Reference in New Issue
Block a user