mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 16:28:43 -03:30
create LaunchedByDetail to consolidate shared code between detail & list
This commit is contained in:
51
awx/ui_next/src/components/DetailList/LaunchedByDetail.jsx
Normal file
51
awx/ui_next/src/components/DetailList/LaunchedByDetail.jsx
Normal file
@@ -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 (
|
||||||
|
<Detail
|
||||||
|
label={i18n._(t`Launched By`)}
|
||||||
|
value={
|
||||||
|
launchedByLink ? (
|
||||||
|
<Link to={`${launchedByLink}`}>{launchedByValue}</Link>
|
||||||
|
) : (
|
||||||
|
launchedByValue
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ export { default as DeletedDetail } from './DeletedDetail';
|
|||||||
export { default as UserDateDetail } from './UserDateDetail';
|
export { default as UserDateDetail } from './UserDateDetail';
|
||||||
export { default as DetailBadge } from './DetailBadge';
|
export { default as DetailBadge } from './DetailBadge';
|
||||||
export { default as ArrayDetail } from './ArrayDetail';
|
export { default as ArrayDetail } from './ArrayDetail';
|
||||||
|
export { default as LaunchedByDetail } from './LaunchedByDetail';
|
||||||
/*
|
/*
|
||||||
NOTE: CodeDetail cannot be imported here, as it causes circular
|
NOTE: CodeDetail cannot be imported here, as it causes circular
|
||||||
dependencies in testing environment. Import it directly from
|
dependencies in testing environment. Import it directly from
|
||||||
|
|||||||
@@ -8,41 +8,12 @@ import { RocketIcon } from '@patternfly/react-icons';
|
|||||||
import { ActionsTd, ActionItem } from '../PaginatedTable';
|
import { ActionsTd, ActionItem } from '../PaginatedTable';
|
||||||
import LaunchButton from '../LaunchButton';
|
import LaunchButton from '../LaunchButton';
|
||||||
import StatusLabel from '../StatusLabel';
|
import StatusLabel from '../StatusLabel';
|
||||||
import { DetailList, Detail } from '../DetailList';
|
import { DetailList, Detail, LaunchedByDetail } from '../DetailList';
|
||||||
import ChipGroup from '../ChipGroup';
|
import ChipGroup from '../ChipGroup';
|
||||||
import CredentialChip from '../CredentialChip';
|
import CredentialChip from '../CredentialChip';
|
||||||
import { formatDateString } from '../../util/dates';
|
import { formatDateString } from '../../util/dates';
|
||||||
import { JOB_TYPE_URL_SEGMENTS } from '../../constants';
|
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({
|
function JobListItem({
|
||||||
i18n,
|
i18n,
|
||||||
job,
|
job,
|
||||||
@@ -63,8 +34,6 @@ function JobListItem({
|
|||||||
workflow_job: i18n._(t`Workflow Job`),
|
workflow_job: i18n._(t`Workflow Job`),
|
||||||
};
|
};
|
||||||
|
|
||||||
const { value: launchedByValue, link: launchedByLink } =
|
|
||||||
getLaunchedByDetails(job) || {};
|
|
||||||
const { credentials, inventory, labels } = job.summary_fields;
|
const { credentials, inventory, labels } = job.summary_fields;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -141,16 +110,7 @@ function JobListItem({
|
|||||||
label={i18n._(t`Finished`)}
|
label={i18n._(t`Finished`)}
|
||||||
value={formatDateString(job.started)}
|
value={formatDateString(job.started)}
|
||||||
/>
|
/>
|
||||||
<Detail
|
<LaunchedByDetail job={job} i18n={i18n} />
|
||||||
label={i18n._(t`Launched By`)}
|
|
||||||
value={
|
|
||||||
launchedByLink ? (
|
|
||||||
<Link to={`${launchedByLink}`}>{launchedByValue}</Link>
|
|
||||||
) : (
|
|
||||||
launchedByValue
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
{credentials && credentials.length > 0 && (
|
{credentials && credentials.length > 0 && (
|
||||||
<Detail
|
<Detail
|
||||||
fullWidth
|
fullWidth
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
DetailList,
|
DetailList,
|
||||||
Detail,
|
Detail,
|
||||||
UserDateDetail,
|
UserDateDetail,
|
||||||
|
LaunchedByDetail,
|
||||||
} from '../../../components/DetailList';
|
} from '../../../components/DetailList';
|
||||||
import { CardBody, CardActionsRow } from '../../../components/Card';
|
import { CardBody, CardActionsRow } from '../../../components/Card';
|
||||||
import ChipGroup from '../../../components/ChipGroup';
|
import ChipGroup from '../../../components/ChipGroup';
|
||||||
@@ -53,35 +54,6 @@ const VERBOSITY = {
|
|||||||
4: '4 (Connection Debug)',
|
4: '4 (Connection Debug)',
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLaunchedByDetails = ({ summary_fields = {}, related = {} }) => {
|
|
||||||
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 }) {
|
function JobDetail({ job, i18n }) {
|
||||||
const {
|
const {
|
||||||
created_by,
|
created_by,
|
||||||
@@ -106,9 +78,6 @@ function JobDetail({ job, i18n }) {
|
|||||||
workflow_job: i18n._(t`Workflow Job`),
|
workflow_job: i18n._(t`Workflow Job`),
|
||||||
};
|
};
|
||||||
|
|
||||||
const { value: launchedByValue, link: launchedByLink } =
|
|
||||||
getLaunchedByDetails(job) || {};
|
|
||||||
|
|
||||||
const deleteJob = async () => {
|
const deleteJob = async () => {
|
||||||
try {
|
try {
|
||||||
switch (job.type) {
|
switch (job.type) {
|
||||||
@@ -196,16 +165,7 @@ function JobDetail({ job, i18n }) {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Detail label={i18n._(t`Job Type`)} value={jobTypes[job.type]} />
|
<Detail label={i18n._(t`Job Type`)} value={jobTypes[job.type]} />
|
||||||
<Detail
|
<LaunchedByDetail job={job} i18n={i18n} />
|
||||||
label={i18n._(t`Launched By`)}
|
|
||||||
value={
|
|
||||||
launchedByLink ? (
|
|
||||||
<Link to={`${launchedByLink}`}>{launchedByValue}</Link>
|
|
||||||
) : (
|
|
||||||
launchedByValue
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
{inventory && (
|
{inventory && (
|
||||||
<Detail
|
<Detail
|
||||||
label={i18n._(t`Inventory`)}
|
label={i18n._(t`Inventory`)}
|
||||||
@@ -360,4 +320,3 @@ JobDetail.propTypes = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default withI18n()(JobDetail);
|
export default withI18n()(JobDetail);
|
||||||
export { getLaunchedByDetails };
|
|
||||||
|
|||||||
Reference in New Issue
Block a user