-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ import thunkMiddleware from 'redux-thunk'; | |
import { hot } from 'react-hot-loader'; | ||
|
||
import { initFeatureFlags } from 'src/featureFlags'; | ||
import getInitialState from './getInitialState'; | ||
import rootReducer from './reducers'; | ||
import getInitialState from './reducers/getInitialState'; | ||
import rootReducer from './reducers/index'; | ||
import { initEnhancer } from '../reduxUtils'; | ||
import App from './components/App'; | ||
import setupApp from '../setup/setupApp'; | ||
|
@@ -20,14 +20,31 @@ setupApp(); | |
const appContainer = document.getElementById('app'); | ||
const bootstrapData = JSON.parse(appContainer.getAttribute('data-bootstrap')); | ||
initFeatureFlags(bootstrapData.common.feature_flags); | ||
const state = getInitialState(bootstrapData); | ||
const initialState = getInitialState(bootstrapData); | ||
const sqlLabPersistStateConfig = { | ||
paths: ['sqlLab'], | ||
config: { | ||
slicer: paths => (state) => { | ||
const subset = {}; | ||
paths.forEach((path) => { | ||
// this line is used to remove old data from browser localStorage. | ||
// we used to persist all redux state into localStorage, but | ||
// it caused configurations passed from server-side got override. | ||
// see PR 6257 for details | ||
delete state[path].common; // eslint-disable-line no-param-reassign | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
subset[path] = state[path]; | ||
}); | ||
return subset; | ||
}, | ||
}, | ||
}; | ||
|
||
const store = createStore( | ||
rootReducer, | ||
state, | ||
initialState, | ||
compose( | ||
applyMiddleware(thunkMiddleware), | ||
initEnhancer(), | ||
initEnhancer(true, sqlLabPersistStateConfig), | ||
), | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function commonReducer(state = {}) { | ||
return state; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { combineReducers } from 'redux'; | ||
|
||
import sqlLab from './sqlLab'; | ||
import messageToasts from '../../messageToasts/reducers/index'; | ||
import common from './common'; | ||
|
||
export default combineReducers({ | ||
sqlLab, | ||
messageToasts, | ||
common, | ||
}); |
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 undersqlLab
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.