mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 19:30:39 -03:30
Fetch new inventory on location change
This commit is contained in:
parent
d35eba8afb
commit
d549c217bb
@ -183,10 +183,6 @@
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
.at-u-textRight {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
//
|
||||
// AlertModal styles
|
||||
//
|
||||
|
||||
@ -85,22 +85,16 @@ class Inventories extends Component {
|
||||
path={`${match.path}/smart_inventory/add`}
|
||||
render={() => <SmartInventoryAdd />}
|
||||
/>
|
||||
<Route
|
||||
path={`${match.path}/inventory/:id`}
|
||||
render={({ match: newRouteMatch }) => (
|
||||
<Config>
|
||||
{({ me }) => (
|
||||
<Inventory
|
||||
history={history}
|
||||
location={location}
|
||||
setBreadcrumb={this.setBreadCrumbConfig}
|
||||
me={me || {}}
|
||||
match={newRouteMatch}
|
||||
/>
|
||||
)}
|
||||
</Config>
|
||||
)}
|
||||
/>
|
||||
<Route path={`${match.path}/inventory/:id`}>
|
||||
<Config>
|
||||
{({ me }) => (
|
||||
<Inventory
|
||||
setBreadcrumb={this.setBreadCrumbConfig}
|
||||
me={me || {}}
|
||||
/>
|
||||
)}
|
||||
</Config>
|
||||
</Route>
|
||||
<Route
|
||||
path={`${match.path}/smart_inventory/:id`}
|
||||
render={({ match: newRouteMatch }) => (
|
||||
|
||||
@ -2,7 +2,15 @@ import React, { useEffect, useState } from 'react';
|
||||
import { t } from '@lingui/macro';
|
||||
import { withI18n } from '@lingui/react';
|
||||
import { Card, PageSection } from '@patternfly/react-core';
|
||||
import { Switch, Route, Redirect, withRouter, Link } from 'react-router-dom';
|
||||
import {
|
||||
Switch,
|
||||
Route,
|
||||
Redirect,
|
||||
Link,
|
||||
useHistory,
|
||||
useLocation,
|
||||
useRouteMatch,
|
||||
} from 'react-router-dom';
|
||||
import { TabbedCardHeader } from '@components/Card';
|
||||
import CardCloseButton from '@components/CardCloseButton';
|
||||
import ContentError from '@components/ContentError';
|
||||
@ -17,10 +25,15 @@ import InventorySources from './InventorySources';
|
||||
import { InventoriesAPI } from '@api';
|
||||
import InventoryEdit from './InventoryEdit';
|
||||
|
||||
function Inventory({ history, i18n, location, match, setBreadcrumb }) {
|
||||
function Inventory({ i18n, setBreadcrumb }) {
|
||||
const [contentError, setContentError] = useState(null);
|
||||
const [hasContentLoading, setHasContentLoading] = useState(true);
|
||||
const [inventory, setInventory] = useState(null);
|
||||
const history = useHistory();
|
||||
const location = useLocation();
|
||||
const match = useRouteMatch({
|
||||
path: '/inventories/inventory/:id',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchData() {
|
||||
@ -36,7 +49,7 @@ function Inventory({ history, i18n, location, match, setBreadcrumb }) {
|
||||
}
|
||||
|
||||
fetchData();
|
||||
}, [match.params.id, setBreadcrumb]);
|
||||
}, [match.params.id, location.pathname, setBreadcrumb]);
|
||||
|
||||
const tabsArray = [
|
||||
{ name: i18n._(t`Details`), link: `${match.url}/details`, id: 0 },
|
||||
@ -132,7 +145,6 @@ function Inventory({ history, i18n, location, match, setBreadcrumb }) {
|
||||
<InventoryGroups
|
||||
location={location}
|
||||
match={match}
|
||||
history={history}
|
||||
setBreadcrumb={setBreadcrumb}
|
||||
inventory={inventory}
|
||||
/>
|
||||
@ -178,4 +190,4 @@ function Inventory({ history, i18n, location, match, setBreadcrumb }) {
|
||||
}
|
||||
|
||||
export { Inventory as _Inventory };
|
||||
export default withI18n()(withRouter(Inventory));
|
||||
export default withI18n()(Inventory);
|
||||
|
||||
@ -7,6 +7,13 @@ import mockInventory from './shared/data.inventory.json';
|
||||
import Inventory from './Inventory';
|
||||
|
||||
jest.mock('@api');
|
||||
jest.mock('react-router-dom', () => ({
|
||||
...jest.requireActual('react-router-dom'),
|
||||
useRouteMatch: () => ({
|
||||
url: '/inventories/1',
|
||||
params: { id: 1 },
|
||||
}),
|
||||
}));
|
||||
|
||||
InventoriesAPI.readDetail.mockResolvedValue({
|
||||
data: mockInventory,
|
||||
@ -17,9 +24,7 @@ describe('<Inventory />', () => {
|
||||
|
||||
test('initially renders succesfully', async () => {
|
||||
await act(async () => {
|
||||
wrapper = mountWithContexts(
|
||||
<Inventory setBreadcrumb={() => {}} match={{ params: { id: 1 } }} />
|
||||
);
|
||||
wrapper = mountWithContexts(<Inventory setBreadcrumb={() => {}} />);
|
||||
});
|
||||
await waitForElement(wrapper, 'ContentLoading', el => el.length === 0);
|
||||
await waitForElement(wrapper, '.pf-c-tabs__item', el => el.length === 6);
|
||||
|
||||
@ -90,12 +90,15 @@ function InventoryEdit({ inventory }) {
|
||||
setError(err);
|
||||
}
|
||||
};
|
||||
|
||||
if (contentLoading) {
|
||||
return <ContentLoading />;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <ContentError />;
|
||||
}
|
||||
|
||||
return (
|
||||
<CardBody>
|
||||
<InventoryForm
|
||||
|
||||
@ -221,8 +221,8 @@ class InventoriesList extends Component {
|
||||
inventory={inventory}
|
||||
detailUrl={
|
||||
inventory.kind === 'smart'
|
||||
? `${match.url}/smart_inventory/${inventory.id}`
|
||||
: `${match.url}/inventory/${inventory.id}`
|
||||
? `${match.url}/smart_inventory/${inventory.id}/details`
|
||||
: `${match.url}/inventory/${inventory.id}/details`
|
||||
}
|
||||
onSelect={() => this.handleSelect(inventory)}
|
||||
isSelected={selected.some(row => row.id === inventory.id)}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user