Skip to content

Commit 1a615ce

Browse files
committed
fix: streamline filter removal logic in filtersTools module
1 parent 06e7908 commit 1a615ce

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

adminforth/modules/filtersTools.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,24 @@ export const filtersTools = {
1111
if (!Array.isArray(query.filters)) {
1212
throw new Error('query.filters is not an array');
1313
}
14-
14+
1515
if (!this.checkTopFilterExists(field)) {
1616
throw new Error(`Top-level filter for field "${field}" not found`);
1717
}
18-
19-
query.filters = query.filters.filter((f: any) => f.field !== field);
18+
19+
this.removeTopFilterIfExists(field);
2020
},
21-
21+
2222
removeTopFilterIfExists(field: string) {
23-
try {
24-
this.removeTopFilter(field);
25-
} catch (e) {
26-
console.log(e);
27-
}
23+
if (!Array.isArray(query.filters)) return;
24+
query.filters = query.filters.filter((f: any) => f.field !== field);
2825
},
2926

3027
replaceOrAddTopFilter(filter: { field: string; value: any; operator: string }) {
31-
if (!Array.isArray(query.filters)) query.filters = [];
32-
this.removeTopFilterIfExists(filter.field);
33-
query.filters.push(filter);
34-
}
28+
if (!Array.isArray(query.filters)) query.filters = [];
29+
this.removeTopFilterIfExists(filter.field);
30+
query.filters.push(filter);
31+
}
3532
};
3633
}
3734
};

0 commit comments

Comments
 (0)