foreman_ansible 6.1.1 → 6.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ansible_roles_controller.rb +12 -8
  3. data/app/controllers/ansible_variables_controller.rb +4 -0
  4. data/app/controllers/api/v2/ansible_roles_controller.rb +32 -11
  5. data/app/controllers/api/v2/ansible_variables_controller.rb +6 -4
  6. data/app/controllers/foreman_ansible/concerns/import_controller_helper.rb +3 -3
  7. data/app/helpers/foreman_ansible/ansible_reports_helper.rb +9 -4
  8. data/app/helpers/foreman_ansible/ansible_roles_data_preparations.rb +95 -0
  9. data/app/helpers/foreman_ansible/ansible_roles_helper.rb +20 -1
  10. data/app/jobs/sync_roles_and_variables.rb +20 -0
  11. data/app/models/concerns/foreman_ansible/host_managed_extensions.rb +7 -4
  12. data/app/models/concerns/foreman_ansible/hostgroup_extensions.rb +8 -5
  13. data/app/models/foreman_ansible/ansible_provider.rb +2 -1
  14. data/app/models/host_ansible_role.rb +1 -0
  15. data/app/models/hostgroup_ansible_role.rb +1 -0
  16. data/app/models/setting/ansible.rb +9 -0
  17. data/app/services/foreman_ansible/ansible_report_importer.rb +4 -0
  18. data/app/services/foreman_ansible/ansible_report_scanner.rb +15 -1
  19. data/app/services/foreman_ansible/api_roles_importer.rb +23 -11
  20. data/app/services/foreman_ansible/fact_parser.rb +21 -1
  21. data/app/services/foreman_ansible/import_roles_and_variables_error_notification.rb +31 -0
  22. data/app/services/foreman_ansible/import_roles_and_variables_success_notification.rb +26 -0
  23. data/app/services/foreman_ansible/inventory_creator.rb +3 -7
  24. data/app/services/foreman_ansible/operating_system_parser.rb +1 -1
  25. data/app/services/foreman_ansible/roles_importer.rb +3 -2
  26. data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
  27. data/app/services/foreman_ansible/variables_importer.rb +36 -1
  28. data/app/views/ansible_roles/import.html.erb +10 -50
  29. data/app/views/ansible_variables/index.html.erb +1 -2
  30. data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
  31. data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +8 -17
  32. data/app/views/foreman_ansible/config_reports/_ansible.html.erb +13 -6
  33. data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
  34. data/app/views/foreman_ansible/job_templates/ansible_roles_-_install_from_galaxy.erb +1 -1
  35. data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
  36. data/config/routes.rb +5 -4
  37. data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
  38. data/db/seeds.d/100_common_parameters.rb +7 -0
  39. data/db/seeds.d/90_notification_blueprints.rb +19 -1
  40. data/lib/foreman_ansible/engine.rb +1 -0
  41. data/lib/foreman_ansible/register.rb +8 -7
  42. data/lib/foreman_ansible/version.rb +1 -1
  43. data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
  44. data/locale/ca/foreman_ansible.po +1 -1
  45. data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
  46. data/locale/cs_CZ/foreman_ansible.po +1 -1
  47. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  48. data/locale/de/foreman_ansible.po +1 -1
  49. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  50. data/locale/en/foreman_ansible.po +1 -1
  51. data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
  52. data/locale/en_GB/foreman_ansible.po +1 -1
  53. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  54. data/locale/es/foreman_ansible.po +1 -1
  55. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  56. data/locale/fr/foreman_ansible.po +1 -1
  57. data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
  58. data/locale/gl/foreman_ansible.po +1 -1
  59. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  60. data/locale/it/foreman_ansible.po +1 -1
  61. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  62. data/locale/ja/foreman_ansible.po +1 -1
  63. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  64. data/locale/ko/foreman_ansible.po +1 -1
  65. data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
  66. data/locale/nl_NL/foreman_ansible.po +1 -1
  67. data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
  68. data/locale/pl/foreman_ansible.po +1 -1
  69. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  70. data/locale/pt_BR/foreman_ansible.po +1 -1
  71. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  72. data/locale/ru/foreman_ansible.po +1 -1
  73. data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
  74. data/locale/sv_SE/foreman_ansible.po +1 -1
  75. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  76. data/locale/zh_CN/foreman_ansible.po +1 -1
  77. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  78. data/locale/zh_TW/foreman_ansible.po +1 -1
  79. data/package.json +11 -42
  80. data/test/factories/ansible_roles.rb +12 -0
  81. data/test/factories/host_ansible_enhancements.rb +23 -0
  82. data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
  83. data/test/functional/ansible_variables_controller_test.rb +0 -15
  84. data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
  85. data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
  86. data/test/functional/api/v2/hosts_controller_test.rb +9 -8
  87. data/test/functional/hosts_controller_test.rb +10 -6
  88. data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
  89. data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
  90. data/test/unit/host_ansible_role_test.rb +2 -1
  91. data/test/unit/hostgroup_ansible_role_test.rb +15 -1
  92. data/test/unit/ignore_roles_test.rb +43 -0
  93. data/test/unit/import_roles_and_variables.rb +60 -0
  94. data/test/unit/services/ansible_variables_importer_test.rb +13 -0
  95. data/test/unit/services/api_roles_importer_test.rb +22 -5
  96. data/test/unit/services/fact_parser_test.rb +16 -0
  97. data/test/unit/services/inventory_creator_test.rb +15 -7
  98. data/test/unit/services/ui_roles_importer_test.rb +2 -2
  99. data/webpack/__mocks__/foremanReact/common/helpers.js +13 -0
  100. data/webpack/__mocks__/foremanReact/components/common/forms/OrderableSelect/helpers.js +5 -0
  101. data/webpack/__mocks__/foremanReact/redux/API.js +7 -0
  102. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
  103. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
  104. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
  105. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
  106. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
  107. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
  108. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
  109. data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
  110. data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
  111. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +25 -27
  112. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
  113. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +20 -14
  114. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
  115. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
  116. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
  117. data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
  118. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +6 -4
  119. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +1 -9
  120. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +3 -16
  121. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -8
  122. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
  123. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
  124. data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +1 -1
  125. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
  126. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +1 -1
  127. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
  128. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
  129. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
  130. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +4 -1
  131. data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +1 -1
  132. data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
  133. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
  134. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
  135. data/webpack/components/AnsibleRolesSwitcher/index.js +4 -8
  136. data/webpack/index.js +6 -13
  137. metadata +63 -18
  138. data/app/views/ansible_variables/import.html.erb +0 -56
  139. data/webpack/test_setup.js +0 -12
