mirror of
https://github.com/ansible/awx.git
synced 2026-01-15 11:50:42 -03:30
Use setState instead of sessionStorage for config data.
This commit is contained in:
parent
6dc11a926e
commit
4eb04b6f5c
19
src/App.jsx
19
src/App.jsx
@ -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} />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user