mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 20:05:03 -02:30
Merge pull request #131 from keithjgrant/add-org-ux-improvements
UX improvements for Add Organization screen
This commit is contained in:
@@ -1,69 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { mount } from 'enzyme';
|
|
||||||
import Tooltip from '../../src/components/Tooltip';
|
|
||||||
|
|
||||||
describe('<Tooltip />', () => {
|
|
||||||
let elem;
|
|
||||||
let content;
|
|
||||||
let mouseOverHandler;
|
|
||||||
let mouseOutHandler;
|
|
||||||
const child = (<span>foo</span>);
|
|
||||||
const message = 'hi';
|
|
||||||
|
|
||||||
test('initially renders without crashing', () => {
|
|
||||||
elem = mount(
|
|
||||||
<Tooltip message={message}>
|
|
||||||
{child}
|
|
||||||
</Tooltip>
|
|
||||||
);
|
|
||||||
expect(elem.length).toBe(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('shows/hides with mouse over and leave', () => {
|
|
||||||
elem = mount(
|
|
||||||
<Tooltip message={message}>
|
|
||||||
{child}
|
|
||||||
</Tooltip>
|
|
||||||
);
|
|
||||||
mouseOverHandler = elem.find('.mouseOverHandler');
|
|
||||||
mouseOutHandler = elem.find('.mouseOutHandler');
|
|
||||||
expect(elem.state().isDisplayed).toBe(false);
|
|
||||||
elem.update();
|
|
||||||
content = elem.find('.pf-c-tooltip__content');
|
|
||||||
expect(content.length).toBe(0);
|
|
||||||
mouseOverHandler.props().onMouseOver();
|
|
||||||
expect(elem.state().isDisplayed).toBe(true);
|
|
||||||
elem.update();
|
|
||||||
content = elem.find('.pf-c-tooltip__content');
|
|
||||||
expect(content.length).toBe(1);
|
|
||||||
mouseOutHandler.props().onMouseLeave();
|
|
||||||
expect(elem.state().isDisplayed).toBe(false);
|
|
||||||
elem.update();
|
|
||||||
content = elem.find('.pf-c-tooltip__content');
|
|
||||||
expect(content.length).toBe(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('shows/hides with focus and blur', () => {
|
|
||||||
elem = mount(
|
|
||||||
<Tooltip message={message}>
|
|
||||||
{child}
|
|
||||||
</Tooltip>
|
|
||||||
);
|
|
||||||
mouseOverHandler = elem.find('.mouseOverHandler');
|
|
||||||
mouseOutHandler = elem.find('.mouseOutHandler');
|
|
||||||
expect(elem.state().isDisplayed).toBe(false);
|
|
||||||
elem.update();
|
|
||||||
content = elem.find('.pf-c-tooltip__content');
|
|
||||||
expect(content.length).toBe(0);
|
|
||||||
mouseOverHandler.props().onFocus();
|
|
||||||
expect(elem.state().isDisplayed).toBe(true);
|
|
||||||
elem.update();
|
|
||||||
content = elem.find('.pf-c-tooltip__content');
|
|
||||||
expect(content.length).toBe(1);
|
|
||||||
mouseOutHandler.props().onBlur();
|
|
||||||
expect(elem.state().isDisplayed).toBe(false);
|
|
||||||
elem.update();
|
|
||||||
content = elem.find('.pf-c-tooltip__content');
|
|
||||||
expect(content.length).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount } from 'enzyme';
|
import { mount } from 'enzyme';
|
||||||
import { MemoryRouter } from 'react-router-dom';
|
import { MemoryRouter, Router } from 'react-router-dom';
|
||||||
import { I18nProvider } from '@lingui/react';
|
import { I18nProvider } from '@lingui/react';
|
||||||
import { ConfigContext } from '../../../../src/context';
|
import { ConfigContext } from '../../../../src/context';
|
||||||
import OrganizationAdd from '../../../../src/pages/Organizations/screens/OrganizationAdd';
|
import OrganizationAdd from '../../../../src/pages/Organizations/screens/OrganizationAdd';
|
||||||
@@ -18,6 +18,7 @@ describe('<OrganizationAdd />', () => {
|
|||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('calls "onFieldChange" when input values change', () => {
|
test('calls "onFieldChange" when input values change', () => {
|
||||||
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onFieldChange');
|
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onFieldChange');
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
@@ -35,6 +36,7 @@ describe('<OrganizationAdd />', () => {
|
|||||||
wrapper.find('input#add-org-form-description').simulate('change', { target: { value: 'bar' } });
|
wrapper.find('input#add-org-form-description').simulate('change', { target: { value: 'bar' } });
|
||||||
expect(spy).toHaveBeenCalledTimes(2);
|
expect(spy).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('calls "onSubmit" when Save button is clicked', () => {
|
test('calls "onSubmit" when Save button is clicked', () => {
|
||||||
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onSubmit');
|
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onSubmit');
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
@@ -51,6 +53,7 @@ describe('<OrganizationAdd />', () => {
|
|||||||
wrapper.find('button[aria-label="Save"]').prop('onClick')();
|
wrapper.find('button[aria-label="Save"]').prop('onClick')();
|
||||||
expect(spy).toBeCalled();
|
expect(spy).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('calls "onCancel" when Cancel button is clicked', () => {
|
test('calls "onCancel" when Cancel button is clicked', () => {
|
||||||
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onCancel');
|
const spy = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onCancel');
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
@@ -68,6 +71,25 @@ describe('<OrganizationAdd />', () => {
|
|||||||
expect(spy).toBeCalled();
|
expect(spy).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('calls "onCancel" when close button (x) is clicked', () => {
|
||||||
|
const wrapper = mount(
|
||||||
|
<MemoryRouter initialEntries={['/organizations/add']} initialIndex={0}>
|
||||||
|
<I18nProvider>
|
||||||
|
<OrganizationAdd
|
||||||
|
match={{ path: '/organizations/add', url: '/organizations/add' }}
|
||||||
|
location={{ search: '', pathname: '/organizations/add' }}
|
||||||
|
/>
|
||||||
|
</I18nProvider>
|
||||||
|
</MemoryRouter>
|
||||||
|
);
|
||||||
|
const history = wrapper.find(Router).prop('history');
|
||||||
|
expect(history.length).toBe(1);
|
||||||
|
expect(history.location.pathname).toEqual('/organizations/add');
|
||||||
|
wrapper.find('button[aria-label="Close"]').prop('onClick')();
|
||||||
|
expect(history.length).toBe(2);
|
||||||
|
expect(history.location.pathname).toEqual('/organizations');
|
||||||
|
});
|
||||||
|
|
||||||
test('Successful form submission triggers redirect', (done) => {
|
test('Successful form submission triggers redirect', (done) => {
|
||||||
const onSuccess = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onSuccess');
|
const onSuccess = jest.spyOn(OrganizationAdd.WrappedComponent.prototype, 'onSuccess');
|
||||||
const mockedResp = { data: { id: 1, related: { instance_groups: '/bar' } } };
|
const mockedResp = { data: { id: 1, related: { instance_groups: '/bar' } } };
|
||||||
|
|||||||
19
src/app.scss
19
src/app.scss
@@ -206,6 +206,21 @@
|
|||||||
--pf-c-card__body--PaddingTop: 24px;
|
--pf-c-card__body--PaddingTop: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// pf tooltip overrides
|
||||||
|
//
|
||||||
|
|
||||||
|
.pf-c-tooltip__content {
|
||||||
|
--pf-c-tooltip__content--PaddingTop: 0.71rem;
|
||||||
|
--pf-c-tooltip__content--PaddingRight: 0.71rem;
|
||||||
|
--pf-c-tooltip__content--PaddingBottom: 0.71rem;
|
||||||
|
--pf-c-tooltip__content--PaddingLeft: 0.71rem;
|
||||||
|
}
|
||||||
|
// higher specificity needed to override PF styles added dynamically to page
|
||||||
|
.pf-c-tooltip .pf-c-tooltip__content {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// pf empty state overrides
|
// pf empty state overrides
|
||||||
//
|
//
|
||||||
@@ -238,3 +253,7 @@
|
|||||||
--pf-c-card__body--PaddingX: 0;
|
--pf-c-card__body--PaddingX: 0;
|
||||||
--pf-c-card__body--PaddingY: 0;
|
--pf-c-card__body--PaddingY: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.at-u-textRight {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
Toolbar,
|
Toolbar,
|
||||||
ToolbarGroup,
|
ToolbarGroup,
|
||||||
ToolbarItem,
|
ToolbarItem,
|
||||||
|
Tooltip,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
import {
|
import {
|
||||||
BarsIcon,
|
BarsIcon,
|
||||||
@@ -30,7 +31,6 @@ import {
|
|||||||
Link
|
Link
|
||||||
} from 'react-router-dom';
|
} from 'react-router-dom';
|
||||||
|
|
||||||
import Tooltip from '../Tooltip';
|
|
||||||
import VerticalSeparator from '../VerticalSeparator';
|
import VerticalSeparator from '../VerticalSeparator';
|
||||||
|
|
||||||
const flexGrowStyling = {
|
const flexGrowStyling = {
|
||||||
@@ -291,7 +291,7 @@ class DataListToolbar extends React.Component {
|
|||||||
<LevelItem>
|
<LevelItem>
|
||||||
{ showDelete && (
|
{ showDelete && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
message={i18n._(t`Delete`)}
|
content={i18n._(t`Delete`)}
|
||||||
position="top"
|
position="top"
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { Button } from '@patternfly/react-core';
|
import { Button, Tooltip } from '@patternfly/react-core';
|
||||||
import { TimesIcon } from '@patternfly/react-icons';
|
import { TimesIcon } from '@patternfly/react-icons';
|
||||||
import Tooltip from '../Tooltip';
|
|
||||||
import './tabs.scss';
|
import './tabs.scss';
|
||||||
|
|
||||||
const Tabs = ({ children, labelText, closeButton }) => (
|
const Tabs = ({ children, labelText, closeButton }) => (
|
||||||
@@ -17,7 +16,7 @@ const Tabs = ({ children, labelText, closeButton }) => (
|
|||||||
{closeButton
|
{closeButton
|
||||||
&& (
|
&& (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
message={closeButton.text}
|
content={closeButton.text}
|
||||||
position="top"
|
position="top"
|
||||||
>
|
>
|
||||||
<Link to={closeButton.link}>
|
<Link to={closeButton.link}>
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
|
|
||||||
const toolTipContent = {
|
|
||||||
padding: '10px',
|
|
||||||
minWidth: '100px',
|
|
||||||
};
|
|
||||||
|
|
||||||
class Tooltip extends React.Component {
|
|
||||||
transforms = {
|
|
||||||
top: {
|
|
||||||
bottom: '100%',
|
|
||||||
left: '50%',
|
|
||||||
transform: 'translate(-50%, -25%)'
|
|
||||||
},
|
|
||||||
bottom: {
|
|
||||||
top: '100%',
|
|
||||||
left: '50%',
|
|
||||||
transform: 'translate(-50%, 25%)'
|
|
||||||
},
|
|
||||||
left: {
|
|
||||||
top: '50%',
|
|
||||||
right: '100%',
|
|
||||||
transform: 'translate(-25%, -50%)'
|
|
||||||
},
|
|
||||||
right: {
|
|
||||||
bottom: '100%',
|
|
||||||
left: '50%',
|
|
||||||
transform: 'translate(25%, 50%)'
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor (props) {
|
|
||||||
super(props);
|
|
||||||
|
|
||||||
this.state = {
|
|
||||||
isDisplayed: false
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
render () {
|
|
||||||
const {
|
|
||||||
children,
|
|
||||||
message,
|
|
||||||
position,
|
|
||||||
} = this.props;
|
|
||||||
const {
|
|
||||||
isDisplayed
|
|
||||||
} = this.state;
|
|
||||||
|
|
||||||
if (message === '') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<span
|
|
||||||
style={{ position: 'relative' }}
|
|
||||||
className="mouseOutHandler"
|
|
||||||
onMouseLeave={() => this.setState({ isDisplayed: false })}
|
|
||||||
onBlur={() => this.setState({ isDisplayed: false })}
|
|
||||||
>
|
|
||||||
{ isDisplayed
|
|
||||||
&& (
|
|
||||||
<div
|
|
||||||
style={{ position: 'absolute', zIndex: '10', ...this.transforms[position] }}
|
|
||||||
className={`pf-c-tooltip pf-m-${position}`}
|
|
||||||
>
|
|
||||||
<div className="pf-c-tooltip__arrow" />
|
|
||||||
<div className="pf-c-tooltip__content" style={toolTipContent}>
|
|
||||||
{ message }
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
<span
|
|
||||||
className="mouseOverHandler"
|
|
||||||
onMouseOver={() => this.setState({ isDisplayed: true })}
|
|
||||||
onFocus={() => this.setState({ isDisplayed: true })}
|
|
||||||
>
|
|
||||||
{ children }
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Tooltip.propTypes = {
|
|
||||||
children: PropTypes.element.isRequired,
|
|
||||||
message: PropTypes.string.isRequired,
|
|
||||||
position: PropTypes.string,
|
|
||||||
};
|
|
||||||
|
|
||||||
Tooltip.defaultProps = {
|
|
||||||
position: 'top',
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Tooltip;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
import Tooltip from './Tooltip';
|
|
||||||
|
|
||||||
export default Tooltip;
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { I18n, i18nMark } from '@lingui/react';
|
import { I18n, i18nMark } from '@lingui/react';
|
||||||
@@ -10,8 +10,12 @@ import {
|
|||||||
TextInput,
|
TextInput,
|
||||||
Gallery,
|
Gallery,
|
||||||
Card,
|
Card,
|
||||||
|
CardHeader,
|
||||||
CardBody,
|
CardBody,
|
||||||
|
Button,
|
||||||
|
Tooltip,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
|
import { QuestionCircleIcon, TimesIcon } from '@patternfly/react-icons';
|
||||||
|
|
||||||
import { ConfigContext } from '../../../context';
|
import { ConfigContext } from '../../../context';
|
||||||
import Lookup from '../../../components/Lookup';
|
import Lookup from '../../../components/Lookup';
|
||||||
@@ -108,11 +112,25 @@ class OrganizationAdd extends React.Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<PageSection>
|
<PageSection>
|
||||||
<Card>
|
<I18n>
|
||||||
<CardBody>
|
{({ i18n }) => (
|
||||||
<Form autoComplete="off">
|
<Card>
|
||||||
<I18n>
|
<CardHeader className="at-u-textRight">
|
||||||
{({ i18n }) => (
|
<Tooltip
|
||||||
|
content={i18n._(t`Close`)}
|
||||||
|
position="top"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="plain"
|
||||||
|
aria-label={i18n._(t`Close`)}
|
||||||
|
onClick={this.onCancel}
|
||||||
|
>
|
||||||
|
<TimesIcon />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</CardHeader>
|
||||||
|
<CardBody>
|
||||||
|
<Form autoComplete="off">
|
||||||
<Gallery gutter="md">
|
<Gallery gutter="md">
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={i18n._(t`Name`)}
|
label={i18n._(t`Name`)}
|
||||||
@@ -135,7 +153,21 @@ class OrganizationAdd extends React.Component {
|
|||||||
onChange={this.onFieldChange}
|
onChange={this.onFieldChange}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
<FormGroup label={i18n._(t`Instance Groups`)} fieldId="add-org-form-instance-groups">
|
<FormGroup
|
||||||
|
label={(
|
||||||
|
<Fragment>
|
||||||
|
{i18n._(t`Instance Groups`)}
|
||||||
|
{' '}
|
||||||
|
<Tooltip
|
||||||
|
position="right"
|
||||||
|
content={i18n._(t`Select the Instance Groups for this Organization to run on.`)}
|
||||||
|
>
|
||||||
|
<QuestionCircleIcon />
|
||||||
|
</Tooltip>
|
||||||
|
</Fragment>
|
||||||
|
)}
|
||||||
|
fieldId="add-org-form-instance-groups"
|
||||||
|
>
|
||||||
<Lookup
|
<Lookup
|
||||||
lookupHeader={i18n._(t`Instance Groups`)}
|
lookupHeader={i18n._(t`Instance Groups`)}
|
||||||
name="instanceGroups"
|
name="instanceGroups"
|
||||||
@@ -149,7 +181,21 @@ class OrganizationAdd extends React.Component {
|
|||||||
<ConfigContext.Consumer>
|
<ConfigContext.Consumer>
|
||||||
{({ custom_virtualenvs }) => (
|
{({ custom_virtualenvs }) => (
|
||||||
custom_virtualenvs && custom_virtualenvs.length > 1 && (
|
custom_virtualenvs && custom_virtualenvs.length > 1 && (
|
||||||
<FormGroup label={i18n._(t`Ansible Environment`)} fieldId="add-org-custom-virtualenv">
|
<FormGroup
|
||||||
|
label={(
|
||||||
|
<Fragment>
|
||||||
|
{i18n._(t`Ansible Environment`)}
|
||||||
|
{' '}
|
||||||
|
<Tooltip
|
||||||
|
position="right"
|
||||||
|
content={i18n._(t`Select the custom Python virtual environment for this organization to run on.`)}
|
||||||
|
>
|
||||||
|
<QuestionCircleIcon />
|
||||||
|
</Tooltip>
|
||||||
|
</Fragment>
|
||||||
|
)}
|
||||||
|
fieldId="add-org-custom-virtualenv"
|
||||||
|
>
|
||||||
<AnsibleSelect
|
<AnsibleSelect
|
||||||
label={i18n._(t`Ansible Environment`)}
|
label={i18n._(t`Ansible Environment`)}
|
||||||
name="custom_virtualenv"
|
name="custom_virtualenv"
|
||||||
@@ -163,17 +209,17 @@ class OrganizationAdd extends React.Component {
|
|||||||
)}
|
)}
|
||||||
</ConfigContext.Consumer>
|
</ConfigContext.Consumer>
|
||||||
</Gallery>
|
</Gallery>
|
||||||
)}
|
<FormActionGroup
|
||||||
</I18n>
|
onSubmit={this.onSubmit}
|
||||||
<FormActionGroup
|
submitDisabled={!enabled}
|
||||||
onSubmit={this.onSubmit}
|
onCancel={this.onCancel}
|
||||||
submitDisabled={!enabled}
|
/>
|
||||||
onCancel={this.onCancel}
|
{error ? <div>error</div> : ''}
|
||||||
/>
|
</Form>
|
||||||
{error ? <div>error</div> : ''}
|
</CardBody>
|
||||||
</Form>
|
</Card>
|
||||||
</CardBody>
|
)}
|
||||||
</Card>
|
</I18n>
|
||||||
</PageSection>
|
</PageSection>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user