-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create LaunchedByDetail to consolidate shared code between detail & list
- Loading branch information
1 parent
20e5134
commit 2abcc8e
Showing
4 changed files
with
60 additions
and
86 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
awx/ui_next/src/components/DetailList/LaunchedByDetail.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) | ||
} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters