orc-shared 1.6.0-dev.4 → 1.6.0-dev.6

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 (26) hide show
  1. package/dist/actions/globalErrorMessages.js +67 -0
  2. package/dist/actions/makeApiAction.js +1 -1
  3. package/dist/buildStore.js +3 -1
  4. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js +133 -0
  5. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/LookupDisplayValue.js +78 -0
  6. package/dist/components/Scope/useScopeConfirmationModalState.js +1 -1
  7. package/dist/hooks/useDispatchWithErrorHandling.js +106 -0
  8. package/dist/reducers/globalErrorMessages.js +79 -0
  9. package/dist/selectors/globalErrorMessages.js +58 -0
  10. package/dist/utils/responseProcessingHelper.js +86 -0
  11. package/package.json +6 -4
  12. package/src/actions/globalErrorMessages.js +12 -0
  13. package/src/actions/globalErrorMessages.test.js +21 -0
  14. package/src/buildStore.js +2 -0
  15. package/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.js +92 -0
  16. package/src/components/MaterialUI/DataDisplay/PredefinedElements/GlobalErrorMessages.test.js +444 -0
  17. package/src/components/MaterialUI/DataDisplay/PredefinedElements/LookupDisplayValue.js +12 -0
  18. package/src/components/MaterialUI/DataDisplay/PredefinedElements/LookupDisplayValue.test.js +85 -0
  19. package/src/hooks/useDispatchWithErrorHandling.js +57 -0
  20. package/src/hooks/useDispatchWithErrorHandling.test.js +230 -0
  21. package/src/reducers/globalErrorMessages.js +25 -0
  22. package/src/reducers/globalErrorMessages.test.js +66 -0
  23. package/src/selectors/globalErrorMessages.js +11 -0
  24. package/src/selectors/globalErrorMessages.test.js +25 -0
  25. package/src/utils/responseProcessingHelper.js +41 -0
  26. package/src/utils/responseProcessingHelper.test.js +182 -0
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.firstDialogErrorMessageSelector = void 0;
5
+ var _reselect = require("reselect");
6
+ (function () {
7
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
8
+ enterModule && enterModule(module);
9
+ })();
10
+ (function () {
11
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
12
+ enterModule && enterModule(module);
13
+ })();
14
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
15
+ return a;
16
+ };
17
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
18
+ return a;
19
+ };
20
+ var globalMsgData = function globalMsgData(state) {
21
+ return state.get("globalErrorMessages");
22
+ };
23
+ var firstDialogErrorMessageSelector = (0, _reselect.createSelector)(globalMsgData, function (data) {
24
+ var msgs = data.getIn(["dialog", "errorMessages"]);
25
+ if (msgs.size === 0) {
26
+ return null;
27
+ }
28
+ return msgs.first().toJS();
29
+ });
30
+ exports.firstDialogErrorMessageSelector = firstDialogErrorMessageSelector;
31
+ ;
32
+ (function () {
33
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
34
+ if (!reactHotLoader) {
35
+ return;
36
+ }
37
+ reactHotLoader.register(globalMsgData, "globalMsgData", "/home/vsts/work/1/s/src/selectors/globalErrorMessages.js");
38
+ reactHotLoader.register(firstDialogErrorMessageSelector, "firstDialogErrorMessageSelector", "/home/vsts/work/1/s/src/selectors/globalErrorMessages.js");
39
+ })();
40
+ ;
41
+ (function () {
42
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
43
+ leaveModule && leaveModule(module);
44
+ })();
45
+ ;
46
+ (function () {
47
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
48
+ if (!reactHotLoader) {
49
+ return;
50
+ }
51
+ reactHotLoader.register(globalMsgData, "globalMsgData", "/home/vsts/work/1/s/src/selectors/globalErrorMessages.js");
52
+ reactHotLoader.register(firstDialogErrorMessageSelector, "firstDialogErrorMessageSelector", "/home/vsts/work/1/s/src/selectors/globalErrorMessages.js");
53
+ })();
54
+ ;
55
+ (function () {
56
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
57
+ leaveModule && leaveModule(module);
58
+ })();
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.extractStandardErrorMessagesFromResponse = void 0;
5
+ (function () {
6
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
7
+ enterModule && enterModule(module);
8
+ })();
9
+ (function () {
10
+ var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
11
+ enterModule && enterModule(module);
12
+ })();
13
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
14
+ return a;
15
+ };
16
+ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
17
+ return a;
18
+ };
19
+ var extractStandardErrorMessagesFromResponse = function extractStandardErrorMessagesFromResponse(response, validationLookupModule, validationLookupName) {
20
+ var hasErrors = false;
21
+ var messages = [];
22
+ if (response != null && response.error) {
23
+ var _response$payload, _response$payload3;
24
+ hasErrors = true;
25
+ if (((_response$payload = response.payload) == null ? void 0 : _response$payload.status) === 422) {
26
+ var _response$payload2;
27
+ if ((_response$payload2 = response.payload) != null && (_response$payload2 = _response$payload2.response) != null && _response$payload2.failures) {
28
+ // uses structure from our .Net ValidationFailuresExceptionHandler
29
+ response.payload.response.failures.forEach(function (failure) {
30
+ if (failure.errorCode) {
31
+ messages.push({
32
+ message: failure.errorMessage,
33
+ lookupModule: validationLookupModule,
34
+ lookupName: validationLookupName,
35
+ lookupKey: failure.errorCode
36
+ });
37
+ }
38
+ });
39
+ }
40
+ } else if (((_response$payload3 = response.payload) == null ? void 0 : _response$payload3.status) === 500) {
41
+ var _response$payload4;
42
+ if ((_response$payload4 = response.payload) != null && (_response$payload4 = _response$payload4.response) != null && _response$payload4.errors) {
43
+ // uses structure from our .Net OrckestraExceptionErrorHandler
44
+ response.payload.response.errors.forEach(function (err) {
45
+ messages.push({
46
+ message: err.message,
47
+ lookupModule: err.lookupModule,
48
+ lookupName: err.lookupName,
49
+ lookupKey: err.lookupKey
50
+ });
51
+ });
52
+ }
53
+ }
54
+ }
55
+ return {
56
+ hasErrors: hasErrors,
57
+ messages: messages
58
+ };
59
+ };
60
+ exports.extractStandardErrorMessagesFromResponse = extractStandardErrorMessagesFromResponse;
61
+ ;
62
+ (function () {
63
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
64
+ if (!reactHotLoader) {
65
+ return;
66
+ }
67
+ reactHotLoader.register(extractStandardErrorMessagesFromResponse, "extractStandardErrorMessagesFromResponse", "/home/vsts/work/1/s/src/utils/responseProcessingHelper.js");
68
+ })();
69
+ ;
70
+ (function () {
71
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
72
+ leaveModule && leaveModule(module);
73
+ })();
74
+ ;
75
+ (function () {
76
+ var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
77
+ if (!reactHotLoader) {
78
+ return;
79
+ }
80
+ reactHotLoader.register(extractStandardErrorMessagesFromResponse, "extractStandardErrorMessagesFromResponse", "/home/vsts/work/1/s/src/utils/responseProcessingHelper.js");
81
+ })();
82
+ ;
83
+ (function () {
84
+ var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
85
+ leaveModule && leaveModule(module);
86
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "1.6.0-dev.4",
3
+ "version": "1.6.0-dev.6",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -47,12 +47,14 @@
47
47
  "cultureIso": "fr-CA"
48
48
  }
49
49
  ],
