/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React, { useState, useCallback, useMemo } from 'react'; import { EuiPopover, EuiPopoverTitle, EuiFilterGroup, EuiFilterButton, EuiSelectable, EuiSelectableOption, EuiIcon, } from '@elastic/eui'; import { STATUS_FILTER, STATUS_VALUE } from '../../../common'; export interface IOption { value: STATUS_VALUE; checked: 'on' | undefined; } interface Props { options: IOption[]; onUpdateFilters: (filters: IOption[]) => void; loading?: boolean; } interface IItem { label: string; // undefined represents unselected in EUI checked: 'on' | undefined; prepend: JSX.Element; value: STATUS_VALUE; } export const StatusFilter = ({ onUpdateFilters, options, loading }: Props) => { const [isPopoverOpen, setIsPopoverOpen] = useState(false); const items = useMemo(() => { return options.map((item) => { const status = STATUS_FILTER.find((option) => option.value === item.value); return { ...item, label: status!.label, prepend: , }; }); }, [options]); const onButtonClick = () => { setIsPopoverOpen((previous) => !previous); }; const onClosePopover = () => { setIsPopoverOpen(false); }; const handleSelectableChange = useCallback( (newOptions: Array>) => { const filters = newOptions.map(({ value, checked }) => ({ value, checked, })); onUpdateFilters(filters); }, [onUpdateFilters] ); const button = ( item.checked === 'on')} numActiveFilters={items.filter((item) => item.checked === 'on').length} isLoading={loading} > Status ); return ( <> {(list, search) => { return (
{search} {list}
); }}
); };