Skip to content

Commit

Permalink
fix(native-filters): values is not sorted when setting sort option (#…
Browse files Browse the repository at this point in the history
…18145)

* fix(native-filters): values is not sorted when setting sort option

* fix: revert

* pass sortComparator
  • Loading branch information
stephenLYZ authored Jan 28, 2022
1 parent ac2545e commit 7c937ca
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import {
t,
tn,
} from '@superset-ui/core';
import { LabeledValue as AntdLabeledValue } from 'antd/lib/select';
import React, { useCallback, useEffect, useState, useMemo } from 'react';
import { Select } from 'src/components';
import debounce from 'lodash/debounce';
import { SLOW_DEBOUNCE } from 'src/constants';
import { useImmerReducer } from 'use-immer';
import { propertyComparator } from 'src/components/Select/Select';
import { PluginFilterSelectProps, SelectValue } from './types';
import { StyledFormItem, FilterPluginStyle, StatusMessage } from '../common';
import { getDataRecordFormatter, getSelectExtraFormData } from '../../utils';
Expand Down Expand Up @@ -278,6 +280,17 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
return options;
}, [data, datatype, groupby, labelFormatter]);

const sortComparator = useCallback(
(a: AntdLabeledValue, b: AntdLabeledValue) => {
const labelComparator = propertyComparator('label');
if (formData.sortAscending) {
return labelComparator(a, b);
}
return labelComparator(b, a);
},
[formData.sortAscending],
);

return (
<FilterPluginStyle height={height} width={width}>
<StyledFormItem
Expand Down Expand Up @@ -309,6 +322,7 @@ export default function PluginFilterSelect(props: PluginFilterSelectProps) {
invertSelection={inverseSelection}
// @ts-ignore
options={options}
sortComparator={sortComparator}
/>
</StyledFormItem>
</FilterPluginStyle>
Expand Down

0 comments on commit 7c937ca

Please sign in to comment.