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