50
- "devDependencies": {},
50
+ "devDependencies": {
51
+ "@testing-library/react": "^10.4.9"
52
+ },
51
53
  "peerDependencies": {
52
- "orc-scripts": "1.7.0-dev.1"
54
+ "orc-scripts": "1.7.0-dev.2"
53
55
  },
54
56
  "dependencies": {
55
- "orc-scripts": "1.7.0-dev.1"
57
+ "orc-scripts": "1.7.0-dev.2"
56
58
  },
57
59
  "sideEffects": false,
58
60
  "lint-staged": {
@@ -0,0 +1,12 @@
1
+ export const PUSH_GLOBAL_ERROR_MESSAGE = "PUSH_GLOBAL_ERROR_MESSAGE";
2
+
3
+ export const pushGlobalErrorMessage = msg => ({
4
+ type: PUSH_GLOBAL_ERROR_MESSAGE,
5
+ payload: msg,
6
+ });
7
+
8
+ export const POP_GLOBAL_ERROR_MESSAGE = "POP_GLOBAL_ERROR_MESSAGE";
9
+
10
+ export const popGlobalErrorMessage = () => ({
11
+ type: POP_GLOBAL_ERROR_MESSAGE,
12
+ });
@@ -0,0 +1,21 @@
1
+ import {
2
+ POP_GLOBAL_ERROR_MESSAGE,
3
+ popGlobalErrorMessage,
4
+ PUSH_GLOBAL_ERROR_MESSAGE,
5
+ pushGlobalErrorMessage,
6
+ } from "./globalErrorMessages";
7
+
8
+ describe("pushGlobalErrorMessage", () => {
9
+ it("create action with message", () =>
10
+ expect(pushGlobalErrorMessage, "when called with", [{ custom: "message" }], "to equal", {
11
+ type: PUSH_GLOBAL_ERROR_MESSAGE,
12
+ payload: { custom: "message" },
13
+ }));
14
+ });
15
+
16
+ describe("popGlobalErrorMessage", () => {
17
+ it("create action", () =>
18
+ expect(popGlobalErrorMessage, "when called with", [], "to equal", {
19
+ type: POP_GLOBAL_ERROR_MESSAGE,
20
+ }));
21
+ });
package/src/buildStore.js CHANGED
@@ -21,6 +21,7 @@ import modulesReducer from "./reducers/modules";
21
21
  import metadataReducer from "./reducers/metadata";
22
22
  import requestStatesReducer from "./reducers/requestStates";
23
23
  import tasksReducer from "./reducers/tasks";
24
+ import globalErrorMessagesReducer from "./reducers/globalErrorMessages";
24
25
 
25
26
  window.BUILD_ID = BUILD_ID;
26
27
  window.BUILD_NUMBER = BUILD_NUMBER;
@@ -67,6 +68,7 @@ const buildStore = (reducers, devOptions = {}) => {
67
68
  metadata: metadataReducer,
68
69
  requestStates: requestStatesReducer,
69
70
  tasks: tasksReducer,
71
+ globalErrorMessages: globalErrorMessagesReducer,
70
72
  });
