@truedat/dd 7.8.1 → 7.8.2

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": "7.8.1",
3
+ "version": "7.8.2",
4
4
  "description": "Truedat Web Data Dictionary",
5
5
  "sideEffects": false,
6
6
  "module": "src/index.js",
@@ -48,7 +48,7 @@
48
48
  "@testing-library/jest-dom": "^6.6.3",
49
49
  "@testing-library/react": "^16.3.0",
50
50
  "@testing-library/user-event": "^14.6.1",
51
- "@truedat/test": "7.7.2",
51
+ "@truedat/test": "7.8.2",
52
52
  "identity-obj-proxy": "^3.0.0",
53
53
  "jest": "^29.7.0",
54
54
  "redux-saga-test-plan": "^4.0.6"
@@ -83,5 +83,5 @@
83
83
  "svg-pan-zoom": "^3.6.2",
84
84
  "swr": "^2.3.3"
85
85
  },
86
- "gitHead": "c5687bea50fd81f4899bdadb4a25e459dacd58ec"
86
+ "gitHead": "666bad523fceed945598849935266d7c46a46432"
87
87
  }
@@ -1,16 +1,16 @@
1
1
  import PropTypes from "prop-types";
2
- import { useDispatch } from "react-redux";
2
+ import { useWebContext } from "@truedat/core/webContext";
3
3
  import { Dropdown } from "semantic-ui-react";
4
4
  import { useIntl } from "react-intl";
5
5
  import { UploadModal } from "@truedat/core/components";
6
- import { uploadStructures } from "../routines";
7
6
  import { useDataStructureUpload } from "../hooks/useStructures";
7
+ import { getUploadAlertMessage } from "../selectors/messages";
8
8
 
