@truedat/dd 6.1.1 → 6.1.3

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": "6.1.1",
3
+ "version": "6.1.3",
4
4
  "description": "Truedat Web Data Dictionary",
5
5
  "sideEffects": false,
6
6
  "jsnext:main": "src/index.js",
@@ -34,7 +34,7 @@
34
34
  "@testing-library/jest-dom": "^5.16.5",
35
35
  "@testing-library/react": "^12.0.0",
36
36
  "@testing-library/user-event": "^13.2.1",
37
- "@truedat/test": "6.1.1",
37
+ "@truedat/test": "6.1.3",
38
38
  "babel-jest": "^28.1.0",
39
39
  "babel-plugin-dynamic-import-node": "^2.3.3",
40
40
  "babel-plugin-lodash": "^3.3.4",
@@ -88,9 +88,9 @@
88
88
  },
89
89
  "dependencies": {
90
90
  "@apollo/client": "^3.7.1",
91
- "@truedat/auth": "6.1.1",
92
- "@truedat/core": "6.1.1",
93
- "@truedat/df": "6.1.1",
91
+ "@truedat/auth": "6.1.3",
92
+ "@truedat/core": "6.1.3",
93
+ "@truedat/df": "6.1.3",
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": "8ba2e1d68380956d654d6927a6117734f1c50076"
118
+ "gitHead": "0f50f152b947693a64e36e6eb946fac33978ea8c"
119
119
  }
@@ -38,7 +38,23 @@ export const GrantHeader = ({ grant, title, actions, onStatusChange }) => {
38
38
  ...structure.data,
39
39
  ...structure.data.data_structure,
40
40
  };
41
+
41
42
  const { formatMessage } = useIntl();
