From 8e92a158f3a7fcf46db5221f56cf7f8eecb45ee2 Mon Sep 17 00:00:00 2001 From: justinpark Date: Wed, 12 Jun 2024 11:52:27 -0700 Subject: [PATCH 1/2] fix(sqllab): run previous state query --- .../src/SqlLab/actions/sqlLab.js | 4 ++-- .../src/SqlLab/actions/sqlLab.test.js | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index 0a5a655a06de9..b7dc2e597918a 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -134,11 +134,11 @@ 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, + ...queryEditors.find(qe => qe.id === id), ...(id === unsavedQueryEditor.id && unsavedQueryEditor), }; } diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js index 9dca13a11ba75..4f7e94bd84aaa 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js @@ -36,6 +36,28 @@ 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], + }, + }; + expect(actions.getUpToDateQuery(state, outOfUpdatedQueryEditor)).toEqual( + queryEditor, + ); + }); +}); + describe('async actions', () => { const mockBigNumber = '9223372036854775807'; const queryEditor = { From 8dbbc99a8d842dd35f32d61129999026a25a16e8 Mon Sep 17 00:00:00 2001 From: justinpark Date: Wed, 12 Jun 2024 13:32:49 -0700 Subject: [PATCH 2/2] fix failed units --- superset-frontend/src/SqlLab/actions/sqlLab.js | 1 + .../src/SqlLab/actions/sqlLab.test.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index b7dc2e597918a..eb197f1a7c9d9 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -138,6 +138,7 @@ export function getUpToDateQuery(rootState, queryEditor, key) { } = rootState; const id = key ?? queryEditor.id; return { + id, ...queryEditors.find(qe => qe.id === id), ...(id === unsavedQueryEditor.id && unsavedQueryEditor), }; diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js index 4f7e94bd84aaa..05b4423066a3e 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js @@ -50,6 +50,7 @@ describe('getUpToDateQuery', () => { const state = { sqlLab: { queryEditors: [queryEditor], + unsavedQueryEditor: {}, }, }; expect(actions.getUpToDateQuery(state, outOfUpdatedQueryEditor)).toEqual( @@ -737,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); @@ -753,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);