diff --git a/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx b/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx index 1d110768a1..db7f5be27c 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryAdd/InventoryAdd.jsx @@ -1,20 +1,18 @@ import React, { useState, useEffect } from 'react'; -import { withI18n } from '@lingui/react'; -import { withRouter } from 'react-router-dom'; -import { t } from '@lingui/macro'; -import { PageSection, Card, CardHeader, Tooltip } from '@patternfly/react-core'; +import { useHistory } from 'react-router-dom'; +import { PageSection, Card } from '@patternfly/react-core'; import { CardBody } from '@components/Card'; import ContentError from '@components/ContentError'; import ContentLoading from '@components/ContentLoading'; -import CardCloseButton from '@components/CardCloseButton'; import { InventoriesAPI, CredentialTypesAPI } from '@api'; import InventoryForm from '../shared/InventoryForm'; -function InventoryAdd({ history, i18n }) { +function InventoryAdd() { const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(true); const [credentialTypeId, setCredentialTypeId] = useState(null); + const history = useHistory(); useEffect(() => { const loadData = async () => { @@ -86,18 +84,6 @@ function InventoryAdd({ history, i18n }) { return ( - - - - - ', () => { let wrapper; let history; + beforeEach(async () => { history = createMemoryHistory({ initialEntries: ['/inventories'] }); await act(async () => { @@ -40,6 +41,7 @@ describe('', () => { test('Initially renders successfully', () => { expect(wrapper.length).toBe(1); }); + test('handleSubmit should call the api', async () => { const instanceGroups = [{ name: 'Bizz', id: 1 }, { name: 'Buzz', id: 2 }]; await waitForElement(wrapper, 'isLoading', el => el.length === 0); @@ -63,9 +65,10 @@ describe('', () => { ) ); }); + test('handleCancel should return the user back to the inventories list', async () => { await waitForElement(wrapper, 'isLoading', el => el.length === 0); - wrapper.find('CardCloseButton').simulate('click'); + wrapper.find('Button[aria-label="Cancel"]').simulate('click'); expect(history.location.pathname).toEqual('/inventories'); }); }); diff --git a/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.jsx b/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.jsx index 584709dce3..f5ec4bd931 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.jsx @@ -1,23 +1,20 @@ import React, { useState, useEffect } from 'react'; -import { withI18n } from '@lingui/react'; -import { withRouter } from 'react-router-dom'; -import { t } from '@lingui/macro'; -import { CardHeader, Tooltip } from '@patternfly/react-core'; +import { useHistory } from 'react-router-dom'; import { object } from 'prop-types'; import { CardBody } from '@components/Card'; -import CardCloseButton from '@components/CardCloseButton'; import { InventoriesAPI, CredentialTypesAPI } from '@api'; import ContentLoading from '@components/ContentLoading'; import ContentError from '@components/ContentError'; import InventoryForm from '../shared/InventoryForm'; import { getAddedAndRemoved } from '../../../util/lists'; -function InventoryEdit({ history, i18n, inventory }) { +function InventoryEdit({ inventory }) { const [error, setError] = useState(null); const [associatedInstanceGroups, setInstanceGroups] = useState(null); const [contentLoading, setContentLoading] = useState(true); const [credentialTypeId, setCredentialTypeId] = useState(null); + const history = useHistory(); useEffect(() => { const loadData = async () => { @@ -47,7 +44,12 @@ function InventoryEdit({ history, i18n, inventory }) { }, [inventory.id, contentLoading, inventory, credentialTypeId]); const handleCancel = () => { - history.push('/inventories'); + const url = + inventory.kind === 'smart' + ? `/inventories/smart_inventory/${inventory.id}/details` + : `/inventories/inventory/${inventory.id}/details`; + + history.push(`${url}`); }; const handleSubmit = async values => { @@ -95,29 +97,15 @@ function InventoryEdit({ history, i18n, inventory }) { return ; } return ( - <> - - - - - - - - - + + + ); } @@ -126,4 +114,4 @@ InventoryEdit.proptype = { }; export { InventoryEdit as _InventoryEdit }; -export default withI18n()(withRouter(InventoryEdit)); +export default InventoryEdit; diff --git a/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.test.jsx b/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.test.jsx index 38a2fbdd42..5c312f98cc 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.test.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryEdit/InventoryEdit.test.jsx @@ -75,6 +75,7 @@ InventoriesAPI.readInstanceGroups.mockResolvedValue({ describe('', () => { let wrapper; let history; + beforeEach(async () => { history = createMemoryHistory({ initialEntries: ['/inventories'] }); await act(async () => { @@ -83,6 +84,7 @@ describe('', () => { }); }); }); + afterEach(() => { wrapper.unmount(); }); @@ -95,10 +97,12 @@ describe('', () => { expect(InventoriesAPI.readInstanceGroups).toBeCalledWith(1); }); - test('handleCancel returns the user to the inventories list', async () => { + test('handleCancel returns the user to inventory detail', async () => { await waitForElement(wrapper, 'isLoading', el => el.length === 0); - wrapper.find('CardCloseButton').simulate('click'); - expect(history.location.pathname).toEqual('/inventories'); + wrapper.find('Button[aria-label="Cancel"]').simulate('click'); + expect(history.location.pathname).toEqual( + '/inventories/inventory/1/details' + ); }); test('handleSubmit should post to the api', async () => { diff --git a/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.jsx b/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.jsx index 65837ce73e..3d501b2d71 100644 --- a/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.jsx +++ b/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.jsx @@ -1,17 +1,14 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { useHistory } from 'react-router-dom'; -import { withI18n } from '@lingui/react'; -import { t } from '@lingui/macro'; -import { PageSection, Card, CardHeader, Tooltip } from '@patternfly/react-core'; +import { PageSection, Card } from '@patternfly/react-core'; import { OrganizationsAPI } from '@api'; import { Config } from '@contexts/Config'; import { CardBody } from '@components/Card'; -import CardCloseButton from '@components/CardCloseButton'; import OrganizationForm from '../shared/OrganizationForm'; -function OrganizationAdd({ i18n }) { +function OrganizationAdd() { const history = useHistory(); const [formError, setFormError] = useState(null); @@ -36,11 +33,6 @@ function OrganizationAdd({ i18n }) { return ( - - - - - {({ me }) => ( @@ -63,4 +55,4 @@ OrganizationAdd.contextTypes = { }; export { OrganizationAdd as _OrganizationAdd }; -export default withI18n()(OrganizationAdd); +export default OrganizationAdd; diff --git a/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.jsx b/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.jsx index 216100c51c..0e499e8cda 100644 --- a/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.jsx +++ b/awx/ui_next/src/screens/Organization/OrganizationAdd/OrganizationAdd.test.jsx @@ -36,18 +36,6 @@ describe('', () => { expect(history.location.pathname).toEqual('/organizations'); }); - test('should navigate to organizations list when close (x) is clicked', async () => { - const history = createMemoryHistory({}); - let wrapper; - await act(async () => { - wrapper = mountWithContexts(, { - context: { router: { history } }, - }); - wrapper.find('button[aria-label="Close"]').invoke('onClick')(); - }); - expect(history.location.pathname).toEqual('/organizations'); - }); - test('successful form submission should trigger redirect', async () => { const history = createMemoryHistory({}); const orgData = { diff --git a/awx/ui_next/src/screens/Project/ProjectAdd/ProjectAdd.jsx b/awx/ui_next/src/screens/Project/ProjectAdd/ProjectAdd.jsx index 16433f6013..919b8b2c71 100644 --- a/awx/ui_next/src/screens/Project/ProjectAdd/ProjectAdd.jsx +++ b/awx/ui_next/src/screens/Project/ProjectAdd/ProjectAdd.jsx @@ -1,15 +1,7 @@ import React, { useState } from 'react'; -import { withRouter } from 'react-router-dom'; -import { withI18n } from '@lingui/react'; -import { t } from '@lingui/macro'; +import { useHistory } from 'react-router-dom'; import styled from 'styled-components'; -import { - Card as _Card, - CardHeader, - PageSection, - Tooltip, -} from '@patternfly/react-core'; -import CardCloseButton from '@components/CardCloseButton'; +import { Card as _Card, PageSection } from '@patternfly/react-core'; import { CardBody } from '@components/Card'; import ProjectForm from '../shared/ProjectForm'; import { ProjectsAPI } from '@api'; @@ -19,8 +11,9 @@ const Card = styled(_Card)` --pf-c-card--child--PaddingRight: 0; `; -function ProjectAdd({ history, i18n }) { +function ProjectAdd() { const [formSubmitError, setFormSubmitError] = useState(null); + const history = useHistory(); const handleSubmit = async values => { if (values.scm_type === 'manual') { @@ -44,11 +37,6 @@ function ProjectAdd({ history, i18n }) { return ( - - - - - ', () => { expect(wrapper.find('ProjectAdd .formSubmitError').length).toBe(1); }); - test('CardHeader close button should navigate to projects list', async () => { - const history = createMemoryHistory(); - await act(async () => { - wrapper = mountWithContexts(, { - context: { router: { history } }, - }).find('ProjectAdd CardHeader'); - }); - await act(async () => { - wrapper.find('CardCloseButton').simulate('click'); - }); - expect(history.location.pathname).toEqual('/projects'); - }); - test('CardBody cancel button should navigate to projects list', async () => { const history = createMemoryHistory(); await act(async () => { diff --git a/awx/ui_next/src/screens/Project/ProjectEdit/ProjectEdit.jsx b/awx/ui_next/src/screens/Project/ProjectEdit/ProjectEdit.jsx index 879675e82e..6f44ec8ab0 100644 --- a/awx/ui_next/src/screens/Project/ProjectEdit/ProjectEdit.jsx +++ b/awx/ui_next/src/screens/Project/ProjectEdit/ProjectEdit.jsx @@ -1,11 +1,8 @@ import React, { useState } from 'react'; -import { withRouter } from 'react-router-dom'; -import { withI18n } from '@lingui/react'; -import { t } from '@lingui/macro'; +import { useHistory } from 'react-router-dom'; import styled from 'styled-components'; -import { Card as _Card, CardHeader, Tooltip } from '@patternfly/react-core'; +import { Card as _Card } from '@patternfly/react-core'; import { CardBody } from '@components/Card'; -import CardCloseButton from '@components/CardCloseButton'; import ProjectForm from '../shared/ProjectForm'; import { ProjectsAPI } from '@api'; @@ -16,8 +13,9 @@ const Card = styled(_Card)` --pf-c-card--child--PaddingRight: 0; `; -function ProjectEdit({ project, history, i18n }) { +function ProjectEdit({ project }) { const [formSubmitError, setFormSubmitError] = useState(null); + const history = useHistory(); const handleSubmit = async values => { if (values.scm_type === 'manual') { @@ -39,11 +37,6 @@ function ProjectEdit({ project, history, i18n }) { return ( - - - - - ', () => { expect(wrapper.find('ProjectEdit .formSubmitError').length).toBe(1); }); - test('CardHeader close button should navigate to project details', async () => { - const history = createMemoryHistory(); - await act(async () => { - wrapper = mountWithContexts(, { - context: { router: { history } }, - }); - wrapper.find('CardCloseButton').simulate('click'); - }); - expect(history.location.pathname).toEqual('/projects/123/details'); - }); - test('CardBody cancel button should navigate to project details', async () => { const history = createMemoryHistory(); await act(async () => { diff --git a/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx b/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx index 06ac875b7c..9670ed8315 100644 --- a/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx +++ b/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.jsx @@ -1,14 +1,10 @@ import React from 'react'; import { withRouter } from 'react-router-dom'; -import { withI18n } from '@lingui/react'; -import { t } from '@lingui/macro'; -import { PageSection, Card, CardHeader, Tooltip } from '@patternfly/react-core'; +import { PageSection, Card } from '@patternfly/react-core'; import { TeamsAPI } from '@api'; import { Config } from '@contexts/Config'; import { CardBody } from '@components/Card'; -import CardCloseButton from '@components/CardCloseButton'; - import TeamForm from '../shared/TeamForm'; class TeamAdd extends React.Component { @@ -36,16 +32,10 @@ class TeamAdd extends React.Component { render() { const { error } = this.state; - const { i18n } = this.props; return ( - - - - - {({ me }) => ( @@ -65,4 +55,4 @@ class TeamAdd extends React.Component { } export { TeamAdd as _TeamAdd }; -export default withI18n()(withRouter(TeamAdd)); +export default withRouter(TeamAdd); diff --git a/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx b/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx index 02225fa733..07aa2382fc 100644 --- a/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx +++ b/awx/ui_next/src/screens/Team/TeamAdd/TeamAdd.test.jsx @@ -32,17 +32,6 @@ describe('', () => { expect(history.location.pathname).toEqual('/teams'); }); - test('should navigate to teams list when close (x) is clicked', async () => { - const history = createMemoryHistory({}); - const wrapper = mountWithContexts(, { - context: { router: { history } }, - }); - await act(async () => { - wrapper.find('button[aria-label="Close"]').invoke('onClick')(); - }); - expect(history.location.pathname).toEqual('/teams'); - }); - test('successful form submission should trigger redirect', async () => { const history = createMemoryHistory({}); const teamData = { diff --git a/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx b/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx index 1b39b95bb5..f21887d483 100644 --- a/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx +++ b/awx/ui_next/src/screens/Template/JobTemplateAdd/JobTemplateAdd.jsx @@ -1,15 +1,13 @@ import React, { useState } from 'react'; -import { withRouter } from 'react-router-dom'; -import { withI18n } from '@lingui/react'; -import { t } from '@lingui/macro'; -import { Card, CardHeader, PageSection, Tooltip } from '@patternfly/react-core'; +import { useHistory } from 'react-router-dom'; +import { Card, PageSection } from '@patternfly/react-core'; import { CardBody } from '@components/Card'; -import CardCloseButton from '@components/CardCloseButton'; import JobTemplateForm from '../shared/JobTemplateForm'; import { JobTemplatesAPI } from '@api'; -function JobTemplateAdd({ history, i18n }) { +function JobTemplateAdd() { const [formSubmitError, setFormSubmitError] = useState(null); + const history = useHistory(); async function handleSubmit(values) { const { @@ -71,11 +69,6 @@ function JobTemplateAdd({ history, i18n }) { return ( - - - - - { setFormSubmitError(null); @@ -41,11 +34,6 @@ function UserAdd({ history, i18n }) { return ( - - - - - @@ -59,4 +47,4 @@ function UserAdd({ history, i18n }) { ); } -export default withI18n()(withRouter(UserAdd)); +export default UserAdd; diff --git a/awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx b/awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx index 49ec8baa11..0ea4d56e19 100644 --- a/awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx +++ b/awx/ui_next/src/screens/User/UserAdd/UserAdd.test.jsx @@ -42,19 +42,6 @@ describe('', () => { expect(history.location.pathname).toEqual('/users'); }); - test('should navigate to users list when close (x) is clicked', async () => { - const history = createMemoryHistory({}); - await act(async () => { - wrapper = mountWithContexts(, { - context: { router: { history } }, - }); - }); - await act(async () => { - wrapper.find('button[aria-label="Close"]').prop('onClick')(); - }); - expect(history.location.pathname).toEqual('/users'); - }); - test('successful form submission should trigger redirect', async () => { const history = createMemoryHistory({}); const userData = {