Skip to content

Commit

Permalink
[fix] Enforcing main dttm column (apache#5584)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Aug 13, 2018
1 parent 50981db commit 2685ab4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions superset/assets/src/explore/controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -832,22 +832,23 @@ export const controls = {
'column in the table. Also note that the ' +
'filter below is applied against this column or ' +
'expression'),
default: (c) => {
if (c.options && c.options.length > 0) {
return c.options[0].column_name;
}
return null;
},
default: control => control.default,
clearable: false,
optionRenderer: c => <ColumnOption column={c} showType />,
valueRenderer: c => <ColumnOption column={c} />,
valueKey: 'column_name',
mapStateToProps: (state) => {
const newState = {};
const props = {};
if (state.datasource) {
newState.options = state.datasource.columns.filter(c => c.is_dttm);
props.options = state.datasource.columns.filter(c => c.is_dttm);
props.default = null;
if (state.datasource.main_dttm_col) {
props.default = state.datasource.main_dttm_col;
} else if (props.options && props.options.length > 0) {
props.default = props.options[0].column_name;
}
}
return newState;
return props;
},
},

Expand Down
1 change: 1 addition & 0 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ def data(self):
grains = [(g.duration, g.name) for g in grains]
d['granularity_sqla'] = utils.choicify(self.dttm_cols)
d['time_grain_sqla'] = grains
d['main_dttm_col'] = self.main_dttm_col
return d

def values_for_column(self, column_name, limit=10000):
Expand Down

0 comments on commit 2685ab4

Please sign in to comment.