Skip to content

Commit

Permalink
Fix ts errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Mar 4, 2021
1 parent b8abf78 commit 1e1b802
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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}`,
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
onFilterEdit: (editedFilter: AdhocFilter) => void;
partitionColumn?: string;
Expand Down
12 changes: 11 additions & 1 deletion superset-frontend/src/explore/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -45,3 +51,7 @@ export interface ChartState {
triggerQuery: boolean;
asyncJobId?: string;
}

export type OptionSortType = Partial<
ColumnMeta & AdhocMetric & { saved_metric_name: string }
>;

0 comments on commit 1e1b802

Please sign in to comment.