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 (