diff --git a/client/src/app/components/FilterToolbar/SelectFilterControl.tsx b/client/src/app/components/FilterToolbar/SelectFilterControl.tsx index 3e0ed1abb1..e8b6479dda 100644 --- a/client/src/app/components/FilterToolbar/SelectFilterControl.tsx +++ b/client/src/app/components/FilterToolbar/SelectFilterControl.tsx @@ -1,15 +1,15 @@ import * as React from "react"; -import { ToolbarFilter } from "@patternfly/react-core"; import { + MenuToggle, + MenuToggleElement, Select, + SelectList, SelectOption, - SelectOptionObject, -} from "@patternfly/react-core/deprecated"; + SelectOptionProps, + ToolbarFilter, +} from "@patternfly/react-core"; import { IFilterControlProps } from "./FilterControl"; -import { - ISelectFilterCategory, - FilterSelectOptionProps, -} from "./FilterToolbar"; +import { ISelectFilterCategory } from "./FilterToolbar"; import { css } from "@patternfly/react-styles"; import "./select-overrides.css"; @@ -34,29 +34,29 @@ export const SelectFilterControl = ({ >): JSX.Element | null => { const [isFilterDropdownOpen, setIsFilterDropdownOpen] = React.useState(false); - const getOptionKeyFromOptionValue = ( - optionValue: string | SelectOptionObject - ) => - category.selectOptions.find( - (optionProps) => optionProps.value === optionValue - )?.key; - const getChipFromOptionValue = ( - optionValue: string | SelectOptionObject | undefined - ) => (optionValue ? optionValue.toString() : ""); + optionValue: SelectOptionProps | undefined + ) => { + return optionValue ? optionValue.value : ""; + }; const getOptionKeyFromChip = (chip: string) => category.selectOptions.find( (optionProps) => optionProps.value.toString() === chip )?.key; - const getOptionValueFromOptionKey = (optionKey: string) => - category.selectOptions.find((optionProps) => optionProps.key === optionKey) - ?.value; + const getOptionValueFromOptionKey = ( + optionKey: string + ): SelectOptionProps => { + return ( + category.selectOptions.find((optionProps) => { + return optionProps.value === optionKey; + }) || { value: "", children: "", key: "" } + ); + }; - const onFilterSelect = (value: string | SelectOptionObject) => { - const optionKey = getOptionKeyFromOptionValue(value); - setFilterValue(optionKey ? [optionKey] : null); + const onFilterSelect = (value: string) => { + setFilterValue(value ? [value] : null); setIsFilterDropdownOpen(false); }; @@ -68,17 +68,29 @@ export const SelectFilterControl = ({ setFilterValue(newValue.length > 0 ? newValue : null); }; - // Select expects "selections" to be an array of the "value" props from the relevant optionProps - const selections = filterValue + const selections: SelectOptionProps[] = filterValue ? filterValue.map(getOptionValueFromOptionKey) - : null; + : []; const chips = selections ? selections.map(getChipFromOptionValue) : []; - const renderSelectOptions = (options: FilterSelectOptionProps[]) => - options.map((optionProps) => ( - - )); + const toggle = (toggleRef: React.Ref) => { + return ( + { + setIsFilterDropdownOpen(!isFilterDropdownOpen); + }} + isExpanded={isFilterDropdownOpen} + isDisabled={isDisabled || category.selectOptions.length === 0} + > + {filterValue || "Any"} + + ); + }; return ( ({ );