You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/12/04 00:38:45 UTC
[GitHub] [superset] eschutho commented on a change in pull request #17638: fix(select): [WIP] select component sort functionality on certain options
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org