diff --git a/awx/ui_next/src/components/DetailList/LaunchedByDetail.jsx b/awx/ui_next/src/components/DetailList/LaunchedByDetail.jsx new file mode 100644 index 0000000000..6c451a3e51 --- /dev/null +++ b/awx/ui_next/src/components/DetailList/LaunchedByDetail.jsx @@ -0,0 +1,51 @@ +import React from 'react'; +import { Link } from 'react-router-dom'; +import { t } from '@lingui/macro'; +import Detail from './Detail'; + +const getLaunchedByDetails = ({ summary_fields = {}, related = {} }) => { + const { + created_by: createdBy, + job_template: jobTemplate, + schedule, + } = summary_fields; + const { schedule: relatedSchedule } = related; + + if (!createdBy && !schedule) { + return {}; + } + + let link; + let value; + + if (createdBy) { + link = `/users/${createdBy.id}`; + value = createdBy.username; + } else if (relatedSchedule && jobTemplate) { + link = `/templates/job_template/${jobTemplate.id}/schedules/${schedule.id}`; + value = schedule.name; + } else { + link = null; + value = schedule.name; + } + + return { link, value }; +}; + +export default function LaunchedByDetail({ job, i18n }) { + const { value: launchedByValue, link: launchedByLink } = + getLaunchedByDetails(job) || {}; + + return ( + {launchedByValue} + ) : ( + launchedByValue + ) + } + /> + ); +} diff --git a/awx/ui_next/src/components/DetailList/index.js b/awx/ui_next/src/components/DetailList/index.js index d5e2ccd8a4..a393fe72a0 100644 --- a/awx/ui_next/src/components/DetailList/index.js +++ b/awx/ui_next/src/components/DetailList/index.js @@ -4,6 +4,7 @@ export { default as DeletedDetail } from './DeletedDetail'; export { default as UserDateDetail } from './UserDateDetail'; export { default as DetailBadge } from './DetailBadge'; export { default as ArrayDetail } from './ArrayDetail'; +export { default as LaunchedByDetail } from './LaunchedByDetail'; /* NOTE: CodeDetail cannot be imported here, as it causes circular dependencies in testing environment. Import it directly from diff --git a/awx/ui_next/src/components/JobList/JobListItem.jsx b/awx/ui_next/src/components/JobList/JobListItem.jsx index cfc167f468..94e0185fdd 100644 --- a/awx/ui_next/src/components/JobList/JobListItem.jsx +++ b/awx/ui_next/src/components/JobList/JobListItem.jsx @@ -8,41 +8,12 @@ import { RocketIcon } from '@patternfly/react-icons'; import { ActionsTd, ActionItem } from '../PaginatedTable'; import LaunchButton from '../LaunchButton'; import StatusLabel from '../StatusLabel'; -import { DetailList, Detail } from '../DetailList'; +import { DetailList, Detail, LaunchedByDetail } from '../DetailList'; import ChipGroup from '../ChipGroup'; import CredentialChip from '../CredentialChip'; import { formatDateString } from '../../util/dates'; import { JOB_TYPE_URL_SEGMENTS } from '../../constants'; -const getLaunchedByDetails = ({ summary_fields = {}, related = {} }) => { - const { - created_by: createdBy, - job_template: jobTemplate, - schedule, - } = summary_fields; - const { schedule: relatedSchedule } = related; - - if (!createdBy && !schedule) { - return {}; - } - - let link; - let value; - - if (createdBy) { - link = `/users/${createdBy.id}`; - value = createdBy.username; - } else if (relatedSchedule && jobTemplate) { - link = `/templates/job_template/${jobTemplate.id}/schedules/${schedule.id}`; - value = schedule.name; - } else { - link = null; - value = schedule.name; - } - - return { link, value }; -}; - function JobListItem({ i18n, job, @@ -63,8 +34,6 @@ function JobListItem({ workflow_job: i18n._(t`Workflow Job`), }; - const { value: launchedByValue, link: launchedByLink } = - getLaunchedByDetails(job) || {}; const { credentials, inventory, labels } = job.summary_fields; return ( @@ -141,16 +110,7 @@ function JobListItem({ label={i18n._(t`Finished`)} value={formatDateString(job.started)} /> - {launchedByValue} - ) : ( - launchedByValue - ) - } - /> + {credentials && credentials.length > 0 && ( { - const { - created_by: createdBy, - job_template: jobTemplate, - schedule, - } = summary_fields; - const { schedule: relatedSchedule } = related; - - if (!createdBy && !schedule) { - return null; - } - - let link; - let value; - - if (createdBy) { - link = `/users/${createdBy.id}`; - value = createdBy.username; - } else if (relatedSchedule && jobTemplate) { - link = `/templates/job_template/${jobTemplate.id}/schedules/${schedule.id}`; - value = schedule.name; - } else { - link = null; - value = schedule.name; - } - - return { link, value }; -}; - function JobDetail({ job, i18n }) { const { created_by, @@ -106,9 +78,6 @@ function JobDetail({ job, i18n }) { workflow_job: i18n._(t`Workflow Job`), }; - const { value: launchedByValue, link: launchedByLink } = - getLaunchedByDetails(job) || {}; - const deleteJob = async () => { try { switch (job.type) { @@ -196,16 +165,7 @@ function JobDetail({ job, i18n }) { /> )} - {launchedByValue} - ) : ( - launchedByValue - ) - } - /> + {inventory && (