orc-shared 5.7.0-dev.0 → 5.7.0-dev.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.
Files changed (34) hide show
  1. package/dist/components/MaterialUI/DataDisplay/Modal.js +3 -3
  2. package/dist/components/MaterialUI/DataDisplay/TransferList.js +2 -3
  3. package/dist/components/MaterialUI/Inputs/Checkbox.js +3 -4
  4. package/dist/components/MaterialUI/Inputs/CheckboxGroup.js +5 -6
  5. package/dist/components/MaterialUI/Inputs/InputBase.js +11 -0
  6. package/dist/components/MaterialUI/Inputs/Select.js +1 -2
  7. package/dist/components/MaterialUI/Inputs/StandaloneRadio.js +2 -3
  8. package/dist/components/MaterialUI/Inputs/createInput.js +3 -4
  9. package/dist/components/MaterialUI/muiThemes.js +10 -11
  10. package/dist/components/Routing/SubPage.js +5 -4
  11. package/dist/constants.js +53 -1
  12. package/dist/hocs/withToggle.js +1 -2
  13. package/dist/hooks/useDispatchWithErrorHandling.js +24 -9
  14. package/dist/reducers/authentication.js +3 -0
  15. package/dist/sharedMessages.js +8 -0
  16. package/dist/utils/modelValidationHelper.js +5 -6
  17. package/dist/utils/propertyBagHelper.js +265 -0
  18. package/dist/utils/responseProcessingHelper.js +17 -3
  19. package/package.json +1 -1
  20. package/src/components/MaterialUI/Inputs/InputBase.js +18 -0
  21. package/src/components/MaterialUI/Inputs/InputBase.test.js +156 -0
  22. package/src/components/Routing/SubPage.js +6 -5
  23. package/src/constants.js +48 -0
  24. package/src/hooks/useDispatchWithErrorHandling.js +16 -2
  25. package/src/hooks/useDispatchWithErrorHandling.test.js +15 -13
  26. package/src/reducers/authentication.js +5 -0
  27. package/src/reducers/authentication.test.js +81 -0
  28. package/src/sharedMessages.js +8 -0
  29. package/src/translations/en-US.json +2 -0
  30. package/src/translations/fr-CA.json +2 -0
  31. package/src/utils/propertyBagHelper.js +239 -0
  32. package/src/utils/propertyBagHelper.test.js +709 -0
  33. package/src/utils/responseProcessingHelper.js +28 -3
  34. package/src/utils/responseProcessingHelper.test.js +256 -12
@@ -1,4 +1,28 @@
1
- export const extractStandardErrorMessagesFromResponse = (response, validationLookupModule, validationLookupName) => {
1
+ import { getPropertyBagFormattedPrimitiveValue } from "./propertyBagHelper";
2
+
3
+ const parseFailureContext = (context, formatMessage, formatDate, formatTime) => {
4
+ if (!context) {
5
+ return context;
6
+ }
7
+
8
+ const newContext = {};
9
+
10
+ Object.keys(context).forEach(key => {
11
+ newContext[key] = getPropertyBagFormattedPrimitiveValue(context[key], formatMessage, formatDate, formatTime);
12
+ });
13
+
14
+ return newContext;
15
+ };
16
+
17
+ export const extractStandardErrorMessagesFromResponse = (
18
+ response,
19
+ validationLookupModule,
20
+ validationLookupName,
21
+ formatMessage,
22
+ formatDate,
23
+ formatTime,
24
+ lookupKeyCustomizer,
25
+ ) => {
2
26
  let hasErrors = false;
3
27
  const messages = [];
4
28
 
@@ -14,7 +38,8 @@ export const extractStandardErrorMessagesFromResponse = (response, validationLoo
14
38
  message: failure.errorMessage,
15
39
  lookupModule: validationLookupModule,
16
40
  lookupName: validationLookupName,
17
- lookupKey: failure.errorCode,
41
+ lookupKey: lookupKeyCustomizer ? lookupKeyCustomizer(failure.errorCode) : failure.errorCode,
42
+ lookupReplacementValues: parseFailureContext(failure.context, formatMessage, formatDate, formatTime),
18
43
  });
19
44
  }
