foreman_ansible 17.0.7 → 17.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/foreman_ansible/version.rb +1 -1
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.js +74 -95
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcher.scss +40 -28
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherActions.js +13 -34
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherConstants.js +1 -3
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherHelpers.js +1 -7
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherReducer.js +27 -34
- data/webpack/components/AnsibleRolesSwitcher/AnsibleRolesSwitcherSelectors.js +4 -14
- data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js +1 -12
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcher.test.js +129 -25
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherReducer.test.js +57 -47
- data/webpack/components/AnsibleRolesSwitcher/__tests__/AnsibleRolesSwitcherSelectors.test.js +47 -19
- data/webpack/components/AnsibleRolesSwitcher/components/AnsiblePermissionDenied.test.js +40 -6
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleInputs.test.js +51 -15
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRolesSwitcherError.js +9 -8
- data/webpack/components/AnsibleRolesSwitcher/components/InheritedRolesList.js +39 -0
- data/webpack/components/AnsibleRolesSwitcher/components/InheritedRolesList.test.js +38 -0
- data/webpack/components/AnsibleRolesSwitcher/index.js +0 -6
- data/webpack/components/DualList/ListItem.js +1 -1
- data/webpack/components/DualList/index.js +1 -1
- metadata +3 -17
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcher.test.js.snap +0 -75
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherReducer.test.js.snap +0 -310
- data/webpack/components/AnsibleRolesSwitcher/__tests__/__snapshots__/AnsibleRolesSwitcherSelectors.test.js.snap +0 -35
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.js +0 -80
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRole.test.js +0 -29
- data/webpack/components/AnsibleRolesSwitcher/components/AnsibleRoleActionButton.js +0 -28
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.js +0 -91
- data/webpack/components/AnsibleRolesSwitcher/components/AssignedRolesList.test.js +0 -29
- data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.js +0 -53
- data/webpack/components/AnsibleRolesSwitcher/components/AvailableRolesList.test.js +0 -22
- data/webpack/components/AnsibleRolesSwitcher/components/OrderedRolesTooltip.js +0 -22
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsiblePermissionDenied.test.js.snap +0 -28
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRole.test.js.snap +0 -94
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AnsibleRoleInputs.test.js.snap +0 -51
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AssignedRolesList.test.js.snap +0 -64
- data/webpack/components/AnsibleRolesSwitcher/components/__snapshots__/AvailableRolesList.test.js.snap +0 -58
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b6cd8765eae0204e9dec617d7d3e267abfffc55d402d87026812deadcb720049
|
|
4
|
+
data.tar.gz: 47d5ba9efc868bcf4164dc28106a67ee42010a74017bf70551e00b856a696b33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3aac0662ea3b05bcdae57b8aa80a5bc51b7008b775686c39f024e24c1c294ea51404965e5bf699b888a7a436862255162b9085e8fdd706e5297177e732ad13a9
|
|
7
|
+
data.tar.gz: 4feef7c8a25d8688d24d5e05826d994050bfbfbc6407480ccd773eaae862fdde5a30ba899f0c9e85e51c5cd3a788313cf6802d39be1cdd225e5391247de3de3c
|
|
@@ -1,107 +1,93 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Grid, Row, Col } from 'patternfly-react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
3
2
|
import { lowerCase } from 'lodash';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
4
|
+
import { Spinner } from '@patternfly/react-core';
|
|
5
|
+
import { InfoCircleIcon } from '@patternfly/react-icons';
|
|
5
6
|
import { translate as __ } from 'foremanReact/common/I18n';
|
|
6
7
|
|
|
7
|
-
import
|
|
8
|
-
import AssignedRolesList from './components/AssignedRolesList';
|
|
8
|
+
import DualList from '../DualList';
|
|
9
9
|
import AnsibleRolesSwitcherError from './components/AnsibleRolesSwitcherError';
|
|
10
|
-
import
|
|
11
|
-
import
|
|
10
|
+
import AnsibleRoleInputs from './components/AnsibleRoleInputs';
|
|
11
|
+
import InheritedRolesList from './components/InheritedRolesList';
|
|
12
|
+
import { roleNames } from './AnsibleRolesSwitcherHelpers';
|
|
13
|
+
import './AnsibleRolesSwitcher.scss';
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const AnsibleRolesSwitcher = ({
|
|
16
|
+
initialAssignedRoles,
|
|
17
|
+
availableRolesUrl,
|
|
18
|
+
inheritedRoleIds,
|
|
19
|
+
resourceId,
|
|
20
|
+
resourceName,
|
|
21
|
+
getAnsibleRoles,
|
|
22
|
+
loading,
|
|
23
|
+
assignedRoles,
|
|
24
|
+
unassignedRoles,
|
|
25
|
+
toDestroyRoles,
|
|
26
|
+
dualListChange,
|
|
27
|
+
error,
|
|
28
|
+
}) => {
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
getAnsibleRoles(
|
|
24
31
|
availableRolesUrl,
|
|
25
32
|
initialAssignedRoles,
|
|
26
33
|
inheritedRoleIds,
|
|
27
34
|
resourceId,
|
|
28
35
|
resourceName,
|
|
29
|
-
|
|
36
|
+
{ perPage: 'all' }
|
|
30
37
|
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
render() {
|
|
34
|
-
const {
|
|
35
|
-
loading,
|
|
36
|
-
pagination,
|
|
37
|
-
itemCount,
|
|
38
|
-
addAnsibleRole,
|
|
39
|
-
removeAnsibleRole,
|
|
40
|
-
moveAnsibleRole,
|
|
41
|
-
getAnsibleRoles,
|
|
42
|
-
assignedRoles,
|
|
43
|
-
unassignedRoles,
|
|
44
|
-
toDestroyRoles,
|
|
45
|
-
error,
|
|
46
|
-
} = this.props;
|
|
38
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
resourceId,
|
|
52
|
-
resourceName,
|
|
53
|
-
} = this.props;
|
|
40
|
+
const inheritedRoles = assignedRoles.filter(role => role.inherited);
|
|
41
|
+
const ownAssignedRoles = assignedRoles.filter(role => !role.inherited);
|
|
42
|
+
const resourceNameLower = lowerCase(resourceName || '');
|
|
54
43
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
availableRolesUrl,
|
|
58
|
-
assignedRoles,
|
|
59
|
-
inheritedRoleIds,
|
|
60
|
-
resourceId,
|
|
61
|
-
resourceName,
|
|
62
|
-
paginationArgs,
|
|
63
|
-
excludeAssignedRolesSearch(assignedRoles)
|
|
64
|
-
);
|
|
44
|
+
const onListChange = (_availableNames, chosenNames) =>
|
|
45
|
+
dualListChange(chosenNames);
|
|
65
46
|
|
|
66
|
-
|
|
67
|
-
<Grid bsClass="container-fluid" id="ansibleRolesSwitcher">
|
|
68
|
-
<Row className="row-eq-height">
|
|
69
|
-
<AnsibleRolesSwitcherError error={error} />
|
|
70
|
-
<Col sm={6} className="available-roles-container">
|
|
71
|
-
<div className="available-roles-header">
|
|
72
|
-
<h2>{__('Available Ansible Roles')}</h2>
|
|
73
|
-
</div>
|
|
74
|
-
<AvailableRolesList
|
|
75
|
-
unassignedRoles={unassignedRoles}
|
|
76
|
-
pagination={pagination}
|
|
77
|
-
itemCount={itemCount}
|
|
78
|
-
onListingChange={onListingChange}
|
|
79
|
-
onAddRole={addAnsibleRole}
|
|
80
|
-
loading={loading}
|
|
81
|
-
/>
|
|
82
|
-
</Col>
|
|
47
|
+
const ownRolesForInputs = ownAssignedRoles.concat(toDestroyRoles);
|
|
83
48
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
49
|
+
return (
|
|
50
|
+
<div id="ansibleRolesSwitcher">
|
|
51
|
+
<AnsibleRolesSwitcherError error={error} />
|
|
52
|
+
{loading ? (
|
|
53
|
+
<Spinner size="lg" />
|
|
54
|
+
) : (
|
|
55
|
+
<>
|
|
56
|
+
<InheritedRolesList
|
|
57
|
+
roles={inheritedRoles}
|
|
58
|
+
resourceName={resourceNameLower}
|
|
59
|
+
/>
|
|
60
|
+
<DualList
|
|
61
|
+
availableOptions={roleNames(unassignedRoles)}
|
|
62
|
+
chosenOptions={roleNames(ownAssignedRoles)}
|
|
63
|
+
onListChange={onListChange}
|
|
64
|
+
/>
|
|
65
|
+
<p className="ansible-roles-order-info">
|
|
66
|
+
<InfoCircleIcon
|
|
67
|
+
className="ansible-roles-order-info-icon"
|
|
68
|
+
aria-hidden
|
|
98
69
|
/>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
70
|
+
<span>
|
|
71
|
+
{__(
|
|
72
|
+
'Use drag and drop to change order of the assigned roles. Ordering of roles is respected for Ansible runs, inherited roles are always before those assigned directly'
|
|
73
|
+
)}
|
|
74
|
+
</span>
|
|
75
|
+
</p>
|
|
76
|
+
<div className="ansible-roles-hidden-inputs">
|
|
77
|
+
{ownRolesForInputs.map((role, idx) => (
|
|
78
|
+
<AnsibleRoleInputs
|
|
79
|
+
key={role.id}
|
|
80
|
+
role={role}
|
|
81
|
+
idx={idx}
|
|
82
|
+
resourceName={resourceNameLower}
|
|
83
|
+
/>
|
|
84
|
+
))}
|
|
85
|
+
</div>
|
|
86
|
+
</>
|
|
87
|
+
)}
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
105
91
|
|
|
106
92
|
AnsibleRolesSwitcher.propTypes = {
|
|
107
93
|
initialAssignedRoles: PropTypes.arrayOf(PropTypes.object),
|
|
@@ -110,15 +96,8 @@ AnsibleRolesSwitcher.propTypes = {
|
|
|
110
96
|
resourceId: PropTypes.number,
|
|
111
97
|
resourceName: PropTypes.string,
|
|
112
98
|
getAnsibleRoles: PropTypes.func.isRequired,
|
|
99
|
+
dualListChange: PropTypes.func.isRequired,
|
|
113
100
|
loading: PropTypes.bool.isRequired,
|
|
114
|
-
pagination: PropTypes.shape({
|
|
115
|
-
page: PropTypes.number,
|
|
116
|
-
perPage: PropTypes.number,
|
|
117
|
-
}).isRequired,
|
|
118
|
-
itemCount: PropTypes.number.isRequired,
|
|
119
|
-
addAnsibleRole: PropTypes.func.isRequired,
|
|
120
|
-
removeAnsibleRole: PropTypes.func.isRequired,
|
|
121
|
-
moveAnsibleRole: PropTypes.func.isRequired,
|
|
122
101
|
assignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
123
102
|
toDestroyRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
124
103
|
unassignedRoles: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
@@ -1,43 +1,55 @@
|
|
|
1
1
|
@import 'foremanReact/common/variables';
|
|
2
2
|
|
|
3
3
|
#ansibleRolesSwitcher {
|
|
4
|
-
.list-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
.pf-v5-c-dual-list-selector {
|
|
5
|
+
margin: var(--pf-v5-global--spacer--md) 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.ansible-inherited-roles {
|
|
9
|
+
--pf-v5-c-dual-list-selector__title-text--FontWeight: var(
|
|
10
|
+
--pf-v5-global--FontWeight--bold
|
|
11
|
+
);
|
|
12
|
+
--pf-v5-c-dual-list-selector__header--MarginBottom: var(
|
|
13
|
+
--pf-v5-global--spacer--sm
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
.pf-v5-c-dual-list-selector__header {
|
|
17
|
+
margin-block-end: var(--pf-v5-c-dual-list-selector__header--MarginBottom);
|
|
10
18
|
}
|
|
11
19
|
|
|
12
|
-
.
|
|
13
|
-
|
|
20
|
+
.pf-v5-c-dual-list-selector__title-text {
|
|
21
|
+
font-weight: var(--pf-v5-c-dual-list-selector__title-text--FontWeight);
|
|
14
22
|
}
|
|
15
|
-
}
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
ul {
|
|
25
|
+
list-style: none;
|
|
26
|
+
padding: 0;
|
|
27
|
+
margin: 0;
|
|
28
|
+
}
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
li {
|
|
31
|
+
padding: 0.5rem 0.75rem;
|
|
32
|
+
margin-bottom: 0.25rem;
|
|
33
|
+
background-color: var(--pf-v5-global--BackgroundColor--200);
|
|
34
|
+
color: var(--pf-v5-global--Color--200);
|
|
35
|
+
border-radius: 3px;
|
|
36
|
+
}
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
.ansible-roles-order-info {
|
|
40
|
+
display: flex;
|
|
41
|
+
gap: var(--pf-v5-global--spacer--sm);
|
|
42
|
+
margin: 0;
|
|
43
|
+
font-size: var(--pf-v5-global--FontSize--sm);
|
|
44
|
+
color: var(--pf-v5-global--Color--200);
|
|
32
45
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
46
|
+
.ansible-roles-order-info-icon {
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
margin-top: 0.15rem;
|
|
49
|
+
}
|
|
36
50
|
}
|
|
37
51
|
|
|
38
|
-
.
|
|
39
|
-
|
|
40
|
-
font-size: 12px;
|
|
41
|
-
font-weight: normal;
|
|
52
|
+
.ansible-roles-hidden-inputs {
|
|
53
|
+
display: none;
|
|
42
54
|
}
|
|
43
55
|
}
|
|
@@ -9,10 +9,7 @@ import {
|
|
|
9
9
|
ANSIBLE_ROLES_REQUEST,
|
|
10
10
|
ANSIBLE_ROLES_SUCCESS,
|
|
11
11
|
ANSIBLE_ROLES_FAILURE,
|
|
12
|
-
|
|
13
|
-
ANSIBLE_ROLES_REMOVE,
|
|
14
|
-
ANSIBLE_ROLES_MOVE,
|
|
15
|
-
ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
|
12
|
+
ANSIBLE_ROLES_DUAL_LIST_CHANGE,
|
|
16
13
|
} from './AnsibleRolesSwitcherConstants';
|
|
17
14
|
|
|
18
15
|
export const getAnsibleRoles = (
|
|
@@ -21,14 +18,12 @@ export const getAnsibleRoles = (
|
|
|
21
18
|
inheritedRoleIds,
|
|
22
19
|
resourceId,
|
|
23
20
|
resourceName,
|
|
24
|
-
pagination
|
|
25
|
-
search
|
|
21
|
+
pagination
|
|
26
22
|
) => async dispatch => {
|
|
27
23
|
dispatch({ type: ANSIBLE_ROLES_REQUEST });
|
|
28
24
|
|
|
29
25
|
const params = {
|
|
30
26
|
...propsToSnakeCase(pagination || {}),
|
|
31
|
-
...(search || {}),
|
|
32
27
|
...propsToSnakeCase({ resourceId, resourceName }),
|
|
33
28
|
};
|
|
34
29
|
|
|
@@ -43,34 +38,18 @@ export const getAnsibleRoles = (
|
|
|
43
38
|
},
|
|
44
39
|
});
|
|
45
40
|
} catch (error) {
|
|
46
|
-
|
|
41
|
+
const err = {
|
|
42
|
+
errorMsg: __('Failed to fetch Ansible Roles from server.'),
|
|
43
|
+
statusText: error.response?.statusText,
|
|
44
|
+
};
|
|
45
|
+
return dispatch({
|
|
46
|
+
type: ANSIBLE_ROLES_FAILURE,
|
|
47
|
+
payload: { error: err },
|
|
48
|
+
});
|
|
47
49
|
}
|
|
48
50
|
};
|
|
49
51
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
statusText: err.response.statusText,
|
|
54
|
-
};
|
|
55
|
-
return { type: msg, payload: { error } };
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const addAnsibleRole = role => ({
|
|
59
|
-
type: ANSIBLE_ROLES_ADD,
|
|
60
|
-
payload: { role },
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
export const removeAnsibleRole = role => ({
|
|
64
|
-
type: ANSIBLE_ROLES_REMOVE,
|
|
65
|
-
payload: { role },
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
export const moveAnsibleRole = roles => ({
|
|
69
|
-
type: ANSIBLE_ROLES_MOVE,
|
|
70
|
-
payload: { roles },
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
export const changeAssignedPage = pagination => ({
|
|
74
|
-
type: ANSIBLE_ROLES_ASSIGNED_PAGE_CHANGE,
|
|
75
|
-
payload: { pagination },
|
|
52
|
+
export const dualListChange = chosenNames => ({
|
|
53
|
+
type: ANSIBLE_ROLES_DUAL_LIST_CHANGE,
|
|
54
|
+
payload: { chosenNames },
|
|
76
55
|
});
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export const ANSIBLE_ROLES_REQUEST = 'ANSIBLE_ROLES_REQUEST';
|
|
2
2
|
export const ANSIBLE_ROLES_SUCCESS = 'ANSIBLE_ROLES_SUCCESS';
|
|
3
3
|
export const ANSIBLE_ROLES_FAILURE = 'ANSIBLE_ROLES_FAILURE';
|
|
4
|
-
export const
|
|
5
|
-
export const ANSIBLE_ROLES_REMOVE = 'ANSIBLE_ROLES_REMOVE';
|
|
6
|
-
export const ANSIBLE_ROLES_MOVE = 'ANSIBLE_ROLE_MOVE';
|
|
4
|
+
export const ANSIBLE_ROLES_DUAL_LIST_CHANGE = 'ANSIBLE_ROLES_DUAL_LIST_CHANGE';
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
export const
|
|
2
|
-
const searchString =
|
|
3
|
-
assignedRoles.length === 0
|
|
4
|
-
? ''
|
|
5
|
-
: `id !^ (${assignedRoles.map(role => role.id).join(', ')})`;
|
|
6
|
-
return { search: searchString };
|
|
7
|
-
};
|
|
1
|
+
export const roleNames = roles => roles.map(role => role.name);
|
|
@@ -4,18 +4,11 @@ import {
|
|
|
4
4
|
ANSIBLE_ROLES_REQUEST,
|
|
5
5
|
ANSIBLE_ROLES_SUCCESS,
|
|
6
6
|
ANSIBLE_ROLES_FAILURE,
|
|
7
|
-
|
|
8
|
-
ANSIBLE_ROLES_REMOVE,
|
|
9
|
-
ANSIBLE_ROLES_MOVE,
|
|
7
|
+
ANSIBLE_ROLES_DUAL_LIST_CHANGE,
|
|
10
8
|
} from './AnsibleRolesSwitcherConstants';
|
|
11
9
|
|
|
12
10
|
export const initialState = Immutable({
|
|
13
11
|
loading: false,
|
|
14
|
-
itemCount: 0,
|
|
15
|
-
pagination: {
|
|
16
|
-
page: 1,
|
|
17
|
-
perPage: 10,
|
|
18
|
-
},
|
|
19
12
|
assignedRoles: [],
|
|
20
13
|
toDestroyRoles: [],
|
|
21
14
|
inheritedRoleIds: [],
|
|
@@ -32,40 +25,40 @@ const ansibleRoles = (state = initialState, action) => {
|
|
|
32
25
|
case ANSIBLE_ROLES_SUCCESS:
|
|
33
26
|
return state.merge({
|
|
34
27
|
loading: false,
|
|
35
|
-
itemCount: Number(payload.subtotal),
|
|
36
|
-
pagination: {
|
|
37
|
-
page: Number(payload.page),
|
|
38
|
-
perPage: Number(payload.perPage),
|
|
39
|
-
},
|
|
40
28
|
results: payload.results,
|
|
41
29
|
assignedRoles: payload.initialAssignedRoles,
|
|
42
30
|
inheritedRoleIds: payload.inheritedRoleIds,
|
|
31
|
+
error: { errorMsg: '', status: '', statusText: '' },
|
|
43
32
|
});
|
|
44
33
|
case ANSIBLE_ROLES_FAILURE:
|
|
45
34
|
return state.merge({ error: payload.error, loading: false });
|
|
46
|
-
case
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
case ANSIBLE_ROLES_DUAL_LIST_CHANGE: {
|
|
36
|
+
const { chosenNames } = payload;
|
|
37
|
+
const inherited = state.assignedRoles.filter(role =>
|
|
38
|
+
state.inheritedRoleIds.includes(role.id)
|
|
39
|
+
);
|
|
40
|
+
const currentOwn = state.assignedRoles.filter(
|
|
41
|
+
role => !state.inheritedRoleIds.includes(role.id)
|
|
42
|
+
);
|
|
43
|
+
const roleByName = name =>
|
|
44
|
+
currentOwn.find(role => role.name === name) ||
|
|
45
|
+
state.results.find(role => role.name === name) ||
|
|
46
|
+
state.toDestroyRoles.find(role => role.name === name);
|
|
47
|
+
|
|
48
|
+
const removed = currentOwn.filter(
|
|
49
|
+
role => !chosenNames.includes(role.name)
|
|
50
|
+
);
|
|
51
|
+
const newOwn = chosenNames
|
|
52
|
+
.map(name => roleByName(name))
|
|
53
|
+
.filter(role => role && !state.inheritedRoleIds.includes(role.id));
|
|
54
|
+
|
|
55
55
|
return state.merge({
|
|
56
|
-
assignedRoles:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
? state.results
|
|
61
|
-
: state.results.concat([payload.role]),
|
|
62
|
-
toDestroyRoles: state.toDestroyRoles.concat([
|
|
63
|
-
{ ...payload.role, destroy: true },
|
|
64
|
-
]),
|
|
65
|
-
itemCount: state.itemCount + 1,
|
|
56
|
+
assignedRoles: inherited.concat(newOwn),
|
|
57
|
+
toDestroyRoles: state.toDestroyRoles
|
|
58
|
+
.filter(item => !newOwn.some(role => role.id === item.id))
|
|
59
|
+
.concat(removed.map(role => ({ ...role, destroy: true }))),
|
|
66
60
|
});
|
|
67
|
-
|
|
68
|
-
return state.set('assignedRoles', payload.roles);
|
|
61
|
+
}
|
|
69
62
|
default:
|
|
70
63
|
return state;
|
|
71
64
|
}
|
|
@@ -10,13 +10,11 @@ const markInheritedRoles = (roles, inheritedRoleIds) =>
|
|
|
10
10
|
includes(inheritedRoleIds, role.id) ? { ...role, inherited: true } : role
|
|
11
11
|
);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
const selectResults = state =>
|
|
14
14
|
Immutable(
|
|
15
15
|
Immutable.asMutable(switcherState(state).results.map(propsToCamelCase))
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
export const selectItemCount = state => switcherState(state).itemCount;
|
|
19
|
-
|
|
20
18
|
export const selectAssignedRoles = state =>
|
|
21
19
|
Immutable.asMutable(
|
|
22
20
|
markInheritedRoles(
|
|
@@ -26,20 +24,12 @@ export const selectAssignedRoles = state =>
|
|
|
26
24
|
);
|
|
27
25
|
|
|
28
26
|
export const selectToDestroyRoles = state =>
|
|
29
|
-
|
|
27
|
+
Immutable.asMutable(
|
|
28
|
+
switcherState(state).toDestroyRoles.map(propsToCamelCase)
|
|
29
|
+
);
|
|
30
30
|
|
|
31
31
|
export const selectLoading = state => switcherState(state).loading;
|
|
32
32
|
export const selectError = state => switcherState(state).error;
|
|
33
|
-
export const selectPagination = state => switcherState(state).pagination;
|
|
34
|
-
|
|
35
|
-
export const selectPaginationMemoized = createSelector(
|
|
36
|
-
selectPagination,
|
|
37
|
-
selectResults,
|
|
38
|
-
(pagination, results) =>
|
|
39
|
-
results.length > pagination.perPage
|
|
40
|
-
? { ...pagination, perPage: results.length }
|
|
41
|
-
: pagination
|
|
42
|
-
);
|
|
43
33
|
|
|
44
34
|
export const selectUnassignedRoles = createSelector(
|
|
45
35
|
selectResults,
|
data/webpack/components/AnsibleRolesSwitcher/__fixtures__/ansibleRolesSwitcherReducer.fixtures.js
CHANGED
|
@@ -3,9 +3,6 @@ import Immutable from 'seamless-immutable';
|
|
|
3
3
|
import { ansibleRolesLong } from './ansibleRolesData.fixtures';
|
|
4
4
|
|
|
5
5
|
export const successPayload = {
|
|
6
|
-
page: 1,
|
|
7
|
-
perPage: 5,
|
|
8
|
-
subtotal: 11,
|
|
9
6
|
results: ansibleRolesLong,
|
|
10
7
|
initialAssignedRoles: ansibleRolesLong.slice(3, 6),
|
|
11
8
|
inheritedRoleIds: [4],
|
|
@@ -13,21 +10,13 @@ export const successPayload = {
|
|
|
13
10
|
|
|
14
11
|
export const successState = Immutable({
|
|
15
12
|
loading: false,
|
|
16
|
-
itemCount: 11,
|
|
17
|
-
pagination: {
|
|
18
|
-
page: 1,
|
|
19
|
-
perPage: 5,
|
|
20
|
-
},
|
|
21
13
|
assignedRoles: [
|
|
22
14
|
{ ...ansibleRolesLong[3], inherited: true },
|
|
23
15
|
...ansibleRolesLong.slice(4, 6),
|
|
24
16
|
],
|
|
25
17
|
results: ansibleRolesLong,
|
|
26
18
|
toDestroyRoles: [],
|
|
27
|
-
|
|
28
|
-
page: 1,
|
|
29
|
-
perPage: 20,
|
|
30
|
-
},
|
|
19
|
+
inheritedRoleIds: [4],
|
|
31
20
|
error: { errorMsg: '', status: '', statusText: '' },
|
|
32
21
|
});
|
|
33
22
|
|