diff --git a/superset/assets/src/explore/reducers/exploreReducer.js b/superset/assets/src/explore/reducers/exploreReducer.js index dff7ab901..a0b4cab14 100644 --- a/superset/assets/src/explore/reducers/exploreReducer.js +++ b/superset/assets/src/explore/reducers/exploreReducer.js @@ -36,9 +36,30 @@ export default function exploreReducer(state = {}, action) { }; }, [actions.SET_DATASOURCE]() { - return { + const newFormData = { ...state.form_data }; + if (action.datasource.type !== state.datasource.type) { + if (action.datasource.type === 'table') { + newFormData.granularity_sqla = action.datasource.granularity_sqla; + newFormData.time_grain_sqla = action.datasource.time_grain_sqla; + delete newFormData.druid_time_origin; + delete newFormData.granularity; + } else { + newFormData.druid_time_origin = action.datasource.druid_time_origin; + newFormData.granularity = action.datasource.granularity; + delete newFormData.granularity_sqla; + delete newFormData.time_grain_sqla; + } + } + const newState = { ...state, datasource: action.datasource, + datasource_id: action.datasource.id, + datasource_type: action.datasource.type, + }; + return { + ...newState, + form_data: newFormData, + controls: getControlsState(newState, newFormData), }; }, [actions.FETCH_DATASOURCES_STARTED]() {