diff --git a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx index 4f4e1002e5..6eb9ec0ecc 100644 --- a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx @@ -44,7 +44,10 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) { setValue('limit', values.limit); setValue('job_tags', values.job_tags); setValue('skip_tags', values.skip_tags); - setValue('extra_vars', mergeExtraVars(values.extra_vars, surveyValues)); + const extraVars = config.ask_variables_on_launch + ? values.extra_vars || '---' + : resource.extra_vars; + setValue('extra_vars', mergeExtraVars(extraVars, surveyValues)); setValue('scm_branch', values.scm_branch); onLaunch(postValues); }; diff --git a/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.js b/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.js index 261c02a875..5cb60ac2ac 100644 --- a/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.js +++ b/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.js @@ -1,6 +1,6 @@ import yaml from 'js-yaml'; -export default function mergeExtraVars(extraVars, survey = {}) { +export default function mergeExtraVars(extraVars = '', survey = {}) { const vars = yaml.safeLoad(extraVars) || {}; return { ...vars, diff --git a/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.test.js b/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.test.js index bd696ab9e5..bd3d04cae9 100644 --- a/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.test.js +++ b/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.test.js @@ -32,6 +32,10 @@ describe('mergeExtraVars', () => { }); }); + test('should handle undefined', () => { + expect(mergeExtraVars(undefined, undefined)).toEqual({}); + }); + describe('maskPasswords', () => { test('should mask password fields', () => { const vars = { diff --git a/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx b/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx index f7e8ed1c36..835fbba18d 100644 --- a/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx @@ -8,27 +8,32 @@ import getSurveyValues from '../getSurveyValues'; function PreviewStep({ resource, config, survey, formErrors }) { const { values } = useFormikContext(); const surveyValues = getSurveyValues(values); - let extraVars; - if (survey && survey.spec) { - const passwordFields = survey.spec - .filter(q => q.type === 'password') - .map(q => q.variable); - const masked = maskPasswords(surveyValues, passwordFields); - extraVars = yaml.safeDump( - mergeExtraVars(values.extra_vars || '---', masked) - ); - } else { - extraVars = values.extra_vars || '---'; + + const overrides = { ...values }; + + if (config.ask_variables_on_launch || config.survey_enabled) { + const initialExtraVars = config.ask_variables_on_launch + ? values.extra_vars || '---' + : resource.extra_vars; + if (survey && survey.spec) { + const passwordFields = survey.spec + .filter(q => q.type === 'password') + .map(q => q.variable); + const masked = maskPasswords(surveyValues, passwordFields); + overrides.extra_vars = yaml.safeDump( + mergeExtraVars(initialExtraVars, masked) + ); + } else { + overrides.extra_vars = initialExtraVars; + } } + return ( <> {formErrors && (