You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2021/08/26 22:20:51 UTC

[superset] branch master updated: fix: queryEditor bug (#16452)

This is an automated email from the ASF dual-hosted git repository.

elizabeth 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 ee2eccd  fix: queryEditor bug (#16452)
ee2eccd is described below

commit ee2eccdb674c87347d60e80c8d43d315743a6d93
Author: AAfghahi <48...@users.noreply.github.com>
AuthorDate: Thu Aug 26 18:20:02 2021 -0400

    fix: queryEditor bug (#16452)
    
    * queryEditor bug
    
    * update tests
    
    Co-authored-by: Elizabeth Thompson <es...@gmail.com>
---
 .../spec/javascripts/sqllab/actions/sqlLab_spec.js | 40 ++++++++++++++++------
 superset-frontend/src/SqlLab/actions/sqlLab.js     | 17 ++++-----
 2 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/superset-frontend/spec/javascripts/sqllab/actions/sqlLab_spec.js b/superset-frontend/spec/javascripts/sqllab/actions/sqlLab_spec.js
index 44e468c..a3f7e5b 100644
--- a/superset-frontend/spec/javascripts/sqllab/actions/sqlLab_spec.js
+++ b/superset-frontend/spec/javascripts/sqllab/actions/sqlLab_spec.js
@@ -399,7 +399,7 @@ describe('async actions', () => {
 
     let isFeatureEnabledMock;
 
-    beforeAll(() => {
+    beforeEach(() => {
       isFeatureEnabledMock = jest
         .spyOn(featureFlags, 'isFeatureEnabled')
         .mockImplementation(
@@ -407,7 +407,7 @@ describe('async actions', () => {
         );
     });
 
-    afterAll(() => {
+    afterEach(() => {
       isFeatureEnabledMock.mockRestore();
     });
 
@@ -612,9 +612,29 @@ describe('async actions', () => {
     });
 
     describe('queryEditorSetSql', () => {
+      describe('with backend persistence flag on', () => {
+        it('does not update the tab state in the backend', () => {
+          expect.assertions(2);
+
+          const sql = 'SELECT * ';
+          const store = mockStore({});
+
+          return store
+            .dispatch(actions.queryEditorSetSql(queryEditor, sql))
+            .then(() => {
+              expect(store.getActions()).toHaveLength(0);
+              expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
+            });
+        });
+      });
+    });
+    describe('with backend persistence flag off', () => {
       it('updates the tab state in the backend', () => {
-        expect.assertions(2);
-
+        const backendPersistenceOffMock = jest
+          .spyOn(featureFlags, 'isFeatureEnabled')
+          .mockImplementation(
+            feature => !(feature === 'SQLLAB_BACKEND_PERSISTENCE'),
+          );
         const sql = 'SELECT * ';
         const store = mockStore({});
         const expectedActions = [
@@ -624,12 +644,12 @@ describe('async actions', () => {
             sql,
           },
         ];
-        return store
-          .dispatch(actions.queryEditorSetSql(queryEditor, sql))
-          .then(() => {
-            expect(store.getActions()).toEqual(expectedActions);
-            expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(1);
-          });
+
+        store.dispatch(actions.queryEditorSetSql(queryEditor, sql));
+
+        expect(store.getActions()).toEqual(expectedActions);
+        expect(fetchMock.calls(updateTabStateEndpoint)).toHaveLength(0);
+        backendPersistenceOffMock.mockRestore();
       });
     });
 
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js
index 94391e0..56353ce 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.js
@@ -898,16 +898,11 @@ export function updateSavedQuery(query) {
 
 export function queryEditorSetSql(queryEditor, sql) {
   return function (dispatch) {
-    const sync = isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)
-      ? SupersetClient.put({
-          endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
-          postPayload: { sql, latest_query_id: queryEditor.latestQueryId },
-        })
-      : Promise.resolve();
-
-    return sync
-      .then(() => dispatch({ type: QUERY_EDITOR_SET_SQL, queryEditor, sql }))
-      .catch(() =>
+    if (isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)) {
+      return SupersetClient.put({
+        endpoint: encodeURI(`/tabstateview/${queryEditor.id}`),
+        postPayload: { sql, latest_query_id: queryEditor.latestQueryId },
+      }).catch(() =>
         dispatch(
           addDangerToast(
             t(
@@ -918,6 +913,8 @@ export function queryEditorSetSql(queryEditor, sql) {
           ),
         ),
       );
+    }
+    return dispatch({ type: QUERY_EDITOR_SET_SQL, queryEditor, sql });
   };
 }