foreman_ansible 6.2.0 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) 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 +8 -0
  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 +7 -4
  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/roles_importer.rb +3 -2
  25. data/app/services/foreman_ansible/ui_roles_importer.rb +2 -2
  26. data/app/services/foreman_ansible/variables_importer.rb +32 -2
  27. data/app/views/ansible_roles/import.html.erb +10 -50
  28. data/app/views/ansible_variables/index.html.erb +1 -2
  29. data/app/views/api/v2/ansible_roles/sync.json.rabl +5 -0
  30. data/app/views/foreman_ansible/ansible_roles/_select_tab_content.html.erb +1 -2
  31. data/app/views/foreman_ansible/config_reports/_ansible.html.erb +13 -6
  32. data/app/views/foreman_ansible/job_templates/ansible_collections_-_install_from_galaxy.erb +28 -0
  33. data/app/views/foreman_ansible/job_templates/convert_to_rhel.erb +44 -0
  34. data/config/routes.rb +5 -4
  35. data/db/migrate/20210120150019_add_position_to_ansible_role.rb +27 -0
  36. data/db/seeds.d/100_common_parameters.rb +7 -0
  37. data/db/seeds.d/90_notification_blueprints.rb +19 -1
  38. data/lib/foreman_ansible/engine.rb +1 -0
  39. data/lib/foreman_ansible/register.rb +5 -5
  40. data/lib/foreman_ansible/version.rb +1 -1
  41. data/locale/ca/LC_MESSAGES/foreman_ansible.mo +0 -0
  42. data/locale/ca/foreman_ansible.po +1 -1
  43. data/locale/cs_CZ/LC_MESSAGES/foreman_ansible.mo +0 -0
  44. data/locale/cs_CZ/foreman_ansible.po +1 -1
  45. data/locale/de/LC_MESSAGES/foreman_ansible.mo +0 -0
  46. data/locale/de/foreman_ansible.po +1 -1
  47. data/locale/en/LC_MESSAGES/foreman_ansible.mo +0 -0
  48. data/locale/en/foreman_ansible.po +1 -1
  49. data/locale/en_GB/LC_MESSAGES/foreman_ansible.mo +0 -0
  50. data/locale/en_GB/foreman_ansible.po +1 -1
  51. data/locale/es/LC_MESSAGES/foreman_ansible.mo +0 -0
  52. data/locale/es/foreman_ansible.po +1 -1
  53. data/locale/fr/LC_MESSAGES/foreman_ansible.mo +0 -0
  54. data/locale/fr/foreman_ansible.po +1 -1
  55. data/locale/gl/LC_MESSAGES/foreman_ansible.mo +0 -0
  56. data/locale/gl/foreman_ansible.po +1 -1
  57. data/locale/it/LC_MESSAGES/foreman_ansible.mo +0 -0
  58. data/locale/it/foreman_ansible.po +1 -1
  59. data/locale/ja/LC_MESSAGES/foreman_ansible.mo +0 -0
  60. data/locale/ja/foreman_ansible.po +1 -1
  61. data/locale/ko/LC_MESSAGES/foreman_ansible.mo +0 -0
  62. data/locale/ko/foreman_ansible.po +1 -1
  63. data/locale/nl_NL/LC_MESSAGES/foreman_ansible.mo +0 -0
  64. data/locale/nl_NL/foreman_ansible.po +1 -1
  65. data/locale/pl/LC_MESSAGES/foreman_ansible.mo +0 -0
  66. data/locale/pl/foreman_ansible.po +1 -1
  67. data/locale/pt_BR/LC_MESSAGES/foreman_ansible.mo +0 -0
  68. data/locale/pt_BR/foreman_ansible.po +1 -1
  69. data/locale/ru/LC_MESSAGES/foreman_ansible.mo +0 -0
  70. data/locale/ru/foreman_ansible.po +1 -1
  71. data/locale/sv_SE/LC_MESSAGES/foreman_ansible.mo +0 -0
  72. data/locale/sv_SE/foreman_ansible.po +1 -1
  73. data/locale/zh_CN/LC_MESSAGES/foreman_ansible.mo +0 -0
  74. data/locale/zh_CN/foreman_ansible.po +1 -1
  75. data/locale/zh_TW/LC_MESSAGES/foreman_ansible.mo +0 -0
  76. data/locale/zh_TW/foreman_ansible.po +1 -1
  77. data/test/factories/ansible_roles.rb +12 -0
  78. data/test/factories/host_ansible_enhancements.rb +23 -0
  79. data/test/foreman_ansible/helpers/ansible_roles_helper_test.rb +45 -0
  80. data/test/functional/ansible_variables_controller_test.rb +0 -15
  81. data/test/functional/api/v2/ansible_roles_controller_test.rb +23 -0
  82. data/test/functional/api/v2/hostgroups_controller_test.rb +5 -4
  83. data/test/functional/api/v2/hosts_controller_test.rb +9 -8
  84. data/test/functional/hosts_controller_test.rb +10 -6
  85. data/test/unit/concerns/host_managed_extensions_test.rb +17 -3
  86. data/test/unit/concerns/hostgroup_extensions_test.rb +13 -7
  87. data/test/unit/host_ansible_role_test.rb +2 -1
  88. data/test/unit/hostgroup_ansible_role_test.rb +2 -1
  89. data/test/unit/ignore_roles_test.rb +43 -0
  90. data/test/unit/import_roles_and_variables.rb +60 -0
  91. data/test/unit/services/api_roles_importer_test.rb +22 -5
  92. data/test/unit/services/fact_parser_test.rb +16 -0
  93. data/test/unit/services/inventory_creator_test.rb +15 -7
  94. data/test/unit/services/ui_roles_importer_test.rb +2 -2
  95. data/webpack/__mocks__/foremanReact/common/helpers.js +13 -0
  96. data/webpack/__mocks__/foremanReact/components/common/forms/OrderableSelect/helpers.js +5 -0
  97. data/webpack/__mocks__/foremanReact/redux/API.js +7 -0
  98. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.js +178 -0
  99. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariables.scss +9 -0
  100. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesActions.js +39 -0
  101. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesConstants.js +4 -0
  102. data/webpack/components/AnsibleRolesAndVariables/AnsibleRolesAndVariablesHelpers.js +11 -0
  103. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesHelpers.test.js +50 -0
  104. data/webpack/components/AnsibleRolesAndVariables/__test__/AnsibleRolesAndVariablesImport.test.js +39 -0
  105. data/webpack/components/AnsibleRolesAndVariables/__test__/__snapshots__/AnsibleRolesAndVariablesImport.test.js.snap +177 -0
  106. data/webpack/components/AnsibleRolesAndVariables/index.js +31 -0
  107. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +14 -18
  108. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +1 -1
  109. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +6 -0
  110. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -2
  111. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +13 -8
  112. data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +8 -28
  113. data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -0
  114. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +2 -0
  115. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +0 -8
  116. data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +2 -15
  117. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +4 -9
  118. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +8 -97
  119. data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +5 -30
  120. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +5 -2
  121. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.js +43 -0
  122. data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +19 -0
  123. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +63 -51
  124. data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +3 -0
  125. data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +23 -0
  126. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +51 -0
  127. data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +28 -28
  128. data/webpack/components/AnsibleRolesSwitcher/index.js +3 -7
  129. data/webpack/index.js +6 -0
  130. metadata +55 -9
  131. data/app/views/ansible_variables/import.html.erb +0 -56