@@ -3,8 +3,8 @@
3
3
  exports[`AnsibleRolesSwitcherSelectors should return all roles when no roles assigned 1`] = `
4
4
  Array [
5
5
  Object {
6
- "id": 4,
7
- "name": "geerlingguy.java",
6
+ "id": 1,
7
+ "name": "sthirugn.motd",
8
8
  },
9
9
  Object {
10
10
  "id": 2,
@@ -15,46 +15,21 @@ Array [
15
15
  "name": "rvm.ruby",
16
16
  },
17
17
  Object {
18
- "id": 1,
19
- "name": "sthirugn.motd",
18
+ "id": 4,
19
+ "name": "geerlingguy.java",
20
20
  },
21
21
  ]
22
22
  `;
23
23
 
24
- exports[`AnsibleRolesSwitcherSelectors should return requested page 1`] = `
24
+ exports[`AnsibleRolesSwitcherSelectors should return unassigned roles 1`] = `
25
25
  Array [
26
- Object {
27
- "id": 5,
28
- "name": "naftulikay.golang",
29
- },
30
- Object {
31
- "id": 8,
32
- "name": "puppet.puppet",
33
- },
34
- Object {
35
- "id": 3,
36
- "name": "rvm.ruby",
37
- },
38
- Object {
39
- "id": 10,
40
- "name": "salt.salt",
41
- },
42
26
  Object {
43
27
  "id": 1,
44
28
  "name": "sthirugn.motd",
45
29
  },
46
- ]
47
- `;
48
-
49
- exports[`AnsibleRolesSwitcherSelectors should return unassigned roles 1`] = `
50
- Array [
51
30
  Object {
52
31
  "id": 3,
53
32
  "name": "rvm.ruby",
54
33
  },
55
- Object {
56
- "id": 1,
57
- "name": "sthirugn.motd",
58
- },
59
34
  ]
