diff --git a/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx b/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx index 2d7ec1795..6d92efabe 100644 --- a/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx +++ b/client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx @@ -14,6 +14,7 @@ import { ToolbarChip, ToolbarFilter, } from "@patternfly/react-core"; +import { CaretDownIcon, CaretRightIcon } from "@patternfly/react-icons"; import { IFilterControlProps } from "./FilterControl"; import { FilterSelectOptionProps, @@ -229,6 +230,24 @@ export const MultiselectFilterControl = ({ const withGroupPrefix = (group: string) => group === category.title ? group : `${category.title}/${group}`; + const groups = Array.from( + new Set( + filteredOptions + .filter((item) => item && item.groupLabel) + .map((item) => item.groupLabel) + ) + ); + + const [openGroups, setOpenGroups] = React.useState([]); + + const toggleGroup = (groupLabel: string) => { + setOpenGroups((prev) => + prev.includes(groupLabel) + ? prev.filter((label) => label !== groupLabel) + : [...prev, groupLabel] + ); + }; + return ( <> { @@ -250,35 +269,80 @@ export const MultiselectFilterControl = ({ onSelect={(_, selection) => onSelect(selection as string)} isOpen={isFilterDropdownOpen} > - - {filteredOptions.map( - ({ groupLabel, label, value, optionProps = {} }, index) => ( + {groups && groups.length > 0 && ( + + {groups.map((groupLabel) => ( + +
{ + toggleGroup(groupLabel!); + }} + > + + {openGroups.includes(groupLabel!) ? ( + + ) : ( + + )} + {groupLabel} + +
+ {openGroups.includes(groupLabel!) && + filteredOptions + .filter((option) => option.groupLabel === groupLabel) + .map(({ label, value, optionProps = {} }, index) => ( + + {label ?? value} + + ))} +
+ ))} +
+ )} + {(!groups || groups.length == 0) && ( + + {filteredOptions.map( + ({ groupLabel, label, value, optionProps = {} }, index) => ( + + {!!groupLabel && }{" "} + {label ?? value} + + ) + )} + {filteredOptions.length === 0 && ( - {!!groupLabel && }{" "} - {label ?? value} + {`No results found for "${inputValue}"`} - ) - )} - {filteredOptions.length === 0 && ( - - {`No results found for "${inputValue}"`} - - )} - + )} +
+ )} }