Skip to content

Commit

Permalink
fix(sqllab): run previous state query (#29230)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored and eschutho committed Jul 24, 2024
1 parent 7e8c771 commit 60b4d98
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
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

0 comments on commit 60b4d98

Please sign in to comment.