71
73
  const rootReducer = buildReducer(reducers);
72
74
 
@@ -0,0 +1,92 @@
1
+ import React from "react";
2
+ import { useIntl } from "react-intl";
3
+ import { makeStyles } from "@material-ui/core/styles";
4
+ import sharedMessages from "../../../../sharedMessages";
5
+ import Grid from "@material-ui/core/Grid";
6
+ import ListItemText from "@material-ui/core/ListItemText";
7
+ import List from "@material-ui/core/List";
8
+ import ListItem from "@material-ui/core/ListItem";
9
+ import ListItemIcon from "@material-ui/core/ListItemIcon";
10
+ import LookupDisplayValue from "./LookupDisplayValue";
11
+ import ActionModal from "./ActionModal";
12
+ import { useDispatch, useSelector } from "react-redux";
13
+ import { firstDialogErrorMessageSelector } from "../../../../selectors/globalErrorMessages";
14
+ import { popGlobalErrorMessage } from "../../../../actions/globalErrorMessages";
15
+
16
+ const useStyles = makeStyles(theme => ({
17
+ grid: {
18
+ maxHeight: "40vh",
19
+ overflowY: "auto",
20
+ },
21
+ }));
22
+
23
+ const GlobalErrorMessagesModal = ({ children }) => {
24
+ const classes = useStyles();
25
+ const { formatMessage } = useIntl();
26
+ const dispatch = useDispatch();
27
+
28
+ const msg = useSelector(firstDialogErrorMessageSelector);
29
+
30
+ if (msg === null) {
31
+ return <>{children}</>;
32
+ }
33
+
34
+ const closeCallback = () => {
35
+ dispatch(popGlobalErrorMessage());
36
+ };
37
+ const actions = [{ label: sharedMessages.close, isPrimary: true, handler: closeCallback }];
38
+
39
+ let content = (
40
+ <Grid container spacing={2} className={classes.grid}>
41
+ <Grid container item spacing={0}>
42
+ {msg.description && (
43
+ <Grid item xs={12}>
44
+ {msg.description}
45
+ </Grid>
46
+ )}
47
+
48
+ {msg.messages?.length > 0 && (
49
+ <Grid item xs={12}>
50
+ <List className={classes.root}>
51
+ {msg.messages.map((msg, index) => {
52
+ const hasLookup = msg.lookupModule && msg.lookupName && msg.lookupKey;
53
+
54
+ return (
55
+ <ListItem key={index}>
56
+ <ListItemIcon>●</ListItemIcon>
57
+ <ListItemText>
58
+ {hasLookup && (
59
+ <LookupDisplayValue
60
+ moduleName={msg.lookupModule}
61
+ lookupName={msg.lookupName}
62
+ lookupKey={msg.lookupKey}
63
+ />
64
+ )}
65
+ {!hasLookup && msg.message}
66
+ </ListItemText>
67
+ </ListItem>
68
+ );
69
+ })}
70
+ </List>
71
+ </Grid>
72
+ )}
73
+ </Grid>
74
+ </Grid>
75
+ );
76
+
77
+ return (
78
+ <>
79
+ {children}
80
+ {
81
+ <ActionModal
82
+ title={msg.title || formatMessage(sharedMessages.error)}
83
+ message={content}
84
+ open={true}
85
+ actions={actions}
86
+ />
87
+ }
88
+ </>
89
+ );
90
+ };
91
+
92
+ export default GlobalErrorMessagesModal;