60
35
  `;
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
  import AnsiblePermissionDenied from './AnsiblePermissionDenied';
3
3
 
4
4
  jest.mock('foremanReact/components/common/EmptyState');
@@ -6,7 +6,7 @@ import { translate as __ } from 'foremanReact/common/I18n';
6
6
  import AnsibleRoleActionButton from './AnsibleRoleActionButton';
7
7
  import '../AnsibleRolesSwitcher.scss';
8
8
 
9
- const AnsibleRole = ({ role, icon, onClick, resourceName }) => {
9
+ const AnsibleRole = ({ role, icon, onClick, resourceName, index }) => {
10
10
  const text =
11
11
  resourceName === 'hostgroup'
12
12
  ? __('This Ansible role is inherited from parent host group')
@@ -23,6 +23,9 @@ const AnsibleRole = ({ role, icon, onClick, resourceName }) => {
23
23
  onClickFn(ansibleRole);
24
24
  };
25
25
 
26
+ const headingText = (name, idx) =>
27
+ idx || idx === 0 ? `${idx + 1}. ${name}` : name;
28
+
26
29
  const listItem = (click = undefined) => (
27
30
  <ListView.Item
28
31
  id={role.id}
@@ -30,7 +33,7 @@ const AnsibleRole = ({ role, icon, onClick, resourceName }) => {
30
33
  'ansible-role-disabled': role.inherited,
31
34
  'ansible-role-movable': !role.inherited,
32
35
  })}
33
- heading={role.name}
36
+ heading={headingText(role.name, index)}
34
37
  actions={
35
38
  role.inherited ? (
36
39
  ''
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AnsibleRole from './AnsibleRole';
4
4
 
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ const AnsibleRoleInputs = props => {
5
+ const { role, idx, resourceName } = props;
6
+
7
+ const fieldName = attr =>
8
+ `${resourceName}[${resourceName}_ansible_roles_attributes][${idx}][${attr}]`;
9
+
10
+ const attrName = modelName => `${modelName}AnsibleRoleId`;
11
+
12
+ const idField = (
13
+ <input
14
+ name={fieldName('id')}
15
+ value={role[attrName(resourceName)]}
16
+ type="hidden"
17
+ />
18
+ );
19
+ return (
20
+ <React.Fragment>
21
+ {role[attrName(resourceName)] ? idField : null}
22
+ <input
23
+ name={fieldName('ansible_role_id')}
24
+ value={role.id}
25
+ type="hidden"
26
+ />
27
+ <input name={fieldName('position')} value={idx + 1} type="hidden" />
28
+ <input
29
+ name={fieldName('_destroy')}
30
+ value={!!role.destroy}
31
+ type="hidden"
32
+ />
33
+ </React.Fragment>
34
+ );
35
+ };
36
+
37
+ AnsibleRoleInputs.propTypes = {
38
+ role: PropTypes.object.isRequired,
39
+ idx: PropTypes.number.isRequired,
40
+ resourceName: PropTypes.string.isRequired,
41
+ };
42
+
43
+ export default AnsibleRoleInputs;
@@ -0,0 +1,19 @@
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
+
3
+ import AnsibleRoleInputs from './AnsibleRoleInputs';
4
+
5
+ const fixtures = {
6
+ 'should render role to add': {
7
+ role: { id: 2, name: 'test.role', hostAnsibleRoleId: 5, position: 2 },
8
+ resourceName: 'host',
9
+ idx: 14,
10
+ },
11
+ 'should render role to remove': {
12
+ role: { id: 2, name: 'test.role', hostAnsibleRoleId: 5, destroy: true },
13
+ resourceName: 'host',
14
+ idx: 14,
15
+ },
16
+ };
17
+
18
+ describe('AnsibleRoleInputs', () =>
19
+ testComponentSnapshotsWithFixtures(AnsibleRoleInputs, fixtures));
@@ -1,79 +1,91 @@
1
1
  import React from 'react';
2
+ import { DndProvider } from 'react-dnd';
3
+ import HTML5Backend from 'react-dnd-html5-backend';
4
+
2
5
  import { ListView } from 'patternfly-react';
3
- import PaginationWrapper from 'foremanReact/components/Pagination/PaginationWrapper';
4
- import { isEmpty } from 'lodash';
6
+
7
+ import {
8
+ orderable,
9
+ orderDragged,
10
+ } from 'foremanReact/components/common/forms/OrderableSelect/helpers';
11
+
5
12
  import PropTypes from 'prop-types';
6
13
 
7
14
  import AnsibleRole from './AnsibleRole';
15
+ import AnsibleRoleInputs from './AnsibleRoleInputs';
16
+
17
+ const OrderableRole = orderable(AnsibleRole, {
18
+ type: 'ansibleRole',
19
+ getItem: props => ({ id: props.role.id }),
20
+ direction: 'vertical',
21
+ });
8
22
 
9
23
  const AssignedRolesList = ({
24
+ unassignedRoles,
10
25
  assignedRoles,
11
- allAssignedRoles,
12
- pagination,
13
- itemCount,
14
- onPaginationChange,
26
+ toDestroyRoles,
15
27
  onRemoveRole,
28
+ onMoveRole,
16
29
  resourceName,
17
30
  }) => {
18
- const directlyAssignedRoles = allAssignedRoles.filter(
19
- role => !role.inherited
31
+ const moveValue = (dragIndex, hoverIndex) => {
32
+ onMoveRole(orderDragged(assignedRoles, dragIndex, hoverIndex));
33
+ };
34
+
35
+ const allOwnRoles = roles => roles.filter(role => !role.inherited);
36
+
37
+ const renderRole = (role, idx) =>
38
+ role.inherited ? renderInherited(role, idx) : renderOwn(role, idx);
39
+
40
+ const renderInherited = (role, idx) => (
41
+ <AnsibleRole
42
+ key={role.id}
43
+ role={role}
44
+ index={idx}
45
+ icon="fa fa-minus-circle"
46
+ onClick={onRemoveRole}
47
+ resourceName={resourceName}
48
+ />
49
+ );
50
+
51
+ const renderOwn = (role, idx) => (
52
+ <OrderableRole
53
+ key={role.id}
54
+ role={role}
55
+ index={idx}
56
+ moveValue={moveValue}
57
+ icon="fa fa-minus-circle"
58
+ onClick={onRemoveRole}
59
+ resourceName={resourceName}
60
+ />
20
61
  );
21
62
 
22
63
  return (
23
- <div>
24
- <ListView>
25
- <div className="sticky-pagination sticky-pagination-grey">
26
- <PaginationWrapper
27
- viewType="list"
28
- itemCount={itemCount}
29
- pagination={pagination}
30
- onChange={onPaginationChange}
31
- dropdownButtonId="assigned-ansible-roles-pagination-row-dropdown"
32
- />
33
- </div>
34
- {assignedRoles.map(role => (
35
- <AnsibleRole
36
- key={role.id}
37
- role={role}
38
- icon="fa fa-minus-circle"
39
- onClick={onRemoveRole}
40
- resourceName={resourceName}
41
- />
42
- ))}
43
- </ListView>
64
+ <DndProvider backend={HTML5Backend}>
65
+ <ListView>{assignedRoles.map(renderRole)}</ListView>
44
66
  <div>
45
- {isEmpty(directlyAssignedRoles) ? (
46
- <input
47
- type="hidden"
48
- name={`${resourceName}[ansible_role_ids][]`}
49
- value=""
50
- />
51
- ) : (
52
- directlyAssignedRoles.map(role => (
53
- <input
67
+ {allOwnRoles(assignedRoles)
68
+ .concat(toDestroyRoles)
69
+ .map((role, idx) => (
70
+ <AnsibleRoleInputs
54
71
  key={role.id}
55
- type="hidden"
56
- name={`${resourceName}[ansible_role_ids][]`}
57
- value={role.id}
72
+ role={role}
73
+ idx={idx}
74
+ resourceName={resourceName}
58
75
  />
59
- ))
60
- )}
76
+ ))}
61
77
  </div>
62
- </div>
78
+ </DndProvider>
63
79
  );
64
80
  };
65
81
 
66
82
  AssignedRolesList.propTypes = {
83
+ unassignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
67
84
  assignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
68
- allAssignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
69
- pagination: PropTypes.shape({
70
- page: PropTypes.number,
71
- perPage: PropTypes.number,
72
- }).isRequired,
73
- itemCount: PropTypes.number.isRequired,
74
- onPaginationChange: PropTypes.func.isRequired,
75
85
  onRemoveRole: PropTypes.func.isRequired,
86
+ onMoveRole: PropTypes.func.isRequired,
76
87
  resourceName: PropTypes.string.isRequired,
88
+ toDestroyRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
77
89
  };
78
90
 
79
91
  export default AssignedRolesList;
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AssignedRolesList from './AssignedRolesList';
4
4
 
@@ -18,7 +18,10 @@ const fixtures = {
18
18
  itemCount: 2,
19
19
  onPaginationChange: noop,
20
20
  onRemoveRole: noop,
21
+ onMoveRole: noop,
21
22
  resourceName: 'host',
23
+ toDestroyRoles: [],
24
+ unassignedRoles: [],
22
25
  },
23
26
  };
24
27
 
@@ -1,4 +1,4 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
2
 
3
3
  import AvailableRolesList from './AvailableRolesList';
4
4
 
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { translate as __ } from 'foremanReact/common/I18n';
3
+ import { Tooltip, Icon, OverlayTrigger } from 'patternfly-react';
4
+
5
+ const OrderedRolesTooltip = props => {
6
+ const tooltip = (
7
+ <Tooltip id="assigned-ansible-roles-tooltip">
8
+ <span>
9
+ {__(
10
+ 'Use drag and drop to change order of the roles. Ordering of roles is respected for Ansible runs, inherited roles are always before those assigned directly'
11
+ )}
12
+ </span>
13
+ </Tooltip>
14
+ );
15
+
16
+ return (
17
+ <OverlayTrigger overlay={tooltip} trigger={['hover', 'focus']}>
18
+ <Icon type="pf" name="info" style={{ 'margin-right': '10px' }} />
19
+ </OverlayTrigger>
20
+ );
21
+ };
22
+
23
+ export default OrderedRolesTooltip;
@@ -0,0 +1,51 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`AnsibleRoleInputs should render role to add 1`] = `
4
+ <Fragment>
5
+ <input
6
+ name="host[host_ansible_roles_attributes][14][id]"
7
+ type="hidden"
8
+ value={5}
9
+ />
10
+ <input
11
+ name="host[host_ansible_roles_attributes][14][ansible_role_id]"
12
+ type="hidden"
13
+ value={2}
14
+ />
15
+ <input
16
+ name="host[host_ansible_roles_attributes][14][position]"
17
+ type="hidden"
18
+ value={15}
19
+ />
20
+ <input
21
+ name="host[host_ansible_roles_attributes][14][_destroy]"
22
+ type="hidden"
23
+ value={false}
24
+ />
25
+ </Fragment>
26
+ `;
27
+
28
+ exports[`AnsibleRoleInputs should render role to remove 1`] = `
29
+ <Fragment>
30
+ <input
31
+ name="host[host_ansible_roles_attributes][14][id]"
32
+ type="hidden"
33
+ value={5}
34
+ />
35
+ <input
36
+ name="host[host_ansible_roles_attributes][14][ansible_role_id]"
37
+ type="hidden"
38
+ value={2}
39
+ />
40
+ <input
41
+ name="host[host_ansible_roles_attributes][14][position]"
42
+ type="hidden"
43
+ value={15}
44
+ />
45
+ <input
46
+ name="host[host_ansible_roles_attributes][14][_destroy]"
47
+ type="hidden"
48
+ value={true}
49
+ />
50
+ </Fragment>
51
+ `;
@@ -1,29 +1,17 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`AssignedRolesList should render 1`] = `
4
- <div>
4
+ <DndProvider
5
+ backend={[Function]}
6
+ >
5
7
  <ListView
