@ukhomeoffice/cop-react-form-renderer 4.88.0 → 4.89.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.
|
@@ -273,7 +273,13 @@ describe('components', function () {
|
|
|
273
273
|
}]);
|
|
274
274
|
};
|
|
275
275
|
HOOKS = {
|
|
276
|
-
onSubmit: ON_SUBMIT
|
|
276
|
+
onSubmit: ON_SUBMIT,
|
|
277
|
+
onAction: function onAction(formData, patch) {
|
|
278
|
+
return {
|
|
279
|
+
formData: formData,
|
|
280
|
+
patch: patch
|
|
281
|
+
};
|
|
282
|
+
}
|
|
277
283
|
};
|
|
278
284
|
_context10.next = 5;
|
|
279
285
|
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
@@ -27,16 +27,19 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
27
27
|
;
|
|
28
28
|
// Save a copy of data in case submit errors and we need to revert
|
|
29
29
|
var preSubmitData = _objectSpread({}, data);
|
|
30
|
+
var form = formState;
|
|
31
|
+
var update = hooks.onAction(form.page.formData, patch, data, action.customAction);
|
|
32
|
+
form.page.formData = update.formData;
|
|
33
|
+
var _patch = update.patch;
|
|
34
|
+
|
|
30
35
|
// Re-apply the patch to the page's formData.
|
|
31
36
|
// This should normally have no effect but will prevent issues
|
|
32
37
|
// with validation if formData happens to have been wiped.
|
|
33
|
-
|
|
34
|
-
form.page.formData = _objectSpread(_objectSpread({}, form.page.formData), patch);
|
|
38
|
+
form.page.formData = _objectSpread(_objectSpread({}, form.page.formData), _patch);
|
|
35
39
|
// Check to see whether the action is able to proceed, which in
|
|
36
40
|
// in the case of a submission will validate the fields in the page.
|
|
37
41
|
if (_helpers.default.canActionProceed(action, form.page, validate.page)) {
|
|
38
|
-
|
|
39
|
-
_patch = _helpers.default.cleanHiddenNestedData(patch, form.page);
|
|
42
|
+
_patch = _helpers.default.cleanHiddenNestedData(_patch, form.page);
|
|
40
43
|
if (action.addToFormData) {
|
|
41
44
|
var operations = Array.isArray(action.addToFormData) ? action.addToFormData : [action.addToFormData];
|
|
42
45
|
operations.forEach(function (op) {
|
|
@@ -130,6 +130,15 @@ describe('components.FormRenderer.onPageAction', function () {
|
|
|
130
130
|
this.onSubmitArgs = [];
|
|
131
131
|
this.onFormCompleteCalls = 0;
|
|
132
132
|
this.onCancelCalls = 0;
|
|
133
|
+
this.onActionCalls = 0;
|
|
134
|
+
},
|
|
135
|
+
onActionCalls: 0,
|
|
136
|
+
onAction: function onAction(formData, patch) {
|
|
137
|
+
this.onActionCalls += 1;
|
|
138
|
+
return {
|
|
139
|
+
formData: formData,
|
|
140
|
+
patch: patch
|
|
141
|
+
};
|
|
133
142
|
}
|
|
134
143
|
};
|
|
135
144
|
var MOCK_VALIDATE = {
|
|
@@ -260,6 +269,7 @@ describe('components.FormRenderer.onPageAction', function () {
|
|
|
260
269
|
changedFieldValue: argsUsed.patchLabel[firstKey]
|
|
261
270
|
});
|
|
262
271
|
}
|
|
272
|
+
expect(MOCK_HOOKS.onActionCalls).toEqual(1);
|
|
263
273
|
|
|
264
274
|
// Both the success and error paths of the onSubmit hook are tested
|
|
265
275
|
// together to make sure the correct function chains are called for
|
|
@@ -22,6 +22,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
22
22
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
23
23
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
24
24
|
var DEFAULT_HOOKS = {
|
|
25
|
+
onAction: function onAction(formData, patch) {
|
|
26
|
+
return {
|
|
27
|
+
formData: formData,
|
|
28
|
+
patch: patch
|
|
29
|
+
};
|
|
30
|
+
},
|
|
25
31
|
onChange: function onChange(data) {},
|
|
26
32
|
onFormComplete: function onFormComplete() {},
|
|
27
33
|
onFormLoad: function onFormLoad(setCurrentTask) {},
|
|
@@ -61,6 +67,7 @@ var HooksContextProvider = function HooksContextProvider(_ref) {
|
|
|
61
67
|
var overrides = _ref.overrides,
|
|
62
68
|
children = _ref.children;
|
|
63
69
|
var _useState = (0, _react.useState)({
|
|
70
|
+
onAction: (overrides === null || overrides === void 0 ? void 0 : overrides.onAction) || DEFAULT_HOOKS.onAction,
|
|
64
71
|
onChange: (overrides === null || overrides === void 0 ? void 0 : overrides.onChange) || DEFAULT_HOOKS.onChange,
|
|
65
72
|
onFormComplete: (overrides === null || overrides === void 0 ? void 0 : overrides.onFormComplete) || DEFAULT_HOOKS.onFormComplete,
|
|
66
73
|
onFormLoad: (overrides === null || overrides === void 0 ? void 0 : overrides.onFormLoad) || DEFAULT_HOOKS.onFormLoad,
|
|
@@ -104,6 +111,7 @@ exports.default = _default;
|
|
|
104
111
|
HooksContextProvider.propTypes = {
|
|
105
112
|
children: _propTypes.default.node,
|
|
106
113
|
overrides: _propTypes.default.shape({
|
|
114
|
+
onAction: _propTypes.default.func,
|
|
107
115
|
onCancel: _propTypes.default.func,
|
|
108
116
|
onChange: _propTypes.default.func,
|
|
109
117
|
onFormComplete: _propTypes.default.func,
|
|
@@ -121,6 +129,7 @@ HooksContextProvider.propTypes = {
|
|
|
121
129
|
HooksContextProvider.defaultProps = {
|
|
122
130
|
children: null,
|
|
123
131
|
overrides: {
|
|
132
|
+
onAction: undefined,
|
|
124
133
|
onCancel: undefined,
|
|
125
134
|
onChange: undefined,
|
|
126
135
|
onFormComplete: undefined,
|