mirror of
https://github.com/ansible/awx.git
synced 2026-03-08 05:01:09 -02:30
Extend launched by details to handle scheduled JTs and WFJTs
This commit is contained in:
@@ -3,13 +3,43 @@ import { Link } from 'react-router-dom';
|
|||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import Detail from './Detail';
|
import Detail from './Detail';
|
||||||
|
|
||||||
const getLaunchedByDetails = ({ summary_fields = {}, related = {} }) => {
|
function getScheduleURL(template, scheduleId, inventoryId = null) {
|
||||||
|
let scheduleUrl;
|
||||||
|
|
||||||
|
switch (template.unified_job_type) {
|
||||||
|
case 'inventory_update':
|
||||||
|
scheduleUrl =
|
||||||
|
inventoryId &&
|
||||||
|
`/inventories/inventory/${inventoryId}/sources/${template.id}/schedules/${scheduleId}/details`;
|
||||||
|
break;
|
||||||
|
case 'job':
|
||||||
|
scheduleUrl = `/templates/job_template/${template.id}/schedules/${scheduleId}/details`;
|
||||||
|
break;
|
||||||
|
case 'project_update':
|
||||||
|
scheduleUrl = `/projects/${template.id}/schedules/${scheduleId}/details`;
|
||||||
|
break;
|
||||||
|
case 'system_job':
|
||||||
|
scheduleUrl = `/management_jobs/${template.id}/schedules/${scheduleId}/details`;
|
||||||
|
break;
|
||||||
|
case 'workflow_job':
|
||||||
|
scheduleUrl = `/templates/workflow_job_template/${template.id}/schedules/${scheduleId}/details`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return scheduleUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const getLaunchedByDetails = ({ summary_fields = {}, launch_type }, i18n) => {
|
||||||
const {
|
const {
|
||||||
created_by: createdBy,
|
created_by: createdBy,
|
||||||
job_template: jobTemplate,
|
job_template: jobTemplate,
|
||||||
|
unified_job_template: unifiedJT,
|
||||||
|
workflow_job_template: workflowJT,
|
||||||
|
inventory,
|
||||||
schedule,
|
schedule,
|
||||||
} = summary_fields;
|
} = summary_fields;
|
||||||
const { schedule: relatedSchedule } = related;
|
|
||||||
|
|
||||||
if (!createdBy && !schedule) {
|
if (!createdBy && !schedule) {
|
||||||
return {};
|
return {};
|
||||||
@@ -18,15 +48,26 @@ const getLaunchedByDetails = ({ summary_fields = {}, related = {} }) => {
|
|||||||
let link;
|
let link;
|
||||||
let value;
|
let value;
|
||||||
|
|
||||||
if (createdBy) {
|
switch (launch_type) {
|
||||||
link = `/users/${createdBy.id}`;
|
case 'webhook':
|
||||||
value = createdBy.username;
|
value = i18n._(t`Webhook`);
|
||||||
} else if (relatedSchedule && jobTemplate) {
|
link =
|
||||||
link = `/templates/job_template/${jobTemplate.id}/schedules/${schedule.id}`;
|
(jobTemplate && `/templates/job_template/${jobTemplate.id}/details`) ||
|
||||||
value = schedule.name;
|
(workflowJT &&
|
||||||
} else {
|
`/templates/workflow_job_template/${workflowJT.id}/details`);
|
||||||
link = null;
|
break;
|
||||||
value = schedule.name;
|
case 'scheduled':
|
||||||
|
value = schedule.name;
|
||||||
|
link = getScheduleURL(unifiedJT, schedule.id, inventory?.id);
|
||||||
|
break;
|
||||||
|
case 'manual':
|
||||||
|
link = `/users/${createdBy.id}/details`;
|
||||||
|
value = createdBy.username;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
link = createdBy && `/users/${createdBy.id}/details`;
|
||||||
|
value = createdBy && createdBy.username;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { link, value };
|
return { link, value };
|
||||||
@@ -34,7 +75,7 @@ const getLaunchedByDetails = ({ summary_fields = {}, related = {} }) => {
|
|||||||
|
|
||||||
export default function LaunchedByDetail({ job }) {
|
export default function LaunchedByDetail({ job }) {
|
||||||
const { value: launchedByValue, link: launchedByLink } =
|
const { value: launchedByValue, link: launchedByLink } =
|
||||||
getLaunchedByDetails(job) || {};
|
getLaunchedByDetails(job, i18n) || {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Detail
|
<Detail
|
||||||
|
|||||||
@@ -108,6 +108,61 @@ describe('<JobDetail />', () => {
|
|||||||
).toHaveLength(1);
|
).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should show schedule that launched workflow job', async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<JobDetail
|
||||||
|
job={{
|
||||||
|
...mockJobData,
|
||||||
|
launch_type: 'scheduled',
|
||||||
|
summary_fields: {
|
||||||
|
user_capabilities: {},
|
||||||
|
schedule: {
|
||||||
|
name: 'mock wf schedule',
|
||||||
|
id: 999,
|
||||||
|
},
|
||||||
|
unified_job_template: {
|
||||||
|
unified_job_type: 'workflow_job',
|
||||||
|
id: 888,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
const launchedByDetail = wrapper.find('Detail[label="Launched By"] dd');
|
||||||
|
expect(launchedByDetail).toHaveLength(1);
|
||||||
|
expect(launchedByDetail.text()).toBe('mock wf schedule');
|
||||||
|
expect(
|
||||||
|
launchedByDetail.find(
|
||||||
|
'a[href="/templates/workflow_job_template/888/schedules/999/details"]'
|
||||||
|
)
|
||||||
|
).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should hide "Launched By" detail for JT launched from a workflow launched by a schedule', async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<JobDetail
|
||||||
|
job={{
|
||||||
|
...mockJobData,
|
||||||
|
launch_type: 'workflow',
|
||||||
|
type: 'job',
|
||||||
|
summary_fields: {
|
||||||
|
user_capabilities: {},
|
||||||
|
source_workflow_job: {
|
||||||
|
name: 'mock wf job',
|
||||||
|
id: 888,
|
||||||
|
},
|
||||||
|
unified_job_template: {
|
||||||
|
unified_job_type: 'job',
|
||||||
|
id: 111,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
expect(wrapper.find('Detail[label="Launched By"] dt')).toHaveLength(0);
|
||||||
|
expect(wrapper.find('Detail[label="Launched By"] dd')).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
test('should properly delete job', async () => {
|
test('should properly delete job', async () => {
|
||||||
wrapper = mountWithContexts(<JobDetail job={mockJobData} />);
|
wrapper = mountWithContexts(<JobDetail job={mockJobData} />);
|
||||||
wrapper.find('button[aria-label="Delete"]').simulate('click');
|
wrapper.find('button[aria-label="Delete"]').simulate('click');
|
||||||
|
|||||||
Reference in New Issue
Block a user