43
+
44
+ const getTodayDate = () => {
45
+ const today = new Date();
46
+ const year = today.getFullYear();
47
+ const month = today.getMonth() + 1;
48
+ const formatedMonth = month < 10 ? "0" + month : month;
49
+ const day = today.getDate();
50
+ const formatedDay = day < 10 ? "0" + day : day;
51
+
52
+ return `${year}-${formatedMonth}-${formatedDay}`;
53
+ };
54
+
55
+ const isGrantExpired = () =>
56
+ !_.isNil(grant.end_date) && _.lte(grant.end_date, getTodayDate());
57
+
42
58
  return (
43
59
  <Grid>
44
60
  <Grid.Row>
@@ -53,25 +69,29 @@ export const GrantHeader = ({ grant, title, actions, onStatusChange }) => {
53
69
  </Header>
54
70
  </Grid.Column>
55
71
  <Grid.Column width={4} textAlign="right">
56
- {actions?.update && !loading ? (
57
- <GrantChangeRequest
58
- structure={data_structure}
59
- grant={grant}
60
- key="requestChange"
61
- >
62
- <Button
63
- className="button icon group-actions"
64
- content={formatMessage({
65
- id: "structure.grant.request_grant_change",
66
- })}
72
+ {!isGrantExpired() ? (
73
+ <>
74
+ {actions?.update && !loading ? (
75
+ <GrantChangeRequest
76
+ structure={data_structure}
77
+ grant={grant}
78
+ key="requestChange"
79
+ >
80
+ <Button
81
+ className="button icon group-actions"
82
+ content={formatMessage({
83
+ id: "structure.grant.request_grant_change",
84
+ })}
85
+ />
86
+ </GrantChangeRequest>
87
+ ) : null}
88
+ <GrantRemoval
89
+ actions={actions}
90
+ grant={grant}
91
+ onConfirm={onStatusChange}
67
92
  />
68
- </GrantChangeRequest>
93
+ </>
69
94
  ) : null}
70
- <GrantRemoval
71
- actions={actions}
72
- grant={grant}
73
- onConfirm={onStatusChange}
74
- />
75
95
  </Grid.Column>
76
96
  </Grid.Row>
77
97
  </Grid>
@@ -190,11 +210,15 @@ export const Grant = ({ grant, actions, loading, onStatusChange }) => {
190
210
  {formatMessage({ id: "grant.header.end_date" })}
191
211
  </List.Header>
192
212
  <List.Description>
193
- <Moment
194
- locale="es"
195
- date={grant?.end_date}
196
- format="YYYY-MM-DD"
197
- />
213
+ {grant?.end_date ? (
214
+ <Moment
215
+ locale="es"
216
+ date={grant.end_date}
217
+ format="YYYY-MM-DD"
218
+ />
219
+ ) : (
220
+ formatMessage({ id: "grant.cell.end_date.null" })
221
+ )}
198
222
  </List.Description>
199
223
  </List.Item>
200
224
  {_.isEmpty(grant?.detail) ? null : (
@@ -46,7 +46,7 @@ export const GrantRequestRow = ({
46
46
  * inside an anchor, such as an icon) is clicked
47
47
  */
48
48
  !ev.target.closest("a") &&
49
- history.push(linkTo.GRANT_REQUEST(grantRequest))
49
+ history.push(linkTo.GRANT_REQUEST(grantRequest));
50
50
  }}
51
51
  content={columnDecoratorComponent(column)(grantRequest)}
52
52
  />
@@ -2,10 +2,11 @@ import _ from "lodash/fp";
2
2
  import React from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import { Button, Dropdown, Popup, Header } from "semantic-ui-react";
5
- import { useIntl } from "react-intl";
5
+ import { FormattedMessage, useIntl } from "react-intl";
6
6
  import { useHistory } from "react-router-dom";
7
7
  import { linkTo } from "@truedat/core/routes";
8
8
  import { Date } from "@truedat/core/components";
9
+ import { config } from "@truedat/core/truedatConfig";
9
10
 
10
11
  import GrantChangeRequest from "./GrantChangeRequest";
11
12
  import GrantRequestCancel from "./GrantRequestCancel";
@@ -97,6 +98,9 @@ export const StructureGrantDropdown = ({
97
98
  header: isModification
98
99
  ? "structure.grant.requested_modification"
99
100
  : "structure.grant.requested_access",
101
+ buttonContent: isModification
102
+ ? "structure.grant.requested_modification.short"
103
+ : "structure.grant.requested_access.short",
100
104
  },
101
105
  processingRequest: {
102
106
  color: "grey",
@@ -104,11 +108,15 @@ export const StructureGrantDropdown = ({
104
108
  header: isModification
105
109
  ? "structure.grant.modification.attended"
106
110
  : "structure.grant.access.attended",
111
+ buttonContent: isModification
112
+ ? "structure.grant.modification.attended.short"
113
+ : "structure.grant.access.attended.short",
107
114
  },
108
115
  activeGrant: {
109
116
  color: "green",
110
117
  options: [actions["requestChange"]],
111
118
  header: "structure.grant.has_grant",
119
+ buttonContent: "structure.grant.has_grant.short",
112
120
  },
113
121
  };
114
122
 
@@ -145,11 +153,23 @@ export const StructureGrantDropdown = ({
145
153
  </>
146
154
  );
147
155
 
156
+ const buttonContent = (
157
+ <FormattedMessage
158
+ id={stateProps?.buttonContent}
159
+ defaultMessage={stateProps?.buttonContent}
160
+ />
161
+ );
162
+
148
163
  const optionsWithCart =
149
164
  authorized && !requested
150
165
  ? [actions["addToCart"], ...stateProps.options]
151
166
  : stateProps?.options;
152
167
 
168
+ const { iconName, hasText } = config?.structureGrantRequestButton || {
169
+ iconName: "shield",
170
+ hasText: false,
171
+ };
172
+
153
173
  const trigger = (
154
174
  <Dropdown
155
175
  icon={null}
@@ -159,7 +179,8 @@ export const StructureGrantDropdown = ({
159
179
  <Button
160
180
  color={stateProps.color}
161
181
  className="button basic icon group-actions"
162
- icon="shield"
182
+ icon={iconName || null}
183
+ content={hasText ? buttonContent : null}
163
184
  />
164
185
  }
165
186
  >
@@ -1,8 +1,9 @@
1
1
  import React from "react";
2
2
  import PropTypes from "prop-types";
3
- import { Button, Icon, Popup } from "semantic-ui-react";
3
+ import { Button, Popup } from "semantic-ui-react";
4
4
  import { connect } from "react-redux";
5
5
  import { useIntl } from "react-intl";
6
+ import { config } from "@truedat/core/truedatConfig";
6
7
  import { addGrantRequestToCart, removeGrantRequestFromCart } from "../routines";
7
8
 
8
9
  export const StructureGrantRequestButton = ({
@@ -12,6 +13,10 @@ export const StructureGrantRequestButton = ({
12
13
  addGrantRequestToCart,
13
14
  removeGrantRequestFromCart,
14
15
  }) => {
16
+ const { iconName, hasText } = config?.structureGrantRequestButton || {
17
+ iconName: "shield",
18
+ hasText: false,
19
+ };
15
20
  const { formatMessage } = useIntl();
16
21
  const addRequest = () => {
17
22
  addGrantRequestToCart(structure);
@@ -20,14 +25,24 @@ export const StructureGrantRequestButton = ({
20
25
  const removeRequest = () => {
21
26
  removeGrantRequestFromCart(structure);
22
27
  };
23
- const content = formatMessage({
28
+ const popupContent = formatMessage({
24
29
  id: requested
25
30
  ? "structure.grant.requested_grant"
26
31
  : "structure.grant.request_grant",
27
32
  });
28
- const trigger = (
33
+
34
+ const buttonContentMessageId = requested
35
+ ? "structure.grant.requested_grant.short"
36
+ : "structure.grant.request_grant.short";
37
+ const buttonContent = formatMessage({
38
+ id: buttonContentMessageId,
39
+ defaultMessage: buttonContentMessageId,
40
+ });
41
+
42
+ const button = (
29
43
  <Button
30
- icon={<Icon name="shield" />}
44
+ icon={iconName || null}
45
+ content={hasText ? buttonContent : null}
31
46
  className="button basic icon group-actions"
32
47
  color={requested ? "blue" : "orange"}
33
48
  onClick={requested ? removeRequest : addRequest}
@@ -35,7 +50,7 @@ export const StructureGrantRequestButton = ({
35
50
  );
36
51
 
37
52
  return authorized ? (
38
- <Popup content={content} position="top center" trigger={trigger} />
53
+ <Popup content={popupContent} position="top center" trigger={button} />
39
54
  ) : null;
40
55
  };
41
56
 
@@ -36,7 +36,7 @@ describe("<Grant />", () => {
36
36
  bar: "baz",
37
37
  },
38
38
  start_date: "2018-12-01",
39
- end_date: "2019-12-31",
39
+ end_date: "2029-12-31",
40
40
  inserted_at: "2022-12-12T12:49:09.789722Z",
41
41
  pending_removal: false,
42
42
  external_ref: "foo",
@@ -111,4 +111,20 @@ describe("<Grant />", () => {
111
111
  id: 1,
112
112
  });
113
113
  });
114
+
115
+ it("don't show buttons of edit and remove if the grant is expired", async () => {
116
+ const updatedGrant = {
117
+ ...defaultProps.grant,
118
+ end_date: "2024-01-01",
119
+ };
120
+
121
+ const updatedProps = {
122
+ ...defaultProps,
123
+ grant: updatedGrant,
124
+ };
125
+
126
+ const { queryByText } = render(<Grant {...updatedProps} />, renderOpts);
127
+ const buttonText = queryByText("request grant change");
128
+ expect(buttonText).toBeNull();
129
+ });
114
130
  });
@@ -190,9 +190,9 @@ exports[`<Grant /> matches the latest snapshot 1`] = `
190
190
  class="description"
191
191
  >
192
192
  <time
193
- datetime="1577750400000"
193
+ datetime="1893369600000"
194
194
  >
195
- 2019-12-31
195
+ 2029-12-31
196
196
  </time>
197
197
  </div>
198
198
  </div>
@@ -411,9 +411,9 @@ exports[`<Grant /> matches the latest snapshot with manage_grant_removal action
411
411
  class="description"
412
412
  >
413
413
  <time
414
- datetime="1577750400000"
414
+ datetime="1893369600000"
415
415
  >
416
- 2019-12-31
416
+ 2029-12-31
417
417
  </time>
418
418
  </div>
419
419
  </div>
@@ -685,9 +685,9 @@ exports[`<Grant /> matches the latest snapshot with update action 1`] = `
685
685
  class="description"
686
686
  >
687
687
  <time
688
- datetime="1577750400000"
688
+ datetime="1893369600000"
689
689
  >
690
- 2019-12-31
690
+ 2029-12-31
691
691
  </time>
692
692
  </div>
693
693
  </div>
@@ -55,7 +55,7 @@ export const StructureDecorator = ({
55
55
  content={formatMessage({ id: "request.grantRemoval" })}
56
56
  trigger={
57
57
  <Link to={linkTo.GRANT({ id: grant.id })}>
58
- <Icon name="key" />
58
+ <Icon name="user delete" style={{ color: "black" }} />{" "}
59
59
  </Link>
60
60
  }
61
61
  />
@@ -45,7 +45,7 @@ export const StructureDecorator = (grantRequest) => {
45
45
  content={formatMessage({ id: "request.grantRemoval" })}
46
46
  trigger={
47
47
  <Link to={linkTo.GRANT({ id: grantRequest.grant.id })}>
48
- <Icon name="key" />
48
+ <Icon name="user delete" style={{ color: "black" }} />{" "}
49
49
  </Link>
50
50
  }
51
51
  />
@@ -39,7 +39,7 @@ export const GrantRequestStructureDecorator = (grantRequest) => {
39
39
  }
40
40
  />
41
41
  ) : null}
42
- { grantRequest?.data_structure_version?.name ||
42
+ {grantRequest?.data_structure_version?.name ||
43
43
  grantRequest?.grant?.data_structure_version?.name}
44
44
  </>
45
45
  );
@@ -65,4 +65,4 @@ export const StatusDecorator = ({ status }) => {
65
65
 
66
66
  StatusDecorator.propTypes = {
67
67
  status: PropTypes.string,
68
- };
68
+ };