Skip to content

Commit

Permalink
feat: address PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Aug 29, 2023
1 parent fb05e7e commit 284d431
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
27 changes: 14 additions & 13 deletions public/components/common/options_filter/options_filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useCallback, useMemo, useRef, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import {
EuiPopover,
EuiPopoverTitle,
Expand All @@ -16,6 +16,7 @@ import {
import { OptionsFilterItem } from './options_filter_item';

export interface OptionsFilterProps<T extends string | number = string> {
id?: string;
name: string;
searchPlaceholder: string;
searchWidth?: number;
Expand All @@ -33,11 +34,8 @@ export const OptionsFilter = <T extends string | number = string>({
searchPlaceholder,
searchWidth,
onChange,
...restProps
}: OptionsFilterProps<T>) => {
const valueRef = useRef(value);
valueRef.current = value;
const onChangeRef = useRef(onChange);
onChangeRef.current = onChange;
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [searchText, setSearchText] = useState<string>();

Expand All @@ -61,17 +59,19 @@ export const OptionsFilter = <T extends string | number = string>({
setIsPopoverOpen(false);
}, []);

const handleFilterItemClick = useCallback((clickItemValue: T) => {
onChangeRef.current(
valueRef.current.includes(clickItemValue)
? valueRef.current.filter((item) => item !== clickItemValue)
: valueRef.current.concat(clickItemValue)
);
}, []);
const handleFilterItemClick = useCallback(
(clickItemValue: T) => {
onChange(
value.includes(clickItemValue)
? value.filter((item) => item !== clickItemValue)
: value.concat(clickItemValue)
);
},
[value, onChange]
);

return (
<EuiPopover
id="popoverExampleMultiSelect"
button={
<EuiFilterButton
iconType="arrowDown"
Expand All @@ -85,6 +85,7 @@ export const OptionsFilter = <T extends string | number = string>({
isOpen={isPopoverOpen}
closePopover={closePopover}
panelPaddingSize="none"
{...restProps}
>
<EuiPopoverTitle style={{ padding: 12 }}>
<EuiFieldSearch
Expand Down
1 change: 1 addition & 0 deletions public/components/monitoring/model_connector_filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const ModelConnectorFilter = ({

return (
<OptionsFilter
id="modelConnectorNameFilter"
name="Connector name"
searchPlaceholder="Search"
options={options}
Expand Down
5 changes: 3 additions & 2 deletions public/components/monitoring/model_source_filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { OptionsFilter, OptionsFilterProps } from '../common/options_filter';

type SourceOptionValue = 'local' | 'external';

const sourceOptions = [
const SOURCE_OPTIONS = [
{
name: 'Local',
value: 'local' as const,
Expand All @@ -24,9 +24,10 @@ export const ModelSourceFilter = (
) => {
return (
<OptionsFilter<SourceOptionValue>
id="modelSourceFilter"
name="Source"
searchPlaceholder="Search"
options={sourceOptions}
options={SOURCE_OPTIONS}
{...props}
/>
);
Expand Down

0 comments on commit 284d431

Please sign in to comment.