-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Add sql lab localStorage config #6257
Conversation
Codecov Report
@@ 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.
|
dbb9860
to
67b970d
Compare
There was a problem hiding this 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?
superset/assets/src/reduxUtils.js
Outdated
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') { |
There was a problem hiding this comment.
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();
There was a problem hiding this 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: { |
There was a problem hiding this comment.
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
)?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
c7c5868
to
d364de1
Compare
@@ -278,7 +278,12 @@ export const sqlLabReducer = function (state = {}, action) { | |||
return state; | |||
}; | |||
|
|||
export const commonReducer = function (state = {}) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
d364de1
to
67b9e92
Compare
For redux root level key |
8a54415
to
502b6e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
502b6e1
to
fdf6177
Compare
fdf6177
to
c152b37
Compare
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:

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 incommon
section. it's a waste of localStorage resource.this PR will
common
out ofsqlLab
, and set it as root level in redux state.sqlLab
into localStorage.@jeffreythewang @timifasubaa @kristw @williaster