Skip to content

Commit 185304b

Browse files
committed
fix: export getSelectPickerOptionByValue and common out the code
1 parent 358f56f commit 185304b

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -247,35 +247,25 @@ export const SelectPickerGroupHeading = <OptionValue,>({
247247
acc[selectProps.getOptionValue(option)] = true
248248
return acc
249249
}, {})
250+
const selectedOptionsWithoutGroupOptions = selectedOptions.filter(
251+
(selectedOption) => !groupOptionsMapByValue[selectProps.getOptionValue(selectedOption)],
252+
)
250253

251254
// Clear all the selection(s) in the group if any of the option is selected
252255
if (checkboxValue) {
253-
selectProps?.onChange?.(
254-
selectedOptions.filter(
255-
(selectedOption) => !groupOptionsMapByValue[selectProps.getOptionValue(selectedOption)],
256-
),
257-
{
258-
action: ReactSelectInputAction.deselectOption,
259-
option: null,
260-
},
261-
)
256+
selectProps?.onChange?.(selectedOptionsWithoutGroupOptions, {
257+
action: ReactSelectInputAction.deselectOption,
258+
option: null,
259+
})
262260

263261
return
264262
}
265263

266264
// Select all options
267-
selectProps?.onChange?.(
268-
[
269-
...selectedOptions.filter(
270-
(selectedOption) => !groupOptionsMapByValue[selectProps.getOptionValue(selectedOption)],
271-
),
272-
...structuredClone(groupHeadingOptions),
273-
],
274-
{
275-
action: ReactSelectInputAction.selectOption,
276-
option: null,
277-
},
278-
)
265+
selectProps?.onChange?.([...selectedOptionsWithoutGroupOptions, ...structuredClone(groupHeadingOptions)], {
266+
action: ReactSelectInputAction.selectOption,
267+
option: null,
268+
})
279269
}
280270

281271
const handleToggleCheckbox = (e: ChangeEvent<HTMLInputElement>) => {

src/Shared/Components/SelectPicker/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
export { default as SelectPicker } from './SelectPicker.component'
1818
export { default as FilterSelectPicker } from './FilterSelectPicker'
1919
export * from './type'
20+
export { getSelectPickerOptionByValue } from './utils'

0 commit comments

Comments
 (0)