Skip to content

Commit

Permalink
[explorev2] fix textfield and druid bug (#1732)
Browse files Browse the repository at this point in the history
* Fixed bug with textfield being empty

* Only return time grains for sqla table
  • Loading branch information
vera-liu authored Dec 5, 2016
1 parent abd0974 commit 76aa9f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 10 additions & 6 deletions superset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2471,10 +2471,7 @@ def fetch_datasource_metadata(self):
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,
Expand All @@ -2486,8 +2483,6 @@ def fetch_datasource_metadata(self):
'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,
Expand All @@ -2499,6 +2494,15 @@ def fetch_datasource_metadata(self):
'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"
Expand Down

0 comments on commit 76aa9f7

Please sign in to comment.