Fix JT form edit save bug when inventory has no value

This commit is contained in:
Marliana Lara 2020-03-20 15:20:46 -04:00
parent e17ff3e03a
commit 53c8c80f7f
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE
2 changed files with 14 additions and 9 deletions

View File

@ -57,7 +57,7 @@ function Template({ i18n, me, setBreadcrumb }) {
);
useEffect(() => {
loadTemplateAndRoles();
}, [loadTemplateAndRoles]);
}, [loadTemplateAndRoles, location.pathname]);
const loadScheduleOptions = () => {
return JobTemplatesAPI.readScheduleOptions(templateId);

View File

@ -109,12 +109,15 @@ function JobTemplateForm({
return undefined;
};
const handleProjectUpdate = newProject => {
setProject(newProject);
setFieldValue('project', newProject.id);
setFieldValue('playbook', 0);
setFieldValue('scm_branch', '');
};
const handleProjectUpdate = useCallback(
newProject => {
setProject(newProject);
setFieldValue('project', newProject.id);
setFieldValue('playbook', 0);
setFieldValue('scm_branch', '');
},
[setFieldValue, setProject]
);
const jobTypeOptions = [
{
@ -245,7 +248,7 @@ function JobTemplateForm({
)}
</Field>
</FieldWithPrompt>
<Field name="project" validate={() => handleProjectValidation()}>
<Field name="project" validate={handleProjectValidation}>
{({ form }) => (
<ProjectLookup
value={project}
@ -631,9 +634,11 @@ const FormikApp = withFormik({
inventory: { organization: null },
},
} = template;
const hasInventory = summary_fields.inventory
? summary_fields.inventory.organization_id
: null;
return {
ask_credential_on_launch: template.ask_credential_on_launch || false,
ask_diff_mode_on_launch: template.ask_diff_mode_on_launch || false,
@ -648,7 +653,7 @@ const FormikApp = withFormik({
name: template.name || '',
description: template.description || '',
job_type: template.job_type || 'run',
inventory: template.inventory || '',
inventory: template.inventory || null,
project: template.project || '',
scm_branch: template.scm_branch || '',
playbook: template.playbook || '',