9
9
  export const StructuresUploadOption = ({ canAutoPublish }) => {
10
10
  const { formatMessage, locale } = useIntl();
11
11
  const { trigger: triggerUpload, isMutating: structuresUploading } =
12
12
  useDataStructureUpload();
13
- const dispatch = useDispatch();
13
+ const { setAlertMessage } = useWebContext();
14
14
  const extraAction = {
15
15
  key: "yesWithAutoPublish",
16
16
  primary: true,
@@ -19,7 +19,8 @@ export const StructuresUploadOption = ({ canAutoPublish }) => {
19
19
  data.append("auto_publish", canAutoPublish);
20
20
  data.append("lang", locale);
21
21
  triggerUpload(data).then(({ status, data }) => {
22
- dispatch(uploadStructures.success({ status, data }));
22
+ const alertMessate = getUploadAlertMessage({ status, data });
23
+ setAlertMessage(alertMessate);
23
24
  });
24
25
  },
25
26
  };
@@ -45,7 +46,8 @@ export const StructuresUploadOption = ({ canAutoPublish }) => {
45
46
  handleSubmit={(data) => {
46
47
  data.append("lang", locale);
47
48
  triggerUpload(data).then(({ status, data }) => {
48
- dispatch(uploadStructures.success({ status, data }));
49
+ const alertMessate = getUploadAlertMessage({ status, data });
50
+ setAlertMessage(alertMessate);
49
51
  });
50
52
  }}
51
53
  />
@@ -5,7 +5,6 @@ import {
5
5
  updateReferenceDataset,
6
6
  updateStructureType,
7
7
  updateStructure,
8
- uploadStructures,
9
8
  } from "../../routines";
10
9
  import { structureRedirect, initialState } from "../structureRedirect";
11
10
 
@@ -47,14 +46,6 @@ describe("reducers: structureRedirect", () => {
47
46
  ).toBe(fooState);
48
47
  });
49
48
 
50
- it("should be /structures after receiving uploadStructures.SUCCESS", () => {
51
- expect(
52
- structureRedirect(fooState, {
53
- type: uploadStructures.SUCCESS,
54
- })
55
- ).toBe("/structures");
56
- });
57
-
58
49
  it("should be /referenceDatasets/42 after receiving createReferenceDataset.SUCCESS", () => {
59
50
  expect(
60
51
  structureRedirect(
@@ -1,98 +1,43 @@
1
1
  import _ from "lodash/fp";
2
2
  import { dismissAlert } from "@truedat/core/routines";
3
- import { STRUCTURES_UPLOAD_EVENTS } from "@truedat/core/routes";
3
+ import { getUploadAlertMessage } from "../selectors/messages";
4
4
  import {
5
5
  bulkUpdateStructures,
6
6
  createReferenceDataset,
7
7
  deleteReferenceDataset,
8
8
  updateReferenceDataset,
9
- uploadStructures,
10
9
  updateStructureType,
11
10
  uploadStructuresDomains,
12
11
  } from "../routines";
13
12
 
14
13
  export const initialState = null;
15
14
 
16
- const bulkUpdateErrors = (payload) => {
17
- const messagesImp = _.has("errors")(payload.data)
18
- ? _.flow(
19
- _.propOr([], "errors"),
20
- _.map((error) => ({
21
- id: `structures.bulkUpdateStructures.failed.note.${error.message}`,
22
- fields: {
23
- row: error.row,
24
- id: error.id,
25
- field: error.field,
26
- externalId: error.external_id,
27
- message: error.message,
28
- },
29
- defaultMessage: "structures.bulkUploadStructures.success.errors",
30
- }))
31
- )(payload.data)
32
- : "";
33
- return {
34
- error: false,
35
- header: "structures.bulkUpdateStructures.success.header",
36
- icon: "check",
37
- color: payload.data.errors.length >= 1 ? "orange" : "green",
38
- text: "",
39
- messages: messagesImp,
40
- fields: {
41
- count_ids: payload.data.ids.length,
42
- count_errors: payload.data.errors.length,
43
- },
44
- downloadable: true,
45
- initialMaxListItems: 5,
46
- };
47
- };
48
-
49
- const bulkUpdateAccepted = () => {
50
- return {
51
- error: false,
52
- header: "structures.bulkUpdateStructures.success.accepted.header",
53
- icon: "check",
54
- color: "blue",
55
- text: "",
56
- anchor: {
57
- reference: STRUCTURES_UPLOAD_EVENTS,
58
- label: "sidemenu.structures_upload_events",
59
- },
60
- };
61
- };
62
-
63
15
  const ddMessage = (state = initialState, { type, payload }) => {
64
16
  switch (type) {
65
17
  case dismissAlert.TRIGGER:
66
18
  return initialState;
67
- case uploadStructures.SUCCESS:
68
- case bulkUpdateStructures.SUCCESS: {
69
- if (payload.status === 202) {
70
- return bulkUpdateAccepted(payload.data);
71
- } else if (payload.status === 200) {
72
- return bulkUpdateErrors(payload);
73
- }
74
- }
75
-
19
+ case bulkUpdateStructures.SUCCESS:
20
+ return getUploadAlertMessage(payload);
76
21
  case uploadStructuresDomains.SUCCESS: {
77
22
  const messagesImp = _.has("errors")(payload.data)
78
23
  ? _.flow(
79
- _.propOr([], "errors"),
80
- _.map((error) => {
81
- const errorMessage = Object.entries(error.message)
82
- .map(([field, messages]) => `${field}: ${messages.join(", ")}`)
83
- .join(" | ");
84
- return {
85
- id: `structures.bulkUploadStructuresDomains.success.errors.${errorMessage}`,
86
- fields: {
87
- row: error.row,
88
- id: error.id,
89
- field: error.field,
90
- externalId: error.external_id,
91
- message: errorMessage,
92
- },
93
- };
94
- })
95
- )(payload.data)
24
+ _.propOr([], "errors"),
25
+ _.map((error) => {
26
+ const errorMessage = Object.entries(error.message)
27
+ .map(([field, messages]) => `${field}: ${messages.join(", ")}`)
28
+ .join(" | ");
29
+ return {
30
+ id: `structures.bulkUploadStructuresDomains.success.errors.${errorMessage}`,
31
+ fields: {
32
+ row: error.row,
33
+ id: error.id,
34
+ field: error.field,
35
+ externalId: error.external_id,
36
+ message: errorMessage,
37
+ },
38
+ };
39
+ })
40
+ )(payload.data)
96
41
  : "";
97
42
  return {
98
43
  error: false,
@@ -114,12 +59,12 @@ const ddMessage = (state = initialState, { type, payload }) => {
114
59
  return payload.status !== 422
115
60
  ? state
116
61
  : {
117
- error: true,
118
- header: "structures.uploadStructuresDomains.failed.header",
119
- icon: "attention",
120
- content: payload?.data?.error?.message,
121
- initialMaxListItems: 5,
122
- };
62
+ error: true,
63
+ header: "structures.uploadStructuresDomains.failed.header",
64
+ icon: "attention",
65
+ content: payload?.data?.error?.message,
66
+ initialMaxListItems: 5,
67
+ };
123
68
 
124
69
  case updateStructureType.SUCCESS:
125
70
  return {
@@ -128,43 +73,6 @@ const ddMessage = (state = initialState, { type, payload }) => {
128
73
  icon: "check",
129
74
  color: "green",
130
75
  };
131
-
132
- case uploadStructures.FAILURE:
133
- if (payload.status != 500) {
134
- const { data } = payload;
135
-
136
- const row = _.path("errors.row")(data);
137
- const field = _.path("errors.field")(data);
138
- const messages = _.has("errors")(data)
139
- ? _.flow(
140
- _.propOr([], "errors"),
141
- _.toPairs,
142
- _.filter(([k, _v]) => k !== "row" && k !== "field"),
143
- _.map(([k, v]) =>
144
- _.map((e) => ({
145
- id: `structures.uploadStructures.failed.${k}.${e}`,
146
- fields: { row, field },
147
- defaultMessage: "structures.uploadStructures.failed.default",
148
- }))(v)
149
- ),
150
- _.flatten
151
- )(data)
152
- : _.flow(_.path("error.message"), (m) => [
153
- {
154
- id: `structures.uploadStructures.failed.${m}`,
155
- defaultMessage: "structures.uploadStructures.failed.default",
156
- },
157
- ])(data);
158
- return {
159
- error: true,
160
- header: "structures.uploadStructures.failed.header",
161
- icon: "attention",
162
- text: "",
163
- messages,
164
- };
165
- } else {
166
- return state;
167
- }
168
76
  case createReferenceDataset.SUCCESS:
169
77
  return {
170
78
  error: false,
@@ -33,7 +33,6 @@ import {
33
33
  updateStructureType,
34
34
  updateSystem,
35
35
  updateTag,
36
- uploadStructures,
37
36
  } from "../routines";
38
37
 
39
38
  export const initialState = "";
@@ -67,9 +66,6 @@ export const structureRedirect = (
67
66
  ? linkTo.GRANT_REQUEST({ id: requests[0].id })
68
67
  : MY_GRANT_REQUESTS;
69
68
  }
70
- case uploadStructures.SUCCESS: {
71
- return STRUCTURES;
72
- }
73
69
  case doStructureNoteAction.SUCCESS: {
74
70
  return meta?.redirect
75
71
  ? linkTo.STRUCTURE_NOTES({ id: meta?.data_structure_id })
package/src/routines.js CHANGED
@@ -170,7 +170,6 @@ export const updateStructure = createRoutine("UPDATE_STRUCTURE");
170
170
  export const updateStructureType = createRoutine("UPDATE_STRUCTURE_TYPE");
171
171
  export const updateSystem = createRoutine("UPDATE_SYSTEM");
172
172
  export const updateTag = createRoutine("UPDATE_TAG");
173
- export const uploadStructures = createRoutine("UPLOAD_STRUCTURES");
174
173
  export const uploadStructuresDomains = createRoutine(
175
174
  "UPLOAD_STRUCTURES_DOMAINS"
176
175
  );
@@ -0,0 +1,58 @@
1
+
2
+ import { STRUCTURES_UPLOAD_EVENTS } from "@truedat/core/routes";
3
+
4
+ const uploadWithErrors = (data) => {
5
+ const messagesImp = _.has("errors")(data)
6
+ ? _.flow(
7
+ _.propOr([], "errors"),
8
+ _.map((error) => ({
9
+ id: `structures.bulkUpdateStructures.failed.note.${error.message}`,
10
+ fields: {
11
+ row: error.row,
12
+ id: error.id,
13
+ field: error.field,
14
+ externalId: error.external_id,
15
+ message: error.message,
16
+ },
17
+ defaultMessage: "structures.bulkUploadStructures.success.errors",
18
+ }))
19
+ )(data)
20
+ : "";
21
+ return {
22
+ error: false,
23
+ header: "structures.bulkUpdateStructures.success.header",
24
+ icon: "check",
25
+ color: data.errors.length >= 1 ? "orange" : "green",
26
+ text: "",
27
+ messages: messagesImp,
28
+ fields: {
29
+ count_ids: data.ids.length,
30
+ count_errors: data.errors.length,
31
+ },
32
+ downloadable: true,
33
+ initialMaxListItems: 5,
34
+ };
35
+ };
36
+
37
+ const uploadAccepted = () => {
38
+ return {
39
+ error: false,
40
+ header: "structures.bulkUpdateStructures.success.accepted.header",
41
+ icon: "check",
42
+ color: "blue",
43
+ text: "",
44
+ anchor: {
45
+ reference: STRUCTURES_UPLOAD_EVENTS,
46
+ label: "sidemenu.structures_upload_events",
47
+ },
48
+ };
49
+ };
50
+
51
+ export const getUploadAlertMessage = ({ status, data }) => {
52
+ if (status === 202) {
53
+ return uploadAccepted();
54
+ }
55
+ if (status === 200) {
56
+ return uploadWithErrors(data);
57
+ }
58
+ };