20
45
  });
@@ -27,7 +52,7 @@ export const extractStandardErrorMessagesFromResponse = (response, validationLoo
27
52
  message: err.message,
28
53
  lookupModule: err.lookupModule,
29
54
  lookupName: err.lookupName,
30
- lookupKey: err.lookupKey,
55
+ lookupKey: lookupKeyCustomizer ? lookupKeyCustomizer(err.lookupKey) : err.lookupKey,
31
56
  lookupReplacementValues: err.lookupReplacementValues,
32
57
  });
33
58
  });
@@ -1,9 +1,24 @@
1
1
  import { extractStandardErrorMessagesFromResponse } from "./responseProcessingHelper";
2
+ import sinon from "sinon";
2
3
 
3
4
  describe("extractStandardErrorMessagesFromResponse", () => {
5
+ let formatMessage, formatDate, formatTime;
6
+ beforeEach(() => {
7
+ formatMessage = sinon.stub().named("formatMessage").returns("fm");
8
+ formatDate = sinon.stub().named("formatDate").returns("fd");
9
+ formatTime = sinon.stub().named("formatTime").returns("ft");
10
+ });
11
+
4
12
  it("Returns success when response is null", () => {
5
13
  const response = null;
6
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
14
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
15
+ response,
16
+ "fallback module",
17
+ "fallback name",
18
+ formatMessage,
19
+ formatDate,
20
+ formatTime,
21
+ );
7
22
  expect(extractedMessages, "to equal", {
8
23
  hasErrors: false,
9
24
  messages: [],
@@ -12,7 +27,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
12
27
 
13
28
  it("Returns success when response is empty", () => {
14
29
  const response = {};
15
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
30
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
31
+ response,
32
+ "fallback module",
33
+ "fallback name",
34
+ formatMessage,
35
+ formatDate,
36
+ formatTime,
37
+ );
16
38
 
17
39
  expect(extractedMessages, "to equal", {
18
40
  hasErrors: false,
@@ -24,7 +46,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
24
46
  const response = {
25
47
  error: false,
26
48
  };
27
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
49
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
50
+ response,
51
+ "fallback module",
52
+ "fallback name",
53
+ formatMessage,
54
+ formatDate,
55
+ formatTime,
56
+ );
28
57
 
29
58
  expect(extractedMessages, "to equal", {
30
59
  hasErrors: false,
@@ -39,7 +68,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
39
68
  status: 422,
40
69
  },
41
70
  };
42
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
71
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
72
+ response,
73
+ "fallback module",
74
+ "fallback name",
75
+ formatMessage,
76
+ formatDate,
77
+ formatTime,
78
+ );
43
79
 
44
80
  expect(extractedMessages, "to equal", {
45
81
  hasErrors: true,
@@ -55,7 +91,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
55
91
  failures: [],
56
92
  },
57
93
  };
58
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
94
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
95
+ response,
96
+ "fallback module",
97
+ "fallback name",
98
+ formatMessage,
99
+ formatDate,
100
+ formatTime,
101
+ );
59
102
 
60
103
  expect(extractedMessages, "to equal", {
61
104
  hasErrors: true,
@@ -77,7 +120,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
77
120
  },
78
121
  },
79
122
  };
80
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
123
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
124
+ response,
125
+ "fallback module",
126
+ "fallback name",
127
+ formatMessage,
128
+ formatDate,
129
+ formatTime,
130
+ );
81
131
 
82
132
  expect(extractedMessages, "to equal", {
83
133
  hasErrors: true,
@@ -88,6 +138,126 @@ describe("extractStandardErrorMessagesFromResponse", () => {
88
138
  });
89
139
  });
90
140
 
141
+ it("Returns error with empty messages with 422 errors and transformed lookupKey", () => {
142
+ const response = {
143
+ error: true,
144
+ payload: {
145
+ status: 422,
146
+ response: {
147
+ failures: [
148
+ { invalid: "format" },
149
+ { errorCode: "code1", errorMessage: "msg1" },
150
+ { errorCode: "code2", errorMessage: "msg2" },
151
+ ],
152
+ },
153
+ },
154
+ };
155
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
156
+ response,
157
+ "fallback module",
158
+ "fallback name",
159
+ formatMessage,
160
+ formatDate,
161
+ formatTime,
162
+ key => key.replace("code", "rep"),
163
+ );
164
+
165
+ expect(extractedMessages, "to equal", {
166
+ hasErrors: true,
167
+ messages: [
168
+ { message: "msg1", lookupModule: "fallback module", lookupName: "fallback name", lookupKey: "rep1" },
169
+ { message: "msg2", lookupModule: "fallback module", lookupName: "fallback name", lookupKey: "rep2" },
170
+ ],
171
+ });
172
+ });
173
+
174
+ it("Returns error with empty messages with 422 with message containing replacement values", () => {
175
+ const response = {
176
+ error: true,
177
+ payload: {
178
+ status: 422,
179
+ response: {
180
+ failures: [
181
+ { invalid: "format" },
182
+ {
183
+ errorCode: "code1",
184
+ errorMessage: "msg1 {A}, {B}, {C}, {D} {InventoryLocationId}, {Sku}",
185
+ context: {
186
+ InventoryLocationId: {
187
+ __type:
188
+ "Orckestra.Overture.Entities.ValueContainer`1[[System.String, mscorlib]], Orckestra.Overture.Entities",
189
+ value: "BRC-411",
190
+ },
191
+ Sku: {
192
+ __type:
193
+ "Orckestra.Overture.Entities.ValueContainer`1[[System.String, mscorlib]], Orckestra.Overture.Entities",
194
+ value: "85948533",
195
+ },
196
+ A: {
197
+ __type:
198
+ "Orckestra.Overture.Entities.ValueContainer`1[[System.Int32, mscorlib]], Orckestra.Overture.Entities",
199
+ value: 123,
200
+ },
201
+ B: {
202
+ __type:
203
+ "Orckestra.Overture.Entities.ValueContainer`1[[System.String, mscorlib]], Orckestra.Overture.Entities",
204
+ value: "B",
205
+ },
206
+ C: {
207
+ __type:
208
+ "Orckestra.Overture.Entities.ValueContainer`1[[System.Boolean, mscorlib]], Orckestra.Overture.Entities",
209
+ value: true,
210
+ },
211
+ D: {
212
+ __type:
213
+ "Orckestra.Overture.Entities.ValueContainer`1[[System.DateTime, mscorlib]], Orckestra.Overture.Entities",
214
+ value: "2023-10-27T15:40:49.9783715Z",
215
+ },
216
+ E: {
217
+ __type:
218
+ "Orckestra.Overture.Entities.ValueContainer`1[[System.String, mscorlib]], Orckestra.Overture.Entities",
219
+ value: "C",
220
+ },
221
+ },
222
+ },
223
+ { errorCode: "code2", errorMessage: "msg2" },
224
+ ],
225
+ },
226
+ },
227
+ };
228
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
229
+ response,
230
+ "fallback module",
231
+ "fallback name",
232
+ formatMessage,
233
+ formatDate,
234
+ formatTime,
235
+ key => key.replace("code", "rep"),
236
+ );
237
+
238
+ expect(extractedMessages, "to equal", {
239
+ hasErrors: true,
240
+ messages: [
241
+ {
242
+ message: "msg1 {A}, {B}, {C}, {D} {InventoryLocationId}, {Sku}",
243
+ lookupModule: "fallback module",
244
+ lookupName: "fallback name",
245
+ lookupKey: "rep1",
246
+ lookupReplacementValues: {
247
+ A: "123",
248
+ B: "B",
249
+ C: "fm",
250
+ D: "fd ft",
251
+ E: "C",
252
+ InventoryLocationId: "BRC-411",
253
+ Sku: "85948533",
254
+ },
255
+ },
256
+ { message: "msg2", lookupModule: "fallback module", lookupName: "fallback name", lookupKey: "rep2" },
257
+ ],
258
+ });
259
+ });
260
+
91
261
  it("Returns error with empty messages with 422 errors", () => {
92
262
  const response = {
93
263
  error: true,
@@ -102,7 +272,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
102
272
  },
103
273
  },
104
274
  };
105
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
275
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
276
+ response,
277
+ "fallback module",
278
+ "fallback name",
279
+ formatMessage,
280
+ formatDate,
281
+ formatTime,
282
+ );
106
283
 
