From fd1e574fcb70a17eba003753c3b0912ae5800dc2 Mon Sep 17 00:00:00 2001 From: Alex Corey Date: Wed, 15 Jan 2020 13:27:31 -0500 Subject: [PATCH] Resets playbook and scm-branch fields when project is changed The playbook field becomes undefined and the scm-branch field becomes ''. This ensures that the user has to assign a playbook to the template that is associated with the project and suggests to the user to review their scm-branch. TODO: when the user updates project with scm-branch override allow the user to type in playbook in dropdown. Then, check if playbook is present in list of playbooks. If no, add it to the list of playbooks. --- .../src/screens/Template/shared/JobTemplateForm.jsx | 10 +++++----- .../src/screens/Template/shared/PlaybookSelect.jsx | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx index 4d3242d2d0..0ff31b887f 100644 --- a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx +++ b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx @@ -100,8 +100,8 @@ class JobTemplateForm extends Component { const { project } = this.state; if (project && project.id) { try { - const { data } = await ProjectsAPI.readDetail(project.id); - this.setState({ project: data }); + const { data: projectData } = await ProjectsAPI.readDetail(project.id); + this.setState({ project: projectData }); } catch (err) { this.setState({ contentError: err }); } @@ -139,9 +139,8 @@ class JobTemplateForm extends Component { handleProjectUpdate(project) { const { setFieldValue } = this.props; setFieldValue('project', project.id); - if (!project.allow_override) { - setFieldValue('scm_branch', null); - } + setFieldValue('playbook', undefined); + setFieldValue('scm_branch', ''); this.setState({ project }); } @@ -165,6 +164,7 @@ class JobTemplateForm extends Component { i18n, template, } = this.props; + const jobTypeOptions = [ { value: '', diff --git a/awx/ui_next/src/screens/Template/shared/PlaybookSelect.jsx b/awx/ui_next/src/screens/Template/shared/PlaybookSelect.jsx index 8f0687ba2a..b0e24fe283 100644 --- a/awx/ui_next/src/screens/Template/shared/PlaybookSelect.jsx +++ b/awx/ui_next/src/screens/Template/shared/PlaybookSelect.jsx @@ -15,6 +15,7 @@ function PlaybookSelect({ i18n, }) { const [options, setOptions] = useState([]); + useEffect(() => { if (!projectId) { return; @@ -28,6 +29,7 @@ function PlaybookSelect({ label: playbook, isDisabled: false, })); + opts.unshift({ value: '', key: '', @@ -40,7 +42,6 @@ function PlaybookSelect({ } })(); }, [projectId, i18n, onError]); - return (