From 5fb9afc9f5c64bf2dbfae7180f2fdcab163d5667 Mon Sep 17 00:00:00 2001 From: nixocio Date: Thu, 6 May 2021 16:44:36 -0400 Subject: [PATCH] Allow modify scm branch override * Source Control Branch was not being displayed as part of the JobTemplate Edit, since the project did not have the variable `allow_override` as part of the summary_fields. * Add source control details for JobDetail and WorkflowJobTemplateDetail See: https://github.com/ansible/awx/issues/8788 --- awx/api/serializers.py | 2 +- .../src/components/Lookup/ProjectLookup.jsx | 1 - .../src/screens/Job/JobDetail/JobDetail.jsx | 8 ++++++ .../screens/Job/JobDetail/JobDetail.test.jsx | 1 + .../src/screens/Job/shared/data.job.json | 1 + .../screens/Project/shared/ProjectForm.jsx | 1 - .../WorkflowJobTemplateDetail.jsx | 8 ++++++ .../WorkflowJobTemplateDetail.test.jsx | 6 +++++ .../Template/shared/JobTemplateForm.jsx | 4 ++- .../Template/shared/JobTemplateForm.test.jsx | 27 ++++++++++++++++++- .../shared/WorkflowJobTemplateForm.jsx | 3 ++- awx/ui_next/src/types.js | 1 + 12 files changed, 57 insertions(+), 6 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 48a6eebdfc..fe8d288552 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -150,7 +150,7 @@ SUMMARIZABLE_FK_FIELDS = { 'group': DEFAULT_SUMMARY_FIELDS, 'default_environment': DEFAULT_SUMMARY_FIELDS + ('image',), 'execution_environment': DEFAULT_SUMMARY_FIELDS + ('image',), - 'project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'), + 'project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type', 'allow_override'), 'source_project': DEFAULT_SUMMARY_FIELDS + ('status', 'scm_type'), 'project_update': DEFAULT_SUMMARY_FIELDS + ('status', 'failed'), 'credential': DEFAULT_SUMMARY_FIELDS + ('kind', 'cloud', 'kubernetes', 'credential_type_id'), diff --git a/awx/ui_next/src/components/Lookup/ProjectLookup.jsx b/awx/ui_next/src/components/Lookup/ProjectLookup.jsx index 2739a7b48f..cf894909d0 100644 --- a/awx/ui_next/src/components/Lookup/ProjectLookup.jsx +++ b/awx/ui_next/src/components/Lookup/ProjectLookup.jsx @@ -24,7 +24,6 @@ const QS_CONFIG = getQSConfig('project', { function ProjectLookup({ helperTextInvalid, autoPopulate, - isValid, onChange, required, diff --git a/awx/ui_next/src/screens/Job/JobDetail/JobDetail.jsx b/awx/ui_next/src/screens/Job/JobDetail/JobDetail.jsx index 768aa135d4..c8759694a0 100644 --- a/awx/ui_next/src/screens/Job/JobDetail/JobDetail.jsx +++ b/awx/ui_next/src/screens/Job/JobDetail/JobDetail.jsx @@ -68,6 +68,7 @@ function JobDetail({ job }) { source_workflow_job, execution_environment: executionEnvironment, } = job.summary_fields; + const { scm_branch: scmBranch } = job; const [errorMsg, setErrorMsg] = useState(); const history = useHistory(); @@ -224,6 +225,13 @@ function JobDetail({ job }) { } /> )} + {scmBranch && ( + + )} diff --git a/awx/ui_next/src/screens/Job/JobDetail/JobDetail.test.jsx b/awx/ui_next/src/screens/Job/JobDetail/JobDetail.test.jsx index ce7897d6aa..fbcbd21a27 100644 --- a/awx/ui_next/src/screens/Job/JobDetail/JobDetail.test.jsx +++ b/awx/ui_next/src/screens/Job/JobDetail/JobDetail.test.jsx @@ -64,6 +64,7 @@ describe('', () => { assertDetail('Job Slice', '0/1'); assertDetail('Credentials', 'SSH: Demo Credential'); assertDetail('Machine Credential', 'SSH: Machine cred'); + assertDetail('Source Control Branch', 'main'); const executionEnvironment = wrapper.find('ExecutionEnvironmentDetail'); expect(executionEnvironment).toHaveLength(1); diff --git a/awx/ui_next/src/screens/Job/shared/data.job.json b/awx/ui_next/src/screens/Job/shared/data.job.json index 8b2d31a197..343c223aac 100644 --- a/awx/ui_next/src/screens/Job/shared/data.job.json +++ b/awx/ui_next/src/screens/Job/shared/data.job.json @@ -103,6 +103,7 @@ "inventory": 1, "project": 6, "playbook": "chatty_tasks.yml", + "scm_branch": "main", "forks": 0, "limit": "", "verbosity": 0, diff --git a/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx b/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx index 20b407c4cc..625ee19f29 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx @@ -70,7 +70,6 @@ function ProjectFormFields({ project_base_dir, project_local_paths, formik, - setCredentials, credentials, scmTypeOptions, diff --git a/awx/ui_next/src/screens/Template/WorkflowJobTemplateDetail/WorkflowJobTemplateDetail.jsx b/awx/ui_next/src/screens/Template/WorkflowJobTemplateDetail/WorkflowJobTemplateDetail.jsx index ed781f09c8..7f2ce66236 100644 --- a/awx/ui_next/src/screens/Template/WorkflowJobTemplateDetail/WorkflowJobTemplateDetail.jsx +++ b/awx/ui_next/src/screens/Template/WorkflowJobTemplateDetail/WorkflowJobTemplateDetail.jsx @@ -44,6 +44,7 @@ function WorkflowJobTemplateDetail({ template }) { related, webhook_credential, webhook_key, + scm_branch: scmBranch, } = template; const urlOrigin = window.location.origin; @@ -130,6 +131,13 @@ function WorkflowJobTemplateDetail({ template }) { } /> )} + {scmBranch && ( + + )} {summary_fields?.execution_environment && ( ', () => { webhook_service: 'Github', webhook_key: 'Foo webhook key', execution_environment: 4, + scm_branch: 'main', }; beforeEach(async () => { @@ -109,6 +110,11 @@ describe('', () => { prop: 'value', value: 'http://localhost/api/v2/workflow_job_templates/45/github/', }, + { + element: 'Detail[label="Source Control Branch"]', + prop: 'value', + value: 'main', + }, { element: "Detail[label='Webhook Service']", prop: 'value', diff --git a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx index 73929011f7..afdb122b80 100644 --- a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx +++ b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.jsx @@ -313,10 +313,11 @@ function JobTemplateForm({ > { scmHelpers.setValue(value); }} + value={scmField.value} + aria-label={t`source control branch`} /> )} @@ -660,6 +661,7 @@ JobTemplateForm.defaultProps = { inventory: undefined, project: undefined, playbook: '', + scm_branch: '', summary_fields: { inventory: null, labels: { results: [] }, diff --git a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.test.jsx b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.test.jsx index 0b1acb3fd8..882aa1de96 100644 --- a/awx/ui_next/src/screens/Template/shared/JobTemplateForm.test.jsx +++ b/awx/ui_next/src/screens/Template/shared/JobTemplateForm.test.jsx @@ -40,6 +40,7 @@ describe('', () => { project: { id: 3, name: 'qux', + allow_override: false, }, labels: { results: [ @@ -113,7 +114,7 @@ describe('', () => { ProjectsAPI.readDetail.mockReturnValue({ name: 'foo', id: 1, - allow_override: true, + allow_override: false, }); ProjectsAPI.readPlaybooks.mockReturnValue({ data: ['debug.yml'], @@ -152,6 +153,30 @@ describe('', () => { ); }); + test('should not render source control branch when allow_override is false', async () => { + let wrapper; + await act(async () => { + wrapper = mountWithContexts( + + ); + }); + wrapper.update(); + expect(wrapper.find('TextInputBase#template-scm-branch').length).toEqual(0); + await act(async () => { + wrapper.find('ProjectLookup').invoke('onChange')({ + id: 4, + name: 'project', + allow_override: true, + }); + }); + wrapper.update(); + expect(wrapper.find('TextInputBase#template-scm-branch').length).toEqual(1); + }); + test('should update form values on input changes', async () => { let wrapper; await act(async () => { diff --git a/awx/ui_next/src/screens/Template/shared/WorkflowJobTemplateForm.jsx b/awx/ui_next/src/screens/Template/shared/WorkflowJobTemplateForm.jsx index 92e1358b26..56c967fcd3 100644 --- a/awx/ui_next/src/screens/Template/shared/WorkflowJobTemplateForm.jsx +++ b/awx/ui_next/src/screens/Template/shared/WorkflowJobTemplateForm.jsx @@ -186,10 +186,11 @@ function WorkflowJobTemplateForm({ > { scmHelpers.setValue(value); }} + aria-label={t`source control branch`} />