From ae021c37e3910b46ef3753b9a3cd9cce8faa295f Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Fri, 3 Apr 2020 14:56:20 -0400 Subject: [PATCH] Add inventory source prompt details --- .../components/PromptDetail/PromptDetail.jsx | 12 ++ .../PromptInventorySourceDetail.jsx | 161 ++++++++++++++++++ .../PromptInventorySourceDetail.test.jsx | 77 +++++++++ .../PromptDetail/PromptJobTemplateDetail.jsx | 8 + .../PromptDetail/PromptProjectDetail.test.jsx | 55 ++++++ .../PromptWFJobTemplateDetail.jsx | 8 + .../PromptDetail/data.inventory_source.json | 118 +++++++++++++ .../components/PromptDetail/data.project.json | 107 ++++++++++++ 8 files changed, 546 insertions(+) create mode 100644 awx/ui_next/src/components/PromptDetail/PromptInventorySourceDetail.jsx create mode 100644 awx/ui_next/src/components/PromptDetail/PromptInventorySourceDetail.test.jsx create mode 100644 awx/ui_next/src/components/PromptDetail/PromptJobTemplateDetail.jsx create mode 100644 awx/ui_next/src/components/PromptDetail/PromptProjectDetail.test.jsx create mode 100644 awx/ui_next/src/components/PromptDetail/PromptWFJobTemplateDetail.jsx create mode 100644 awx/ui_next/src/components/PromptDetail/data.inventory_source.json create mode 100644 awx/ui_next/src/components/PromptDetail/data.project.json diff --git a/awx/ui_next/src/components/PromptDetail/PromptDetail.jsx b/awx/ui_next/src/components/PromptDetail/PromptDetail.jsx index e0df62172a..eaf97ec88a 100644 --- a/awx/ui_next/src/components/PromptDetail/PromptDetail.jsx +++ b/awx/ui_next/src/components/PromptDetail/PromptDetail.jsx @@ -10,6 +10,9 @@ import { VariablesDetail } from '@components/CodeMirrorInput'; import { DetailList, Detail, UserDateDetail } from '@components/DetailList'; import PromptProjectDetail from './PromptProjectDetail'; +import PromptInventorySourceDetail from './PromptInventorySourceDetail'; +import PromptJobTemplateDetail from './PromptJobTemplateDetail'; +import PromptWFJobTemplateDetail from './PromptWFJobTemplateDetail'; const PromptHeader = styled.h2` font-weight: bold; @@ -84,6 +87,15 @@ function PromptDetail({ i18n, resource, launchConfig = {} }) { {resource?.type === 'project' && ( )} + {resource?.type === 'inventory_source' && ( + + )} + {resource?.type === 'job_template' && ( + + )} + {resource?.type === 'workflow_job_template' && ( + + )} + {overwrite && {i18n._(t`Overwrite`)}} + {overwrite_vars && ( + {i18n._(t`Overwrite Variables`)} + )} + {update_on_launch && {i18n._(t`Update on Launch`)}} + {update_on_project_update && ( + {i18n._(t`Update on Project Update`)} + )} + + ); + } + + return ( + <> + {summary_fields?.inventory && ( + + {summary_fields?.inventory?.name} + + } + /> + )} + + + {summary_fields?.source_project && ( + + {summary_fields.source_project?.name} + + } + /> + )} + + + + + {summary_fields?.credentials?.length > 0 && ( + ( + + ))} + /> + )} + {source_regions && ( + + {source_regions.split(',').map(region => ( + + {region} + + ))} + + } + /> + )} + {instance_filters && ( + + {instance_filters.split(',').map(filter => ( + + {filter} + + ))} + + } + /> + )} + {group_by && ( + + {group_by.split(',').map(group => ( + + {group} + + ))} + + } + /> + )} + {optionsList && } + {source_vars && ( + + )} + + ); +} + +export default withI18n()(PromptInventorySourceDetail); diff --git a/awx/ui_next/src/components/PromptDetail/PromptInventorySourceDetail.test.jsx b/awx/ui_next/src/components/PromptDetail/PromptInventorySourceDetail.test.jsx new file mode 100644 index 0000000000..1bfb838b3a --- /dev/null +++ b/awx/ui_next/src/components/PromptDetail/PromptInventorySourceDetail.test.jsx @@ -0,0 +1,77 @@ +import React from 'react'; +import { mountWithContexts } from '@testUtils/enzymeHelpers'; +import PromptInventorySourceDetail from './PromptInventorySourceDetail'; +import mockInvSource from './data.inventory_source.json'; + +describe('PromptInventorySourceDetail', () => { + let wrapper; + + beforeAll(() => { + wrapper = mountWithContexts( + + ); + }); + + afterAll(() => { + wrapper.unmount(); + }); + + test('should render successfully', () => { + expect(wrapper.find('PromptInventorySourceDetail')).toHaveLength(1); + }); + + test('should render expected details', () => { + function assertDetail(label, value) { + expect(wrapper.find(`Detail[label="${label}"] dt`).text()).toBe(label); + expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value); + } + + assertDetail('Inventory', 'Demo Inventory'); + assertDetail('Source', 'scm'); + assertDetail('Project', 'Mock Project'); + assertDetail('Inventory File', 'foo'); + assertDetail('Custom Inventory Script', 'Mock Script'); + assertDetail('Verbosity', '2 (More Verbose)'); + assertDetail('Cache Timeout', '2 Seconds'); + expect( + wrapper + .find('Detail[label="Regions"]') + .containsAllMatchingElements([ + us-east-1, + us-east-2, + ]) + ).toEqual(true); + expect( + wrapper + .find('Detail[label="Instance Filters"]') + .containsAllMatchingElements([ + filter1, + filter2, + filter3, + ]) + ).toEqual(true); + expect( + wrapper + .find('Detail[label="Only Group By"]') + .containsAllMatchingElements([ + group1, + group2, + group3, + ]) + ).toEqual(true); + expect(wrapper.find('CredentialChip').text()).toBe('Cloud: mock cred'); + expect(wrapper.find('VariablesDetail').prop('value')).toEqual( + '---\nfoo: bar' + ); + expect( + wrapper + .find('Detail[label="Options"]') + .containsAllMatchingElements([ +
  • Overwrite
  • , +
  • Overwrite Variables
  • , +
  • Update on Launch
  • , +
  • Update on Project Update
  • , + ]) + ).toEqual(true); + }); +}); diff --git a/awx/ui_next/src/components/PromptDetail/PromptJobTemplateDetail.jsx b/awx/ui_next/src/components/PromptDetail/PromptJobTemplateDetail.jsx new file mode 100644 index 0000000000..ab68ca4b28 --- /dev/null +++ b/awx/ui_next/src/components/PromptDetail/PromptJobTemplateDetail.jsx @@ -0,0 +1,8 @@ +import React from 'react'; +import { CardBody } from '@components/Card'; + +function PromptJobTemplateDetail() { + return Coming soon :); +} + +export default PromptJobTemplateDetail; diff --git a/awx/ui_next/src/components/PromptDetail/PromptProjectDetail.test.jsx b/awx/ui_next/src/components/PromptDetail/PromptProjectDetail.test.jsx new file mode 100644 index 0000000000..3cb18d2b7c --- /dev/null +++ b/awx/ui_next/src/components/PromptDetail/PromptProjectDetail.test.jsx @@ -0,0 +1,55 @@ +import React from 'react'; +import { mountWithContexts } from '@testUtils/enzymeHelpers'; +import PromptProjectDetail from './PromptProjectDetail'; +import mockProject from './data.project.json'; + +describe('PromptProjectDetail', () => { + let wrapper; + + beforeAll(() => { + const config = { + project_base_dir: 'dir/foo/bar', + }; + wrapper = mountWithContexts( + , + { + context: { config }, + } + ); + }); + + afterAll(() => { + wrapper.unmount(); + }); + + test('should render successfully', () => { + expect(wrapper.find('PromptProjectDetail')).toHaveLength(1); + }); + + test('should render expected details', () => { + function assertDetail(label, value) { + expect(wrapper.find(`Detail[label="${label}"] dt`).text()).toBe(label); + expect(wrapper.find(`Detail[label="${label}"] dd`).text()).toBe(value); + } + + assertDetail('SCM Type', 'Git'); + assertDetail('SCM URL', 'https://github.com/ansible/ansible-tower-samples'); + assertDetail('SCM Branch', 'foo'); + assertDetail('SCM Refspec', 'refs/'); + assertDetail('Cache Timeout', '3 Seconds'); + assertDetail('Ansible Environment', 'mock virtual env'); + assertDetail('Project Base Path', 'dir/foo/bar'); + assertDetail('Playbook Directory', '_6__demo_project'); + assertDetail('SCM Credential', 'Scm: mock scm'); + expect( + wrapper + .find('Detail[label="Options"]') + .containsAllMatchingElements([ +
  • Clean
  • , +
  • Delete on Update
  • , +
  • Update Revision on Launch
  • , +
  • Allow Branch Override
  • , + ]) + ).toEqual(true); + }); +}); diff --git a/awx/ui_next/src/components/PromptDetail/PromptWFJobTemplateDetail.jsx b/awx/ui_next/src/components/PromptDetail/PromptWFJobTemplateDetail.jsx new file mode 100644 index 0000000000..cceaa02cd8 --- /dev/null +++ b/awx/ui_next/src/components/PromptDetail/PromptWFJobTemplateDetail.jsx @@ -0,0 +1,8 @@ +import React from 'react'; +import { CardBody } from '@components/Card'; + +function PromptWFJobTemplateDetail() { + return Coming soon :); +} + +export default PromptWFJobTemplateDetail; diff --git a/awx/ui_next/src/components/PromptDetail/data.inventory_source.json b/awx/ui_next/src/components/PromptDetail/data.inventory_source.json new file mode 100644 index 0000000000..2b70f4b196 --- /dev/null +++ b/awx/ui_next/src/components/PromptDetail/data.inventory_source.json @@ -0,0 +1,118 @@ +{ + "id":53, + "type":"inventory_source", + "url":"/api/v2/inventory_sources/53/", + "related":{ + "named_url":"/api/v2/inventory_sources/src++Demo Inventory++Default/", + "created_by":"/api/v2/users/1/", + "modified_by":"/api/v2/users/1/", + "update":"/api/v2/inventory_sources/53/update/", + "inventory_updates":"/api/v2/inventory_sources/53/inventory_updates/", + "schedules":"/api/v2/inventory_sources/53/schedules/", + "activity_stream":"/api/v2/inventory_sources/53/activity_stream/", + "hosts":"/api/v2/inventory_sources/53/hosts/", + "groups":"/api/v2/inventory_sources/53/groups/", + "notification_templates_started":"/api/v2/inventory_sources/53/notification_templates_started/", + "notification_templates_success":"/api/v2/inventory_sources/53/notification_templates_success/", + "notification_templates_error":"/api/v2/inventory_sources/53/notification_templates_error/", + "inventory":"/api/v2/inventories/1/", + "source_project":"/api/v2/projects/8/", + "credentials":"/api/v2/inventory_sources/53/credentials/" + }, + "summary_fields":{ + "organization":{ + "id":1, + "name":"Default", + "description":"" + }, + "inventory":{ + "id":1, + "name":"Demo Inventory", + "description":"", + "has_active_failures":false, + "total_hosts":1, + "hosts_with_active_failures":0, + "total_groups":2, + "has_inventory_sources":true, + "total_inventory_sources":5, + "inventory_sources_with_failures":0, + "organization_id":1, + "kind":"" + }, + "source_project":{ + "id":8, + "name":"Mock Project", + "description":"", + "status":"never updated", + "scm_type":"git" + }, + "source_script": { + "name": "Mock Script", + "description": "" + }, + "created_by":{ + "id":1, + "username":"admin", + "first_name":"", + "last_name":"" + }, + "modified_by":{ + "id":1, + "username":"admin", + "first_name":"", + "last_name":"" + }, + "user_capabilities":{ + "edit":true, + "delete":true, + "start":true, + "schedule":true + }, + "credential": { + "id": 8, + "name": "mock cred", + "description": "", + "kind": "vmware", + "cloud": true, + "credential_type_id": 7 + }, + "credentials":[ + { + "id": 8, + "name": "mock cred", + "description": "", + "kind": "vmware", + "cloud": true, + "credential_type_id": 7 + } + ] + }, + "created":"2020-04-02T18:59:08.474167Z", + "modified":"2020-04-02T19:52:23.924252Z", + "name":"mock inv source", + "description":"mock description", + "source":"scm", + "source_path": "foo", + "source_script": "Mock Script", + "source_vars":"---\nfoo: bar", + "credential": 8, + "source_regions": "us-east-1,us-east-2", + "instance_filters": "filter1,filter2,filter3", + "group_by": "group1,group2,group3", + "overwrite":true, + "overwrite_vars":true, + "custom_virtualenv":null, + "timeout":0, + "verbosity":2, + "last_job_run":null, + "last_job_failed":false, + "next_job_run":null, + "status":"never updated", + "inventory":1, + "update_on_launch":true, + "update_cache_timeout":2, + "source_project":8, + "update_on_project_update":true, + "last_update_failed": true, + "last_updated":null +} \ No newline at end of file diff --git a/awx/ui_next/src/components/PromptDetail/data.project.json b/awx/ui_next/src/components/PromptDetail/data.project.json new file mode 100644 index 0000000000..b7ac2271a1 --- /dev/null +++ b/awx/ui_next/src/components/PromptDetail/data.project.json @@ -0,0 +1,107 @@ +{ + "id":6, + "type":"project", + "url":"/api/v2/projects/6/", + "related":{ + "named_url":"/api/v2/projects/Demo Project++Default/", + "created_by":"/api/v2/users/1/", + "modified_by":"/api/v2/users/1/", + "teams":"/api/v2/projects/6/teams/", + "playbooks":"/api/v2/projects/6/playbooks/", + "inventory_files":"/api/v2/projects/6/inventories/", + "update":"/api/v2/projects/6/update/", + "project_updates":"/api/v2/projects/6/project_updates/", + "scm_inventory_sources":"/api/v2/projects/6/scm_inventory_sources/", + "schedules":"/api/v2/projects/6/schedules/", + "activity_stream":"/api/v2/projects/6/activity_stream/", + "notification_templates_started":"/api/v2/projects/6/notification_templates_started/", + "notification_templates_success":"/api/v2/projects/6/notification_templates_success/", + "notification_templates_error":"/api/v2/projects/6/notification_templates_error/", + "access_list":"/api/v2/projects/6/access_list/", + "object_roles":"/api/v2/projects/6/object_roles/", + "copy":"/api/v2/projects/6/copy/", + "organization":"/api/v2/organizations/1/" + }, + "summary_fields":{ + "organization":{ + "id":1, + "name":"Default", + "description":"" + }, + "credential": { + "id": 9, + "name": "mock scm", + "description": "", + "kind": "scm", + "cloud": false, + "kubernetes": false, + "credential_type_id": 2 + }, + "created_by":{ + "id":1, + "username":"admin", + "first_name":"", + "last_name":"" + }, + "modified_by":{ + "id":1, + "username":"admin", + "first_name":"", + "last_name":"" + }, + "object_roles":{ + "admin_role":{ + "description":"Can manage all aspects of the project", + "name":"Admin", + "id":15 + }, + "use_role":{ + "description":"Can use the project in a job template", + "name":"Use", + "id":16 + }, + "update_role":{ + "description":"May update the project", + "name":"Update", + "id":17 + }, + "read_role":{ + "description":"May view settings for the project", + "name":"Read", + "id":18 + } + }, + "user_capabilities":{ + "edit":true, + "delete":true, + "start":true, + "schedule":true, + "copy":true + } + }, + "created":"2020-04-02T18:16:15.862724Z", + "modified":"2020-04-02T18:16:15.862738Z", + "name":"Demo Project", + "description":"", + "local_path":"_6__demo_project", + "scm_type":"git", + "scm_url":"https://github.com/ansible/ansible-tower-samples", + "scm_branch":"foo", + "scm_refspec":"refs/", + "scm_clean":true, + "scm_delete_on_update":true, + "credential":9, + "timeout":0, + "scm_revision":"", + "last_job_run":"2020-03-11T20:18:14Z", + "last_job_failed":false, + "next_job_run":null, + "status":"never updated", + "organization":1, + "scm_update_on_launch":true, + "scm_update_cache_timeout":3, + "allow_override":true, + "custom_virtualenv": "mock virtual env", + "last_update_failed":false, + "last_updated":"2020-03-11T20:18:14Z" +} \ No newline at end of file