superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grace...@apache.org
Subject [incubator-superset] branch master updated: [fix] reduce content in sql lab localStorage (#7998)
Date Wed, 07 Aug 2019 04:23:47 GMT
This is an automated email from the ASF dual-hosted git repository.

graceguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new b380879  [fix] reduce content in sql lab localStorage (#7998)
b380879 is described below

commit b380879c41e785efbaa155a5b20254f619f08093
Author: Grace Guo <grace.guo@airbnb.com>
AuthorDate: Tue Aug 6 21:23:40 2019 -0700

    [fix] reduce content in sql lab localStorage (#7998)
---
 .../assets/spec/javascripts/sqllab/fixtures.js     |  7 ++++++
 .../sqllab/utils/emptyQueryResults_spec.js         | 14 ++++++++---
 superset/assets/src/SqlLab/App.jsx                 |  4 +++-
 ...esults.js => reduxStateToLocalStorageHelper.js} | 27 +++++++++++++++++++++-
 4 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/superset/assets/spec/javascripts/sqllab/fixtures.js b/superset/assets/spec/javascripts/sqllab/fixtures.js
index 2b737fe..30cff0b 100644
--- a/superset/assets/spec/javascripts/sqllab/fixtures.js
+++ b/superset/assets/spec/javascripts/sqllab/fixtures.js
@@ -179,6 +179,13 @@ export const defaultQueryEditor = {
   selectedText: null,
   sql: 'SELECT *\nFROM\nWHERE',
   title: 'Untitled Query',
+  schemaOptions: [
+    {
+      value: 'main',
+      label: 'main',
+      title: 'main',
+    },
+  ],
 };
 export const queries = [
   {
diff --git a/superset/assets/spec/javascripts/sqllab/utils/emptyQueryResults_spec.js b/superset/assets/spec/javascripts/sqllab/utils/emptyQueryResults_spec.js
index f202430..4480627 100644
--- a/superset/assets/spec/javascripts/sqllab/utils/emptyQueryResults_spec.js
+++ b/superset/assets/spec/javascripts/sqllab/utils/emptyQueryResults_spec.js
@@ -16,11 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import emptyQueryResults from '../../../../src/SqlLab/utils/emptyQueryResults';
+import { emptyQueryResults, clearQueryEditors } from '../../../../src/SqlLab/utils/reduxStateToLocalStorageHelper';
 import { LOCALSTORAGE_MAX_QUERY_AGE_MS } from '../../../../src/SqlLab/constants';
-import { queries } from '../fixtures';
+import { queries, defaultQueryEditor } from '../fixtures';
 
-describe('emptyQueryResults', () => {
+describe('reduxStateToLocalStorageHelper', () => {
   const queriesObj = {};
   beforeEach(() => {
     queries.forEach((q) => {
@@ -39,4 +39,12 @@ describe('emptyQueryResults', () => {
     expect(emptiedQuery[id].startDttm).toBe(startDttm);
     expect(emptiedQuery[id].results).toEqual({});
   });
+
+  it('should only return selected keys for query editor', () => {
+    const queryEditors = [defaultQueryEditor];
+    expect(Object.keys(queryEditors[0])).toContain('schemaOptions');
+
+    const clearedQueryEditors = clearQueryEditors(queryEditors);
+    expect(Object.keys(clearedQueryEditors)[0]).not.toContain('schemaOptions');
+  });
 });
diff --git a/superset/assets/src/SqlLab/App.jsx b/superset/assets/src/SqlLab/App.jsx
index 3883591..af35a1e 100644
--- a/superset/assets/src/SqlLab/App.jsx
+++ b/superset/assets/src/SqlLab/App.jsx
@@ -27,7 +27,7 @@ import getInitialState from './reducers/getInitialState';
 import rootReducer from './reducers/index';
 import { initEnhancer } from '../reduxUtils';
 import App from './components/App';
-import emptyQueryResults from './utils/emptyQueryResults';
+import { emptyQueryResults, clearQueryEditors } from './utils/reduxStateToLocalStorageHelper';
 import { BYTES_PER_CHAR, KB_STORAGE } from './constants';
 import setupApp from '../setup/setupApp';
 
@@ -57,6 +57,8 @@ const sqlLabPersistStateConfig = {
           subset[path] = {
             ...state[path],
             queries: emptyQueryResults(state[path].queries),
+            queryEditors: clearQueryEditors(state[path].queryEditors),
+            tables: [],
           };
         }
       });
diff --git a/superset/assets/src/SqlLab/utils/emptyQueryResults.js b/superset/assets/src/SqlLab/utils/reduxStateToLocalStorageHelper.js
similarity index 69%
rename from superset/assets/src/SqlLab/utils/emptyQueryResults.js
rename to superset/assets/src/SqlLab/utils/reduxStateToLocalStorageHelper.js
index 2798168..6a517f6 100644
--- a/superset/assets/src/SqlLab/utils/emptyQueryResults.js
+++ b/superset/assets/src/SqlLab/utils/reduxStateToLocalStorageHelper.js
@@ -18,7 +18,19 @@
  */
 import { LOCALSTORAGE_MAX_QUERY_AGE_MS } from '../constants';
 
-export default function emptyQueryResults(queries) {
+const PERSISTENT_QUERY_EDITOR_KEYS = new Set([
+  'autorun',
+  'dbId',
+  'id',
+  'latestQueryId',
+  'queryLimit',
+  'selectedText',
+  'sql',
+  'templateParams',
+  'title',
+]);
+
+export function emptyQueryResults(queries) {
   return Object.keys(queries)
     .reduce((accu, key) => {
       const { startDttm, results } = queries[key];
@@ -35,3 +47,16 @@ export default function emptyQueryResults(queries) {
       return updatedQueries;
     }, {});
 }
+
+export function clearQueryEditors(queryEditors) {
+  return queryEditors
+    .map(editor =>
+    // only return selected keys
+    Object.keys(editor)
+      .filter(key => PERSISTENT_QUERY_EDITOR_KEYS.has(key))
+      .reduce((accumulator, key) => ({
+        ...accumulator,
+        [key]: editor[key],
+      }), {}),
+    );
+}


Mime
View raw message