From 47a076e4ada33bc4c39451c0487bf16cfa54281c Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Thu, 6 Jun 2024 14:08:29 -0400 Subject: [PATCH] Limit tag label grouping by categorykey Signed-off-by: Ian Bolton --- .../MultiselectFilterControl.tsx | 149 +++++++++--------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx b/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx index cebddd971d..4c8715873f 100644 --- a/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx +++ b/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx @@ -57,14 +57,21 @@ export const MultiselectFilterControl = ({ .some((it) => it.includes(inputValue?.trim().toLowerCase() ?? "")) ); - const [firstGroup, ...otherGroups] = [ - ...new Set([ - ...(category.selectOptions - ?.map(({ groupLabel }) => groupLabel) - .filter(Boolean) ?? []), - defaultGroup, - ]), - ]; + const groupLabels = React.useMemo(() => { + if (category.categoryKey === "tags") { + return [ + ...new Set([ + ...(category.selectOptions + ?.map(({ groupLabel }) => groupLabel) + .filter(Boolean) ?? []), + defaultGroup, + ]), + ]; + } + return [defaultGroup]; + }, [category.selectOptions, defaultGroup, category.categoryKey]); + + const [firstGroup, ...otherGroups] = groupLabels; const onFilterClearGroup = (groupName: string) => setFilterValue( @@ -78,21 +85,17 @@ export const MultiselectFilterControl = ({ filter, groupLabel, ]) - .filter(([, groupLabel]) => groupLabel != groupName) + .filter(([, groupLabel]) => groupLabel !== groupName) .map(([filter]) => filter) ); const onFilterClear = (chip: string | ToolbarChip) => { const value = typeof chip === "string" ? chip : chip.key; - if (value) { const newValue = filterValue?.filter((val) => val !== value) ?? []; setFilterValue(newValue.length > 0 ? newValue : null); } }; - /* - * Note: Create chips only as `ToolbarChip` (no plain string) - */ const chipsFor = (groupName: string) => filterValue ?.map((filter) => @@ -105,7 +108,6 @@ export const MultiselectFilterControl = ({ .map((option) => { const { chipLabel, label, value } = option; const displayValue: string = chipLabel ?? label ?? value ?? ""; - return { key: value, node: displayValue, @@ -204,7 +206,6 @@ export const MultiselectFilterControl = ({ isExpanded={isFilterDropdownOpen} aria-controls={withPrefix("select-typeahead-listbox")} /> - {!!inputValue && (