mirror of
https://github.com/ansible/awx.git
synced 2026-05-13 12:27:37 -02:30
Merge pull request #7003 from keithjgrant/survey-launch-fix
Fix launch prompt errors when no survey present Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -8,10 +8,18 @@ import getSurveyValues from '../getSurveyValues';
|
|||||||
function PreviewStep({ resource, config, survey, formErrors }) {
|
function PreviewStep({ resource, config, survey, formErrors }) {
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
const surveyValues = getSurveyValues(values);
|
const surveyValues = getSurveyValues(values);
|
||||||
const passwordFields = survey.spec
|
let extraVars;
|
||||||
.filter(q => q.type === 'password')
|
if (survey && survey.spec) {
|
||||||
.map(q => q.variable);
|
const passwordFields = survey.spec
|
||||||
const masked = maskPasswords(surveyValues, passwordFields);
|
.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 || '---';
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PromptDetail
|
<PromptDetail
|
||||||
@@ -19,7 +27,7 @@ function PreviewStep({ resource, config, survey, formErrors }) {
|
|||||||
launchConfig={config}
|
launchConfig={config}
|
||||||
overrides={{
|
overrides={{
|
||||||
...values,
|
...values,
|
||||||
extra_vars: yaml.safeDump(mergeExtraVars(values.extra_vars, masked)),
|
extra_vars: extraVars,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{formErrors && (
|
{formErrors && (
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { act } from 'react-dom/test-utils';
|
||||||
|
import { Formik } from 'formik';
|
||||||
|
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
|
||||||
|
import PreviewStep from './PreviewStep';
|
||||||
|
|
||||||
|
const resource = {
|
||||||
|
id: 1,
|
||||||
|
type: 'job_template',
|
||||||
|
summary_fields: {
|
||||||
|
inventory: { id: 12 },
|
||||||
|
recent_jobs: [],
|
||||||
|
},
|
||||||
|
related: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const survey = {
|
||||||
|
name: '',
|
||||||
|
spec: [
|
||||||
|
{
|
||||||
|
variable: 'foo',
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('PreviewStep', () => {
|
||||||
|
test('should render PromptDetail', async () => {
|
||||||
|
let wrapper;
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Formik initialValues={{ limit: '4', survey_foo: 'abc' }}>
|
||||||
|
<PreviewStep
|
||||||
|
resource={resource}
|
||||||
|
config={{
|
||||||
|
ask_limit_on_launch: true,
|
||||||
|
survey_enabled: true,
|
||||||
|
}}
|
||||||
|
survey={survey}
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const detail = wrapper.find('PromptDetail');
|
||||||
|
expect(detail).toHaveLength(1);
|
||||||
|
expect(detail.prop('resource')).toEqual(resource);
|
||||||
|
expect(detail.prop('overrides')).toEqual({
|
||||||
|
extra_vars: 'foo: abc\n',
|
||||||
|
limit: '4',
|
||||||
|
survey_foo: 'abc',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should render PromptDetail without survey', async () => {
|
||||||
|
let wrapper;
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Formik initialValues={{ limit: '4' }}>
|
||||||
|
<PreviewStep
|
||||||
|
resource={resource}
|
||||||
|
config={{
|
||||||
|
ask_limit_on_launch: true,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const detail = wrapper.find('PromptDetail');
|
||||||
|
expect(detail).toHaveLength(1);
|
||||||
|
expect(detail.prop('resource')).toEqual(resource);
|
||||||
|
expect(detail.prop('overrides')).toEqual({
|
||||||
|
extra_vars: '---',
|
||||||
|
limit: '4',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -9,6 +9,9 @@ export default function useInventoryStep(config, resource, visitedSteps, i18n) {
|
|||||||
const [stepErrors, setStepErrors] = useState({});
|
const [stepErrors, setStepErrors] = useState({});
|
||||||
|
|
||||||
const validate = values => {
|
const validate = values => {
|
||||||
|
if (!config.ask_inventory_on_launch) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
const errors = {};
|
const errors = {};
|
||||||
if (!values.inventory) {
|
if (!values.inventory) {
|
||||||
errors.inventory = i18n._(t`An inventory must be selected`);
|
errors.inventory = i18n._(t`An inventory must be selected`);
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export default function useSurveyStep(config, resource, visitedSteps, i18n) {
|
|||||||
isReady: !isLoading && !!survey,
|
isReady: !isLoading && !!survey,
|
||||||
error,
|
error,
|
||||||
setTouched: setFieldsTouched => {
|
setTouched: setFieldsTouched => {
|
||||||
if (!survey) {
|
if (!survey || !survey.spec) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fields = {};
|
const fields = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user