diff --git a/superset/assets/javascripts/explorev2/reducers/exploreReducer.js b/superset/assets/javascripts/explorev2/reducers/exploreReducer.js index cb57b1834e..a05bd93a25 100644 --- a/superset/assets/javascripts/explorev2/reducers/exploreReducer.js +++ b/superset/assets/javascripts/explorev2/reducers/exploreReducer.js @@ -96,7 +96,8 @@ export const exploreReducer = function (state, action) { if (action.key === 'viz_type') { newFormData.previous_viz_type = state.viz.form_data.viz_type; } - newFormData[action.key] = action.value ? action.value : (!state.viz.form_data[action.key]); + newFormData[action.key] = (action.value !== undefined) + ? action.value : (!state.viz.form_data[action.key]); return Object.assign( {}, state, diff --git a/superset/views.py b/superset/views.py index b3cb78c7f8..fec9f50c31 100755 --- a/superset/views.py +++ b/superset/views.py @@ -2471,10 +2471,7 @@ class Superset(BaseSupersetView): for s in sorted(datasource.column_names): order_by_choices.append((json.dumps([s, True]), s + ' [asc]')) order_by_choices.append((json.dumps([s, False]), s + ' [desc]')) - grains = datasource.database.grains() - grain_choices = [] - if grains: - grain_choices = [(grain.name, grain.name) for grain in grains] + field_options = { 'datasource': [(d.id, d.full_name) for d in datasources], 'metrics': datasource.metrics_combo, @@ -2486,8 +2483,6 @@ class Superset(BaseSupersetView): 'all_columns': all_cols, 'all_columns_x': all_cols, 'all_columns_y': all_cols, - 'granularity_sqla': [(c, c) for c in datasource.dttm_cols], - 'time_grain_sqla': grain_choices, 'timeseries_limit_metric': [('', '')] + datasource.metrics_combo, 'series': gb_cols, 'entity': gb_cols, @@ -2499,6 +2494,15 @@ class Superset(BaseSupersetView): 'filterable_cols': datasource.filterable_column_names, } + if (datasource_type == 'table'): + grains = datasource.database.grains() + grain_choices = [] + if grains: + grain_choices = [(grain.name, grain.name) for grain in grains] + field_options['granularity_sqla'] = \ + [(c, c) for c in datasource.dttm_cols] + field_options['time_grain_sqla'] = grain_choices + return Response( json.dumps({'field_options': field_options}), mimetype="application/json"