mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix shared query (#16753)
This commit is contained in:
parent
a8d5342953
commit
f032cc254c
@ -612,44 +612,44 @@ describe('async actions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('queryEditorSetSql', () => {
|
describe('queryEditorSetSql', () => {
|
||||||
|
const sql = 'SELECT * ';
|
||||||
|
const expectedActions = [
|
||||||
|
{
|
||||||
|
type: actions.QUERY_EDITOR_SET_SQL,
|
||||||
|
queryEditor,
|
||||||
|
sql,
|
||||||
|
},
|
||||||
|
];
|
||||||
describe('with backend persistence flag on', () => {
|
describe('with backend persistence flag on', () => {
|
||||||
it('updates the tab state in the backend', () => {
|
it('updates the tab state in the backend', () => {
|
||||||
expect.assertions(2);
|
expect.assertions(2);
|
||||||
|
|
||||||
const sql = 'SELECT * ';
|
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
|
|
||||||
return store
|
return store
|
||||||
.dispatch(actions.queryEditorSetSql(queryEditor, sql))
|
.dispatch(actions.queryEditorSetSql(queryEditor, sql))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(store.getActions()).toHaveLength(0);
|
expect(store.getActions()).toEqual(expectedActions);
|
||||||
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
|
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
describe('with backend persistence flag off', () => {
|
||||||
describe('with backend persistence flag off', () => {
|
it('does not update the tab state in the backend', () => {
|
||||||
it('does not update the tab state in the backend', () => {
|
const backendPersistenceOffMock = jest
|
||||||
const backendPersistenceOffMock = jest
|
.spyOn(featureFlags, 'isFeatureEnabled')
|
||||||
.spyOn(featureFlags, 'isFeatureEnabled')
|
.mockImplementation(
|
||||||
.mockImplementation(
|
feature => !(feature === 'SQLLAB_BACKEND_PERSISTENCE'),
|
||||||
feature => !(feature === 'SQLLAB_BACKEND_PERSISTENCE'),
|
);
|
||||||
);
|
|
||||||
const sql = 'SELECT * ';
|
|
||||||
const store = mockStore({});
|
|
||||||
const expectedActions = [
|
|
||||||
{
|
|
||||||
type: actions.QUERY_EDITOR_SET_SQL,
|
|
||||||
queryEditor,
|
|
||||||
sql,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
store.dispatch(actions.queryEditorSetSql(queryEditor, sql));
|
const store = mockStore({});
|
||||||
|
|
||||||
expect(store.getActions()).toEqual(expectedActions);
|
store.dispatch(actions.queryEditorSetSql(queryEditor, sql));
|
||||||
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(0);
|
|
||||||
backendPersistenceOffMock.mockRestore();
|
expect(store.getActions()).toEqual(expectedActions);
|
||||||
|
expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(0);
|
||||||
|
backendPersistenceOffMock.mockRestore();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -898,6 +898,8 @@ export function updateSavedQuery(query) {
|
|||||||
|
|
||||||
export function queryEditorSetSql(queryEditor, sql) {
|
export function queryEditorSetSql(queryEditor, sql) {
|
||||||
return function (dispatch) {
|
return function (dispatch) {
|
||||||
|
// saved query and set tab state use this action
|
||||||
|
dispatch({ type: QUERY_EDITOR_SET_SQL, queryEditor, sql });
|
||||||
if (isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)) {
|
if (isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)) {
|
||||||
return SupersetClient.put({
|
return SupersetClient.put({
|
||||||
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
|
endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
|
||||||
@ -914,7 +916,7 @@ export function queryEditorSetSql(queryEditor, sql) {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return dispatch({ type: QUERY_EDITOR_SET_SQL, queryEditor, sql });
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user