6
8
  className=""
7
9
  >
8
- <div
9
- className="sticky-pagination sticky-pagination-grey"
10
- >
11
- <PaginationWrapper
12
- dropdownButtonId="assigned-ansible-roles-pagination-row-dropdown"
13
- itemCount={2}
14
- onChange={[Function]}
15
- pagination={
16
- Object {
17
- "page": 1,
18
- "perPage": 25,
19
- }
20
- }
21
- viewType="list"
22
- />
23
- </div>
24
- <AnsibleRole
10
+ <Component
25
11
  icon="fa fa-minus-circle"
12
+ index={0}
26
13
  key="1"
14
+ moveValue={[Function]}
27
15
  onClick={[Function]}
28
16
  resourceName="host"
29
17
  role={
@@ -33,9 +21,11 @@ exports[`AssignedRolesList should render 1`] = `
33
21
  }
34
22
  }
35
23
  />
36
- <AnsibleRole
24
+ <Component
37
25
  icon="fa fa-minus-circle"
26
+ index={1}
38
27
  key="2"
28
+ moveValue={[Function]}
39
29
  onClick={[Function]}
40
30
  resourceName="host"
41
31
  role={
@@ -47,18 +37,28 @@ exports[`AssignedRolesList should render 1`] = `
47
37
  />
48
38
  </ListView>
49
39
  <div>
50
- <input
40
+ <AnsibleRoleInputs
41
+ idx={0}
51
42
  key="1"
52
- name="host[ansible_role_ids][]"
53
- type="hidden"
54
- value={1}
43
+ resourceName="host"
44
+ role={
45
+ Object {
46
+ "id": 1,
47
+ "name": "fake.role",
48
+ }
49
+ }
55
50
  />
56
- <input
51
+ <AnsibleRoleInputs
52
+ idx={1}
57
53
  key="2"
58
- name="host[ansible_role_ids][]"
59
- type="hidden"
60
- value={2}
54
+ resourceName="host"
55
+ role={
56
+ Object {
57
+ "id": 2,
58
+ "name": "test.role",
59
+ }
60
+ }
61
61
  />
62
62
  </div>
63
- </div>
63
+ </DndProvider>
64
64
  `;