Use setState instead of sessionStorage for config data.

This commit is contained in:
kialam
2018-12-21 10:20:07 -05:00
parent 6dc11a926e
commit 4eb04b6f5c

View File

@@ -79,10 +79,6 @@ class App extends React.Component {
}; };
} }
getSessionObject(key) {
return JSON.parse(sessionStorage.getItem(key) || '{}');
}
onNavToggle = () => { onNavToggle = () => {
this.setState(({ isNavOpen }) => ({ isNavOpen: !isNavOpen })); this.setState(({ isNavOpen }) => ({ isNavOpen: !isNavOpen }));
}; };
@@ -94,20 +90,15 @@ class App extends React.Component {
onDevLogout = async () => { onDevLogout = async () => {
await api.get(API_LOGOUT); await api.get(API_LOGOUT);
this.setState({ activeGroup: 'views_group', activeItem: 'views_group_dashboard' }); this.setState({ activeGroup: 'views_group', activeItem: 'views_group_dashboard' });
if (sessionStorage.config) {
sessionStorage.clear();
}
} }
async componentDidMount() { async componentDidMount() {
// Grab our config data from the API and store in sessionStorage // Grab our config data from the API and store in state
if (!sessionStorage.config) { const { data } = await api.get(API_CONFIG);
const { data } = await api.get(API_CONFIG); this.setState({ config: data });
sessionStorage.setItem('config', JSON.stringify(data));
}
} }
render() { render() {
const { isNavOpen } = this.state; const { isNavOpen, config } = this.state;
const { logo, loginInfo, history } = this.props; const { logo, loginInfo, history } = this.props;
const PageToolbar = ( const PageToolbar = (
@@ -235,7 +226,7 @@ class App extends React.Component {
<ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/projects" component={Projects} /> <ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/projects" component={Projects} />
<ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/inventories" component={Inventories} /> <ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/inventories" component={Inventories} />
<ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/inventory_scripts" component={InventoryScripts} /> <ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/inventory_scripts" component={InventoryScripts} />
<ConfigContext.Provider value={this.getSessionObject('config')}> <ConfigContext.Provider value={config}>
<ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/organizations" component={Organizations} /> <ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/organizations" component={Organizations} />
</ConfigContext.Provider> </ConfigContext.Provider>
<ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/users" component={Users} /> <ConditionalRedirect shouldRedirect={() => !api.isAuthenticated()} redirectPath="/login" path="/users" component={Users} />