Hide instance group for Inventory Details if the data is not available

Hide instance group for Inventory Details if the data is not available.
This is the the same approach used in other details screens.

See: https://github.com/ansible/awx/issues/8620
This commit is contained in:
nixocio 2020-11-18 11:45:43 -05:00
parent cb590be095
commit 4b5b95a0f8
2 changed files with 47 additions and 18 deletions

View File

@ -80,19 +80,21 @@ function InventoryDetail({ inventory, i18n }) {
</Link>
}
/>
<Detail
fullWidth
label={i18n._(t`Instance Groups`)}
value={
<ChipGroup numChips={5} totalChips={instanceGroups.length}>
{instanceGroups.map(ig => (
<Chip key={ig.id} isReadOnly>
{ig.name}
</Chip>
))}
</ChipGroup>
}
/>
{instanceGroups && instanceGroups.length > 0 && (
<Detail
fullWidth
label={i18n._(t`Instance Groups`)}
value={
<ChipGroup numChips={5} totalChips={instanceGroups.length}>
{instanceGroups.map(ig => (
<Chip key={ig.id} isReadOnly>
{ig.name}
</Chip>
))}
</ChipGroup>
}
/>
)}
<VariablesDetail
label={i18n._(t`Variables`)}
value={inventory.variables}

View File

@ -63,11 +63,6 @@ const associatedInstanceGroups = [
name: 'Foo',
},
];
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: associatedInstanceGroups,
},
});
function expectDetailToMatch(wrapper, label, value) {
const detail = wrapper.find(`Detail[label="${label}"]`);
@ -77,6 +72,12 @@ function expectDetailToMatch(wrapper, label, value) {
describe('<InventoryDetail />', () => {
test('should render details', async () => {
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: associatedInstanceGroups,
},
});
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
@ -105,6 +106,12 @@ describe('<InventoryDetail />', () => {
});
test('should load instance groups', async () => {
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: associatedInstanceGroups,
},
});
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
@ -119,4 +126,24 @@ describe('<InventoryDetail />', () => {
expect(chip.prop('isReadOnly')).toEqual(true);
expect(chip.prop('children')).toEqual('Foo');
});
test('should not load instance groups', async () => {
InventoriesAPI.readInstanceGroups.mockResolvedValue({
data: {
results: [],
},
});
let wrapper;
await act(async () => {
wrapper = mountWithContexts(
<InventoryDetail inventory={mockInventory} />
);
});
wrapper.update();
expect(InventoriesAPI.readInstanceGroups).toHaveBeenCalledWith(
mockInventory.id
);
expect(wrapper.find(`Detail[label="Instance Groups"]`)).toHaveLength(0);
});
});