chore: migrate `sqllab_viz` endpoint to api v1 (#23729)
This commit is contained in:
parent
40ae074ff0
commit
fa8f98472c
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue