From f24208acdd88bd27c483f70af2bfd6a751216575 Mon Sep 17 00:00:00 2001 From: Dan Labrecque Date: Tue, 23 Jan 2024 19:31:58 -0500 Subject: [PATCH] Refactor select component wrapper --- .../components/perspective/Perspective.tsx | 20 +------------------ .../selectWrapper/selectWrapper.test.tsx | 4 ++-- .../selectWrapper/selectWrapper.tsx | 6 +++--- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/src/routes/components/perspective/Perspective.tsx b/src/routes/components/perspective/Perspective.tsx index bac4876f..adce9499 100644 --- a/src/routes/components/perspective/Perspective.tsx +++ b/src/routes/components/perspective/Perspective.tsx @@ -62,29 +62,11 @@ const Perspective: React.FC = ({ id={id} isDisabled={isDisabled} onSelect={onSelect} + options={selectOptions} selection={selection} - selectOptions={selectOptions} /> ); - // }; return ( diff --git a/src/routes/components/selectWrapper/selectWrapper.test.tsx b/src/routes/components/selectWrapper/selectWrapper.test.tsx index 0f3833ee..afe4dd9e 100644 --- a/src/routes/components/selectWrapper/selectWrapper.test.tsx +++ b/src/routes/components/selectWrapper/selectWrapper.test.tsx @@ -14,10 +14,10 @@ test('primary selector', async () => { ]; render( handleOnSelect(select.value)} + onSelect={(_evt, selection) => handleOnSelect(selection.value)} + options={selectOptions} placeholder={'Resources'} selection={selectOptions[0]} - selectOptions={selectOptions} /> ); expect(screen.queryAllByText('CPU').length).toBe(1); diff --git a/src/routes/components/selectWrapper/selectWrapper.tsx b/src/routes/components/selectWrapper/selectWrapper.tsx index 70de8c2d..27f5245c 100644 --- a/src/routes/components/selectWrapper/selectWrapper.tsx +++ b/src/routes/components/selectWrapper/selectWrapper.tsx @@ -18,9 +18,9 @@ interface SelectWrapperOwnProps { isDisabled?: boolean; onSelect?: (event, value: SelectWrapperOption) => void; placeholder?: string; + options?: SelectWrapperOption[]; position?: 'right' | 'left' | 'center' | 'start' | 'end'; selection?: string | SelectWrapperOption; - selectOptions?: SelectWrapperOption[]; toggleIcon?: React.ReactNode; } @@ -32,10 +32,10 @@ const SelectWrapper: React.FC = ({ id, isDisabled, onSelect = () => {}, + options, placeholder = null, position, selection, - selectOptions, toggleIcon, }) => { const [isOpen, setIsOpen] = useState(false); @@ -98,7 +98,7 @@ const SelectWrapper: React.FC = ({ toggle={toggle} > - {selectOptions.map((option, index) => getSelectOption(option, index))} + {options?.map((option, index) => getSelectOption(option, index))}