Skip to content

Commit

Permalink
Add label styling for tag group
Browse files Browse the repository at this point in the history
Additional changes: fix problem with chip groups disappearing when other
filter type was chosen.

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed May 10, 2024
1 parent ce32254 commit 08aaa0e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 48 deletions.
107 changes: 60 additions & 47 deletions client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react";
import {
Badge,
Button,
Label,
MenuToggle,
MenuToggleElement,
Select,
Expand Down Expand Up @@ -54,7 +55,7 @@ export const MultiselectFilterControl = <TItem,>({
.includes(inputValue?.trim().toLowerCase() ?? "")
);

const groups = [
const [firstGroup, ...otherGroups] = [

Check warning on line 58 in client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx#L58

Added line #L58 was not covered by tests
...new Set([
...(category.selectOptions
?.map(({ groupLabel }) => groupLabel)
Expand Down Expand Up @@ -225,60 +226,72 @@ export const MultiselectFilterControl = <TItem,>({

return (
<>
{groups.reduce(
(acc, groupName) => (
{[
<ToolbarFilter
id={`${idPrefix}-${firstGroup}`}
chips={chipsFor(firstGroup)}
deleteChip={(_, chip) => onFilterClear(chip)}
deleteChipGroup={() => onFilterClearAll(firstGroup)}

Check warning on line 234 in client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx#L233-L234

Added lines #L233 - L234 were not covered by tests
categoryName={firstGroup}
key={firstGroup}
showToolbarItem={showToolbarItem}
>
<Select
isScrollable={isScrollable}
aria-label={category.title}
toggle={toggle}
selected={filterValue}
onOpenChange={(isOpen) => setIsFilterDropdownOpen(isOpen)}
onSelect={(_, selection) => onSelect(selection as string)}

Check warning on line 245 in client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx#L244-L245

Added lines #L244 - L245 were not covered by tests
isOpen={isFilterDropdownOpen}
>
<SelectList id={withPrefix("select-typeahead-listbox")}>
{[
...filteredOptions.map(
({ groupLabel, label, value, optionProps = {} }, index) => (
<SelectOption

Check warning on line 252 in client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx#L252

Added line #L252 was not covered by tests
{...optionProps}
{...(!optionProps.isDisabled && { hasCheckbox: true })}
key={value}
id={withPrefix(`option-${index}`)}
value={value}
isFocused={focusedItemIndex === index}
isSelected={filterValue?.includes(value)}
>
{!!groupLabel && <Label>{groupLabel}</Label>}{" "}
{label ?? value}
</SelectOption>
)
),
!filteredOptions.length && (
<SelectOption

Check warning on line 267 in client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx#L267

Added line #L267 was not covered by tests
isDisabled
hasCheckbox={false}
key={NO_RESULTS}
value={NO_RESULTS}
isSelected={false}
>
{`No results found for "${inputValue}"`}
</SelectOption>
),
].filter(Boolean)}
</SelectList>
</Select>
</ToolbarFilter>,
...otherGroups.map((groupName) => (
<ToolbarFilter

Check warning on line 282 in client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx#L282

Added line #L282 was not covered by tests
id={`${idPrefix}-${groupName}`}
chips={chipsFor(groupName)}
deleteChip={(_, chip) => onFilterClear(chip)}
deleteChipGroup={() => onFilterClearAll(groupName)}

Check warning on line 286 in client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/FilterToolbar/MultiselectFilterControl.tsx#L285-L286

Added lines #L285 - L286 were not covered by tests
categoryName={groupName}
showToolbarItem={showToolbarItem}
key={groupName}
showToolbarItem={false}
>
{acc}
{" "}
</ToolbarFilter>
),
<Select
isScrollable={isScrollable}
aria-label={category.title}
toggle={toggle}
selected={filterValue}
onOpenChange={(isOpen) => setIsFilterDropdownOpen(isOpen)}
onSelect={(_, selection) => onSelect(selection as string)}
isOpen={isFilterDropdownOpen}
>
<SelectList id={withPrefix("select-typeahead-listbox")}>
{[
...filteredOptions.map(
({ label, value, optionProps = {} }, index) => (
<SelectOption
{...optionProps}
{...(!optionProps.isDisabled && { hasCheckbox: true })}
key={value}
id={withPrefix(`option-${index}`)}
value={value}
isFocused={focusedItemIndex === index}
isSelected={filterValue?.includes(value)}
>
{label ?? value}
</SelectOption>
)
),
!filteredOptions.length && (
<SelectOption
isDisabled
hasCheckbox={false}
key={NO_RESULTS}
value={NO_RESULTS}
isSelected={false}
>
{`No results found for "${inputValue}"`}
</SelectOption>
),
].filter(Boolean)}
</SelectList>
</Select>
)}
)),
]}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export const ApplicationsTable: React.FC = () => {
}) + "...",
selectOptions: tagItems.map(({ name, tagName, categoryName }) => ({
value: name,
label: name,
label: tagName,
chipLabel: tagName,
groupLabel: categoryName,
})),
Expand Down

0 comments on commit 08aaa0e

Please sign in to comment.