From 31d7ffde85169ed584f34e8b03a3207ba61649c0 Mon Sep 17 00:00:00 2001 From: Tom Winter Date: Thu, 14 Nov 2024 12:59:55 +0100 Subject: [PATCH] fix: prevent duplicate keys in filter options (#2640) Co-authored-by: sadaf895 <116058905+sadaf895@users.noreply.github.com> --- src/app/core/filter/filters/filters.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app/core/filter/filters/filters.ts b/src/app/core/filter/filters/filters.ts index 2e06c14640..ddf6aab69e 100644 --- a/src/app/core/filter/filters/filters.ts +++ b/src/app/core/filter/filters/filters.ts @@ -78,13 +78,18 @@ export class SelectableFilter extends Filter { valuesToMatchAsOptions: (string | number)[], attributeName: string, ): FilterSelectionOption[] { - return valuesToMatchAsOptions - .filter((k) => !!k) - .map((k) => ({ - key: k.toString().toLowerCase(), - label: k.toString(), - filter: { [attributeName]: k } as DataFilter, - })); + let keys = new Set(); + return ( + valuesToMatchAsOptions + .filter((k) => !!k) + .map((k) => ({ + key: k.toString().toLowerCase(), + label: k.toString(), + filter: { [attributeName]: k } as DataFilter, + })) + // remove duplicates: + .filter((value) => !keys.has(value.key) && keys.add(value.key)) + ); } /**