Skip to content

Commit a289e19

Browse files
committed
Implement review suggestions
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
1 parent 2542d4c commit a289e19

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

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

+48-48
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ export const MultiselectFilterControl = <TItem,>({
4949
const withPrefix = (id: string) => `${idPrefix}-${id}`;
5050
const defaultGroup = category.title;
5151

52-
const filteredOptions = category.selectOptions?.filter(({ label, value }) =>
53-
String(label ?? value ?? "")
54-
.toLowerCase()
55-
.includes(inputValue?.trim().toLowerCase() ?? "")
52+
const filteredOptions = category.selectOptions?.filter(
53+
({ label, value, groupLabel }) =>
54+
[label ?? value, groupLabel]
55+
.filter(Boolean)
56+
.map((it) => it.toLocaleLowerCase())
57+
.some((it) => it.includes(inputValue?.trim().toLowerCase() ?? ""))
5658
);
5759

5860
const [firstGroup, ...otherGroups] = [
@@ -64,7 +66,7 @@ export const MultiselectFilterControl = <TItem,>({
6466
]),
6567
];
6668

67-
const onFilterClearAll = (groupName: string) =>
69+
const onFilterClearGroup = (groupName: string) =>
6870
setFilterValue(
6971
filterValue
7072
?.map((filter): [string, FilterSelectOptionProps | undefined] => [
@@ -226,12 +228,12 @@ export const MultiselectFilterControl = <TItem,>({
226228

227229
return (
228230
<>
229-
{[
231+
{
230232
<ToolbarFilter
231233
id={`${idPrefix}-${firstGroup}`}
232234
chips={chipsFor(firstGroup)}
233235
deleteChip={(_, chip) => onFilterClear(chip)}
234-
deleteChipGroup={() => onFilterClearAll(firstGroup)}
236+
deleteChipGroup={() => onFilterClearGroup(firstGroup)}
235237
categoryName={firstGroup}
236238
key={firstGroup}
237239
showToolbarItem={showToolbarItem}
@@ -246,52 +248,50 @@ export const MultiselectFilterControl = <TItem,>({
246248
isOpen={isFilterDropdownOpen}
247249
>
248250
<SelectList id={withPrefix("select-typeahead-listbox")}>
249-
{[
250-
...filteredOptions.map(
251-
({ groupLabel, label, value, optionProps = {} }, index) => (
252-
<SelectOption
253-
{...optionProps}
254-
{...(!optionProps.isDisabled && { hasCheckbox: true })}
255-
key={value}
256-
id={withPrefix(`option-${index}`)}
257-
value={value}
258-
isFocused={focusedItemIndex === index}
259-
isSelected={filterValue?.includes(value)}
260-
>
261-
{!!groupLabel && <Label>{groupLabel}</Label>}{" "}
262-
{label ?? value}
263-
</SelectOption>
264-
)
265-
),
266-
!filteredOptions.length && (
251+
{filteredOptions.map(
252+
({ groupLabel, label, value, optionProps = {} }, index) => (
267253
<SelectOption
268-
isDisabled
269-
hasCheckbox={false}
270-
key={NO_RESULTS}
271-
value={NO_RESULTS}
272-
isSelected={false}
254+
{...optionProps}
255+
{...(!optionProps.isDisabled && { hasCheckbox: true })}
256+
key={value}
257+
id={withPrefix(`option-${index}`)}
258+
value={value}
259+
isFocused={focusedItemIndex === index}
260+
isSelected={filterValue?.includes(value)}
273261
>
274-
{`No results found for "${inputValue}"`}
262+
{!!groupLabel && <Label>{groupLabel}</Label>}{" "}
263+
{label ?? value}
275264
</SelectOption>
276-
),
277-
].filter(Boolean)}
265+
)
266+
)}
267+
{filteredOptions.length === 0 && (
268+
<SelectOption
269+
isDisabled
270+
hasCheckbox={false}
271+
key={NO_RESULTS}
272+
value={NO_RESULTS}
273+
isSelected={false}
274+
>
275+
{`No results found for "${inputValue}"`}
276+
</SelectOption>
277+
)}
278278
</SelectList>
279279
</Select>
280-
</ToolbarFilter>,
281-
...otherGroups.map((groupName) => (
282-
<ToolbarFilter
283-
id={`${idPrefix}-${groupName}`}
284-
chips={chipsFor(groupName)}
285-
deleteChip={(_, chip) => onFilterClear(chip)}
286-
deleteChipGroup={() => onFilterClearAll(groupName)}
287-
categoryName={groupName}
288-
key={groupName}
289-
showToolbarItem={false}
290-
>
291-
{" "}
292-
</ToolbarFilter>
293-
)),
294-
]}
280+
</ToolbarFilter>
281+
}
282+
{otherGroups.map((groupName) => (
283+
<ToolbarFilter
284+
id={`${idPrefix}-${groupName}`}
285+
chips={chipsFor(groupName)}
286+
deleteChip={(_, chip) => onFilterClear(chip)}
287+
deleteChipGroup={() => onFilterClearGroup(groupName)}
288+
categoryName={groupName}
289+
key={groupName}
290+
showToolbarItem={false}
291+
>
292+
{" "}
293+
</ToolbarFilter>
294+
))}
295295
</>
296296
);
297297
};

0 commit comments

Comments
 (0)