@truedat/dd 5.16.4 → 5.17.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@truedat/dd",
3
- "version": "5.16.4",
3
+ "version": "5.17.0",
4
4
  "description": "Truedat Web Data Dictionary",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -88,9 +88,9 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "@apollo/client": "^3.7.1",
91
- "@truedat/auth": "5.16.4",
92
- "@truedat/core": "5.16.4",
93
- "@truedat/df": "5.16.4",
91
+ "@truedat/auth": "5.17.0",
92
+ "@truedat/core": "5.17.0",
93
+ "@truedat/df": "5.17.0",
94
94
  "lodash": "^4.17.21",
95
95
  "moment": "^2.29.4",
96
96
  "path-to-regexp": "^1.7.0",
@@ -115,5 +115,5 @@
115
115
  "react-dom": ">= 16.8.6 < 17",
116
116
  "semantic-ui-react": ">= 2.0.3 < 2.2"
117
117
  },
118
- "gitHead": "cf52894dd17d128c97fc65f97b6976fb07bcb171"
118
+ "gitHead": "5fbcca7a428b2b92de1c610eb44f2d4a281c1655"
119
119
  }
@@ -40,10 +40,6 @@ import StructureFiltersLoader from "./StructureFiltersLoader";
40
40
  import UserSearchFiltersLoader from "./UserSearchFiltersLoader";
41
41
  import GrantRequestsFiltersLoader from "./GrantRequestsFiltersLoader";
42
42
 
43
- const RolesLoader = React.lazy(() =>
44
- import("@truedat/auth/roles/components/RolesLoader")
45
- );
46
-
47
43
  const TemplatesLoader = React.lazy(() =>
48
44
  import("@truedat/df/templates/components/TemplatesLoader")
49
45
  );
