diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index 7ec2e7761..6b7802a4c 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -1501,7 +1501,7 @@ export function createDatasourceStarted() { return { type: CREATE_DATASOURCE_STARTED }; } export function createDatasourceSuccess(data) { - const datasource = `${data.table_id}__table`; + const datasource = `${data.id}__table`; return { type: CREATE_DATASOURCE_SUCCESS, datasource }; } export function createDatasourceFailed(err) { @@ -1511,9 +1511,18 @@ export function createDatasourceFailed(err) { export function createDatasource(vizOptions) { return dispatch => { dispatch(createDatasourceStarted()); + const { dbId, schema, datasourceName, sql } = vizOptions; return SupersetClient.post({ - endpoint: '/superset/sqllab_viz/', - postPayload: { data: vizOptions }, + endpoint: '/api/v1/dataset/', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + database: dbId, + schema, + sql, + table_name: datasourceName, + is_managed_externally: false, + external_url: null, + }), }) .then(({ json }) => { dispatch(createDatasourceSuccess(json)); diff --git a/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx b/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx index b1ab18eb0..c51c6158d 100644 --- a/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx +++ b/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx @@ -300,10 +300,10 @@ export const SaveDatasetModal = ({ columns: selectedColumns, }), ) - .then((data: { table_id: number }) => - postFormData(data.table_id, 'table', { + .then((data: { id: number }) => + postFormData(data.id, 'table', { ...formDataWithDefaults, - datasource: `${data.table_id}__table`, + datasource: `${data.id}__table`, ...(defaultVizType === 'table' && { all_columns: selectedColumns.map(column => column.column_name), }), diff --git a/superset-frontend/src/explore/actions/datasourcesActions.test.ts b/superset-frontend/src/explore/actions/datasourcesActions.test.ts index 996758b26..bca3aecfd 100644 --- a/superset-frontend/src/explore/actions/datasourcesActions.test.ts +++ b/superset-frontend/src/explore/actions/datasourcesActions.test.ts @@ -68,7 +68,7 @@ const defaultDatasourcesReducerState = { [CURRENT_DATASOURCE.uid]: CURRENT_DATASOURCE, }; -const saveDatasetEndpoint = `glob:*/superset/sqllab_viz/`; +const saveDatasetEndpoint = `glob:*/api/v1/dataset/`; test('sets new datasource', () => { const newState = datasourcesReducer( diff --git a/superset-frontend/src/explore/actions/datasourcesActions.ts b/superset-frontend/src/explore/actions/datasourcesActions.ts index 9306c180e..c11be07be 100644 --- a/superset-frontend/src/explore/actions/datasourcesActions.ts +++ b/superset-frontend/src/explore/actions/datasourcesActions.ts @@ -35,6 +35,16 @@ export function setDatasource(datasource: Dataset) { return { type: SET_DATASOURCE, datasource }; } +export function changeDatasource(newDatasource: Dataset) { + return function (dispatch: Dispatch, getState: () => ExplorePageState) { + const { + explore: { datasource: prevDatasource }, + } = getState(); + dispatch(setDatasource(newDatasource)); + dispatch(updateFormDataByDatasource(prevDatasource, newDatasource)); + }; +} + export function saveDataset({ schema, sql, @@ -49,18 +59,16 @@ export function saveDataset({ const { json: { data }, } = await SupersetClient.post({ - endpoint: '/superset/sqllab_viz/', - postPayload: { - data: { - schema, - sql, - dbId: database?.id, - templateParams, - datasourceName, - metrics: [], - columns, - }, - }, + endpoint: '/api/v1/dataset/', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + database: database?.id, + table_name: datasourceName, + schema, + sql, + template_params: templateParams, + columns, + }), }); // Update form_data to point to new dataset dispatch(changeDatasource(data)); @@ -74,16 +82,6 @@ export function saveDataset({ }; } -export function changeDatasource(newDatasource: Dataset) { - return function (dispatch: Dispatch, getState: () => ExplorePageState) { - const { - explore: { datasource: prevDatasource }, - } = getState(); - dispatch(setDatasource(newDatasource)); - dispatch(updateFormDataByDatasource(prevDatasource, newDatasource)); - }; -} - export const datasourcesActions = { setDatasource, changeDatasource, diff --git a/superset/views/core.py b/superset/views/core.py index 774c04599..ec6e84068 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -1985,6 +1985,7 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods @has_access @expose("/sqllab_viz/", methods=["POST"]) @event_logger.log_this + @deprecated() def sqllab_viz(self) -> FlaskResponse: # pylint: disable=no-self-use data = json.loads(request.form["data"]) try: