Add column to display resource related to a schedule

Add column to display what resource is related to a schedule

See: https://github.com/ansible/awx/issues/5012
This commit is contained in:
nixocio
2022-06-10 14:04:20 -04:00
parent 23aaf5b3ad
commit 8a92a01652
3 changed files with 52 additions and 6 deletions

View File

@@ -166,7 +166,8 @@ function ScheduleList({
headerRow={ headerRow={
<HeaderRow qsConfig={QS_CONFIG}> <HeaderRow qsConfig={QS_CONFIG}>
<HeaderCell sortKey="name">{t`Name`}</HeaderCell> <HeaderCell sortKey="name">{t`Name`}</HeaderCell>
<HeaderCell sortKey="unified_job_template__polymorphic_ctype__model">{t`Type`}</HeaderCell> <HeaderCell sortKey="unified_job_template">{t`Related resource`}</HeaderCell>
<HeaderCell sortKey="unified_job_template__polymorphic_ctype__model">{t`Resource type`}</HeaderCell>
<HeaderCell sortKey="next_run">{t`Next Run`}</HeaderCell> <HeaderCell sortKey="next_run">{t`Next Run`}</HeaderCell>
<HeaderCell>{t`Actions`}</HeaderCell> <HeaderCell>{t`Actions`}</HeaderCell>
</HeaderRow> </HeaderRow>

View File

@@ -41,22 +41,28 @@ function ScheduleListItem({
}; };
let scheduleBaseUrl; let scheduleBaseUrl;
let relatedResourceUrl;
switch (schedule.summary_fields.unified_job_template.unified_job_type) { switch (schedule.summary_fields.unified_job_template.unified_job_type) {
case 'inventory_update': case 'inventory_update':
scheduleBaseUrl = `/inventories/inventory/${schedule.summary_fields.inventory.id}/sources/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`; scheduleBaseUrl = `/inventories/inventory/${schedule.summary_fields.inventory.id}/sources/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
relatedResourceUrl = `/inventories/inventory/${schedule.summary_fields.inventory.id}/sources/${schedule.summary_fields.unified_job_template.id}/details`;
break; break;
case 'job': case 'job':
scheduleBaseUrl = `/templates/job_template/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`; scheduleBaseUrl = `/templates/job_template/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
relatedResourceUrl = `/templates/job_template/${schedule.summary_fields.unified_job_template.id}/details`;
break; break;
case 'project_update': case 'project_update':
scheduleBaseUrl = `/projects/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`; scheduleBaseUrl = `/projects/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
relatedResourceUrl = `/projects/${schedule.summary_fields.unified_job_template.id}/details`;
break; break;
case 'system_job': case 'system_job':
scheduleBaseUrl = `/management_jobs/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`; scheduleBaseUrl = `/management_jobs/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
relatedResourceUrl = `/management_jobs`;
break; break;
case 'workflow_job': case 'workflow_job':
scheduleBaseUrl = `/templates/workflow_job_template/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`; scheduleBaseUrl = `/templates/workflow_job_template/${schedule.summary_fields.unified_job_template.id}/schedules/${schedule.id}`;
relatedResourceUrl = `/templates/workflow_job_template/${schedule.summary_fields.unified_job_template.id}/details`;
break; break;
default: default:
break; break;
@@ -94,7 +100,15 @@ function ScheduleListItem({
</span> </span>
)} )}
</TdBreakWord> </TdBreakWord>
<Td dataLabel={t`Type`}> <TdBreakWord
id={`related-resource-${schedule.id}`}
dataLabel={t`Related resource`}
>
<Link to={`${relatedResourceUrl}`}>
<b>{schedule.summary_fields.unified_job_template.name}</b>
</Link>
</TdBreakWord>
<Td dataLabel={t`Resource type`}>
{ {
jobTypeLabels[ jobTypeLabels[
schedule.summary_fields.unified_job_template.unified_job_type schedule.summary_fields.unified_job_template.unified_job_type

View File

@@ -65,14 +65,30 @@ describe('ScheduleListItem', () => {
}); });
test('Name correctly shown with correct link', () => { test('Name correctly shown with correct link', () => {
expect(wrapper.find('Td').at(1).prop('dataLabel')).toBe('Name');
expect(wrapper.find('Td').at(1).text()).toBe('Mock Schedule'); expect(wrapper.find('Td').at(1).text()).toBe('Mock Schedule');
expect(wrapper.find('Td').at(1).find('Link').props().to).toBe( expect(wrapper.find('Td').at(1).find('Link').props().to).toBe(
'/templates/job_template/12/schedules/6/details' '/templates/job_template/12/schedules/6/details'
); );
}); });
test('Type correctly shown', () => { test('Related resource correctly shown', () => {
expect(wrapper.find('Td').at(2).text()).toBe('Playbook Run'); expect(wrapper.find('Td').at(2).prop('dataLabel')).toBe(
'Related resource'
);
expect(wrapper.find('Td').at(2).text()).toBe('Mock JT');
});
test('Resource type correctly shown', () => {
expect(wrapper.find('Td').at(3).prop('dataLabel')).toBe('Resource type');
expect(wrapper.find('Td').at(3).text()).toBe('Playbook Run');
});
test('Next run correctly shown', () => {
expect(wrapper.find('Td').at(4).prop('dataLabel')).toBe('Next Run');
expect(wrapper.find('Td').at(4).text()).toBe(
'Next Run2/20/2020, 12:00:00 AM'
);
}); });
test('Edit button shown with correct link', () => { test('Edit button shown with correct link', () => {
@@ -120,16 +136,31 @@ describe('ScheduleListItem', () => {
}); });
test('Name correctly shown with correct link', () => { test('Name correctly shown with correct link', () => {
expect(wrapper.find('Td').at(1).prop('dataLabel')).toBe('Name');
expect(wrapper.find('Td').at(1).text()).toBe('Mock Schedule'); expect(wrapper.find('Td').at(1).text()).toBe('Mock Schedule');
expect(wrapper.find('Td').at(1).find('Link').props().to).toBe( expect(wrapper.find('Td').at(1).find('Link').props().to).toBe(
'/templates/job_template/12/schedules/6/details' '/templates/job_template/12/schedules/6/details'
); );
}); });
test('Type correctly shown', () => { test('Related resource correctly shown', () => {
expect(wrapper.find('Td').at(2).text()).toBe('Playbook Run'); expect(wrapper.find('Td').at(2).prop('dataLabel')).toBe(
'Related resource'
);
expect(wrapper.find('Td').at(2).text()).toBe('Mock JT');
}); });
test('Resource type correctly shown', () => {
expect(wrapper.find('Td').at(3).prop('dataLabel')).toBe('Resource type');
expect(wrapper.find('Td').at(3).text()).toBe('Playbook Run');
});
test('Next run correctly shown', () => {
expect(wrapper.find('Td').at(4).prop('dataLabel')).toBe('Next Run');
expect(wrapper.find('Td').at(4).text()).toBe(
'Next Run2/20/2020, 12:00:00 AM'
);
});
test('Edit button hidden', () => { test('Edit button hidden', () => {
expect(wrapper.find('PencilAltIcon').length).toBe(0); expect(wrapper.find('PencilAltIcon').length).toBe(0);
}); });