Skip to content

Commit

Permalink
move datatime columns lookup into sharedControls
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie committed Sep 22, 2022
1 parent ba735cc commit 8f64fe5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
ComparisionType,
isAdhocColumn,
isPhysicalColumn,
ensureIsArray,
} from '@superset-ui/core';

import {
Expand All @@ -57,7 +58,13 @@ import {
DEFAULT_NUMBER_FORMAT,
} from '../utils';
import { TIME_FILTER_LABELS } from '../constants';
import { SharedControlConfig, Dataset, ColumnMeta } from '../types';
import {
SharedControlConfig,
Dataset,
ColumnMeta,
ControlState,
ControlPanelState,
} from '../types';

import {
dndAdhocFilterControl,
Expand Down Expand Up @@ -340,6 +347,16 @@ const show_empty_columns: SharedControlConfig<'CheckboxControl'> = {
description: t('Show empty columns'),
};

const datetime_columns_lookup: SharedControlConfig<'HiddenControl'> = {
type: 'HiddenControl',
initialValue: (control: ControlState, state: ControlPanelState) =>
Object.fromEntries(
ensureIsArray<Record<string, any>>(state?.datasource?.columns)
.filter(option => option.is_dttm)
.map(option => [option.column_name ?? option.name, option.is_dttm]),
),
};

export default {
metrics: dndAdhocMetricsControl,
metric: dndAdhocMetricControl,
Expand Down Expand Up @@ -376,4 +393,5 @@ export default {
truncate_metric,
x_axis: dndXAxisControl,
show_empty_columns,
datetime_columns_lookup,
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function buildQuery(formData: PivotTableQueryFormData) {
isPhysicalColumn(col) &&
formData.time_grain_sqla &&
isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES) &&
formData?.datetimeColumnLookup?.[col]
formData?.datetime_columns_lookup?.[col]
) {
return {
timeGrain: formData.time_grain_sqla,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import {
emitFilterControl,
Dataset,
getStandardizedControls,
ControlState,
ControlPanelState,
} from '@superset-ui/chart-controls';
import { MetricsLayoutEnum } from '../types';

Expand Down Expand Up @@ -81,11 +79,11 @@ const config: ControlPanelConfig = {
option => [option.column_name, option.is_dttm],
),
);
const selections = [

return [
...ensureIsArray(controls?.groupbyColumns.value),
...ensureIsArray(controls?.groupbyRows.value),
];
return selections
]
.map(selection => {
if (isAdhocColumn(selection)) {
return true;
Expand All @@ -101,23 +99,7 @@ const config: ControlPanelConfig = {
}
: null,
isFeatureEnabled(FeatureFlag.GENERIC_CHART_AXES)
? {
name: 'datetimeColumnLookup',
config: {
type: 'HiddenControl',
default: (control: ControlState, state: ControlPanelState) =>
Object.fromEntries(
ensureIsArray<Record<string, any>>(
state?.datasource?.columns,
)
.filter(option => option.is_dttm)
.map(option => [
option.column_name ?? option.name,
option.is_dttm,
]),
),
},
}
? 'datetime_columns_lookup'
: null,
],
[
Expand Down

0 comments on commit 8f64fe5

Please sign in to comment.