From f82f824527e95df56a83c1be7a849b1bc80f046a Mon Sep 17 00:00:00 2001 From: Stephen Liu <750188453@qq.com> Date: Fri, 28 Jan 2022 10:15:53 +0800 Subject: [PATCH] fix(native-filters): values is not sorted when setting sort option (#18145) * fix(native-filters): values is not sorted when setting sort option * fix: revert * pass sortComparator --- .../components/Select/SelectFilterPlugin.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx b/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx index 15d85eea9874f..a34891e98cc97 100644 --- a/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx +++ b/superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx @@ -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'; @@ -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 (