mirror of
https://github.com/ansible/awx.git
synced 2026-04-09 03:59:21 -02:30
Source variables provided at build time
This commit is contained in:
4
awx/ui_next/public/static/media/default.strings.json
Normal file
4
awx/ui_next/public/static/media/default.strings.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"BRAND_NAME": "AWX",
|
||||||
|
"PENDO_API_KEY": ""
|
||||||
|
}
|
||||||
@@ -25,6 +25,14 @@ class Root extends Base {
|
|||||||
logout() {
|
logout() {
|
||||||
return this.http.get(`${this.baseUrl}logout/`);
|
return this.http.get(`${this.baseUrl}logout/`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readAssetVariables() {
|
||||||
|
// TODO: There's better ways of doing this. Build tools, scripts,
|
||||||
|
// automation etc. should relocate this variable file to an importable
|
||||||
|
// location in src prior to building. That said, a raw http call
|
||||||
|
// works for now.
|
||||||
|
return this.http.get('/static/media/default.strings.json');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Root;
|
export default Root;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { t } from '@lingui/macro';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { LoginForm, LoginPage as PFLoginPage } from '@patternfly/react-core';
|
import { LoginForm, LoginPage as PFLoginPage } from '@patternfly/react-core';
|
||||||
import { RootAPI } from '../../api';
|
import { RootAPI } from '../../api';
|
||||||
import { BrandName } from '../../variables';
|
|
||||||
|
|
||||||
const loginLogoSrc = '/static/media/logo-login.svg';
|
const loginLogoSrc = '/static/media/logo-login.svg';
|
||||||
|
|
||||||
@@ -28,6 +27,7 @@ class AWXLogin extends Component {
|
|||||||
isLoading: true,
|
isLoading: true,
|
||||||
logo: null,
|
logo: null,
|
||||||
loginInfo: null,
|
loginInfo: null,
|
||||||
|
brandName: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.handleChangeUsername = this.handleChangeUsername.bind(this);
|
this.handleChangeUsername = this.handleChangeUsername.bind(this);
|
||||||
@@ -43,16 +43,24 @@ class AWXLogin extends Component {
|
|||||||
async loadCustomLoginInfo() {
|
async loadCustomLoginInfo() {
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
try {
|
try {
|
||||||
const {
|
const [
|
||||||
data: { custom_logo, custom_login_info },
|
{
|
||||||
} = await RootAPI.read();
|
data: { custom_logo, custom_login_info },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: { BRAND_NAME },
|
||||||
|
},
|
||||||
|
] = await Promise.all([RootAPI.read(), RootAPI.readAssetVariables()]);
|
||||||
const logo = custom_logo
|
const logo = custom_logo
|
||||||
? `data:image/jpeg;${custom_logo}`
|
? `data:image/jpeg;${custom_logo}`
|
||||||
: loginLogoSrc;
|
: loginLogoSrc;
|
||||||
|
this.setState({
|
||||||
this.setState({ logo, loginInfo: custom_login_info });
|
brandName: BRAND_NAME,
|
||||||
|
logo,
|
||||||
|
loginInfo: custom_login_info,
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.setState({ logo: loginLogoSrc });
|
this.setState({ brandName: 'AWX', logo: loginLogoSrc });
|
||||||
} finally {
|
} finally {
|
||||||
this.setState({ isLoading: false });
|
this.setState({ isLoading: false });
|
||||||
}
|
}
|
||||||
@@ -93,6 +101,7 @@ class AWXLogin extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
brandName,
|
||||||
hasAuthError,
|
hasAuthError,
|
||||||
hasValidationError,
|
hasValidationError,
|
||||||
username,
|
username,
|
||||||
@@ -102,10 +111,6 @@ class AWXLogin extends Component {
|
|||||||
loginInfo,
|
loginInfo,
|
||||||
} = this.state;
|
} = this.state;
|
||||||
const { alt, i18n, isAuthenticated } = this.props;
|
const { alt, i18n, isAuthenticated } = this.props;
|
||||||
// Setting BrandName to a variable here is necessary to get the jest tests
|
|
||||||
// passing. Attempting to use BrandName in the template literal results
|
|
||||||
// in failing tests.
|
|
||||||
const brandName = BrandName;
|
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return null;
|
return null;
|
||||||
@@ -126,7 +131,11 @@ class AWXLogin extends Component {
|
|||||||
<LoginPage
|
<LoginPage
|
||||||
brandImgSrc={logo}
|
brandImgSrc={logo}
|
||||||
brandImgAlt={alt || brandName}
|
brandImgAlt={alt || brandName}
|
||||||
loginTitle={i18n._(t`Welcome to Ansible ${brandName}! Please Sign In.`)}
|
loginTitle={
|
||||||
|
brandName
|
||||||
|
? i18n._(t`Welcome to Ansible ${brandName}! Please Sign In.`)
|
||||||
|
: ''
|
||||||
|
}
|
||||||
textContent={loginInfo}
|
textContent={loginInfo}
|
||||||
>
|
>
|
||||||
<LoginForm
|
<LoginForm
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ describe('<Login />', () => {
|
|||||||
custom_logo: 'images/foo.jpg',
|
custom_logo: 'images/foo.jpg',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
RootAPI.readAssetVariables.mockResolvedValue({
|
||||||
|
data: {
|
||||||
|
BRAND_NAME: 'AWX',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user