@truedat/dd 4.51.2 → 4.51.4
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.
- package/CHANGELOG.md +13 -0
- package/package.json +6 -6
- package/src/api/queries.js +24 -0
- package/src/api.js +0 -2
- package/src/components/DictionaryRoutes.js +0 -5
- package/src/components/EditDomainForm.js +15 -20
- package/src/components/GrantRequest.js +12 -0
- package/src/components/GrantRequests.js +24 -15
- package/src/components/LineageForm.js +23 -34
- package/src/components/PendingStructureNoteRow.js +5 -8
- package/src/components/PendingStructureNotes.js +25 -46
- package/src/components/PendingStructureNotesTable.js +46 -57
- package/src/components/StructureGrantCartCheckout.js +7 -6
- package/src/components/{StructureGrantCartTemplate.js → StructureGrantCartInformation.js} +15 -5
- package/src/components/StructureGrantCartUserSelector.js +93 -0
- package/src/components/StructureGrantDropdown.js +45 -18
- package/src/components/StructureGrantRequestAddCart.js +26 -0
- package/src/components/StructuresRoutes.js +1 -11
- package/src/components/__tests__/EditDomainForm.spec.js +31 -46
- package/src/components/__tests__/LineageForm.spec.js +37 -122
- package/src/components/__tests__/MyGrantRequests.spec.js +14 -2
- package/src/components/__tests__/PendingStructureNoteRow.spec.js +2 -2
- package/src/components/__tests__/PendingStructureNotes.spec.js +13 -15
- package/src/components/__tests__/{StructureGrantCartTemplate.spec.js → StructureGrantCartInformation.spec.js} +3 -3
- package/src/components/__tests__/StructureGrantCartUserSelector.js +21 -0
- package/src/components/__tests__/__snapshots__/EditDomainForm.spec.js.snap +2 -71
- package/src/components/__tests__/__snapshots__/LineageForm.spec.js.snap +13 -14
- package/src/components/__tests__/__snapshots__/MyGrantRequests.spec.js.snap +1 -1
- package/src/components/__tests__/__snapshots__/PendingStructureNotes.spec.js.snap +1 -2
- package/src/components/__tests__/__snapshots__/PendingStructureNotesTable.spec.js.snap +8 -16
- package/src/components/__tests__/__snapshots__/{StructureGrantCartTemplate.spec.js.snap → StructureGrantCartInformation.spec.js.snap} +2 -2
- package/src/components/__tests__/__snapshots__/StructureGrantCartUserSelector.js.snap +74 -0
- package/src/messages/en.js +3 -1
- package/src/messages/es.js +3 -0
- package/src/reducers/grantRequestsCart.js +10 -0
- package/src/reducers/index.js +0 -2
- package/src/routines.js +1 -1
- package/src/sagas/index.js +0 -3
- package/src/selectors/index.js +0 -1
- package/src/reducers/__tests__/unitDomains.spec.js +0 -27
- package/src/reducers/unitDomains.js +0 -16
- package/src/sagas/__tests__/fetchUnitDomains.spec.js +0 -91
- package/src/sagas/fetchUnitDomains.js +0 -29
- package/src/selectors/__tests__/getDomainOptions.spec.js +0 -32
- package/src/selectors/getDomainOptions.js +0 -17
|
@@ -8,7 +8,7 @@ import { HistoryBackButton } from "@truedat/core/components";
|
|
|
8
8
|
import { useIntl, FormattedMessage } from "react-intl";
|
|
9
9
|
import { checkoutGrantRequest } from "../routines";
|
|
10
10
|
import StructureGrantCart from "./StructureGrantCart";
|
|
11
|
-
import
|
|
11
|
+
import StructureGrantCartInformation from "./StructureGrantCartInformation";
|
|
12
12
|
|
|
13
13
|
export const StructureGrantCartCheckout = ({
|
|
14
14
|
grantRequestsCart,
|
|
@@ -16,7 +16,7 @@ export const StructureGrantCartCheckout = ({
|
|
|
16
16
|
}) => {
|
|
17
17
|
const { formatMessage } = useIntl();
|
|
18
18
|
|
|
19
|
-
const { template, templateContent, modificationGrant, validCart } =
|
|
19
|
+
const { template, templateContent, modificationGrant, validCart, user } =
|
|
20
20
|
grantRequestsCart;
|
|
21
21
|
|
|
22
22
|
const checkout = () => {
|
|
@@ -30,11 +30,12 @@ export const StructureGrantCartCheckout = ({
|
|
|
30
30
|
};
|
|
31
31
|
})(grantRequestsCart.structures);
|
|
32
32
|
const payload = {
|
|
33
|
-
grant_request_group: {
|
|
33
|
+
grant_request_group: _.omitBy(_.isNil)({
|
|
34
34
|
requests,
|
|
35
35
|
type: template,
|
|
36
36
|
modification_grant_id: modificationGrant ? modificationGrant.id : null,
|
|
37
|
-
|
|
37
|
+
user_id: user?.id,
|
|
38
|
+
}),
|
|
38
39
|
};
|
|
39
40
|
checkoutGrantRequest(payload);
|
|
40
41
|
};
|
|
@@ -61,14 +62,14 @@ export const StructureGrantCartCheckout = ({
|
|
|
61
62
|
<Button
|
|
62
63
|
primary
|
|
63
64
|
onClick={checkout}
|
|
64
|
-
disabled={!validCart}
|
|
65
|
+
disabled={!validCart || !user.valid}
|
|
65
66
|
content={formatMessage({ id: "actions.save" })}
|
|
66
67
|
/>
|
|
67
68
|
</GridColumn>
|
|
68
69
|
</Grid.Row>
|
|
69
70
|
<Grid.Row>
|
|
70
71
|
<Grid.Column width={5}>
|
|
71
|
-
<
|
|
72
|
+
<StructureGrantCartInformation />
|
|
72
73
|
</Grid.Column>
|
|
73
74
|
<Grid.Column width={11}>
|
|
74
75
|
<StructureGrantCart />
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
import _ from "lodash/fp";
|
|
2
2
|
import React from "react";
|
|
3
|
+
import { useQuery } from "@apollo/client";
|
|
3
4
|
import PropTypes from "prop-types";
|
|
4
5
|
import { Segment, Divider, Form, Header } from "semantic-ui-react";
|
|
5
6
|
import { connect } from "react-redux";
|
|
6
7
|
import { useIntl } from "react-intl";
|
|
8
|
+
import { DOMAINS_QUERY } from "@truedat/core/api/queries";
|
|
7
9
|
import {
|
|
8
10
|
selectGrantRequestTemplate,
|
|
9
11
|
updateGrantRequestTemplateContent,
|
|
10
12
|
} from "../routines";
|
|
13
|
+
import StructureGrantCartUserSelector from "./StructureGrantCartUserSelector";
|
|
11
14
|
|
|
12
15
|
const SelectableDynamicForm = React.lazy(() =>
|
|
13
16
|
import("@truedat/df/components/SelectableDynamicForm")
|
|
14
17
|
);
|
|
15
18
|
|
|
16
|
-
export const
|
|
19
|
+
export const StructureGrantCartInformation = ({
|
|
17
20
|
grantRequestsCart,
|
|
18
21
|
selectGrantRequestTemplate,
|
|
19
22
|
updateGrantRequestTemplateContent,
|
|
20
23
|
}) => {
|
|
21
24
|
const { formatMessage } = useIntl();
|
|
22
|
-
|
|
23
25
|
const templateContent = _.pathOr({}, "templateContent")(grantRequestsCart);
|
|
24
26
|
|
|
27
|
+
const { loading, data } = useQuery(DOMAINS_QUERY, {
|
|
28
|
+
fetchPolicy: "cache-and-network",
|
|
29
|
+
variables: { action: "createForeignGrantRequest" },
|
|
30
|
+
});
|
|
31
|
+
|
|
25
32
|
return (
|
|
26
|
-
<Segment>
|
|
33
|
+
<Segment loading={loading}>
|
|
27
34
|
<Header
|
|
28
35
|
title={`${formatMessage({ id: `structure.grant.cart.template` })}`}
|
|
29
36
|
>
|
|
@@ -31,6 +38,9 @@ export const StructureGrantCartTemplate = ({
|
|
|
31
38
|
</Header>
|
|
32
39
|
<Divider />
|
|
33
40
|
<Form>
|
|
41
|
+
{!loading && !_.isEmpty(data?.domains) ? (
|
|
42
|
+
<StructureGrantCartUserSelector />
|
|
43
|
+
) : null}
|
|
34
44
|
<SelectableDynamicForm
|
|
35
45
|
scope="gr"
|
|
36
46
|
required
|
|
@@ -47,7 +57,7 @@ export const StructureGrantCartTemplate = ({
|
|
|
47
57
|
);
|
|
48
58
|
};
|
|
49
59
|
|
|
50
|
-
|
|
60
|
+
StructureGrantCartInformation.propTypes = {
|
|
51
61
|
grantRequestsCart: PropTypes.object,
|
|
52
62
|
selectGrantRequestTemplate: PropTypes.func,
|
|
53
63
|
updateGrantRequestTemplateContent: PropTypes.func,
|
|
@@ -58,4 +68,4 @@ const mapStateToProps = ({ grantRequestsCart }) => ({ grantRequestsCart });
|
|
|
58
68
|
export default connect(mapStateToProps, {
|
|
59
69
|
selectGrantRequestTemplate,
|
|
60
70
|
updateGrantRequestTemplateContent,
|
|
61
|
-
})(
|
|
71
|
+
})(StructureGrantCartInformation);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import React, { useEffect, useState } from "react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import { Form, Checkbox } from "semantic-ui-react";
|
|
5
|
+
import { connect } from "react-redux";
|
|
6
|
+
import { useIntl } from "react-intl";
|
|
7
|
+
import { lowerDeburrTrim } from "@truedat/core/services/sort";
|
|
8
|
+
import { updateGrantRequestUser } from "../routines";
|
|
9
|
+
|
|
10
|
+
const UsersSearchLoader = React.lazy(() =>
|
|
11
|
+
import("@truedat/auth/users/components/UsersSearchLoader")
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const StructureGrantCartUserSelector = ({
|
|
15
|
+
grantRequestsCart,
|
|
16
|
+
updateGrantRequestUser,
|
|
17
|
+
options,
|
|
18
|
+
}) => {
|
|
19
|
+
const { formatMessage } = useIntl();
|
|
20
|
+
const [usersGroupsQuery, setUsersGroupsQuery] = useState("");
|
|
21
|
+
const [thirdParty, setThirdParty] = useState(false);
|
|
22
|
+
const [userId, setUserId] = useState(_.path("user.id")(grantRequestsCart));
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
updateGrantRequestUser({
|
|
26
|
+
id: userId,
|
|
27
|
+
valid:
|
|
28
|
+
!thirdParty || (thirdParty && !(_.isNil(userId) && _.isEmpty(userId))),
|
|
29
|
+
});
|
|
30
|
+
}, [userId, thirdParty]);
|
|
31
|
+
|
|
32
|
+
const onSearch = (_currentOptions, { searchQuery }) =>
|
|
33
|
+
setUsersGroupsQuery(lowerDeburrTrim(searchQuery));
|
|
34
|
+
|
|
35
|
+
const selectUser = (userId) => {
|
|
36
|
+
setUserId(userId);
|
|
37
|
+
if (!_.isNil(userId)) setThirdParty(true);
|
|
38
|
+
if (userId === "") setThirdParty(false);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<UsersSearchLoader
|
|
44
|
+
query={usersGroupsQuery}
|
|
45
|
+
permission="allow_foreign_grant_request"
|
|
46
|
+
hideLoading
|
|
47
|
+
/>
|
|
48
|
+
<Form.Dropdown
|
|
49
|
+
placeholder={formatMessage({
|
|
50
|
+
id: "grantRequestCart.user.placeholder",
|
|
51
|
+
})}
|
|
52
|
+
clearable
|
|
53
|
+
onChange={(_e, { value }) => selectUser(value)}
|
|
54
|
+
deburr
|
|
55
|
+
onSearchChange={onSearch}
|
|
56
|
+
search={_.identity}
|
|
57
|
+
selection
|
|
58
|
+
required={thirdParty}
|
|
59
|
+
label={
|
|
60
|
+
<Checkbox
|
|
61
|
+
label={formatMessage({ id: "grantRequestCart.user.label" })}
|
|
62
|
+
onChange={(e, data) => {
|
|
63
|
+
setThirdParty(data.checked);
|
|
64
|
+
selectUser(null);
|
|
65
|
+
}}
|
|
66
|
+
checked={thirdParty}
|
|
67
|
+
/>
|
|
68
|
+
}
|
|
69
|
+
options={options}
|
|
70
|
+
value={userId}
|
|
71
|
+
/>
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
StructureGrantCartUserSelector.propTypes = {
|
|
77
|
+
grantRequestsCart: PropTypes.object,
|
|
78
|
+
options: PropTypes.array,
|
|
79
|
+
updateGrantRequestUser: PropTypes.func,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const mapStateToProps = ({ grantRequestsCart, usersSearch }) => ({
|
|
83
|
+
grantRequestsCart,
|
|
84
|
+
options: _.map(({ full_name, id }) => ({
|
|
85
|
+
text: full_name,
|
|
86
|
+
value: id,
|
|
87
|
+
icon: "user",
|
|
88
|
+
}))(usersSearch),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export default connect(mapStateToProps, { updateGrantRequestUser })(
|
|
92
|
+
StructureGrantCartUserSelector
|
|
93
|
+
);
|
|
@@ -11,12 +11,15 @@ import { Date } from "@truedat/core/components";
|
|
|
11
11
|
import GrantChangeRequest from "./GrantChangeRequest";
|
|
12
12
|
import GrantRemoval from "./GrantRemoval";
|
|
13
13
|
import GrantRequestCancel from "./GrantRequestCancel";
|
|
14
|
+
import StructureGrantRequestAddCart from "./StructureGrantRequestAddCart";
|
|
14
15
|
|
|
15
16
|
const isNilOrEmpty = (value) => _.isEmpty(value) || _.isNil(value);
|
|
16
17
|
export const StructureGrantDropdown = ({
|
|
17
18
|
grantRequest,
|
|
18
19
|
structure,
|
|
19
20
|
structureGrantPopup,
|
|
21
|
+
authorized,
|
|
22
|
+
requested,
|
|
20
23
|
}) => {
|
|
21
24
|
const history = useHistory();
|
|
22
25
|
const { formatMessage } = useIntl();
|
|
@@ -32,8 +35,19 @@ export const StructureGrantDropdown = ({
|
|
|
32
35
|
const isModification = _.prop("group.grant")(grantRequest);
|
|
33
36
|
|
|
34
37
|
const actions = {
|
|
38
|
+
addToCart: (
|
|
39
|
+
<StructureGrantRequestAddCart structure={structure} key="addToCart">
|
|
40
|
+
<Dropdown.Item
|
|
41
|
+
icon="cart"
|
|
42
|
+
text={formatMessage({
|
|
43
|
+
id: "structure.grant.request_grant",
|
|
44
|
+
})}
|
|
45
|
+
/>
|
|
46
|
+
</StructureGrantRequestAddCart>
|
|
47
|
+
),
|
|
35
48
|
viewRequest: (
|
|
36
49
|
<Dropdown.Item
|
|
50
|
+
key="viewRequest"
|
|
37
51
|
onClick={() =>
|
|
38
52
|
history.push(linkTo.GRANT_REQUEST({ id: grantRequest.id }))
|
|
39
53
|
}
|
|
@@ -44,7 +58,7 @@ export const StructureGrantDropdown = ({
|
|
|
44
58
|
/>
|
|
45
59
|
),
|
|
46
60
|
requestRemoval: (
|
|
47
|
-
<GrantRemoval grant={grant}>
|
|
61
|
+
<GrantRemoval grant={grant} key="requestRemoval">
|
|
48
62
|
<Dropdown.Item
|
|
49
63
|
icon="delete"
|
|
50
64
|
text={formatMessage({
|
|
@@ -54,7 +68,7 @@ export const StructureGrantDropdown = ({
|
|
|
54
68
|
</GrantRemoval>
|
|
55
69
|
),
|
|
56
70
|
cancelRemoval: (
|
|
57
|
-
<GrantRemoval grant={grant}>
|
|
71
|
+
<GrantRemoval grant={grant} key="cancelRemoval">
|
|
58
72
|
<Dropdown.Item
|
|
59
73
|
icon="delete"
|
|
60
74
|
text={formatMessage({
|
|
@@ -64,7 +78,11 @@ export const StructureGrantDropdown = ({
|
|
|
64
78
|
</GrantRemoval>
|
|
65
79
|
),
|
|
66
80
|
requestChange: (
|
|
67
|
-
<GrantChangeRequest
|
|
81
|
+
<GrantChangeRequest
|
|
82
|
+
structure={structure}
|
|
83
|
+
grant={grant}
|
|
84
|
+
key="requestChange"
|
|
85
|
+
>
|
|
68
86
|
<Dropdown.Item
|
|
69
87
|
icon="edit"
|
|
70
88
|
text={formatMessage({
|
|
@@ -75,6 +93,7 @@ export const StructureGrantDropdown = ({
|
|
|
75
93
|
),
|
|
76
94
|
cancelRequest: (
|
|
77
95
|
<GrantRequestCancel
|
|
96
|
+
key="cancelRequest"
|
|
78
97
|
structureId={structure.id}
|
|
79
98
|
grantRequest={grantRequest}
|
|
80
99
|
>
|
|
@@ -91,36 +110,27 @@ export const StructureGrantDropdown = ({
|
|
|
91
110
|
const dropdownStates = {
|
|
92
111
|
pendingRequest: {
|
|
93
112
|
color: "yellow",
|
|
94
|
-
options:
|
|
95
|
-
|
|
96
|
-
{actions["viewRequest"]}
|
|
97
|
-
{actions["cancelRequest"]}
|
|
98
|
-
</>
|
|
99
|
-
),
|
|
113
|
+
options: [actions["viewRequest"], actions["cancelRequest"]],
|
|
114
|
+
|
|
100
115
|
header: isModification
|
|
101
116
|
? "structure.grant.requested_modification"
|
|
102
117
|
: "structure.grant.requested_access",
|
|
103
118
|
},
|
|
104
119
|
processingRequest: {
|
|
105
120
|
color: "grey",
|
|
106
|
-
options: actions["viewRequest"],
|
|
121
|
+
options: [actions["viewRequest"]],
|
|
107
122
|
header: isModification
|
|
108
123
|
? "structure.grant.modification.attended"
|
|
109
124
|
: "structure.grant.access.attended",
|
|
110
125
|
},
|
|
111
126
|
pendingRemovalGrant: {
|
|
112
127
|
color: "red",
|
|
113
|
-
options: actions["cancelRemoval"],
|
|
128
|
+
options: [actions["cancelRemoval"]],
|
|
114
129
|
header: "structure.grant.has_grant_pending_removal",
|
|
115
130
|
},
|
|
116
131
|
activeGrant: {
|
|
117
132
|
color: "green",
|
|
118
|
-
options:
|
|
119
|
-
<>
|
|
120
|
-
{actions["requestChange"]}
|
|
121
|
-
{actions["requestRemoval"]}
|
|
122
|
-
</>
|
|
123
|
-
),
|
|
133
|
+
options: [actions["requestChange"], actions["requestRemoval"]],
|
|
124
134
|
header: "structure.grant.has_grant",
|
|
125
135
|
},
|
|
126
136
|
};
|
|
@@ -160,6 +170,11 @@ export const StructureGrantDropdown = ({
|
|
|
160
170
|
</>
|
|
161
171
|
);
|
|
162
172
|
|
|
173
|
+
const optionsWithCart =
|
|
174
|
+
authorized && !requested
|
|
175
|
+
? [actions["addToCart"], ...stateProps.options]
|
|
176
|
+
: stateProps.options;
|
|
177
|
+
|
|
163
178
|
const trigger = (
|
|
164
179
|
<Dropdown
|
|
165
180
|
icon={null}
|
|
@@ -173,7 +188,9 @@ export const StructureGrantDropdown = ({
|
|
|
173
188
|
/>
|
|
174
189
|
}
|
|
175
190
|
>
|
|
176
|
-
<Dropdown.Menu>
|
|
191
|
+
<Dropdown.Menu>
|
|
192
|
+
<>{optionsWithCart}</>
|
|
193
|
+
</Dropdown.Menu>
|
|
177
194
|
</Dropdown>
|
|
178
195
|
);
|
|
179
196
|
return <Popup content={popupContent} trigger={trigger} />;
|
|
@@ -183,12 +200,16 @@ StructureGrantDropdown.propTypes = {
|
|
|
183
200
|
grantRequest: PropTypes.object,
|
|
184
201
|
structure: PropTypes.object,
|
|
185
202
|
structureGrantPopup: PropTypes.array,
|
|
203
|
+
authorized: PropTypes.bool,
|
|
204
|
+
requested: PropTypes.bool,
|
|
186
205
|
};
|
|
187
206
|
|
|
188
207
|
const mapStateToProps = ({
|
|
189
208
|
structure,
|
|
190
209
|
structureFields,
|
|
191
210
|
structureGrantPopup,
|
|
211
|
+
userPermissions,
|
|
212
|
+
grantRequestsCart,
|
|
192
213
|
}) => ({
|
|
193
214
|
structure: {
|
|
194
215
|
...structure,
|
|
@@ -196,6 +217,12 @@ const mapStateToProps = ({
|
|
|
196
217
|
structureFields,
|
|
197
218
|
},
|
|
198
219
|
structureGrantPopup,
|
|
220
|
+
requested: _.flow(
|
|
221
|
+
_.pathOr([], "structures"),
|
|
222
|
+
_.find({ id: structure.id }),
|
|
223
|
+
_.negate(_.isUndefined)
|
|
224
|
+
)(grantRequestsCart),
|
|
225
|
+
authorized: _.pathOr(false, "create_foreign_grant_request")(userPermissions),
|
|
199
226
|
});
|
|
200
227
|
|
|
201
228
|
export default connect(mapStateToProps)(StructureGrantDropdown);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { connect } from "react-redux";
|
|
4
|
+
import { addGrantRequestToCart } from "../routines";
|
|
5
|
+
|
|
6
|
+
export const StructureGrantRequestAddCart = ({
|
|
7
|
+
structure,
|
|
8
|
+
addGrantRequestToCart,
|
|
9
|
+
children,
|
|
10
|
+
}) => {
|
|
11
|
+
if (!structure) return;
|
|
12
|
+
|
|
13
|
+
return React.cloneElement(children, {
|
|
14
|
+
onClick: () => addGrantRequestToCart(structure),
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
StructureGrantRequestAddCart.propTypes = {
|
|
19
|
+
structure: PropTypes.object,
|
|
20
|
+
addGrantRequestToCart: PropTypes.func,
|
|
21
|
+
children: PropTypes.node,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default connect(null, { addGrantRequestToCart })(
|
|
25
|
+
StructureGrantRequestAddCart
|
|
26
|
+
);
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
STRUCTURE_EVENTS,
|
|
12
12
|
STRUCTURE_VERSION,
|
|
13
13
|
} from "@truedat/core/routes";
|
|
14
|
-
import DomainsLoader from "@truedat/bg/taxonomy/components/DomainsLoader";
|
|
15
14
|
import StructureCrumbs from "./StructureCrumbs";
|
|
16
15
|
import StructureLoader from "./StructureLoader";
|
|
17
16
|
import UserSearchFiltersLoader from "./UserSearchFiltersLoader";
|
|
@@ -122,16 +121,7 @@ export const StructuresRoutes = () => {
|
|
|
122
121
|
return (
|
|
123
122
|
<Route
|
|
124
123
|
path={STRUCTURES}
|
|
125
|
-
render={() =>
|
|
126
|
-
authorized ? (
|
|
127
|
-
<>
|
|
128
|
-
<AuthorizedRoutes />
|
|
129
|
-
<DomainsLoader actions="manage_structures_domain" />
|
|
130
|
-
</>
|
|
131
|
-
) : (
|
|
132
|
-
<Unauthorized />
|
|
133
|
-
)
|
|
134
|
-
}
|
|
124
|
+
render={() => (authorized ? <AuthorizedRoutes /> : <Unauthorized />)}
|
|
135
125
|
/>
|
|
136
126
|
);
|
|
137
127
|
};
|
|
@@ -2,14 +2,17 @@ import React from "react";
|
|
|
2
2
|
import { waitFor } from "@testing-library/react";
|
|
3
3
|
import userEvent from "@testing-library/user-event";
|
|
4
4
|
import { render } from "@truedat/test/render";
|
|
5
|
+
import { domainsMock } from "@truedat/test/mocks";
|
|
5
6
|
import { EditDomainForm } from "../EditDomainForm";
|
|
6
7
|
|
|
8
|
+
const mocks = [domainsMock({ action: "manageStructuresDomain" })];
|
|
9
|
+
|
|
7
10
|
describe("<EditDomainForm />", () => {
|
|
8
11
|
const updateStructure = jest.fn();
|
|
9
12
|
|
|
10
13
|
const domains = [
|
|
11
|
-
{ id: 1, name: "
|
|
12
|
-
{ id: 2, name: "
|
|
14
|
+
{ id: 1, name: "fooDomain", level: 0 },
|
|
15
|
+
{ id: 2, name: "barDomain", level: 0 },
|
|
13
16
|
];
|
|
14
17
|
|
|
15
18
|
const structure = {
|
|
@@ -20,61 +23,46 @@ describe("<EditDomainForm />", () => {
|
|
|
20
23
|
title: "title",
|
|
21
24
|
updateStructure,
|
|
22
25
|
structure,
|
|
23
|
-
domainOptions: domains,
|
|
24
26
|
};
|
|
25
27
|
|
|
26
|
-
const
|
|
27
|
-
en: {
|
|
28
|
-
"structure.edit_domain.title": "Edit domain",
|
|
29
|
-
"structureDomain.actions.update": "Update",
|
|
30
|
-
"structureDomain.actions.update.inherit": "Apply on children",
|
|
31
|
-
"domain.selector.label": "Domain",
|
|
32
|
-
"domain.selector.placeholder": "Select a domain...",
|
|
33
|
-
"domain.multiple.placeholder": "Select domains ...",
|
|
34
|
-
},
|
|
35
|
-
};
|
|
28
|
+
const renderOpts = { mocks, state: { domains } };
|
|
36
29
|
|
|
37
30
|
beforeEach(() => {
|
|
38
31
|
jest.clearAllMocks();
|
|
39
32
|
});
|
|
40
33
|
|
|
41
34
|
it("matches the latest snapshot", () => {
|
|
42
|
-
const { container } = render(<EditDomainForm {...props} />,
|
|
43
|
-
state: { domains },
|
|
44
|
-
messages,
|
|
45
|
-
});
|
|
35
|
+
const { container } = render(<EditDomainForm {...props} />, renderOpts);
|
|
46
36
|
expect(container).toMatchSnapshot();
|
|
47
37
|
});
|
|
48
38
|
|
|
49
39
|
it("enables send button when selecting domain", async () => {
|
|
50
|
-
const { getByRole } = render(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const { getByRole, findByText } = render(
|
|
41
|
+
<EditDomainForm {...props} />,
|
|
42
|
+
renderOpts
|
|
43
|
+
);
|
|
54
44
|
|
|
55
45
|
const button = getByRole("button", { name: /update/i });
|
|
56
|
-
const option = getByRole("option", { name: /Domain 1/i });
|
|
57
46
|
|
|
58
47
|
expect(button).toBeDisabled();
|
|
59
|
-
userEvent.click(
|
|
48
|
+
userEvent.click(await findByText("fooDomain"));
|
|
60
49
|
await waitFor(() => {
|
|
61
50
|
expect(button).not.toBeDisabled();
|
|
62
51
|
});
|
|
63
52
|
});
|
|
64
53
|
|
|
65
54
|
it("invokes function when send button clicked", async () => {
|
|
66
|
-
const { getByRole } = render(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
const { getByRole, findByText } = render(
|
|
56
|
+
<EditDomainForm {...props} />,
|
|
57
|
+
renderOpts
|
|
58
|
+
);
|
|
70
59
|
|
|
71
60
|
const button = getByRole("button", { name: /update/i });
|
|
72
61
|
const checkbox = getByRole("checkbox");
|
|
73
|
-
const option = getByRole("option", { name: /Domain 1/i });
|
|
74
62
|
|
|
75
63
|
expect(button).toBeDisabled();
|
|
76
64
|
expect(checkbox).toBeChecked();
|
|
77
|
-
userEvent.click(
|
|
65
|
+
userEvent.click(await findByText("fooDomain"));
|
|
78
66
|
await waitFor(() => {
|
|
79
67
|
expect(button).not.toBeDisabled();
|
|
80
68
|
});
|
|
@@ -84,7 +72,7 @@ describe("<EditDomainForm />", () => {
|
|
|
84
72
|
});
|
|
85
73
|
expect(updateStructure).toHaveBeenCalledWith(
|
|
86
74
|
expect.objectContaining({
|
|
87
|
-
data_structure: { domain_ids: [1], id: 42 },
|
|
75
|
+
data_structure: { domain_ids: ["1"], id: 42 },
|
|
88
76
|
inherit: true,
|
|
89
77
|
redirect: "/structures/42/notes",
|
|
90
78
|
})
|
|
@@ -92,18 +80,17 @@ describe("<EditDomainForm />", () => {
|
|
|
92
80
|
});
|
|
93
81
|
|
|
94
82
|
it("invokes function when send button clicked with modified inheritance", async () => {
|
|
95
|
-
const { getByRole } = render(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
const { getByRole, findByText } = render(
|
|
84
|
+
<EditDomainForm {...props} />,
|
|
85
|
+
renderOpts
|
|
86
|
+
);
|
|
99
87
|
|
|
100
88
|
const button = getByRole("button", { name: /update/i });
|
|
101
89
|
const checkbox = getByRole("checkbox");
|
|
102
|
-
const option = getByRole("option", { name: /Domain 1/i });
|
|
103
90
|
|
|
104
91
|
expect(button).toBeDisabled();
|
|
105
92
|
expect(checkbox).toBeChecked();
|
|
106
|
-
userEvent.click(
|
|
93
|
+
userEvent.click(await findByText("fooDomain"));
|
|
107
94
|
userEvent.click(checkbox);
|
|
108
95
|
await waitFor(() => {
|
|
109
96
|
expect(button).not.toBeDisabled();
|
|
@@ -114,7 +101,7 @@ describe("<EditDomainForm />", () => {
|
|
|
114
101
|
});
|
|
115
102
|
expect(updateStructure).toHaveBeenCalledWith(
|
|
116
103
|
expect.objectContaining({
|
|
117
|
-
data_structure: { domain_ids: [1], id: 42 },
|
|
104
|
+
data_structure: { domain_ids: ["1"], id: 42 },
|
|
118
105
|
inherit: false,
|
|
119
106
|
redirect: "/structures/42/notes",
|
|
120
107
|
})
|
|
@@ -122,20 +109,18 @@ describe("<EditDomainForm />", () => {
|
|
|
122
109
|
});
|
|
123
110
|
|
|
124
111
|
it("send selected multiple domain ids when button clicked", async () => {
|
|
125
|
-
const { getByRole } = render(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
112
|
+
const { getByRole, findByText } = render(
|
|
113
|
+
<EditDomainForm {...props} />,
|
|
114
|
+
renderOpts
|
|
115
|
+
);
|
|
129
116
|
|
|
130
117
|
const button = getByRole("button", { name: /update/i });
|
|
131
118
|
const checkbox = getByRole("checkbox");
|
|
132
|
-
const optionOne = getByRole("option", { name: /Domain 1/i });
|
|
133
|
-
const optionTwo = getByRole("option", { name: /Domain 2/i });
|
|
134
119
|
|
|
135
120
|
expect(button).toBeDisabled();
|
|
136
121
|
expect(checkbox).toBeChecked();
|
|
137
|
-
userEvent.click(
|
|
138
|
-
userEvent.click(
|
|
122
|
+
userEvent.click(await findByText("barDomain"));
|
|
123
|
+
userEvent.click(await findByText("fooDomain"));
|
|
139
124
|
await waitFor(() => {
|
|
140
125
|
expect(button).not.toBeDisabled();
|
|
141
126
|
});
|
|
@@ -145,7 +130,7 @@ describe("<EditDomainForm />", () => {
|
|
|
145
130
|
});
|
|
146
131
|
expect(updateStructure).toHaveBeenCalledWith(
|
|
147
132
|
expect.objectContaining({
|
|
148
|
-
data_structure: { domain_ids: [2, 1], id: 42 },
|
|
133
|
+
data_structure: { domain_ids: ["2", "1"], id: 42 },
|
|
149
134
|
inherit: true,
|
|
150
135
|
redirect: "/structures/42/notes",
|
|
151
136
|
})
|