Adds Variables detail to node view when node is a system job template

This commit is contained in:
mabashian 2021-07-01 11:17:46 -04:00
parent d7521efc91
commit 034c665c83
2 changed files with 137 additions and 119 deletions

View File

@ -1,18 +1,15 @@
import 'styled-components/macro';
import React from 'react';
import { shape } from 'prop-types';
import { t, Trans } from '@lingui/macro';
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import { Chip, Divider, Title } from '@patternfly/react-core';
import { toTitleCase } from 'util/strings';
import CredentialChip from '../CredentialChip';
import ChipGroup from '../ChipGroup';
import { DetailList, Detail, UserDateDetail } from '../DetailList';
import { VariablesDetail } from '../CodeEditor';
import PromptProjectDetail from './PromptProjectDetail';
import PromptInventorySourceDetail from './PromptInventorySourceDetail';
import PromptJobTemplateDetail from './PromptJobTemplateDetail';
@ -139,123 +136,136 @@ function PromptDetail({ resource, launchConfig = {}, overrides = {} }) {
user={details?.summary_fields?.modified_by}
/>
)}
{details?.type === 'system_job_template' && (
<VariablesDetail
label={t`Variables`}
rows={4}
value={overrides.extra_vars}
name="extra_vars"
/>
)}
</DetailList>
{hasPromptData(launchConfig) && hasOverrides && (
<>
<PromptTitle headingLevel="h2">{t`Prompted Values`}</PromptTitle>
<PromptDivider />
<PromptDetailList aria-label={t`Prompt Overrides`}>
{launchConfig.ask_job_type_on_launch && (
<Detail
label={t`Job Type`}
value={toTitleCase(overrides.job_type)}
/>
)}
{launchConfig.ask_credential_on_launch && (
<Detail
fullWidth
label={t`Credentials`}
rows={4}
value={
<ChipGroup
numChips={5}
totalChips={overrides.credentials.length}
>
{overrides.credentials.map((cred) => (
<CredentialChip
key={cred.id}
credential={cred}
isReadOnly
/>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_inventory_on_launch && (
<Detail label={t`Inventory`} value={overrides.inventory?.name} />
)}
{launchConfig.ask_scm_branch_on_launch && (
<Detail
label={t`Source Control Branch`}
value={overrides.scm_branch}
/>
)}
{launchConfig.ask_limit_on_launch && (
<Detail label={t`Limit`} value={overrides.limit} />
)}
{Object.prototype.hasOwnProperty.call(overrides, 'verbosity') &&
launchConfig.ask_verbosity_on_launch ? (
<Detail
label={t`Verbosity`}
value={VERBOSITY[overrides.verbosity]}
/>
) : null}
{launchConfig.ask_tags_on_launch && (
<Detail
fullWidth
label={t`Job Tags`}
value={
<ChipGroup
numChips={5}
totalChips={
!overrides.job_tags || overrides.job_tags === ''
? 0
: overrides.job_tags.split(',').length
}
>
{overrides.job_tags.length > 0 &&
overrides.job_tags.split(',').map((jobTag) => (
<Chip key={jobTag} isReadOnly>
{jobTag}
</Chip>
{details?.type !== 'system_job_template' &&
hasPromptData(launchConfig) &&
hasOverrides && (
<>
<PromptTitle headingLevel="h2">{t`Prompted Values`}</PromptTitle>
<PromptDivider />
<PromptDetailList aria-label={t`Prompt Overrides`}>
{launchConfig.ask_job_type_on_launch && (
<Detail
label={t`Job Type`}
value={toTitleCase(overrides.job_type)}
/>
)}
{launchConfig.ask_credential_on_launch && (
<Detail
fullWidth
label={t`Credentials`}
rows={4}
value={
<ChipGroup
numChips={5}
totalChips={overrides.credentials.length}
>
{overrides.credentials.map((cred) => (
<CredentialChip
key={cred.id}
credential={cred}
isReadOnly
/>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_skip_tags_on_launch && (
<Detail
fullWidth
label={t`Skip Tags`}
value={
<ChipGroup
numChips={5}
totalChips={
!overrides.skip_tags || overrides.skip_tags === ''
? 0
: overrides.skip_tags.split(',').length
}
>
{overrides.skip_tags.length > 0 &&
overrides.skip_tags.split(',').map((skipTag) => (
<Chip key={skipTag} isReadOnly>
{skipTag}
</Chip>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_diff_mode_on_launch && (
<Detail
label={t`Show Changes`}
value={overrides.diff_mode === true ? t`On` : t`Off`}
/>
)}
{(launchConfig.survey_enabled ||
launchConfig.ask_variables_on_launch) && (
<VariablesDetail
label={t`Variables`}
rows={4}
value={overrides.extra_vars}
name="extra_vars"
/>
)}
</PromptDetailList>
</>
)}
</ChipGroup>
}
/>
)}
{launchConfig.ask_inventory_on_launch && (
<Detail
label={t`Inventory`}
value={overrides.inventory?.name}
/>
)}
{launchConfig.ask_scm_branch_on_launch && (
<Detail
label={t`Source Control Branch`}
value={overrides.scm_branch}
/>
)}
{launchConfig.ask_limit_on_launch && (
<Detail label={t`Limit`} value={overrides.limit} />
)}
{Object.prototype.hasOwnProperty.call(overrides, 'verbosity') &&
launchConfig.ask_verbosity_on_launch ? (
<Detail
label={t`Verbosity`}
value={VERBOSITY[overrides.verbosity]}
/>
) : null}
{launchConfig.ask_tags_on_launch && (
<Detail
fullWidth
label={t`Job Tags`}
value={
<ChipGroup
numChips={5}
totalChips={
!overrides.job_tags || overrides.job_tags === ''
? 0
: overrides.job_tags.split(',').length
}
>
{overrides.job_tags.length > 0 &&
overrides.job_tags.split(',').map((jobTag) => (
<Chip key={jobTag} isReadOnly>
{jobTag}
</Chip>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_skip_tags_on_launch && (
<Detail
fullWidth
label={t`Skip Tags`}
value={
<ChipGroup
numChips={5}
totalChips={
!overrides.skip_tags || overrides.skip_tags === ''
? 0
: overrides.skip_tags.split(',').length
}
>
{overrides.skip_tags.length > 0 &&
overrides.skip_tags.split(',').map((skipTag) => (
<Chip key={skipTag} isReadOnly>
{skipTag}
</Chip>
))}
</ChipGroup>
}
/>
)}
{launchConfig.ask_diff_mode_on_launch && (
<Detail
label={t`Show Changes`}
value={overrides.diff_mode === true ? t`On` : t`Off`}
/>
)}
{(launchConfig.survey_enabled ||
launchConfig.ask_variables_on_launch) && (
<VariablesDetail
label={t`Variables`}
rows={4}
value={overrides.extra_vars}
name="extra_vars"
/>
)}
</PromptDetailList>
</>
)}
</>
);
}

View File

@ -136,7 +136,11 @@ function NodeViewModal({ readOnly }) {
if (promptValues) {
overrides = promptValues;
if (launchConfig.ask_variables_on_launch || launchConfig.survey_enabled) {
if (
launchConfig.ask_variables_on_launch ||
launchConfig.survey_enabled ||
fullUnifiedJobTemplate.type === 'system_job_template'
) {
overrides.extra_vars = jsonToYaml(
JSON.stringify(promptValues.extra_data)
);
@ -150,7 +154,11 @@ function NodeViewModal({ readOnly }) {
if (launchConfig.ask_scm_branch_on_launch) {
overrides.scm_branch = originalNodeObject.scm_branch;
}
if (launchConfig.ask_variables_on_launch || launchConfig.survey_enabled) {
if (
launchConfig.ask_variables_on_launch ||
launchConfig.survey_enabled ||
fullUnifiedJobTemplate.type === 'system_job_template'
) {
overrides.extra_vars = jsonToYaml(
JSON.stringify(originalNodeObject.extra_data)
);