107
284
  expect(extractedMessages, "to equal", {
108
285
  hasErrors: true,
@@ -120,7 +297,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
120
297
  status: 500,
121
298
  },
122
299
  };
123
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
300
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
301
+ response,
302
+ "fallback module",
303
+ "fallback name",
304
+ formatMessage,
305
+ formatDate,
306
+ formatTime,
307
+ );
124
308
 
125
309
  expect(extractedMessages, "to equal", {
126
310
  hasErrors: true,
@@ -132,7 +316,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
132
316
  const response = {
133
317
  error: true,
134
318
  };
135
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
319
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
320
+ response,
321
+ "fallback module",
322
+ "fallback name",
323
+ formatMessage,
324
+ formatDate,
325
+ formatTime,
326
+ );
136
327
 
137
328
  expect(extractedMessages, "to equal", {
138
329
  hasErrors: true,
@@ -148,7 +339,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
148
339
  errors: [],
149
340
  },
150
341
  };
151
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
342
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
343
+ response,
344
+ "fallback module",
345
+ "fallback name",
346
+ formatMessage,
347
+ formatDate,
348
+ formatTime,
349
+ );
152
350
 
153
351
  expect(extractedMessages, "to equal", {
154
352
  hasErrors: true,
@@ -169,7 +367,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
169
367
  },
170
368
  },
