Skip to content

Commit

Permalink
fix(core/category-filter): options (#479)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Maurer <lukas.maurer@siemens.com>
  • Loading branch information
goncalosard and nuke-ellington committed Apr 18, 2023
1 parent 21eead6 commit 8ceaac6
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/core/src/components/category-filter/category-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class CategoryFilter {
return;
}

if (this.filterTokens.find((value) => value?.value === newToken)) {
if (this.hasToken(newToken)) {
return;
}

Expand Down Expand Up @@ -393,11 +393,28 @@ export class CategoryFilter {
return !isCategoryAlreadySet;
}

private hasToken(token: string) {
return this.filterTokens.some((filterToken) => {
const hasSameValue = filterToken.value === token;

if (!hasSameValue) {
return false;
}

if (this.category) {
return this.category === filterToken.id;
}

if (filterToken.id) {
return filterToken.id === this.ID_CUSTOM_FILTER_VALUE;
}

return hasSameValue;
});
}

private filterDuplicateTokens(value: string) {
const isTokenAlreadySet = this.filterTokens.some(
(token) => token.value === value
);
return !isTokenAlreadySet;
return !this.hasToken(value);
}

private filterByInput(value: string) {
Expand Down

0 comments on commit 8ceaac6

Please sign in to comment.