eschutho commented on a change in pull request #17638:
URL: https://github.com/apache/superset/pull/17638#discussion_r762358677
##########
File path: superset-frontend/src/components/Select/Select.tsx
##########
@@ -289,17 +303,20 @@ const Select = ({
pageSize = DEFAULT_PAGE_SIZE,
placeholder = t('Select ...'),
showSearch = true,
- sortComparator = defaultSortComparator,
+ sortByProperty = 'label',
+ sortComparator = propertyComparator(sortByProperty),
+ sortOptions = false,
value,
...props
}: SelectProps) => {
const isAsync = typeof options === 'function';
const isSingleMode = mode === 'single';
const shouldShowSearch = isAsync || allowNewOptions ? true : showSearch;
const initialOptions =
- options && Array.isArray(options) ? options : EMPTY_OPTIONS;
- const [selectOptions, setSelectOptions] =
- useState<OptionsType>(initialOptions);
+ options && Array.isArray(options) ? [...options] : EMPTY_OPTIONS;
+ const [selectOptions, setSelectOptions] = useState<OptionsType>(
+ sortOptions ? initialOptions.sort(sortComparator) : initialOptions,
Review comment:
@corbinrobb it looks like if someone passes in a sortComparator, then
their intention is to have the list sorted by that value, is that right? If so,
can we make the presence of that prop the deciding factor on whether to sort or
not? Something like:
```
const [selectOptions, setSelectOptions] = useState<OptionsType>(
!!sortComparator?.length ? initialOptions.sort(sortComparator) :
initialOptions,
)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]