@ukhomeoffice/cop-react-form-renderer 5.71.2 → 5.71.4
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/dist/components/CollectionSummary/CollectionSummary.js +3 -25
- package/dist/utils/CollectionPage/getErrorsForCollection.js +55 -0
- package/dist/utils/CollectionPage/getErrorsForCollection.test.js +155 -0
- package/dist/utils/CollectionPage/index.js +2 -0
- package/dist/utils/Component/isEditable.js +1 -1
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
10
|
var _hooks = require("../../hooks");
|
|
11
11
|
var _PageAction = require("../../models/PageAction");
|
|
12
12
|
var _elevateNestedComponents = _interopRequireDefault(require("../../utils/Component/elevateNestedComponents"));
|
|
13
|
+
var _getErrorsForCollection = _interopRequireDefault(require("../../utils/CollectionPage/getErrorsForCollection"));
|
|
13
14
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
14
15
|
var _getCYARow = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARow"));
|
|
15
16
|
var _Answer = _interopRequireDefault(require("../CheckYourAnswers/Answer"));
|
|
@@ -115,31 +116,8 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
115
116
|
return e.raisedBy === config.id;
|
|
116
117
|
});
|
|
117
118
|
}
|
|
118
|
-
var allErrors =
|
|
119
|
-
|
|
120
|
-
// Validation of a collection page uses the data from the
|
|
121
|
-
// active entry, so here we have to set the active ID before
|
|
122
|
-
// validating.
|
|
123
|
-
var childPages = masterPage === null || masterPage === void 0 ? void 0 : masterPage.childPages.map(function (page) {
|
|
124
|
-
return _objectSpread(_objectSpread({}, page), {}, {
|
|
125
|
-
formData: _objectSpread(_objectSpread({}, formData), {}, _defineProperty({}, "".concat(config.collectionName.split('.').pop(), "ActiveId"), entry.id))
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
var allPagesErrors = (childPages === null || childPages === void 0 ? void 0 : childPages.flatMap(function (page) {
|
|
129
|
-
var pageErrors = _utils.default.Validate.page(page);
|
|
130
|
-
return hooks.onValidate(page, pageErrors);
|
|
131
|
-
})) || [];
|
|
132
|
-
// For each error we found, add the entryId so we know what Summary Card
|
|
133
|
-
// we have to pass it to.
|
|
134
|
-
var entryErrors = allPagesErrors.map(function (e) {
|
|
135
|
-
return _objectSpread(_objectSpread({}, e), {}, {
|
|
136
|
-
entryId: entry.id,
|
|
137
|
-
showFor: config.id,
|
|
138
|
-
raisedBy: config.id
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
allErrors = allErrors.concat(entryErrors);
|
|
142
|
-
});
|
|
119
|
+
var allErrors = (0, _getErrorsForCollection.default)(config, masterPage, formData, hooks);
|
|
120
|
+
|
|
143
121
|
// We only queue allErrors if it's not empty to avoid
|
|
144
122
|
// triggering a race condition with the 'data' memo
|
|
145
123
|
// above.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _ = _interopRequireDefault(require(".."));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
var getErrorsForCollection = function getErrorsForCollection(config, masterPage, formData, hooks) {
|
|
16
|
+
var activeIds = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
17
|
+
if (!masterPage) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
// Get data for current collection
|
|
21
|
+
var collectionData = _.default.CollectionPage.getData(masterPage.collection.name, masterPage.formData) || [];
|
|
22
|
+
var allErrors = [];
|
|
23
|
+
|
|
24
|
+
// Loop over each entry in the collection data
|
|
25
|
+
collectionData.forEach(function (entry) {
|
|
26
|
+
var _masterPage$childPage;
|
|
27
|
+
// eslint-disable-next-line no-param-reassign
|
|
28
|
+
activeIds = _objectSpread(_objectSpread({}, activeIds), {}, _defineProperty({}, "".concat(masterPage.collection.name.split('.').pop(), "ActiveId"), entry.id));
|
|
29
|
+
|
|
30
|
+
// Loop over child pages and validate each one
|
|
31
|
+
var allPagesErrors = (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.flatMap(function (page) {
|
|
32
|
+
var pageWithIds = _objectSpread(_objectSpread({}, page), {}, {
|
|
33
|
+
formData: _objectSpread(_objectSpread({}, formData), activeIds)
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Handle nested collections
|
|
37
|
+
if (page.childPages) {
|
|
38
|
+
return getErrorsForCollection(config, pageWithIds, formData, hooks, activeIds);
|
|
39
|
+
}
|
|
40
|
+
var pageErrors = _.default.Validate.page(pageWithIds);
|
|
41
|
+
return hooks.onValidate(pageWithIds, pageErrors);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// For each error add the entryId so we know what Summary Card we have to pass it to.
|
|
45
|
+
allErrors = allErrors.concat(allPagesErrors.map(function (e) {
|
|
46
|
+
return _objectSpread(_objectSpread({}, e), {}, {
|
|
47
|
+
entryId: entry.id,
|
|
48
|
+
showFor: config.id,
|
|
49
|
+
raisedBy: config.id
|
|
50
|
+
});
|
|
51
|
+
}));
|
|
52
|
+
});
|
|
53
|
+
return allErrors;
|
|
54
|
+
};
|
|
55
|
+
var _default = exports.default = getErrorsForCollection;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getErrorsForCollection = _interopRequireDefault(require("./getErrorsForCollection"));
|
|
4
|
+
var _models = require("../../models");
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
describe('Utils.CollectionPage.getErrorsForCollection', function () {
|
|
7
|
+
var HOOKS = {
|
|
8
|
+
onValidate: function onValidate(_, errors) {
|
|
9
|
+
return errors;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var CONFIG = {
|
|
13
|
+
id: 'testId'
|
|
14
|
+
};
|
|
15
|
+
var FORM_DATA = {
|
|
16
|
+
collection: [{
|
|
17
|
+
id: 22,
|
|
18
|
+
item1: 'blue',
|
|
19
|
+
child: [{
|
|
20
|
+
id: 11,
|
|
21
|
+
item4: 'red'
|
|
22
|
+
}]
|
|
23
|
+
}]
|
|
24
|
+
};
|
|
25
|
+
var FORM_DATA_MISSING_TOP = {
|
|
26
|
+
collection: [{
|
|
27
|
+
id: 22,
|
|
28
|
+
item2: 'blue',
|
|
29
|
+
child: [{
|
|
30
|
+
id: 11,
|
|
31
|
+
item4: 'red'
|
|
32
|
+
}]
|
|
33
|
+
}]
|
|
34
|
+
};
|
|
35
|
+
var FORM_DATA_MISSING_NESTED = {
|
|
36
|
+
collection: [{
|
|
37
|
+
id: 22,
|
|
38
|
+
item1: 'blue',
|
|
39
|
+
child: [{
|
|
40
|
+
id: 11,
|
|
41
|
+
item9: 'red'
|
|
42
|
+
}]
|
|
43
|
+
}]
|
|
44
|
+
};
|
|
45
|
+
var FORM_DATA_MISSING_BOTH = {
|
|
46
|
+
collection: [{
|
|
47
|
+
id: 22,
|
|
48
|
+
item9: 'blue',
|
|
49
|
+
child: [{
|
|
50
|
+
id: 11,
|
|
51
|
+
item9: 'red'
|
|
52
|
+
}]
|
|
53
|
+
}]
|
|
54
|
+
};
|
|
55
|
+
var MASTER_PAGE = {
|
|
56
|
+
id: 'masterPage',
|
|
57
|
+
collection: {
|
|
58
|
+
name: 'collection',
|
|
59
|
+
masterPage: true
|
|
60
|
+
},
|
|
61
|
+
formData: FORM_DATA,
|
|
62
|
+
childPages: [{
|
|
63
|
+
id: 'page1',
|
|
64
|
+
collection: {
|
|
65
|
+
name: 'collection'
|
|
66
|
+
},
|
|
67
|
+
formData: FORM_DATA,
|
|
68
|
+
components: [{
|
|
69
|
+
id: 'item1',
|
|
70
|
+
fieldId: 'item1',
|
|
71
|
+
label: 'Item 1',
|
|
72
|
+
required: true,
|
|
73
|
+
type: _models.ComponentTypes.TEXT
|
|
74
|
+
}, {
|
|
75
|
+
id: 'item2',
|
|
76
|
+
fieldId: 'item2',
|
|
77
|
+
label: 'Item 2',
|
|
78
|
+
type: _models.ComponentTypes.TEXT
|
|
79
|
+
}]
|
|
80
|
+
}]
|
|
81
|
+
};
|
|
82
|
+
var MASTER_PAGE_WITH_NESTED = {
|
|
83
|
+
id: 'masterPage',
|
|
84
|
+
collection: {
|
|
85
|
+
name: 'collection',
|
|
86
|
+
masterPage: true
|
|
87
|
+
},
|
|
88
|
+
formData: FORM_DATA,
|
|
89
|
+
childPages: [{
|
|
90
|
+
id: 'page1',
|
|
91
|
+
collection: {
|
|
92
|
+
name: 'collection'
|
|
93
|
+
},
|
|
94
|
+
formData: FORM_DATA,
|
|
95
|
+
components: [{
|
|
96
|
+
id: 'item1',
|
|
97
|
+
fieldId: 'item1',
|
|
98
|
+
label: 'Item 1',
|
|
99
|
+
required: true,
|
|
100
|
+
type: _models.ComponentTypes.TEXT
|
|
101
|
+
}, {
|
|
102
|
+
id: 'item2',
|
|
103
|
+
fieldId: 'item2',
|
|
104
|
+
label: 'Item 2',
|
|
105
|
+
type: _models.ComponentTypes.TEXT
|
|
106
|
+
}]
|
|
107
|
+
}, {
|
|
108
|
+
id: 'page2',
|
|
109
|
+
formData: FORM_DATA,
|
|
110
|
+
collection: {
|
|
111
|
+
name: 'collection.child',
|
|
112
|
+
masterPage: true
|
|
113
|
+
},
|
|
114
|
+
childPages: [{
|
|
115
|
+
id: 'nestedPage',
|
|
116
|
+
formData: FORM_DATA,
|
|
117
|
+
collection: {
|
|
118
|
+
name: 'collection.child'
|
|
119
|
+
},
|
|
120
|
+
components: [{
|
|
121
|
+
id: 'item4',
|
|
122
|
+
fieldId: 'item4',
|
|
123
|
+
label: 'Item 4',
|
|
124
|
+
required: true,
|
|
125
|
+
type: _models.ComponentTypes.TEXT
|
|
126
|
+
}, {
|
|
127
|
+
id: 'item5',
|
|
128
|
+
fieldId: 'item5',
|
|
129
|
+
label: 'Item 5',
|
|
130
|
+
type: _models.ComponentTypes.TEXT
|
|
131
|
+
}]
|
|
132
|
+
}]
|
|
133
|
+
}]
|
|
134
|
+
};
|
|
135
|
+
it('should return nothing for a master page without errors', function () {
|
|
136
|
+
var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE, FORM_DATA, HOOKS);
|
|
137
|
+
expect(errors.length).toEqual(0);
|
|
138
|
+
});
|
|
139
|
+
it('should return erorrs for a master page with errors', function () {
|
|
140
|
+
var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE, FORM_DATA_MISSING_TOP, HOOKS);
|
|
141
|
+
expect(errors.length).toEqual(1);
|
|
142
|
+
});
|
|
143
|
+
it('should return nothing for a master page with a nested master page without errors', function () {
|
|
144
|
+
var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE_WITH_NESTED, FORM_DATA, HOOKS);
|
|
145
|
+
expect(errors.length).toEqual(0);
|
|
146
|
+
});
|
|
147
|
+
it('should return errors for a master page with a nested master page without errors', function () {
|
|
148
|
+
var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE_WITH_NESTED, FORM_DATA_MISSING_NESTED, HOOKS);
|
|
149
|
+
expect(errors.length).toEqual(1);
|
|
150
|
+
});
|
|
151
|
+
it('should return errors for a master page with errors with a nested master page with errors', function () {
|
|
152
|
+
var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE_WITH_NESTED, FORM_DATA_MISSING_BOTH, HOOKS);
|
|
153
|
+
expect(errors.length).toEqual(2);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
@@ -10,6 +10,7 @@ var _duplicateCollectionPageEntry = _interopRequireDefault(require("./duplicateC
|
|
|
10
10
|
var _getCollectionPageActiveId = _interopRequireDefault(require("./getCollectionPageActiveId"));
|
|
11
11
|
var _getCollectionPageActiveIndex = _interopRequireDefault(require("./getCollectionPageActiveIndex"));
|
|
12
12
|
var _getCollectionPageData = _interopRequireDefault(require("./getCollectionPageData"));
|
|
13
|
+
var _getErrorsForCollection = _interopRequireDefault(require("./getErrorsForCollection"));
|
|
13
14
|
var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
|
|
14
15
|
var _removeCollectionPageEntry = _interopRequireDefault(require("./removeCollectionPageEntry"));
|
|
15
16
|
var _setCollectionPageData = _interopRequireDefault(require("./setCollectionPageData"));
|
|
@@ -23,6 +24,7 @@ var CollectionPage = {
|
|
|
23
24
|
getActiveId: _getCollectionPageActiveId.default,
|
|
24
25
|
getActiveIndex: _getCollectionPageActiveIndex.default,
|
|
25
26
|
getData: _getCollectionPageData.default,
|
|
27
|
+
getErrorsForCollection: _getErrorsForCollection.default,
|
|
26
28
|
mergePages: _mergeCollectionPages.default,
|
|
27
29
|
removeEntry: _removeCollectionPageEntry.default,
|
|
28
30
|
setData: _setCollectionPageData.default
|
|
@@ -7,7 +7,7 @@ exports.default = exports.EDITABLE_TYPES = void 0;
|
|
|
7
7
|
var _models = require("../../models");
|
|
8
8
|
// Local imports
|
|
9
9
|
|
|
10
|
-
var EDITABLE_TYPES = exports.EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.MULTI_FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
10
|
+
var EDITABLE_TYPES = exports.EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.COLLECTION_SUMMARY, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.MULTI_FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
|
|
11
11
|
var isEditable = function isEditable(options) {
|
|
12
12
|
return EDITABLE_TYPES.includes(options === null || options === void 0 ? void 0 : options.type) || (options === null || options === void 0 ? void 0 : options.isEditable) || false;
|
|
13
13
|
};
|