diff --git a/superset-frontend/src/explore/actions/exploreActions.ts b/superset-frontend/src/explore/actions/exploreActions.ts index b6f0594ac638e..f393c74850616 100644 --- a/superset-frontend/src/explore/actions/exploreActions.ts +++ b/superset-frontend/src/explore/actions/exploreActions.ts @@ -142,6 +142,14 @@ export function setForceQuery(force: boolean) { }; } +export const SAVE_DATASOURCE = 'SAVE_DATASOURCE'; +export function saveDatasource(datasource: Dataset) { + return function (dispatch: Dispatch) { + dispatch(setDatasource(datasource)); + dispatch({ type: SAVE_DATASOURCE, datasource }); + }; +} + export function changeDatasource(newDatasource: Dataset) { return function (dispatch: Dispatch, getState: () => ExplorePageState) { const { diff --git a/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx b/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx index df97e090990ca..b313fd7fe6a42 100644 --- a/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx +++ b/superset-frontend/src/explore/components/controls/DatasourceControl/index.jsx @@ -170,7 +170,7 @@ class DatasourceControl extends React.PureComponent { } onDatasourceSave = datasource => { - this.props.actions.setDatasource(datasource); + this.props.actions.saveDatasource(datasource); const timeCol = this.props.form_data?.granularity_sqla; const { columns } = this.props.datasource; const firstDttmCol = columns.find(column => column.is_dttm); diff --git a/superset-frontend/src/explore/reducers/exploreReducer.js b/superset-frontend/src/explore/reducers/exploreReducer.js index f99ab9437c435..93743285c6d45 100644 --- a/superset-frontend/src/explore/reducers/exploreReducer.js +++ b/superset-frontend/src/explore/reducers/exploreReducer.js @@ -50,6 +50,19 @@ export default function exploreReducer(state = {}, action) { isDatasourceMetaLoading: true, }; }, + [actions.SAVE_DATASOURCE]() { + return { + ...state, + datasource: action.datasource, + controls: { + ...state.controls, + datasource: { + ...state.controls.datasource, + datasource: action.datasource, + }, + }, + }; + }, [actions.UPDATE_FORM_DATA_BY_DATASOURCE]() { const newFormData = { ...state.form_data }; const { prevDatasource, newDatasource } = action;