mirror of
https://github.com/ansible/awx.git
synced 2026-02-24 14:36:00 -03:30
Use setState instead of sessionStorage for config data.
This commit is contained in:
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 = () => {
|
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} />
|
||||||
|
|||||||
Reference in New Issue
Block a user