@@ -53,12 +49,7 @@ export const GrantRoutes = ({ grantRequestLoaded }) => {
53
49
  <>
54
50
  <Route
55
51
  path={GRANTS_REQUESTS_CHECKOUT}
56
- render={() => (
57
- <>
58
- <RolesLoader />
59
- <StructureGrantCartCheckout />
60
- </>
61
- )}
52
+ render={() => <StructureGrantCartCheckout />}
62
53
  />
63
54
  <Switch>
64
55
  <Route exact path={GRANT} render={() => <GrantView />} />
@@ -1,19 +1,13 @@
1
1
  import _ from "lodash/fp";
2
2
  import React, { useEffect, useState } from "react";
3
3
  import PropTypes from "prop-types";
4
- import {
5
- Form,
6
- Dropdown,
7
- Checkbox,
8
- Header,
9
- Label,
10
- Popup,
11
- } from "semantic-ui-react";
4
+ import { Form, Checkbox, Header, Label, Popup } from "semantic-ui-react";
12
5
  import { connect } from "react-redux";
13
6
  import { useIntl } from "react-intl";
14
7
  import { lowerDeburrTrim } from "@truedat/core/services/sort";
15
8
  import { DomainSelector } from "@truedat/core/components";
16
9
  import { RoleSelector } from "@truedat/auth/roles/components";
10
+ import { useRoles } from "@truedat/auth/hooks/useRoles";
17
11
  import { updateGrantRequestUser } from "../routines";
18
12
 
19
13
  const UsersSearchLoader = React.lazy(() =>
@@ -24,14 +18,13 @@ export const StructureGrantCartUserSelector = ({
24
18
  grantRequestsCart,
25
19
  updateGrantRequestUser,
26
20
  options,
27
- rolesRaw,
28
21
  }) => {
29
22
  const { formatMessage } = useIntl();
30
23
  const [usersGroupsQuery, setUsersGroupsQuery] = useState("");
31
24
  const [thirdParty, setThirdParty] = useState(false);
32
25
  const [domainIds, setDomainIds] = useState([]);
33
- const [roles, setRoles] = useState([]);
34
- const [roleIds, setRoleIds] = useState([]);
26
+ const [selectedRoles, setSelectedRoles] = useState([]);
27
+ const [selectedRoleIds, setSelectedRoleIds] = useState([]);
35
28
 
36
29
  const [userId, setUserId] = useState(_.path("user.id")(grantRequestsCart));
37
30
 
@@ -39,6 +32,9 @@ export const StructureGrantCartUserSelector = ({
39
32
  const updateGrant = !_.isEmpty(modificationGrant);
40
33
 
41
34
  const domainActions = ["publishGrantRequest"];
35
+
36
+ const { data: roles } = useRoles();
37
+
42
38
  useEffect(() => {
43
39
  updateGrantRequestUser({
44
40
  id: userId,
@@ -66,11 +62,11 @@ export const StructureGrantCartUserSelector = ({
66
62
 
67
63
  useEffect(() => {
68
64
  _.flow(
69
- _.filter(({ name }) => _.includes(name)(roles)),
65
+ _.filter(({ name }) => _.includes(name)(selectedRoles)),
70
66
  _.map(({ id }) => id),
71
- setRoleIds
72
- )(rolesRaw);
73
- }, [roles, rolesRaw]);
67
+ setSelectedRoleIds
68
+ )(roles);
69
+ }, [selectedRoles, roles]);
74
70
 
75
71
  const onSearch = (_currentOptions, { searchQuery }) =>
76
72
  setUsersGroupsQuery(lowerDeburrTrim(searchQuery));
@@ -114,8 +110,9 @@ export const StructureGrantCartUserSelector = ({
114
110
  on="click"
115
111
  content={
116
112
  <RoleSelector
117
- onChange={(_e, { value }) => setRoles(value)}
118
- value={roles}
113
+ onChange={(_e, { value }) => setSelectedRoles(value)}
114
+ value={selectedRoles}
115
+ roles={roles}
119
116
  labels
120
117
  multiple={true}
121
118
  />
@@ -123,8 +120,8 @@ export const StructureGrantCartUserSelector = ({
123
120
  trigger={
124
121
  <Label as="a">
125
122
  {formatMessage({ id: "roles.header" })}
126
- {roles.length > 0 ? (
127
- <Label.Detail>{roles.length}</Label.Detail>
123
+ {selectedRoles.length > 0 ? (
124
+ <Label.Detail>{selectedRoles.length}</Label.Detail>
128
125
  ) : null}
129
126
  </Label>
130
127
  }
@@ -146,7 +143,7 @@ export const StructureGrantCartUserSelector = ({
146
143
  <UsersSearchLoader
147
144
  query={usersGroupsQuery}
148
145
  domains={domainIds}
149
- roles={roleIds}
146
+ roles={selectedRoleIds}
150
147
  permission="allow_foreign_grant_request"
151
148
  hideLoading
152
149
  />
@@ -183,17 +180,15 @@ StructureGrantCartUserSelector.propTypes = {
183
180
  grantRequestsCart: PropTypes.object,
184
181
  options: PropTypes.array,
185
182
  updateGrantRequestUser: PropTypes.func,
186
- rolesRaw: PropTypes.array,
187
183
  };
188
184
 
189
- const mapStateToProps = ({ grantRequestsCart, usersSearch, roles }) => ({
185
+ const mapStateToProps = ({ grantRequestsCart, usersSearch }) => ({
190
186
  grantRequestsCart,
191
187
  options: _.map(({ full_name, id }) => ({
192
188
  text: full_name,
193
189
  value: id,
194
190
  icon: "user",
195
191
  }))(usersSearch),
196
- rolesRaw: roles,
197
192
  });
198
193
 
199
194
  export default connect(mapStateToProps, { updateGrantRequestUser })(
@@ -3,6 +3,25 @@ import { render } from "@truedat/test/render";
3
3
  import { singleTemplateMock } from "@truedat/test/mocks";
4
4
  import { StructureGrantCartInformation } from "../StructureGrantCartInformation";
5
5
 
6
+ jest.mock("@truedat/auth/hooks/useRoles", () => {
7
+ const originalModule = jest.requireActual("@truedat/auth/hooks/useRoles");
8
+
9
+ return {
10
+ __esModule: true,
11
+ ...originalModule,
12
+ useRoles: jest.fn(() => ({
13
+ data: {
14
+ data: {
15
+ data: {
16
+ roles: [],
17
+ },
18
+ },
19
+ },
20
+ loading: false,
21
+ })),
22
+ };
23
+ });
24
+
6
25
  describe("<StructureGrantCartInformation />", () => {
7
26
  const selectGrantRequestTemplate = jest.fn();
8
27
  const updateGrantRequestTemplateContent = jest.fn();