1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

add config pass-through to inline render

This commit is contained in:
Jake McDermott 2019-01-03 09:37:02 -05:00
parent 4ccce4cc9e
commit 3e201d3ca0
No known key found for this signature in database
GPG Key ID: 9A6F084352C3A0B7
2 changed files with 21 additions and 16 deletions

View File

@ -24,9 +24,11 @@ class App extends Component {
this.state = {
ansible_version: null,
version: null,
custom_virtualenvs: null,
isAboutModalOpen: false,
isNavOpen,
version: null,
};
this.fetchConfig = this.fetchConfig.bind(this);
@ -41,6 +43,17 @@ class App extends Component {
this.fetchConfig();
}
async fetchConfig () {
const { api } = this.props;
try {
const { data: { ansible_version, custom_virtualenvs, version } } = await api.getConfig();
this.setState({ ansible_version, custom_virtualenvs, version });
} catch (err) {
this.setState({ ansible_version: null, custom_virtualenvs: null, version: null });
}
}
async onLogout () {
const { api } = this.props;
@ -48,17 +61,6 @@ class App extends Component {
window.location.replace('/#/login')
}
async fetchConfig () {
const { api } = this.props;
try {
const { data: { ansible_version, version } } = await api.getConfig();
this.setState({ ansible_version, version });
} catch (err) {
this.setState({ ansible_version: null, version: null });
}
}
onAboutModalOpen () {
this.setState({ isAboutModalOpen: true });
}
@ -78,10 +80,12 @@ class App extends Component {
render () {
const {
ansible_version,
custom_virtualenvs,
isAboutModalOpen,
isNavOpen,
version,
} = this.state;
const {
render,
routeGroups = [],
@ -90,6 +94,7 @@ class App extends Component {
const config = {
ansible_version,
custom_virtualenvs,
version,
};
@ -134,7 +139,7 @@ class App extends Component {
}
>
<ConfigContext.Provider value={config}>
{ render ? render({ routeGroups }) : '' }
{render && render({ routeGroups, config })}
</ConfigContext.Provider>
</Page>
<About

View File

@ -73,8 +73,7 @@ const catalogs = { en, ja };
export async function main (render, api) {
const el = document.getElementById('app');
// fetch additional config from server
const { data } = await api.getRoot();
const { custom_logo, custom_login_info } = data;
const { data: { custom_logo, custom_login_info } } = await api.getRoot();
const loginRoutes = (
<Switch>
@ -252,7 +251,7 @@ export async function main (render, api) {
],
},
]}
render={({ routeGroups }) => (
render={({ routeGroups, config }) => (
routeGroups
.reduce((allRoutes, { routes }) => allRoutes.concat(routes), [])
.map(({ component: PageComponent, path }) => (
@ -263,6 +262,7 @@ export async function main (render, api) {
<PageComponent
api={api}
match={match}
{...config}
/>
)}
/>