Skip to content

Commit

Permalink
Revert "chore: migrate sqllab_viz endpoint to api v1 (apache#23729)"
Browse files Browse the repository at this point in the history
This reverts commit fa8f984.
  • Loading branch information
sadpandajoe committed Jun 1, 2023
1 parent 78d11a4 commit 139614a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
15 changes: 3 additions & 12 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ export function createDatasourceStarted() {
return { type: CREATE_DATASOURCE_STARTED };
}
export function createDatasourceSuccess(data) {
const datasource = `${data.id}__table`;
const datasource = `${data.table_id}__table`;
return { type: CREATE_DATASOURCE_SUCCESS, datasource };
}
export function createDatasourceFailed(err) {
Expand All @@ -1503,18 +1503,9 @@ export function createDatasourceFailed(err) {
export function createDatasource(vizOptions) {
return dispatch => {
dispatch(createDatasourceStarted());
const { dbId, schema, datasourceName, sql } = vizOptions;
return SupersetClient.post({
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,
}),
endpoint: '/superset/sqllab_viz/',
postPayload: { data: vizOptions },
})
.then(({ json }) => {
dispatch(createDatasourceSuccess(json));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ export const SaveDatasetModal = ({
columns: selectedColumns,
}),
)
.then((data: { id: number }) =>
postFormData(data.id, 'table', {
.then((data: { table_id: number }) =>
postFormData(data.table_id, 'table', {
...formDataWithDefaults,
datasource: `${data.id}__table`,
datasource: `${data.table_id}__table`,
...(defaultVizType === 'table' && {
all_columns: selectedColumns.map(column => column.column_name),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const defaultDatasourcesReducerState = {
[CURRENT_DATASOURCE.uid]: CURRENT_DATASOURCE,
};

const saveDatasetEndpoint = `glob:*/api/v1/dataset/`;
const saveDatasetEndpoint = `glob:*/superset/sqllab_viz/`;

test('sets new datasource', () => {
const newState = datasourcesReducer(
Expand Down
42 changes: 22 additions & 20 deletions superset-frontend/src/explore/actions/datasourcesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ 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,
Expand All @@ -59,16 +49,18 @@ export function saveDataset({
const {
json: { data },
} = await SupersetClient.post({
endpoint: '/api/v1/dataset/',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
database: database?.id,
table_name: datasourceName,
schema,
sql,
template_params: templateParams,
columns,
}),
endpoint: '/superset/sqllab_viz/',
postPayload: {
data: {
schema,
sql,
dbId: database?.id,
templateParams,
datasourceName,
metrics: [],
columns,
},
},
});
// Update form_data to point to new dataset
dispatch(changeDatasource(data));
Expand All @@ -82,6 +74,16 @@ 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,
Expand Down
1 change: 0 additions & 1 deletion superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,6 @@ def sqllab_table_viz(self) -> FlaskResponse: # pylint: disable=no-self-use
@has_access
@expose("/sqllab_viz/", methods=("POST",))
@event_logger.log_this
@deprecated(new_target="api/v1/dataset/")
def sqllab_viz(self) -> FlaskResponse: # pylint: disable=no-self-use
data = json.loads(request.form["data"])
try:
Expand Down

0 comments on commit 139614a

Please sign in to comment.