mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Replace withRouter HOC with route hooks
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import {
|
import {
|
||||||
@@ -16,7 +16,8 @@ import { Config } from '@contexts/Config';
|
|||||||
import CardCloseButton from '@components/CardCloseButton';
|
import CardCloseButton from '@components/CardCloseButton';
|
||||||
import OrganizationForm from '../shared/OrganizationForm';
|
import OrganizationForm from '../shared/OrganizationForm';
|
||||||
|
|
||||||
function OrganizationAdd({ history, i18n }) {
|
function OrganizationAdd({ i18n }) {
|
||||||
|
const history = useHistory();
|
||||||
const [formError, setFormError] = useState(null);
|
const [formError, setFormError] = useState(null);
|
||||||
|
|
||||||
const handleSubmit = async (values, groupsToAssociate) => {
|
const handleSubmit = async (values, groupsToAssociate) => {
|
||||||
@@ -67,4 +68,4 @@ OrganizationAdd.contextTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export { OrganizationAdd as _OrganizationAdd };
|
export { OrganizationAdd as _OrganizationAdd };
|
||||||
export default withI18n()(withRouter(OrganizationAdd));
|
export default withI18n()(OrganizationAdd);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Link, withRouter } from 'react-router-dom';
|
import { Link, useRouteMatch } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { CardBody as PFCardBody, Button } from '@patternfly/react-core';
|
import { CardBody as PFCardBody, Button } from '@patternfly/react-core';
|
||||||
@@ -16,10 +16,10 @@ const CardBody = styled(PFCardBody)`
|
|||||||
padding-top: 20px;
|
padding-top: 20px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function OrganizationDetail({ i18n, match, organization }) {
|
function OrganizationDetail({ i18n, organization }) {
|
||||||
const {
|
const {
|
||||||
params: { id },
|
params: { id },
|
||||||
} = match;
|
} = useRouteMatch();
|
||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
@@ -104,4 +104,4 @@ function OrganizationDetail({ i18n, match, organization }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withI18n()(withRouter(OrganizationDetail));
|
export default withI18n()(OrganizationDetail);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { CardBody } from '@patternfly/react-core';
|
import { CardBody } from '@patternfly/react-core';
|
||||||
|
|
||||||
import { OrganizationsAPI } from '@api';
|
import { OrganizationsAPI } from '@api';
|
||||||
@@ -8,8 +8,9 @@ import { Config } from '@contexts/Config';
|
|||||||
|
|
||||||
import OrganizationForm from '../shared/OrganizationForm';
|
import OrganizationForm from '../shared/OrganizationForm';
|
||||||
|
|
||||||
function OrganizationEdit({ history, organization }) {
|
function OrganizationEdit({ organization }) {
|
||||||
const detailsUrl = `/organizations/${organization.id}/details`;
|
const detailsUrl = `/organizations/${organization.id}/details`;
|
||||||
|
const history = useHistory();
|
||||||
const [formError, setFormError] = useState(null);
|
const [formError, setFormError] = useState(null);
|
||||||
|
|
||||||
const handleSubmit = async (
|
const handleSubmit = async (
|
||||||
@@ -65,4 +66,4 @@ OrganizationEdit.contextTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export { OrganizationEdit as _OrganizationEdit };
|
export { OrganizationEdit as _OrganizationEdit };
|
||||||
export default withRouter(OrganizationEdit);
|
export default OrganizationEdit;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { useLocation, useRouteMatch } from 'react-router-dom';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Card, PageSection } from '@patternfly/react-core';
|
import { Card, PageSection } from '@patternfly/react-core';
|
||||||
@@ -22,7 +22,9 @@ const QS_CONFIG = getQSConfig('organization', {
|
|||||||
order_by: 'name',
|
order_by: 'name',
|
||||||
});
|
});
|
||||||
|
|
||||||
function OrganizationsList({ i18n, location, match }) {
|
function OrganizationsList({ i18n }) {
|
||||||
|
const location = useLocation();
|
||||||
|
const match = useRouteMatch();
|
||||||
const [contentError, setContentError] = useState(null);
|
const [contentError, setContentError] = useState(null);
|
||||||
const [deletionError, setDeletionError] = useState(null);
|
const [deletionError, setDeletionError] = useState(null);
|
||||||
const [hasContentLoading, setHasContentLoading] = useState(true);
|
const [hasContentLoading, setHasContentLoading] = useState(true);
|
||||||
@@ -185,4 +187,4 @@ function OrganizationsList({ i18n, location, match }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export { OrganizationsList as _OrganizationsList };
|
export { OrganizationsList as _OrganizationsList };
|
||||||
export default withI18n()(withRouter(OrganizationsList));
|
export default withI18n()(OrganizationsList);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
import { OrganizationsAPI } from '@api';
|
import { OrganizationsAPI } from '@api';
|
||||||
import PaginatedDataList from '@components/PaginatedDataList';
|
import PaginatedDataList from '@components/PaginatedDataList';
|
||||||
@@ -12,7 +12,8 @@ const QS_CONFIG = getQSConfig('team', {
|
|||||||
order_by: 'name',
|
order_by: 'name',
|
||||||
});
|
});
|
||||||
|
|
||||||
function OrganizationTeams({ id, location }) {
|
function OrganizationTeams({ id }) {
|
||||||
|
const location = useLocation();
|
||||||
const [contentError, setContentError] = useState(null);
|
const [contentError, setContentError] = useState(null);
|
||||||
const [hasContentLoading, setHasContentLoading] = useState(false);
|
const [hasContentLoading, setHasContentLoading] = useState(false);
|
||||||
const [itemCount, setItemCount] = useState(0);
|
const [itemCount, setItemCount] = useState(0);
|
||||||
@@ -54,4 +55,4 @@ OrganizationTeams.propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export { OrganizationTeams as _OrganizationTeams };
|
export { OrganizationTeams as _OrganizationTeams };
|
||||||
export default withRouter(OrganizationTeams);
|
export default OrganizationTeams;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
import { shallow } from 'enzyme';
|
|
||||||
|
|
||||||
import { OrganizationsAPI } from '@api';
|
import { OrganizationsAPI } from '@api';
|
||||||
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
import { mountWithContexts } from '@testUtils/enzymeHelpers';
|
||||||
@@ -32,14 +31,16 @@ describe('<OrganizationTeams />', () => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('renders succesfully', () => {
|
test('renders succesfully', async () => {
|
||||||
shallow(
|
await act(async () => {
|
||||||
<OrganizationTeams
|
mountWithContexts(
|
||||||
id={1}
|
<OrganizationTeams
|
||||||
searchString=""
|
id={1}
|
||||||
location={{ search: '', pathname: '/organizations/1/teams' }}
|
searchString=""
|
||||||
/>
|
location={{ search: '', pathname: '/organizations/1/teams' }}
|
||||||
);
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should load teams on mount', async () => {
|
test('should load teams on mount', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user