From d95373f2b77ea9655ba47899da82f9d75f4f1d2b Mon Sep 17 00:00:00 2001 From: mabashian Date: Thu, 10 Dec 2020 09:55:00 -0500 Subject: [PATCH] Fixes bug where page would crash on preview step if extra vars was malformed --- .../components/LaunchPrompt/LaunchPrompt.jsx | 4 ++-- .../LaunchPrompt/steps/PreviewStep.jsx | 10 ++++---- .../Modals/NodeModals/NodeModal.jsx | 24 ++++++++++++++++++- .../prompt}/getSurveyValues.js | 0 .../prompt}/mergeExtraVars.js | 0 .../prompt}/mergeExtraVars.test.js | 0 6 files changed, 29 insertions(+), 9 deletions(-) rename awx/ui_next/src/{components/LaunchPrompt => util/prompt}/getSurveyValues.js (100%) rename awx/ui_next/src/{components/LaunchPrompt => util/prompt}/mergeExtraVars.js (100%) rename awx/ui_next/src/{components/LaunchPrompt => util/prompt}/mergeExtraVars.test.js (100%) diff --git a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx index 991d527c81..00074a3e87 100644 --- a/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/LaunchPrompt.jsx @@ -6,10 +6,10 @@ import { Formik, useFormikContext } from 'formik'; import ContentError from '../ContentError'; import ContentLoading from '../ContentLoading'; import { useDismissableError } from '../../util/useRequest'; -import mergeExtraVars from './mergeExtraVars'; +import mergeExtraVars from '../../util/prompt/mergeExtraVars'; +import getSurveyValues from '../../util/prompt/getSurveyValues'; import useLaunchSteps from './useLaunchSteps'; import AlertModal from '../AlertModal'; -import getSurveyValues from './getSurveyValues'; function PromptModalForm({ launchConfig, diff --git a/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx b/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx index 672956027d..58aa0d3777 100644 --- a/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx +++ b/awx/ui_next/src/components/LaunchPrompt/steps/PreviewStep.jsx @@ -6,9 +6,10 @@ import { t } from '@lingui/macro'; import { useFormikContext } from 'formik'; import { withI18n } from '@lingui/react'; import yaml from 'js-yaml'; -import { parseVariableField } from '../../../util/yaml'; -import mergeExtraVars, { maskPasswords } from '../mergeExtraVars'; -import getSurveyValues from '../getSurveyValues'; +import mergeExtraVars, { + maskPasswords, +} from '../../../util/prompt/mergeExtraVars'; +import getSurveyValues from '../../../util/prompt/getSurveyValues'; import PromptDetail from '../../PromptDetail'; const ExclamationCircleIcon = styled(PFExclamationCircleIcon)` @@ -54,9 +55,6 @@ function PreviewStep({ } } - values.extra_data = - overrides.extra_vars && parseVariableField(overrides?.extra_vars); - return ( {formErrors && ( diff --git a/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Modals/NodeModals/NodeModal.jsx b/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Modals/NodeModals/NodeModal.jsx index 9ae4539cb5..4d58da6dd0 100644 --- a/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Modals/NodeModals/NodeModal.jsx +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplateVisualizer/Modals/NodeModals/NodeModal.jsx @@ -4,7 +4,7 @@ import { useHistory } from 'react-router-dom'; import { withI18n } from '@lingui/react'; import { t } from '@lingui/macro'; import { Formik, useFormikContext } from 'formik'; - +import yaml from 'js-yaml'; import { bool, node, func } from 'prop-types'; import { Button, @@ -18,6 +18,9 @@ import ContentLoading from '../../../../../components/ContentLoading'; import useRequest, { useDismissableError, } from '../../../../../util/useRequest'; +import mergeExtraVars from '../../../../../util/prompt/mergeExtraVars'; +import getSurveyValues from '../../../../../util/prompt/getSurveyValues'; +import { parseVariableField } from '../../../../../util/yaml'; import { WorkflowDispatchContext, WorkflowStateContext, @@ -76,6 +79,25 @@ function NodeModalForm({ delete values.timeoutMinutes; delete values.timeoutSeconds; } + + if ( + ['job_template', 'workflow_job_template'].includes(values.nodeType) && + (launchConfig.ask_variables_on_launch || launchConfig.survey_enabled) + ) { + let extraVars; + const surveyValues = getSurveyValues(values); + const initialExtraVars = + launchConfig.ask_variables_on_launch && (values.extra_vars || '---'); + if (surveyConfig?.spec) { + extraVars = yaml.safeDump( + mergeExtraVars(initialExtraVars, surveyValues) + ); + } else { + extraVars = initialExtraVars; + } + values.extra_data = extraVars && parseVariableField(extraVars); + } + onSave(values, launchConfig); }; diff --git a/awx/ui_next/src/components/LaunchPrompt/getSurveyValues.js b/awx/ui_next/src/util/prompt/getSurveyValues.js similarity index 100% rename from awx/ui_next/src/components/LaunchPrompt/getSurveyValues.js rename to awx/ui_next/src/util/prompt/getSurveyValues.js diff --git a/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.js b/awx/ui_next/src/util/prompt/mergeExtraVars.js similarity index 100% rename from awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.js rename to awx/ui_next/src/util/prompt/mergeExtraVars.js diff --git a/awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.test.js b/awx/ui_next/src/util/prompt/mergeExtraVars.test.js similarity index 100% rename from awx/ui_next/src/components/LaunchPrompt/mergeExtraVars.test.js rename to awx/ui_next/src/util/prompt/mergeExtraVars.test.js