@@ -0,0 +1,39 @@
1
+ import { testComponentSnapshotsWithFixtures } from '@theforeman/test';
2
+ import ImportRolesAndVariablesTable from '../AnsibleRolesAndVariables';
3
+
4
+ const rowsData = [
5
+ {
6
+ cells: [
7
+ 'bennojoy.ntp',
8
+ 'Update Role Variables',
9
+ 'Add: 1 Remove: 2 ',
10
+ '',
11
+ '',
12
+ ],
13
+ kind: 'old',
14
+ id: 'bennojoy.ntp',
15
+ },
16
+ {
17
+ cells: ['0ta2.git_role', 'Import Role ', 'Add: 5 ', '', ''],
18
+ kind: 'new',
19
+ id: '0ta2.git_role',
20
+ },
21
+ ];
22
+
23
+ const columnsData = [
24
+ { title: 'Name' },
25
+ { title: 'Operation' },
26
+ { title: 'Variables' },
27
+ { title: 'Hosts Count' },
28
+ { title: 'Hostgroups count' },
29
+ ];
30
+
31
+ const fixtures = {
32
+ 'should render': {
33
+ rowsData,
34
+ columnsData,
35
+ },
36
+ };
37
+
38
+ describe('ImportRolesAndVariablesTable', () =>
39
+ testComponentSnapshotsWithFixtures(ImportRolesAndVariablesTable, fixtures));
@@ -0,0 +1,177 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`ImportRolesAndVariablesTable should render 1`] = `
4
+ <div
5
+ id="import-ansible-roles-variables"
6
+ >
7
+ <Toolbar>
8
+ <ToolbarContent
9
+ isExpanded={false}
10
+ showClearFiltersButton={false}
11
+ >
12
+ <ForwardRef
13
+ variant="icon-button-group"
14
+ >
15
+ <ToolbarItem>
16
+ <Checkbox
17
+ aria-label="select all checkbox"
18
+ className=""
19
+ id="select-all"
20
+ isChecked={false}
21
+ isDisabled={false}
22
+ isValid={true}
23
+ label="Select all"
24
+ name="select-all"
25
+ onChange={[Function]}
26
+ />
27
+ </ToolbarItem>
28
+ </ForwardRef>
29
+ </ToolbarContent>
30
+ </Toolbar>
31
+ <Table
32
+ aria-label="import roles and variables"
33
+ borders={true}
34
+ canSelectAll={false}
35
+ canSortFavorites={true}
36
+ cells={
37
+ Array [
38
+ Object {
39
+ "title": "Name",
40
+ "transforms": Array [
41
+ [Function],
42
+ ],
43
+ },
44
+ Object {
45
+ "title": "Operation",
46
+ "transforms": Array [
47
+ [Function],
48
+ ],
49
+ },
50
+ Object {
51
+ "title": "Variables",
52
+ "transforms": Array [
53
+ [Function],
54
+ ],
55
+ },
56
+ Object {
57
+ "title": "Hosts Count",
58
+ "transforms": Array [
59
+ [Function],
60
+ ],
61
+ },
62
+ Object {
63
+ "title": "Hostgroups count",
64
+ "transforms": Array [
65
+ [Function],
66
+ ],
67
+ },
68
+ ]
69
+ }
70
+ className=""
71
+ contentId="expanded-content"
72
+ dropdownDirection="down"
73
+ dropdownPosition="right"
74
+ expandId="expandable-toggle"
75
+ gridBreakPoint="grid-md"
76
+ isStickyHeader={false}
77
+ onSelect={[Function]}
78
+ ouiaSafe={true}
79
+ role="grid"
80
+ rowLabeledBy="simple-node"
81
+ rows={
82
+ Array [
83
+ Object {
84
+ "cells": Array [
85
+ "bennojoy.ntp",
86
+ "Update Role Variables",
87
+ "Add: 1 Remove: 2 ",
88
+ "",
89
+ "",
90
+ ],
91
+ "id": "bennojoy.ntp",
92
+ "kind": "old",
93
+ },
94
+ Object {
95
+ "cells": Array [
96
+ "0ta2.git_role",
97
+ "Import Role ",
98
+ "Add: 5 ",
99
+ "",
100
+ "",
101
+ ],
102
+ "id": "0ta2.git_role",
103
+ "kind": "new",
104
+ },
105
+ ]
106
+ }
107
+ selectVariant="checkbox"
108
+ variant={null}
109
+ >
110
+ <TableHeader />
111
+ <Component />
112
+ </Table>
113
+ <Pagination
114
+ className=""
115
+ defaultToFullPage={true}
116
+ firstPage={1}
117
+ isCompact={true}
118
+ isDisabled={false}
119
+ isSticky={false}
120
+ itemCount={2}
121
+ itemsEnd={null}
122
+ itemsStart={null}
123
+ offset={0}
124
+ onFirstClick={[Function]}
125
+ onLastClick={[Function]}
126
+ onNextClick={[Function]}
127
+ onPageInput={[Function]}
128
+ onPerPageSelect={[Function]}
129
+ onPreviousClick={[Function]}
130
+ onSetPage={[Function]}
131
+ ouiaSafe={true}
132
+ page={0}
133
+ perPage={5}
134
+ perPageOptions={
135
+ Array [
136
+ Object {
137
+ "title": "3",
138
+ "value": 3,
139
+ },
140
+ Object {
141
+ "title": "5",
142
+ "value": 5,
143
+ },
144
+ Object {
145
+ "title": "10",
146
+ "value": 10,
147
+ },
148
+ ]
149
+ }
150
+ titles={
151
+ Object {
152
+ "paginationTitle": "top pagination",
153
+ }
154
+ }
155
+ toggleTemplate={[Function]}
156
+ variant="top"
157
+ widgetId="pagination-options-menu"
158
+ />
159
+ <div
160
+ className="submit-cancel-btns"
161
+ >
162
+ <br />
163
+ <br />
164
+ <Button
165
+ onClick={[Function]}
166
+ variant="primary"
167
+ >
168
+ Submit
169
+ </Button>
170
+ <Button
171
+ variant="secondary"
172
+ >
173
+ Cancel
174
+ </Button>
175
+ </div>
176
+ </div>
177
+ `;
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import { useDispatch } from 'react-redux';
3
+ import { push } from 'connected-react-router';
4
+
5
+ import ImportRolesAndVariablesTable from './AnsibleRolesAndVariables';
6
+ import { onSubmit } from './AnsibleRolesAndVariablesActions';
7
+ import { ANSIBLE_ROLES_INDEX } from './AnsibleRolesAndVariablesConstants';
8
+
9
+ const WrappedImportRolesAndVariables = props => {
10
+ const cols = [
11
+ { title: 'Name' },
12
+ { title: 'Operation' },
13
+ { title: 'Variables' },
14
+ { title: 'Hosts Count' },
15
+ { title: 'Hostgroups count' },
16
+ ];
17
+ const dispatch = useDispatch();
18
+ const submit = (rows, proxy) => dispatch(onSubmit(rows, proxy));
19
+ const onCancel = () => {
20
+ dispatch(push(ANSIBLE_ROLES_INDEX));
21
+ };
22
+ return (
23
+ <ImportRolesAndVariablesTable
24
+ {...props}
25
+ columnsData={cols}
26
+ onSubmit={submit}
27
+ onCancel={onCancel}
28
+ />
29
+ );
30
+ };
31
+ export default WrappedImportRolesAndVariables;
@@ -7,6 +7,7 @@ import { translate as __ } from 'foremanReact/common/I18n';
7
7
  import AvailableRolesList from './components/AvailableRolesList';
