Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqllab): run previous state query #29230

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ export const convertQueryToClient = fieldConverter(queryClientMapping);

export function getUpToDateQuery(rootState, queryEditor, key) {
const {
sqlLab: { unsavedQueryEditor },
sqlLab: { unsavedQueryEditor, queryEditors },
} = rootState;
const id = key ?? queryEditor.id;
return {
...queryEditor,
id,
...queryEditors.find(qe => qe.id === id),
...(id === unsavedQueryEditor.id && unsavedQueryEditor),
};
}
Expand Down
39 changes: 37 additions & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ import {
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

describe('getUpToDateQuery', () => {
test('should return the up to date query editor state', () => {
const outOfUpdatedQueryEditor = {
...defaultQueryEditor,
schema: null,
sql: 'SELECT ...',
};
const queryEditor = {
...defaultQueryEditor,
sql: 'SELECT * FROM table',
};
const state = {
sqlLab: {
queryEditors: [queryEditor],
unsavedQueryEditor: {},
},
};
expect(actions.getUpToDateQuery(state, outOfUpdatedQueryEditor)).toEqual(
queryEditor,
);
});
});

describe('async actions', () => {
const mockBigNumber = '9223372036854775807';
const queryEditor = {
Expand Down Expand Up @@ -715,7 +738,13 @@ describe('async actions', () => {
it('updates the tab state in the backend', () => {
expect.assertions(2);

const store = mockStore(initialState);
const store = mockStore({
...initialState,
sqlLab: {
...initialState.sqlLab,
queryEditors: [queryEditor],
},
});
const request = actions.queryEditorSetAndSaveSql(queryEditor, sql);
return request(store.dispatch, store.getState).then(() => {
expect(store.getActions()).toEqual(expectedActions);
Expand All @@ -731,7 +760,13 @@ describe('async actions', () => {
feature => !(feature === 'SQLLAB_BACKEND_PERSISTENCE'),
);

const store = mockStore(initialState);
const store = mockStore({
...initialState,
sqlLab: {
...initialState.sqlLab,
queryEditors: [queryEditor],
},
});
const request = actions.queryEditorSetAndSaveSql(queryEditor, sql);
request(store.dispatch, store.getState);

Expand Down
Loading