mirror of https://github.com/apache/superset.git
[fix] reduce content in sql lab localStorage (#7998)
This commit is contained in:
parent
af2b92d147
commit
b380879c41
|
@ -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 = [
|
||||
{
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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: [],
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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],
|
||||
}), {}),
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue