Add host description in a couple of screens (#12292)

Add host description in a couple of screens

See:https://github.com/ansible/awx/issues/3348
Also: https://github.com/ansible/awx/issues/9363
This commit is contained in:
Kersom
2022-06-02 15:40:41 -04:00
committed by GitHub
parent 3af89c1e2b
commit c31d74100d
15 changed files with 73 additions and 11 deletions

View File

@@ -419,6 +419,7 @@ function HostFilterLookup({
headerRow={ headerRow={
<HeaderRow qsConfig={QS_CONFIG} isSelectable={false}> <HeaderRow qsConfig={QS_CONFIG} isSelectable={false}>
<HeaderCell sortKey="name">{t`Name`}</HeaderCell> <HeaderCell sortKey="name">{t`Name`}</HeaderCell>
<HeaderCell sortKey="description">{t`Description`}</HeaderCell>
<HeaderCell>{t`Inventory`}</HeaderCell> <HeaderCell>{t`Inventory`}</HeaderCell>
</HeaderRow> </HeaderRow>
} }

View File

@@ -6,6 +6,7 @@ function HostListItem({ item }) {
return ( return (
<Tr ouiaId={`host-list-item-${item.id}`}> <Tr ouiaId={`host-list-item-${item.id}`}>
<Td dataLabel={t`Name`}>{item.name}</Td> <Td dataLabel={t`Name`}>{item.name}</Td>
<Td dataLabel={t`Description`}>{item.description}</Td>
<Td dataLabel={t`Inventory`}>{item.summary_fields.inventory.name}</Td> <Td dataLabel={t`Inventory`}>{item.summary_fields.inventory.name}</Td>
</Tr> </Tr>
); );

View File

@@ -8,6 +8,7 @@ describe('HostListItem', () => {
id: 1, id: 1,
type: 'inventory', type: 'inventory',
name: 'Foo', name: 'Foo',
description: 'Buzz',
summary_fields: { summary_fields: {
inventory: { inventory: {
name: 'Bar', name: 'Bar',
@@ -24,6 +25,7 @@ describe('HostListItem', () => {
); );
expect(wrapper.find('HostListItem').length).toBe(1); expect(wrapper.find('HostListItem').length).toBe(1);
expect(wrapper.find('Td').at(0).text()).toBe('Foo'); expect(wrapper.find('Td').at(0).text()).toBe('Foo');
expect(wrapper.find('Td').at(1).text()).toBe('Bar'); expect(wrapper.find('Td').at(1).text()).toBe('Buzz');
expect(wrapper.find('Td').at(2).text()).toBe('Bar');
}); });
}); });

View File

@@ -167,6 +167,7 @@ function HostList() {
headerRow={ headerRow={
<HeaderRow qsConfig={QS_CONFIG} isExpandable> <HeaderRow qsConfig={QS_CONFIG} isExpandable>
<HeaderCell sortKey="name">{t`Name`}</HeaderCell> <HeaderCell sortKey="name">{t`Name`}</HeaderCell>
<HeaderCell sortKey="description">{t`Description`}</HeaderCell>
<HeaderCell>{t`Inventory`}</HeaderCell> <HeaderCell>{t`Inventory`}</HeaderCell>
<HeaderCell>{t`Actions`}</HeaderCell> <HeaderCell>{t`Actions`}</HeaderCell>
</HeaderRow> </HeaderRow>

View File

@@ -52,6 +52,12 @@ function HostListItem({
<b>{host.name}</b> <b>{host.name}</b>
</Link> </Link>
</TdBreakWord> </TdBreakWord>
<TdBreakWord
id={`host-description-${host.id}}`}
dataLabel={t`Description`}
>
{host.description}
</TdBreakWord>
<TdBreakWord dataLabel={t`Inventory`}> <TdBreakWord dataLabel={t`Inventory`}>
{host.summary_fields.inventory && ( {host.summary_fields.inventory && (
<Link <Link

View File

@@ -7,6 +7,7 @@ const mockHost = {
id: 1, id: 1,
name: 'Host 1', name: 'Host 1',
url: '/api/v2/hosts/1', url: '/api/v2/hosts/1',
description: 'Buzz',
inventory: 1, inventory: 1,
summary_fields: { summary_fields: {
inventory: { inventory: {
@@ -38,6 +39,14 @@ describe('<HostsListItem />', () => {
); );
}); });
test('should display expected details', () => {
expect(wrapper.find('HostListItem').length).toBe(1);
expect(wrapper.find('Td[dataLabel="Name"]').find('Link').prop('to')).toBe(
'/host/1'
);
expect(wrapper.find('Td[dataLabel="Description"]').text()).toBe('Buzz');
});
test('edit button shown to users with edit capabilities', () => { test('edit button shown to users with edit capabilities', () => {
expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy(); expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy();
}); });

View File

@@ -213,6 +213,7 @@ function InventoryGroupHostList() {
headerRow={ headerRow={
<HeaderRow qsConfig={QS_CONFIG}> <HeaderRow qsConfig={QS_CONFIG}>
<HeaderCell sortKey="name">{t`Name`}</HeaderCell> <HeaderCell sortKey="name">{t`Name`}</HeaderCell>
<HeaderCell sortKey="description">{t`Description`}</HeaderCell>
<HeaderCell>{t`Activity`}</HeaderCell> <HeaderCell>{t`Activity`}</HeaderCell>
<HeaderCell>{t`Actions`}</HeaderCell> <HeaderCell>{t`Actions`}</HeaderCell>
</HeaderRow> </HeaderRow>

View File

@@ -31,7 +31,7 @@ function InventoryGroupHostListItem({
<Tr <Tr
id={host.id} id={host.id}
ouiaId={`inventory-group-host-row-${host.id}`} ouiaId={`inventory-group-host-row-${host.id}`}
arialabelledby={labelId} aria-labelledby={labelId}
> >
<Td <Td
select={{ select={{
@@ -41,11 +41,12 @@ function InventoryGroupHostListItem({
}} }}
dataLabel={t`Selected`} dataLabel={t`Selected`}
/> />
<Td id={labelId}> <Td dataLabel={t`host-name-${host.id}`} id={labelId}>
<Link to={`${detailUrl}`}> <Link to={`${detailUrl}`}>
<b>{host.name}</b> <b>{host.name}</b>
</Link> </Link>
</Td> </Td>
<Td dataLabel={t`host-description-${host.id}`}>{host.description}</Td>
<Td dataLabel={t`Activity`}> <Td dataLabel={t`Activity`}>
<Sparkline jobs={recentPlaybookJobs} /> <Sparkline jobs={recentPlaybookJobs} />
</Td> </Td>

View File

@@ -26,6 +26,16 @@ describe('<InventoryGroupHostListItem />', () => {
); );
}); });
test('should display expected details', () => {
expect(wrapper.find('InventoryGroupHostListItem').length).toBe(1);
expect(
wrapper.find('Td[dataLabel="host-name-2"]').find('Link').prop('to')
).toBe('/host/1');
expect(wrapper.find('Td[dataLabel="host-description-2"]').text()).toBe(
'Bar'
);
});
test('should display expected row item content', () => { test('should display expected row item content', () => {
expect(wrapper.find('b').text()).toContain( expect(wrapper.find('b').text()).toContain(
'.host-000001.group-00000.dummy' '.host-000001.group-00000.dummy'

View File

@@ -35,6 +35,12 @@ function InventoryHostItem({
<b>{host.name}</b> <b>{host.name}</b>
</Link> </Link>
</TdBreakWord> </TdBreakWord>
<TdBreakWord
id={`host-description-${host.id}`}
dataLabel={t`Description`}
>
{host.description}
</TdBreakWord>
<ActionsTd dataLabel={t`Actions`} gridColumns="auto 40px"> <ActionsTd dataLabel={t`Actions`} gridColumns="auto 40px">
<HostToggle host={host} /> <HostToggle host={host} />
<ActionItem <ActionItem

View File

@@ -6,6 +6,7 @@ const mockHost = {
id: 1, id: 1,
name: 'Host 1', name: 'Host 1',
url: '/api/v2/hosts/1', url: '/api/v2/hosts/1',
description: 'Bar',
inventory: 1, inventory: 1,
summary_fields: { summary_fields: {
inventory: { inventory: {
@@ -44,6 +45,14 @@ describe('<InventoryHostItem />', () => {
); );
}); });
test('should display expected details', () => {
expect(wrapper.find('InventoryHostItem').length).toBe(1);
expect(wrapper.find('Td[dataLabel="Name"]').find('Link').prop('to')).toBe(
'/host/1'
);
expect(wrapper.find('Td[dataLabel="Description"]').text()).toBe('Bar');
});
test('edit button shown to users with edit capabilities', () => { test('edit button shown to users with edit capabilities', () => {
expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy(); expect(wrapper.find('PencilAltIcon').exists()).toBeTruthy();
}); });

View File

@@ -136,6 +136,7 @@ function InventoryHostList() {
headerRow={ headerRow={
<HeaderRow qsConfig={QS_CONFIG}> <HeaderRow qsConfig={QS_CONFIG}>
<HeaderCell sortKey="name">{t`Name`}</HeaderCell> <HeaderCell sortKey="name">{t`Name`}</HeaderCell>
<HeaderCell sortKey="description">{t`Description`}</HeaderCell>
<HeaderCell>{t`Actions`}</HeaderCell> <HeaderCell>{t`Actions`}</HeaderCell>
</HeaderRow> </HeaderRow>
} }

View File

@@ -119,7 +119,7 @@
"created": "2020-02-24T15:10:58.922179Z", "created": "2020-02-24T15:10:58.922179Z",
"modified": "2020-02-26T21:52:43.428530Z", "modified": "2020-02-26T21:52:43.428530Z",
"name": ".host-000001.group-00000.dummy", "name": ".host-000001.group-00000.dummy",
"description": "", "description": "Bar",
"inventory": 2, "inventory": 2,
"enabled": false, "enabled": false,
"instance_id": "", "instance_id": "",
@@ -248,7 +248,7 @@
"created": "2020-02-24T15:10:58.945113Z", "created": "2020-02-24T15:10:58.945113Z",
"modified": "2020-02-27T03:43:43.635871Z", "modified": "2020-02-27T03:43:43.635871Z",
"name": ".host-000002.group-00000.dummy", "name": ".host-000002.group-00000.dummy",
"description": "", "description": "Buzz",
"inventory": 2, "inventory": 2,
"enabled": false, "enabled": false,
"instance_id": "", "instance_id": "",
@@ -377,7 +377,7 @@
"created": "2020-02-24T15:10:58.962312Z", "created": "2020-02-24T15:10:58.962312Z",
"modified": "2020-02-27T03:43:45.528882Z", "modified": "2020-02-27T03:43:45.528882Z",
"name": ".host-000003.group-00000.dummy", "name": ".host-000003.group-00000.dummy",
"description": "", "description": "BarFoo",
"inventory": 2, "inventory": 2,
"enabled": false, "enabled": false,
"instance_id": "", "instance_id": "",

View File

@@ -107,6 +107,12 @@ function HostEventModal({ onClose, hostEvent = {}, isOpen = false }) {
gutter="sm" gutter="sm"
> >
<Detail label={t`Host`} value={hostEvent.host_name} /> <Detail label={t`Host`} value={hostEvent.host_name} />
{hostEvent.summary_fields.host?.description ? (
<Detail
label={t`Description`}
value={hostEvent.summary_fields.host.description}
/>
) : null}
{hostStatus ? ( {hostStatus ? (
<Detail <Detail
label={t`Status`} label={t`Status`}

View File

@@ -43,6 +43,13 @@ const hostEvent = {
task: 'command', task: 'command',
type: 'job_event', type: 'job_event',
url: '/api/v2/job_events/123/', url: '/api/v2/job_events/123/',
summary_fields: {
host: {
id: 1,
name: 'foo',
description: 'Bar',
},
},
}; };
/* eslint-disable no-useless-escape */ /* eslint-disable no-useless-escape */
@@ -86,7 +93,7 @@ describe('HostEventModal', () => {
<HostEventModal hostEvent={hostEvent} onClose={() => {}} isOpen /> <HostEventModal hostEvent={hostEvent} onClose={() => {}} isOpen />
); );
expect(wrapper.find('Tabs').prop('activeKey')).toEqual(0); expect(wrapper.find('Tabs').prop('activeKey')).toEqual(0);
expect(wrapper.find('Detail')).toHaveLength(5); expect(wrapper.find('Detail')).toHaveLength(6);
function assertDetail(index, label, value) { function assertDetail(index, label, value) {
const detail = wrapper.find('Detail').at(index); const detail = wrapper.find('Detail').at(index);
@@ -96,10 +103,11 @@ describe('HostEventModal', () => {
const detail = wrapper.find('Detail').first(); const detail = wrapper.find('Detail').first();
expect(detail.prop('value')).toEqual('foo'); expect(detail.prop('value')).toEqual('foo');
assertDetail(1, 'Play', 'all'); assertDetail(1, 'Description', 'Bar');
assertDetail(2, 'Task', 'command'); assertDetail(2, 'Play', 'all');
assertDetail(3, 'Module', 'command'); assertDetail(3, 'Task', 'command');
assertDetail(4, 'Command', hostEvent.event_data.res.cmd); assertDetail(4, 'Module', 'command');
assertDetail(5, 'Command', hostEvent.event_data.res.cmd);
}); });
test('should display successful host status label', () => { test('should display successful host status label', () => {