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
No known key found for this signature in database
GPG Key ID: 2D0E60E4B8C7EA0F

View File

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