171
369
  };
172
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
370
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
371
+ response,
372
+ "fallback module",
373
+ "fallback name",
374
+ formatMessage,
375
+ formatDate,
376
+ formatTime,
377
+ );
173
378
 
174
379
  expect(extractedMessages, "to equal", {
175
380
  hasErrors: true,
@@ -180,6 +385,38 @@ describe("extractStandardErrorMessagesFromResponse", () => {
180
385
  });
181
386
  });
182
387
 
388
+ it("Returns error with empty messages with 500 with messages and transformed lookupKey", () => {
389
+ const response = {
390
+ error: true,
391
+ payload: {
392
+ status: 500,
393
+ response: {
394
+ errors: [
395
+ { message: "msg1", lookupModule: "mod2", lookupName: "name3", lookupKey: "key4" },
396
+ { message: "", lookupModule: "mod5", lookupName: "name5", lookupKey: "key5" },
397
+ ],
398
+ },
399
+ },
400
+ };
401
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
402
+ response,
403
+ "fallback module",
404
+ "fallback name",
405
+ formatMessage,
406
+ formatDate,
407
+ formatTime,
408
+ key => key.replace("key", "rep"),
409
+ );
410
+
411
+ expect(extractedMessages, "to equal", {
412
+ hasErrors: true,
413
+ messages: [
414
+ { message: "msg1", lookupModule: "mod2", lookupName: "name3", lookupKey: "rep4" },
415
+ { message: "", lookupModule: "mod5", lookupName: "name5", lookupKey: "rep5" },
416
+ ],
417
+ });
418
+ });
419
+
183
420
  it("Returns error with empty messages with 500 with messages containing arguments", () => {
184
421
  const response = {
185
422
  error: true,
@@ -199,7 +436,14 @@ describe("extractStandardErrorMessagesFromResponse", () => {
199
436
  },
200
437
  },
201
438
  };
202
- const extractedMessages = extractStandardErrorMessagesFromResponse(response, "fallback module", "fallback name");
439
+ const extractedMessages = extractStandardErrorMessagesFromResponse(
440
+ response,
441
+ "fallback module",
442
+ "fallback name",
443
+ formatMessage,
444
+ formatDate,
445
+ formatTime,
446
+ );
203
447
 
204
448
  expect(extractedMessages, "to equal", {
205
449
  hasErrors: true,