This is an automated email from the ASF dual-hosted git repository.
justinpark pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new a88979631e fix(sqllab): run previous state query (#29230)
a88979631e is described below
commit a88979631e6abe4de1b00e9c05ad1e411db1c2a7
Author: JUST.in DO IT <[email protected]>
AuthorDate: Wed Jun 12 15:04:19 2024 -0700
fix(sqllab): run previous state query (#29230)
---
superset-frontend/src/SqlLab/actions/sqlLab.js | 5 +--
.../src/SqlLab/actions/sqlLab.test.js | 39 ++++++++++++++++++++--
2 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js
b/superset-frontend/src/SqlLab/actions/sqlLab.js
index 0a5a655a06..eb197f1a7c 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.js
@@ -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),
};
}
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js
b/superset-frontend/src/SqlLab/actions/sqlLab.test.js
index 9dca13a11b..05b4423066 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js
@@ -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 = {
@@ -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);
@@ -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);