mirror of https://github.com/apache/superset.git
fix: save tabs when saving the query bug (#12607)
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
This commit is contained in:
parent
c347ddbfb6
commit
68fe2208ba
|
@ -23,7 +23,7 @@ import configureMockStore from 'redux-mock-store';
|
||||||
import thunk from 'redux-thunk';
|
import thunk from 'redux-thunk';
|
||||||
import shortid from 'shortid';
|
import shortid from 'shortid';
|
||||||
import * as featureFlags from 'src/featureFlags';
|
import * as featureFlags from 'src/featureFlags';
|
||||||
|
import { ADD_TOAST } from 'src/messageToasts/actions';
|
||||||
import * as actions from 'src/SqlLab/actions/sqlLab';
|
import * as actions from 'src/SqlLab/actions/sqlLab';
|
||||||
import { defaultQueryEditor, query } from '../fixtures';
|
import { defaultQueryEditor, query } from '../fixtures';
|
||||||
|
|
||||||
|
@ -62,7 +62,12 @@ describe('async actions', () => {
|
||||||
|
|
||||||
describe('saveQuery', () => {
|
describe('saveQuery', () => {
|
||||||
const saveQueryEndpoint = 'glob:*/savedqueryviewapi/api/create';
|
const saveQueryEndpoint = 'glob:*/savedqueryviewapi/api/create';
|
||||||
fetchMock.post(saveQueryEndpoint, 'ok');
|
fetchMock.post(saveQueryEndpoint, { results: { json: {} } });
|
||||||
|
|
||||||
|
const makeRequest = () => {
|
||||||
|
const request = actions.saveQuery(query);
|
||||||
|
return request(dispatch);
|
||||||
|
};
|
||||||
|
|
||||||
it('posts to the correct url', () => {
|
it('posts to the correct url', () => {
|
||||||
expect.assertions(1);
|
expect.assertions(1);
|
||||||
|
@ -83,6 +88,38 @@ describe('async actions', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('calls 3 dispatch actions', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
|
||||||
|
return makeRequest().then(() => {
|
||||||
|
expect(dispatch.callCount).toBe(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('calls QUERY_EDITOR_SAVED after making a request', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
|
||||||
|
return makeRequest().then(() => {
|
||||||
|
expect(dispatch.args[0][0].type).toBe(actions.QUERY_EDITOR_SAVED);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('onSave calls QUERY_EDITOR_SAVED and QUERY_EDITOR_SET_TITLE', () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
|
||||||
|
const store = mockStore({});
|
||||||
|
const expectedActionTypes = [
|
||||||
|
actions.QUERY_EDITOR_SAVED,
|
||||||
|
ADD_TOAST,
|
||||||
|
actions.QUERY_EDITOR_SET_TITLE,
|
||||||
|
];
|
||||||
|
return store.dispatch(actions.saveQuery(query)).then(() => {
|
||||||
|
expect(store.getActions().map(a => a.type)).toEqual(
|
||||||
|
expectedActionTypes,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('fetchQueryResults', () => {
|
describe('fetchQueryResults', () => {
|
||||||
|
|
|
@ -139,44 +139,10 @@ export function queryValidationFailed(query, message, error) {
|
||||||
return { type: QUERY_VALIDATION_FAILED, query, message, error };
|
return { type: QUERY_VALIDATION_FAILED, query, message, error };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveQuery(query) {
|
|
||||||
return dispatch =>
|
|
||||||
SupersetClient.post({
|
|
||||||
endpoint: '/savedqueryviewapi/api/create',
|
|
||||||
postPayload: convertQueryToServer(query),
|
|
||||||
stringify: false,
|
|
||||||
})
|
|
||||||
.then(result => {
|
|
||||||
dispatch({
|
|
||||||
type: QUERY_EDITOR_SAVED,
|
|
||||||
query,
|
|
||||||
result: convertQueryToClient(result.json.item),
|
|
||||||
});
|
|
||||||
dispatch(addSuccessToast(t('Your query was saved')));
|
|
||||||
})
|
|
||||||
.catch(() =>
|
|
||||||
dispatch(addDangerToast(t('Your query could not be saved'))),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function updateQueryEditor(alterations) {
|
export function updateQueryEditor(alterations) {
|
||||||
return { type: UPDATE_QUERY_EDITOR, alterations };
|
return { type: UPDATE_QUERY_EDITOR, alterations };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateSavedQuery(query) {
|
|
||||||
return dispatch =>
|
|
||||||
SupersetClient.put({
|
|
||||||
endpoint: `/savedqueryviewapi/api/update/${query.remoteId}`,
|
|
||||||
postPayload: convertQueryToServer(query),
|
|
||||||
stringify: false,
|
|
||||||
})
|
|
||||||
.then(() => dispatch(addSuccessToast(t('Your query was updated'))))
|
|
||||||
.catch(() =>
|
|
||||||
dispatch(addDangerToast(t('Your query could not be updated'))),
|
|
||||||
)
|
|
||||||
.then(() => dispatch(updateQueryEditor(query)));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function scheduleQuery(query) {
|
export function scheduleQuery(query) {
|
||||||
return dispatch =>
|
return dispatch =>
|
||||||
SupersetClient.post({
|
SupersetClient.post({
|
||||||
|
@ -847,6 +813,44 @@ export function queryEditorSetTitle(queryEditor, title) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function saveQuery(query) {
|
||||||
|
return dispatch =>
|
||||||
|
SupersetClient.post({
|
||||||
|
endpoint: '/savedqueryviewapi/api/create',
|
||||||
|
postPayload: convertQueryToServer(query),
|
||||||
|
stringify: false,
|
||||||
|
})
|
||||||
|
.then(result => {
|
||||||
|
dispatch({
|
||||||
|
type: QUERY_EDITOR_SAVED,
|
||||||
|
query,
|
||||||
|
result: convertQueryToClient(result.json.item),
|
||||||
|
});
|
||||||
|
dispatch(addSuccessToast(t('Your query was saved')));
|
||||||
|
dispatch(queryEditorSetTitle(query, query.title));
|
||||||
|
})
|
||||||
|
.catch(() =>
|
||||||
|
dispatch(addDangerToast(t('Your query could not be saved'))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateSavedQuery(query) {
|
||||||
|
return dispatch =>
|
||||||
|
SupersetClient.put({
|
||||||
|
endpoint: `/savedqueryviewapi/api/update/${query.remoteId}`,
|
||||||
|
postPayload: convertQueryToServer(query),
|
||||||
|
stringify: false,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
dispatch(addSuccessToast(t('Your query was updated')));
|
||||||
|
dispatch(queryEditorSetTitle(query, query.title));
|
||||||
|
})
|
||||||
|
.catch(() =>
|
||||||
|
dispatch(addDangerToast(t('Your query could not be updated'))),
|
||||||
|
)
|
||||||
|
.then(() => dispatch(updateQueryEditor(query)));
|
||||||
|
}
|
||||||
|
|
||||||
export function queryEditorSetSql(queryEditor, sql) {
|
export function queryEditorSetSql(queryEditor, sql) {
|
||||||
return function (dispatch) {
|
return function (dispatch) {
|
||||||
const sync = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)
|
const sync = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)
|
||||||
|
|
Loading…
Reference in New Issue