Skip to content

Commit

Permalink
feat(chart-controls): dnd version of time column (apache#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored and zhaoyongjie committed Nov 25, 2021
1 parent c6c9eed commit 744a2c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
import { t, validateNonEmpty } from '@superset-ui/core';
import { ExtraControlProps, SharedControlConfig } from '../types';
import { TIME_COLUMN_OPTION } from '../constants';
import { TIME_COLUMN_OPTION, TIME_FILTER_LABELS } from '../constants';

export const dndGroupByControl: SharedControlConfig<'DndColumnSelect'> = {
type: 'DndColumnSelect',
Expand Down Expand Up @@ -138,3 +138,25 @@ export const dnd_secondary_metric: SharedControlConfig<'DndMetricSelect'> = {
validators: [],
description: t('A metric to use for color'),
};

export const dnd_granularity_sqla: typeof dndGroupByControl = {
...dndSeries,
label: TIME_FILTER_LABELS.granularity_sqla,
description: t(
'The time column for the visualization. Note that you ' +
'can define arbitrary expression that return a DATETIME ' +
'column in the table. Also note that the ' +
'filter below is applied against this column or ' +
'expression',
),
canDelete: false,
ghostButtonText: t('Drop temporal column'),
mapStateToProps: ({ datasource }) => {
const temporalColumns = datasource?.columns.filter(c => c.is_dttm) ?? [];
const options = Object.fromEntries(temporalColumns.map(option => [option.column_name, option]));
return {
options,
default: datasource?.main_dttm_col || temporalColumns[0]?.column_name || null,
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
dnd_adhoc_filters,
dnd_adhoc_metric,
dnd_adhoc_metrics,
dnd_granularity_sqla,
dnd_sort_by,
dnd_secondary_metric,
dnd_size,
Expand Down Expand Up @@ -476,7 +477,7 @@ const sharedControls = {
columns: enableExploreDnd ? dndColumnsControl : columnsControl,
druid_time_origin,
granularity,
granularity_sqla,
granularity_sqla: enableExploreDnd ? dnd_granularity_sqla : granularity_sqla,
time_grain_sqla,
time_range,
row_limit,
Expand Down

0 comments on commit 744a2c0

Please sign in to comment.