diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx index 350ba102d4707..2147de2f60d76 100644 --- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx +++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndFilterSelect.tsx @@ -19,11 +19,10 @@ import React, { useEffect, useMemo, useState } from 'react'; import { logging, SupersetClient } from '@superset-ui/core'; import { ColumnMeta, Metric } from '@superset-ui/chart-controls'; -import { - DndFilterSelectProps, - FilterOptionValueType, - OptionSortType, -} from './types'; +import { Tooltip } from 'src/common/components/Tooltip'; +import { OPERATORS } from 'src/explore/constants'; +import { OptionSortType } from 'src/explore/types'; +import { DndFilterSelectProps, FilterOptionValueType } from './types'; import AdhocFilterPopoverTrigger from '../FilterControl/AdhocFilterPopoverTrigger'; import OptionWrapper from './components/OptionWrapper'; import DndSelectLabel from './DndSelectLabel'; @@ -32,8 +31,6 @@ import AdhocFilter, { EXPRESSION_TYPES, } from '../FilterControl/AdhocFilter'; import AdhocMetric from '../MetricControl/AdhocMetric'; -import { Tooltip } from '../../../../common/components/Tooltip'; -import { OPERATORS } from '../../../constants'; import { DatasourcePanelDndItem, DndItemValue, @@ -75,12 +72,12 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => { results: (OptionSortType & { filterOptionName: string })[], option, ) => { - if (option.saved_metric_name) { + if ('saved_metric_name' in option && option.saved_metric_name) { results.push({ ...option, filterOptionName: option.saved_metric_name, }); - } else if (option.column_name) { + } else if ('column_name' in option && option.column_name) { results.push({ ...option, filterOptionName: `_col_${option.column_name}`, @@ -95,10 +92,11 @@ export const DndFilterSelect = (props: DndFilterSelectProps) => { }, [], ) - .sort((a: OptionSortType, b: OptionSortType) => - (a.saved_metric_name || a.column_name || a.label).localeCompare( - b.saved_metric_name || b.column_name || b.label, - ), + .sort( + (a: OptionSortType, b: OptionSortType) => + (a.saved_metric_name || a.column_name || a.label)?.localeCompare( + b.saved_metric_name || b.column_name || b.label || '', + ) ?? 0, ); }; const [options, setOptions] = useState( diff --git a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/types.ts b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/types.ts index 24026fca3d76f..13e30dd3db3f8 100644 --- a/superset-frontend/src/explore/components/controls/DndColumnSelectControl/types.ts +++ b/superset-frontend/src/explore/components/controls/DndColumnSelectControl/types.ts @@ -64,9 +64,3 @@ export interface DndFilterSelectProps { onChange: (filters: FilterOptionValueType[]) => void; options: { string: ColumnMeta }; } - -export type OptionSortType = { - label: string; - saved_metric_name: string; - column_name: string; -}; diff --git a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterPopoverTrigger.tsx b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterPopoverTrigger.tsx index 482cb77d90320..3128c7cee0f62 100644 --- a/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterPopoverTrigger.tsx +++ b/superset-frontend/src/explore/components/controls/FilterControl/AdhocFilterPopoverTrigger.tsx @@ -18,17 +18,13 @@ */ import React from 'react'; import Popover from 'src/common/components/Popover'; -import columnType from 'src/explore/propTypes/columnType'; -import adhocMetricType from 'src/explore/components/controls/MetricControl/adhocMetricType'; +import { OptionSortType } from 'src/explore/types'; import AdhocFilterEditPopover from './AdhocFilterEditPopover'; import AdhocFilter from './AdhocFilter'; interface AdhocFilterPopoverTriggerProps { adhocFilter: AdhocFilter; - options: - | typeof columnType[] - | { saved_metric_name: string }[] - | typeof adhocMetricType[]; + options: OptionSortType[]; datasource: Record; onFilterEdit: (editedFilter: AdhocFilter) => void; partitionColumn?: string; diff --git a/superset-frontend/src/explore/types.ts b/superset-frontend/src/explore/types.ts index 37c46fe770676..7c05fa64a7f2b 100644 --- a/superset-frontend/src/explore/types.ts +++ b/superset-frontend/src/explore/types.ts @@ -16,7 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -import { QueryData, QueryFormData, AnnotationData } from '@superset-ui/core'; +import { + QueryData, + QueryFormData, + AnnotationData, + AdhocMetric, +} from '@superset-ui/core'; +import { ColumnMeta } from '@superset-ui/chart-controls'; export { Slice, Chart } from 'src/types/Chart'; @@ -45,3 +51,7 @@ export interface ChartState { triggerQuery: boolean; asyncJobId?: string; } + +export type OptionSortType = Partial< + ColumnMeta & AdhocMetric & { saved_metric_name: string } +>;