@ukhomeoffice/cop-react-form-renderer 5.68.0 → 5.68.1
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 +14 -11
- package/dist/components/FormComponent/FormComponent.js +1 -0
- package/dist/components/FormRenderer/FormRenderer.js +5 -3
- package/dist/context/ValidationContext/ValidationContext.js +0 -2
- package/dist/utils/Validate/validatePage.js +4 -0
- package/dist/utils/Validate/validatePage.test.js +25 -0
- package/package.json +1 -1
|
@@ -57,6 +57,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
57
57
|
formData = _ref.formData,
|
|
58
58
|
onAction = _ref.onAction,
|
|
59
59
|
onChange = _ref.onChange,
|
|
60
|
+
onTopLevelChange = _ref.onTopLevelChange,
|
|
60
61
|
pages = _ref.pages;
|
|
61
62
|
var _useHooks = (0, _hooks.useHooks)(),
|
|
62
63
|
hooks = _useHooks.hooks;
|
|
@@ -121,7 +122,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
121
122
|
// validating.
|
|
122
123
|
var childPages = masterPage === null || masterPage === void 0 ? void 0 : masterPage.childPages.map(function (page) {
|
|
123
124
|
return _objectSpread(_objectSpread({}, page), {}, {
|
|
124
|
-
formData: _objectSpread(_objectSpread({},
|
|
125
|
+
formData: _objectSpread(_objectSpread({}, formData), {}, _defineProperty({}, "".concat(config.collectionName.split('.').pop(), "ActiveId"), entry.id))
|
|
125
126
|
});
|
|
126
127
|
});
|
|
127
128
|
var allPagesErrors = (childPages === null || childPages === void 0 ? void 0 : childPages.flatMap(function (page) {
|
|
@@ -182,14 +183,14 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
182
183
|
_utils.default.CollectionPage.duplicateEntry(config.collectionName, formData, entry.id, ((_config$card = config.card) === null || _config$card === void 0 || (_config$card = _config$card.duplicateAction) === null || _config$card === void 0 ? void 0 : _config$card.fieldsToIgnore) || [], {
|
|
183
184
|
isDuplicate: true
|
|
184
185
|
});
|
|
185
|
-
var
|
|
186
|
+
var topLevelCollectionName = config.collectionName.split('.').shift();
|
|
186
187
|
// Report the whole top-level collection as being changed. We have to do this
|
|
187
188
|
// because of how patch is applied to formData on a page submission.
|
|
188
|
-
if (typeof
|
|
189
|
-
|
|
189
|
+
if (typeof onTopLevelChange === 'function') {
|
|
190
|
+
onTopLevelChange({
|
|
190
191
|
target: {
|
|
191
|
-
name:
|
|
192
|
-
value: _utils.default.CollectionPage.getData(
|
|
192
|
+
name: topLevelCollectionName,
|
|
193
|
+
value: _utils.default.CollectionPage.getData(topLevelCollectionName, formData)
|
|
193
194
|
}
|
|
194
195
|
});
|
|
195
196
|
validateEntries();
|
|
@@ -200,14 +201,14 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
200
201
|
return;
|
|
201
202
|
}
|
|
202
203
|
_utils.default.CollectionPage.removeEntry(config.collectionName, formData, entryToDelete.id);
|
|
203
|
-
var
|
|
204
|
+
var topLevelCollectionName = config.collectionName.split('.').shift();
|
|
204
205
|
// Report the whole top-level collection as being changed. We have to do this
|
|
205
206
|
// because of how patch is applied to formData on a page submission.
|
|
206
|
-
if (typeof
|
|
207
|
-
|
|
207
|
+
if (typeof onTopLevelChange === 'function') {
|
|
208
|
+
onTopLevelChange({
|
|
208
209
|
target: {
|
|
209
|
-
name:
|
|
210
|
-
value: _utils.default.CollectionPage.getData(
|
|
210
|
+
name: topLevelCollectionName,
|
|
211
|
+
value: _utils.default.CollectionPage.getData(topLevelCollectionName, formData)
|
|
211
212
|
}
|
|
212
213
|
});
|
|
213
214
|
}
|
|
@@ -362,12 +363,14 @@ CollectionSummary.propTypes = {
|
|
|
362
363
|
}).isRequired,
|
|
363
364
|
onAction: _propTypes.default.func,
|
|
364
365
|
onChange: _propTypes.default.func,
|
|
366
|
+
onTopLevelChange: _propTypes.default.func,
|
|
365
367
|
formData: _propTypes.default.shape({}).isRequired,
|
|
366
368
|
pages: _propTypes.default.arrayOf(_propTypes.default.shape({}))
|
|
367
369
|
};
|
|
368
370
|
CollectionSummary.defaultProps = {
|
|
369
371
|
onAction: null,
|
|
370
372
|
onChange: null,
|
|
373
|
+
onTopLevelChange: null,
|
|
371
374
|
pages: []
|
|
372
375
|
};
|
|
373
376
|
var _default = exports.default = CollectionSummary;
|
|
@@ -302,7 +302,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
302
302
|
setData(newData);
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
|
-
if (((_formState$page3 = formState.page) === null || _formState$page3 === void 0 ? void 0 : _formState$page3.type) === _models.FormPages.PARTIAL_CYA) {
|
|
305
|
+
if (((_formState$page3 = formState.page) === null || _formState$page3 === void 0 ? void 0 : _formState$page3.type) === _models.FormPages.PARTIAL_CYA && !cya.disableTaskSwitch) {
|
|
306
306
|
hubDetails.sections.every(function (section) {
|
|
307
307
|
return section.tasks.every(function (task) {
|
|
308
308
|
if (task.pages.includes(page.pageId) && task.name !== currentTask.name) {
|
|
@@ -383,7 +383,8 @@ var propTypes = {
|
|
|
383
383
|
className: _propTypes.default.string,
|
|
384
384
|
components: _propTypes.default.arrayOf(_propTypes.default.shape({})).isRequired,
|
|
385
385
|
cya: _propTypes.default.shape({
|
|
386
|
-
actions: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({}), _propTypes.default.string]))
|
|
386
|
+
actions: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({}), _propTypes.default.string])),
|
|
387
|
+
disableTaskSwitch: _propTypes.default.bool
|
|
387
388
|
}),
|
|
388
389
|
data: _propTypes.default.shape({
|
|
389
390
|
formStatus: _propTypes.default.shape({
|
|
@@ -412,7 +413,8 @@ var defaultProps = {
|
|
|
412
413
|
className: '',
|
|
413
414
|
classModifiers: [],
|
|
414
415
|
cya: {
|
|
415
|
-
actions: []
|
|
416
|
+
actions: [],
|
|
417
|
+
disableTaskSwitch: false
|
|
416
418
|
},
|
|
417
419
|
data: null,
|
|
418
420
|
hashLink: false,
|
|
@@ -112,7 +112,6 @@ var ValidationContextProvider = function ValidationContextProvider(_ref) {
|
|
|
112
112
|
var pageErrors = _utils.default.Validate.page(_page, queuedErrors);
|
|
113
113
|
var allErrors = hooks.onValidate(_page, pageErrors);
|
|
114
114
|
setErrors(allErrors);
|
|
115
|
-
setQueuedErrors([]);
|
|
116
115
|
return allErrors;
|
|
117
116
|
},
|
|
118
117
|
pages: function pages(_pages) {
|
|
@@ -123,7 +122,6 @@ var ValidationContextProvider = function ValidationContextProvider(_ref) {
|
|
|
123
122
|
return hooks.onValidate(page, pageErrors[index]);
|
|
124
123
|
});
|
|
125
124
|
setErrors(allErrors);
|
|
126
|
-
setQueuedErrors([]);
|
|
127
125
|
return allErrors;
|
|
128
126
|
}
|
|
129
127
|
};
|
|
@@ -8,6 +8,7 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
|
8
8
|
var _validateComponent = _interopRequireDefault(require("./validateComponent"));
|
|
9
9
|
var _CollectionPage = _interopRequireDefault(require("../CollectionPage"));
|
|
10
10
|
var _showFormPage = _interopRequireDefault(require("../FormPage/showFormPage"));
|
|
11
|
+
var _showComponent = _interopRequireDefault(require("../Component/showComponent"));
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
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); }
|
|
13
14
|
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; }
|
|
@@ -34,6 +35,9 @@ var validatePage = function validatePage(page) {
|
|
|
34
35
|
}
|
|
35
36
|
if ((0, _showFormPage.default)(page, data) && Array.isArray(page.components)) {
|
|
36
37
|
var errs = page.components.reduce(function (errors, component) {
|
|
38
|
+
if (!(0, _showComponent.default)(component, data)) {
|
|
39
|
+
return errors;
|
|
40
|
+
}
|
|
37
41
|
var queuedComponentErrors = queuedErrors.length > 0 ? queuedErrors.filter(function (e) {
|
|
38
42
|
return e.showFor ? e.showFor === component.id : e.id === component.id;
|
|
39
43
|
}) : [];
|
|
@@ -762,5 +762,30 @@ describe('utils.Validate.Page', function () {
|
|
|
762
762
|
expect(RESULT[0]).toEqual(_objectSpread({}, QUEUED_ERRORS[0]));
|
|
763
763
|
expect(RESULT[1]).toEqual(_objectSpread({}, QUEUED_ERRORS[1]));
|
|
764
764
|
});
|
|
765
|
+
it('should return any queued errors if the component is not shown', function () {
|
|
766
|
+
var COMPONENTS = [_objectSpread(_objectSpread({}, setup('a', _models.ComponentTypes.TEXT, 'Alpha', true)), {}, {
|
|
767
|
+
show_when: [{
|
|
768
|
+
field: 'b',
|
|
769
|
+
op: '=',
|
|
770
|
+
value: 'yes'
|
|
771
|
+
}]
|
|
772
|
+
})];
|
|
773
|
+
var PAGE = {
|
|
774
|
+
components: COMPONENTS,
|
|
775
|
+
formData: {
|
|
776
|
+
a: 'Value',
|
|
777
|
+
b: 'no'
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
var QUEUED_ERRORS = [{
|
|
781
|
+
id: 'a',
|
|
782
|
+
error: 'Error queued for Alpha 1'
|
|
783
|
+
}, {
|
|
784
|
+
id: 'a',
|
|
785
|
+
error: 'Error queued for Alpha 2'
|
|
786
|
+
}];
|
|
787
|
+
var RESULT = (0, _validatePage.default)(PAGE, QUEUED_ERRORS);
|
|
788
|
+
expect(RESULT.length).toEqual(0);
|
|
789
|
+
});
|
|
765
790
|
});
|
|
766
791
|
});
|