Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sql lab localStorage config #6257

Conversation

graceguo-supercat
Copy link

@graceguo-supercat graceguo-supercat commented Nov 1, 2018

Sql lab used redux-localStorage to persist sql lab redux state into localStorage. by default all the state is persisted. Example of sql lab localStorage:
screen shot 2018-11-01 at 8 07 25 am

we should persist user queries data, but not server-side configuration like common section, messageToasts, etc. localStorage will override server-side configuration when page related. this will cause big problem when we try to set values dynamically from server-side. Also we pass whole translation package in common section. it's a waste of localStorage resource.

this PR will

  • move common out of sqlLab, and set it as root level in redux state.
  • only persist sqlLab into localStorage.

@jeffreythewang @timifasubaa @kristw @williaster

@codecov-io
Copy link

codecov-io commented Nov 1, 2018

Codecov Report

Merging #6257 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6257   +/-   ##
=======================================
  Coverage   77.01%   77.01%           
=======================================
  Files          64       64           
  Lines        9508     9508           
=======================================
  Hits         7323     7323           
  Misses       2185     2185

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a4199a...c152b37. Read the comment docs.

@graceguo-supercat graceguo-supercat force-pushed the gg-AddSqlLabLocalStorageConfig branch from dbb9860 to 67b970d Compare November 1, 2018 17:53
Copy link
Contributor

@kristw kristw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM.

I only see changes to reducers.
Double-checking if there is any part that of the code (container?) that use sqlLab.common that need to be updated too?

let enhancer = persist ? compose(persistState()) : compose();
export function initEnhancer(persist = true, persistConfig = {}) {
const { paths, config } = persistConfig;
let enhancer = persist ? compose(persistState(paths, config)) : compose();
if (process.env.WEBPACK_MODE === 'development') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps move the dev mode logic up to reduce duplicate code and mutation.

const composeEnhancers = process.env.WEBPACK_MODE === 'development'
  ? (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose)
  : compose;

const { paths, config } = persistConfig;

return persist 
  ? composeEnhancers(persistState(paths, config))
  : composeEnhancers();

Copy link
Contributor

@jeffreythewang jeffreythewang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this lgtm, and makes localStorage more organized when loading values from the backend, but I don't think it makes adding a new field in TabbedSqlEditors.jsx any cleaner.

@@ -12,6 +12,7 @@ export default function getInitialState({ defaultDbId, ...restBootstrapData }) {
autorun: false,
dbId: defaultDbId,
};
const { common } = restBootstrapData;

return {
sqlLab: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we ever want to add a field here? We'd have to add it outside of this object (like in common), and then store it back in localStorage by adding it somewhere else right (like in TabbedSqlEditors.jsx)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as long as new field is part of sqlLab, it will be persisted into localStorage.
After this PR, for all other root level keys in redux state, will not be persisted.

slicer: paths => (state) => {
const subset = {};
paths.forEach((path) => {
delete state[path].common; // eslint-disable-line no-param-reassign
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a temporary solution for migrating over existing localStorage, and eventually it will be dead code. Do you foresee this happening for any other field currently under sqlLab if we decide to change the schema?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. this line is to fix the screwed localStorage.

@graceguo-supercat graceguo-supercat force-pushed the gg-AddSqlLabLocalStorageConfig branch 2 times, most recently from c7c5868 to d364de1 Compare November 1, 2018 19:32
@@ -278,7 +278,12 @@ export const sqlLabReducer = function (state = {}, action) {
return state;
};

export const commonReducer = function (state = {}) {
Copy link
Contributor

@williaster williaster Nov 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put this in its own file so we define the reducer for one part of the state tree per file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sql lab used single actions and reducers file. one line above is sqlLabReducer. is it really necessary to split actions/reducers into different files?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say yes, the number of files in Superset that have thousands of lines is crazy makes them all harder to read. it's really trivial to add a new file imo. up to you tho.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I split reducers into different files.

slicer: paths => (state) => {
const subset = {};
paths.forEach((path) => {
delete state[path].common; // eslint-disable-line no-param-reassign
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment explaining what is going on here so people that don't have context can understand it?

also, what's the plan for removing this once it becomes dead code? can we safely delete it in a month? 2 months?

Copy link
Author

@graceguo-supercat graceguo-supercat Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good question..we don't have many options on browser's localStorage if user didn't open sql lab. but if user didn't open sql lab for 2 months he probably didn't critically depend on localStorage.

this PR will help @jeffreythewang's feature: #4941. So I am thinking after a few new features in Sql Lab (a month long is also good), we can remove this cleanup line.

@graceguo-supercat graceguo-supercat force-pushed the gg-AddSqlLabLocalStorageConfig branch from d364de1 to 67b9e92 Compare November 1, 2018 21:40
@graceguo-supercat graceguo-supercat force-pushed the gg-AddSqlLabLocalStorageConfig branch 2 times, most recently from 8a54415 to 502b6e1 Compare November 2, 2018 01:01
Copy link
Contributor

@williaster williaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@graceguo-supercat graceguo-supercat force-pushed the gg-AddSqlLabLocalStorageConfig branch from 502b6e1 to fdf6177 Compare November 7, 2018 06:25
@graceguo-supercat graceguo-supercat force-pushed the gg-AddSqlLabLocalStorageConfig branch from fdf6177 to c152b37 Compare November 7, 2018 06:54
@graceguo-supercat graceguo-supercat merged commit 69e8df4 into apache:master Nov 7, 2018
@graceguo-supercat graceguo-supercat deleted the gg-AddSqlLabLocalStorageConfig branch November 7, 2018 07:12
bipinsoniguavus pushed a commit to ThalesGroup/incubator-superset that referenced this pull request Dec 26, 2018
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants