Skip to content

Commit

Permalink
fix: prevent duplicate keys in filter options (#2640)
Browse files Browse the repository at this point in the history
Co-authored-by: sadaf895 <116058905+sadaf895@users.noreply.github.com>
  • Loading branch information
tomwwinter and sadaf895 authored Nov 14, 2024
1 parent 123154b commit 31d7ffd
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/app/core/filter/filters/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ export class SelectableFilter<T extends Entity> extends Filter<T> {
valuesToMatchAsOptions: (string | number)[],
attributeName: string,
): FilterSelectionOption<T>[] {
return valuesToMatchAsOptions
.filter((k) => !!k)
.map((k) => ({
key: k.toString().toLowerCase(),
label: k.toString(),
filter: { [attributeName]: k } as DataFilter<T>,
}));
let keys = new Set();
return (
valuesToMatchAsOptions
.filter((k) => !!k)
.map((k) => ({
key: k.toString().toLowerCase(),
label: k.toString(),
filter: { [attributeName]: k } as DataFilter<T>,
}))
// remove duplicates:
.filter((value) => !keys.has(value.key) && keys.add(value.key))
);
}

/**
Expand Down

0 comments on commit 31d7ffd

Please sign in to comment.