1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

add 'has' prefix to error booleans

This commit is contained in:
Jake McDermott 2019-06-21 12:01:29 -04:00
parent c3823771a7
commit 9dda5404a0
4 changed files with 31 additions and 31 deletions

View File

@ -48,7 +48,7 @@ class App extends Component {
version: null, version: null,
isAboutModalOpen: false, isAboutModalOpen: false,
isNavOpen, isNavOpen,
configError: false, hasConfigError: false,
}; };
this.handleLogout = this.handleLogout.bind(this); this.handleLogout = this.handleLogout.bind(this);
@ -81,7 +81,7 @@ class App extends Component {
} }
handleConfigErrorClose () { handleConfigErrorClose () {
this.setState({ configError: false }); this.setState({ hasConfigError: false });
} }
async loadConfig () { async loadConfig () {
@ -92,7 +92,7 @@ class App extends Component {
this.setState({ ansible_version, custom_virtualenvs, version, me }); this.setState({ ansible_version, custom_virtualenvs, version, me });
} catch (err) { } catch (err) {
this.setState({ configError: true }); this.setState({ hasConfigError: true });
} }
} }
@ -104,7 +104,7 @@ class App extends Component {
isNavOpen, isNavOpen,
me, me,
version, version,
configError, hasConfigError,
} = this.state; } = this.state;
const { const {
i18n, i18n,
@ -170,7 +170,7 @@ class App extends Component {
onClose={this.handleAboutClose} onClose={this.handleAboutClose}
/> />
<AlertModal <AlertModal
isOpen={configError} isOpen={hasConfigError}
variant="danger" variant="danger"
title={i18n._(t`Error!`)} title={i18n._(t`Error!`)}
onClose={this.handleConfigErrorClose} onClose={this.handleConfigErrorClose}

View File

@ -32,7 +32,7 @@ class JobList extends Component {
this.state = { this.state = {
hasContentLoading: true, hasContentLoading: true,
hasContentError: false, hasContentError: false,
deletionError: false, hasDeletionError: false,
selected: [], selected: [],
jobs: [], jobs: [],
itemCount: 0, itemCount: 0,
@ -56,7 +56,7 @@ class JobList extends Component {
} }
handleDeleteErrorClose () { handleDeleteErrorClose () {
this.setState({ deletionError: false }); this.setState({ hasDeletionError: false });
} }
handleSelectAll (isSelected) { handleSelectAll (isSelected) {
@ -76,11 +76,11 @@ class JobList extends Component {
async handleDelete () { async handleDelete () {
const { selected } = this.state; const { selected } = this.state;
this.setState({ hasContentLoading: true, deletionError: false }); this.setState({ hasContentLoading: true, hasDeletionError: false });
try { try {
await Promise.all(selected.map(({ id }) => UnifiedJobsAPI.destroy(id))); await Promise.all(selected.map(({ id }) => UnifiedJobsAPI.destroy(id)));
} catch (err) { } catch (err) {
this.setState({ deletionError: true }); this.setState({ hasDeletionError: true });
} finally { } finally {
await this.loadJobs(); await this.loadJobs();
} }
@ -109,7 +109,7 @@ class JobList extends Component {
const { const {
hasContentError, hasContentError,
hasContentLoading, hasContentLoading,
deletionError, hasDeletionError,
jobs, jobs,
itemCount, itemCount,
selected, selected,
@ -166,7 +166,7 @@ class JobList extends Component {
/> />
</Card> </Card>
<AlertModal <AlertModal
isOpen={deletionError} isOpen={hasDeletionError}
variant="danger" variant="danger"
title={i18n._(t`Error!`)} title={i18n._(t`Error!`)}
onClose={this.handleDeleteErrorClose} onClose={this.handleDeleteErrorClose}

View File

@ -25,8 +25,8 @@ class AWXLogin extends Component {
this.state = { this.state = {
username: '', username: '',
password: '', password: '',
authenticationError: false, hasAuthError: false,
validationError: false, hasValidationError: false,
isAuthenticating: false, isAuthenticating: false,
isLoading: true, isLoading: true,
logo: null, logo: null,
@ -66,16 +66,16 @@ class AWXLogin extends Component {
return; return;
} }
this.setState({ authenticationError: false, isAuthenticating: true }); this.setState({ hasAuthError: false, isAuthenticating: true });
try { try {
// note: if authentication is successful, the appropriate cookie will be set automatically // note: if authentication is successful, the appropriate cookie will be set automatically
// and isAuthenticated() (the source of truth) will start returning true. // and isAuthenticated() (the source of truth) will start returning true.
await RootAPI.login(username, password); await RootAPI.login(username, password);
} catch (err) { } catch (err) {
if (err && err.response && err.response.status === 401) { if (err && err.response && err.response.status === 401) {
this.setState({ validationError: true }); this.setState({ hasValidationError: true });
} else { } else {
this.setState({ authenticationError: true }); this.setState({ hasAuthError: true });
} }
} finally { } finally {
this.setState({ isAuthenticating: false }); this.setState({ isAuthenticating: false });
@ -83,17 +83,17 @@ class AWXLogin extends Component {
} }
handleChangeUsername (value) { handleChangeUsername (value) {
this.setState({ username: value, validationError: false }); this.setState({ username: value, hasValidationError: false });
} }
handleChangePassword (value) { handleChangePassword (value) {
this.setState({ password: value, validationError: false }); this.setState({ password: value, hasValidationError: false });
} }
render () { render () {
const { const {
authenticationError, hasAuthError,
validationError, hasValidationError,
username, username,
password, password,
isLoading, isLoading,
@ -115,7 +115,7 @@ class AWXLogin extends Component {
} }
let helperText; let helperText;
if (validationError) { if (hasValidationError) {
helperText = i18n._(t`Invalid username or password. Please try again.`); helperText = i18n._(t`Invalid username or password. Please try again.`);
} else { } else {
helperText = i18n._(t`There was a problem signing in. Please try again.`); helperText = i18n._(t`There was a problem signing in. Please try again.`);
@ -129,15 +129,15 @@ class AWXLogin extends Component {
textContent={loginInfo} textContent={loginInfo}
> >
<LoginForm <LoginForm
className={(authenticationError || validationError) ? 'pf-m-error' : ''} className={(hasAuthError || hasValidationError) ? 'pf-m-error' : ''}
usernameLabel={i18n._(t`Username`)} usernameLabel={i18n._(t`Username`)}
passwordLabel={i18n._(t`Password`)} passwordLabel={i18n._(t`Password`)}
showHelperText={(authenticationError || validationError)} showHelperText={(hasAuthError || hasValidationError)}
helperText={helperText} helperText={helperText}
usernameValue={username} usernameValue={username}
passwordValue={password} passwordValue={password}
isValidUsername={!validationError} isValidUsername={!hasValidationError}
isValidPassword={!validationError} isValidPassword={!hasValidationError}
onChangeUsername={this.handleChangeUsername} onChangeUsername={this.handleChangeUsername}
onChangePassword={this.handleChangePassword} onChangePassword={this.handleChangePassword}
onLoginButtonClick={this.handleLoginButtonClick} onLoginButtonClick={this.handleLoginButtonClick}

View File

@ -60,7 +60,7 @@ describe('<Login />', () => {
} = await findChildren(loginWrapper); } = await findChildren(loginWrapper);
expect(usernameInput.props().value).toBe(''); expect(usernameInput.props().value).toBe('');
expect(passwordInput.props().value).toBe(''); expect(passwordInput.props().value).toBe('');
expect(awxLogin.state('validationError')).toBe(false); expect(awxLogin.state('hasValidationError')).toBe(false);
expect(submitButton.props().isDisabled).toBe(false); expect(submitButton.props().isDisabled).toBe(false);
done(); done();
}); });
@ -126,14 +126,14 @@ describe('<Login />', () => {
submitButton.simulate('click'); submitButton.simulate('click');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'invalid'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'invalid');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'invalid'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'invalid');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('validationError') === true); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasValidationError') === true);
await waitForElement(loginWrapper, formError, (el) => el.length === 1); await waitForElement(loginWrapper, formError, (el) => el.length === 1);
usernameInput.props().onChange({ currentTarget: { value: 'dsarif' } }); usernameInput.props().onChange({ currentTarget: { value: 'dsarif' } });
passwordInput.props().onChange({ currentTarget: { value: 'freneticpny' } }); passwordInput.props().onChange({ currentTarget: { value: 'freneticpny' } });
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'dsarif'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'dsarif');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'freneticpny'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'freneticpny');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('validationError') === false); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasValidationError') === false);
await waitForElement(loginWrapper, formError, (el) => el.length === 0); await waitForElement(loginWrapper, formError, (el) => el.length === 0);
done(); done();
@ -151,16 +151,16 @@ describe('<Login />', () => {
RootAPI.login.mockRejectedValueOnce({ response: { status: 500 } }); RootAPI.login.mockRejectedValueOnce({ response: { status: 500 } });
submitButton.simulate('click'); submitButton.simulate('click');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === true); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === true);
usernameInput.props().onChange({ currentTarget: { value: 'sgrimes' } }); usernameInput.props().onChange({ currentTarget: { value: 'sgrimes' } });
passwordInput.props().onChange({ currentTarget: { value: 'ovid' } }); passwordInput.props().onChange({ currentTarget: { value: 'ovid' } });
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'sgrimes'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'sgrimes');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'ovid'); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'ovid');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === true); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === true);
submitButton.simulate('click'); submitButton.simulate('click');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === false); await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === false);
done(); done();
}); });