8
8
  import AssignedRolesList from './components/AssignedRolesList';
9
9
  import AnsibleRolesSwitcherError from './components/AnsibleRolesSwitcherError';
10
+ import OrderedRolesTooltip from './components/OrderedRolesTooltip';
10
11
  import { excludeAssignedRolesSearch } from './AnsibleRolesSwitcherHelpers';
11
12
 
12
13
  class AnsibleRolesSwitcher extends React.Component {
@@ -37,13 +38,11 @@ class AnsibleRolesSwitcher extends React.Component {
37
38
  itemCount,
38
39
  addAnsibleRole,
39
40
  removeAnsibleRole,
41
+ moveAnsibleRole,
40
42
  getAnsibleRoles,
41
- changeAssignedPage,
42
- assignedPagination,
43
- assignedRolesCount,
44
43
  assignedRoles,
45
- allAssignedRoles,
46
44
  unassignedRoles,
45
+ toDestroyRoles,
47
46
  error,
48
47
  } = this.props;
49
48
 
@@ -57,12 +56,12 @@ class AnsibleRolesSwitcher extends React.Component {
57
56
  const onListingChange = paginationArgs =>
58
57
  getAnsibleRoles(
59
58
  availableRolesUrl,
60
- allAssignedRoles,
59
+ assignedRoles,
61
60
  inheritedRoleIds,
62
61
  resourceId,
63
62
  resourceName,
64
63
  paginationArgs,
65
- excludeAssignedRolesSearch(allAssignedRoles)
64
+ excludeAssignedRolesSearch(assignedRoles)
66
65
  );
67
66
 
68
67
  return (
@@ -85,16 +84,18 @@ class AnsibleRolesSwitcher extends React.Component {
85
84
 
86
85
  <Col sm={6} className="assigned-roles-container">
87
86
  <div className="assigned-roles-header">
88
- <h2>{__('Assigned Ansible Roles')}</h2>
87
+ <h2>
88
+ <OrderedRolesTooltip />
89
+ {__('Assigned Ansible Roles')}
90
+ </h2>
89
91
  </div>
90
92
  <AssignedRolesList
91
93
  assignedRoles={assignedRoles}
92
- allAssignedRoles={allAssignedRoles}
93
- pagination={assignedPagination}
94
- itemCount={assignedRolesCount}
95
- onPaginationChange={changeAssignedPage}
94
+ unassignedRoles={unassignedRoles}
96
95
  onRemoveRole={removeAnsibleRole}
96
+ onMoveRole={moveAnsibleRole}
97
97
  resourceName={lowerCase(resourceName || '')}
98
+ toDestroyRoles={toDestroyRoles}
98
99
  />
99
100
  </Col>
100
101
  </Row>
@@ -118,14 +119,9 @@ AnsibleRolesSwitcher.propTypes = {
118
119
  itemCount: PropTypes.number.isRequired,
119
120
  addAnsibleRole: PropTypes.func.isRequired,
120
121
  removeAnsibleRole: PropTypes.func.isRequired,
121
- changeAssignedPage: PropTypes.func.isRequired,
122
- assignedPagination: PropTypes.shape({
123
- page: PropTypes.number,
124
- perPage: PropTypes.number,
125
- }).isRequired,
126
- assignedRolesCount: PropTypes.number.isRequired,
122
+ moveAnsibleRole: PropTypes.func.isRequired,
127
123
  assignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
128
- allAssignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
124
+ toDestroyRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
129
125
  unassignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
130
126
  error: PropTypes.shape({
131
127
  errorMsg: PropTypes.string,
@@ -10,7 +10,7 @@
10
10
  }
11
11
 
12
12
  .list-group-item.ansible-role-movable:hover {
13
- cursor: pointer;
13
+ cursor: grab;
14
14
  }
15
15
  }
16
16
 
@@ -10,6 +10,7 @@ import {
10
10
  ANSIBLE_ROLES_FAILURE,
11
11
  ANSIBLE_ROLES_ADD,
12
12
  ANSIBLE_ROLES_REMOVE,
13
+ ANSIBLE_ROLES_MOVE,
13
14
  ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
14
15
  } from './AnsibleRolesSwitcherConstants';
15
16
 
@@ -63,6 +64,11 @@ export const removeAnsibleRole = role => ({
63
64
  payload: { role },
64
65
  });
65
66
 
67
+ export const moveAnsibleRole = roles => ({
68
+ type: ANSIBLE_ROLES_MOVE,
69
+ payload: { roles },
70
+ });
71
+
66
72
  export const changeAssignedPage = pagination => ({
67
73
  type: ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
68
74
  payload: { pagination },
@@ -3,5 +3,4 @@ export const ANSIBLE_ROLES_SUCCESS = 'ANSIBLE_ROLES_SUCCESS';
3
3
  export const ANSIBLE_ROLES_FAILURE = 'ANSIBLE_ROLES_FAILURE';
4
4
  export const ANSIBLE_ROLES_ADD = 'ANSIBLE_ROLES_ADD';
5
5
  export const ANSIBLE_ROLES_REMOVE = 'ANSIBLE_ROLES_REMOVE';
6
- export const ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE =
7
- 'ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE';
6
+ export const ANSIBLE_ROLES_MOVE = 'ANSIBLE_ROLE_MOVE';
@@ -6,7 +6,7 @@ import {
6
6
  ANSIBLE_ROLES_FAILURE,
7
7
  ANSIBLE_ROLES_ADD,
8
8
  ANSIBLE_ROLES_REMOVE,
9
- ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
9
+ ANSIBLE_ROLES_MOVE,
10
10
  } from './AnsibleRolesSwitcherConstants';
11
11
 
12
12
  export const initialState = Immutable({
@@ -17,12 +17,9 @@ export const initialState = Immutable({
17
17
  perPage: 10,
18
18
  },
19
19
  assignedRoles: [],
20
+ toDestroyRoles: [],
20
21
  inheritedRoleIds: [],
21
22
  results: [],
22
- assignedPagination: {
23
- page: 1,
24
- perPage: 10,
25
- },
26
23
  error: { errorMsg: '', status: '', statusText: '' },
27
24
  });
28
25
 
@@ -49,6 +46,9 @@ const ansibleRoles = (state = initialState, action) => {
49
46
  case ANSIBLE_ROLES_ADD:
50
47
  return state.merge({
51
48
  assignedRoles: state.assignedRoles.concat([payload.role]),
49
+ toDestroyRoles: state.toDestroyRoles.filter(
50
+ item => item.id !== payload.role.id
51
+ ),
52
52
  itemCount: state.itemCount - 1,
53
53
  });
54
54
  case ANSIBLE_ROLES_REMOVE:
@@ -56,11 +56,16 @@ const ansibleRoles = (state = initialState, action) => {
56
56
  assignedRoles: Immutable.flatMap(state.assignedRoles, item =>
57
57
  item.id === payload.role.id ? [] : item
58
58
  ),
59
- results: state.results.concat([payload.role]),
59
+ results: state.results.find(item => payload.role.id === item.id)
60
+ ? state.results
61
+ : state.results.concat([payload.role]),
62
+ toDestroyRoles: state.toDestroyRoles.concat([
63
+ { ...payload.role, destroy: true },
64
+ ]),
60
65
  itemCount: state.itemCount + 1,
61
66
  });
62
- case ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE:
63
- return state.set('assignedPagination', payload.pagination);
67
+ case ANSIBLE_ROLES_MOVE:
68
+ return state.set('assignedRoles', payload.roles);
64
69
  default:
65
70
  return state;
66
71
  }
@@ -1,16 +1,7 @@
1
- import { differenceBy, slice, includes, uniq } from 'lodash';
1
+ import { differenceBy, includes } from 'lodash';
2
2
  import Immutable from 'seamless-immutable';
3
3
  import { createSelector } from 'reselect';
4
-
5
- const compare = (a, b) => {
6
- if (a.name < b.name) {
7
- return -1;
8
- }
9
- if (a.name > b.name) {
10
- return 1;
11
- }
12
- return 0;
13
- };
4
+ import { propsToCamelCase } from 'foremanReact/common/helpers';
14
5
 
15
6
  const switcherState = state => state.foremanAnsible.ansibleRolesSwitcher;
16
7
 
@@ -21,7 +12,7 @@ const markInheritedRoles = (roles, inheritedRoleIds) =>
21
12
 
22
13
  export const selectResults = state =>
23
14
  Immutable(
24
- Immutable.asMutable(uniq(switcherState(state).results)).sort(compare)
15
+ Immutable.asMutable(switcherState(state).results.map(propsToCamelCase))
25
16
  );
26
17
 
27
18
  export const selectItemCount = state => switcherState(state).itemCount;
@@ -29,16 +20,15 @@ export const selectItemCount = state => switcherState(state).itemCount;
29
20
  export const selectAssignedRoles = state =>
30
21
  Immutable.asMutable(
31
22
  markInheritedRoles(
32
- switcherState(state).assignedRoles,
23
+ switcherState(state).assignedRoles.map(propsToCamelCase),
33
24
  switcherState(state).inheritedRoleIds
34
25
  )
35
- ).sort(compare);
26
+ );
27
+
28
+ export const selectToDestroyRoles = state =>
29
+ switcherState(state).toDestroyRoles;
36
30
 
37
- export const selectAssignedRolesCount = state =>
38
- selectAssignedRoles(state).length;
39
31
  export const selectLoading = state => switcherState(state).loading;
40
- export const selectAssignedPagination = state =>
41
- switcherState(state).assignedPagination;
42
32
  export const selectError = state => switcherState(state).error;
43
33
  export const selectPagination = state => switcherState(state).pagination;
44
34
 
@@ -56,13 +46,3 @@ export const selectUnassignedRoles = createSelector(
56
46
  selectAssignedRoles,
57
47
  (results, assignedRoles) => differenceBy(results, assignedRoles, 'id')
58
48
  );
59
-
60
- export const selectAssignedRolesPage = createSelector(
61
- selectAssignedPagination,
62
- selectAssignedRoles,
63
- (assignedPagination, assignedRoles) => {
64
- const offset = (assignedPagination.page - 1) * assignedPagination.perPage;
65
-
66
- return slice(assignedRoles, offset, offset + assignedPagination.perPage);
67
- }
68
- );