@truedat/core 5.18.3 → 5.20.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/core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.20.0",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"react-dom": ">= 16.8.6 < 17",
|
|
118
118
|
"semantic-ui-react": ">= 2.0.3 < 2.2"
|
|
119
119
|
},
|
|
120
|
-
"gitHead": "
|
|
120
|
+
"gitHead": "3981bdf2fff50f0d8c79643c6f423dfdc7f5a57f"
|
|
121
121
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
errorsFailure,
|
|
3
|
+
graphQLErrors,
|
|
4
|
+
swrErrors,
|
|
5
|
+
toErrorList,
|
|
6
|
+
} from "../message";
|
|
2
7
|
|
|
3
8
|
describe("services: message", () => {
|
|
4
9
|
describe("toErrorList", () => {
|
|
@@ -38,4 +43,34 @@ describe("services: message", () => {
|
|
|
38
43
|
});
|
|
39
44
|
});
|
|
40
45
|
});
|
|
46
|
+
|
|
47
|
+
describe("swrErrors", () => {
|
|
48
|
+
it("should extract error messages from a SWR error response", () => {
|
|
49
|
+
const errors = {
|
|
50
|
+
fieldWithStringError: "simple string error",
|
|
51
|
+
requests: [
|
|
52
|
+
{ changesetField: ["can't be blank"] },
|
|
53
|
+
{
|
|
54
|
+
someOtherChangesetField: ["changeset error 1", "changeset error 2"],
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const response = { swrErrors: errors, prefix: "grant_requests" };
|
|
60
|
+
|
|
61
|
+
expect(swrErrors(response)).toMatchObject({
|
|
62
|
+
error: true,
|
|
63
|
+
header: "Error",
|
|
64
|
+
icon: "attention",
|
|
65
|
+
errorList: [
|
|
66
|
+
{ name: "grant_requests.fieldWithStringError.simple string error" },
|
|
67
|
+
{ name: "grant_requests.changesetField.can't be blank" },
|
|
68
|
+
{
|
|
69
|
+
name: 'grant_requests.someOtherChangesetField.["changeset error 1","changeset error 2"]',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
text: "List of errors",
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
});
|
|
41
76
|
});
|
package/src/services/message.js
CHANGED
|
@@ -30,11 +30,33 @@ export const defaultMessage = (state, type, payload) => {
|
|
|
30
30
|
return state;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
const changesetErrorTranslation = (error) =>
|
|
34
|
+
// eslint-disable-next-line prettier/prettier
|
|
35
|
+
_.flow(
|
|
36
|
+
_.toPairs,
|
|
37
|
+
_.head,
|
|
38
|
+
([field, errorList]) =>
|
|
39
|
+
errorList.length === 1
|
|
40
|
+
? `${field}.${errorList[0]}`
|
|
41
|
+
: /* This is horrible, showing the raw errorList makes it untranslatable,
|
|
42
|
+
* but Alert does not currently support nested errors
|
|
43
|
+
*/
|
|
44
|
+
`${field}.${JSON.stringify(errorList)}`
|
|
45
|
+
)(error);
|
|
46
|
+
|
|
47
|
+
export const swrErrors = ({ swrErrors, prefix }) => {
|
|
34
48
|
const errors = _.flow(
|
|
35
49
|
_.toPairs,
|
|
36
|
-
_.flatMap(([field,
|
|
37
|
-
|
|
50
|
+
_.flatMap(([field, errorOrErrors]) =>
|
|
51
|
+
// errorOrErrors may be a simple string or an array
|
|
52
|
+
_.isArray(errorOrErrors)
|
|
53
|
+
? _.map((error) =>
|
|
54
|
+
// if error is an object, it is (hopefully) a changeset error
|
|
55
|
+
_.isObject(error)
|
|
56
|
+
? `${prefix}.${changesetErrorTranslation(error)}`
|
|
57
|
+
: `${prefix}.${field}.${error}`
|
|
58
|
+
)(errorOrErrors)
|
|
59
|
+
: `${prefix}.${field}.${errorOrErrors}`
|
|
38
60
|
),
|
|
39
61
|
_.map((name) => ({ name }))
|
|
40
62
|
)(swrErrors);
|