@ukhomeoffice/cop-react-form-renderer 4.73.0 → 4.74.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/dist/components/FormRenderer/handlers/navigate.js +3 -1
- package/dist/components/FormRenderer/onPageAction.js +7 -4
- package/dist/components/FormRenderer/onPageAction.test.js +38 -2
- package/dist/utils/Operate/getFirstOf.test.js +1 -1
- package/dist/utils/Operate/setValueInFormData.test.js +1 -1
- package/package.json +1 -1
|
@@ -12,8 +12,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
* @param {object} action The invoked action.
|
|
13
13
|
* @param {string} currentPageId The current pageId.
|
|
14
14
|
* @param {Function} onNavigate The handler to call if the pageId is different to the currentPageId.
|
|
15
|
+
* @param {object|undefined} state State to pass to the handler on change
|
|
15
16
|
*/
|
|
16
|
-
var navigate = function navigate(action, currentPageId, onNavigate
|
|
17
|
+
var navigate = function navigate(action, currentPageId, onNavigate) {
|
|
18
|
+
var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
|
|
17
19
|
var pageId = (0, _getPageId.default)(action, currentPageId);
|
|
18
20
|
if (pageId !== currentPageId) {
|
|
19
21
|
onNavigate(pageId, state);
|
|
@@ -24,18 +24,21 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
24
24
|
hooks.onCancel();
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
// Save a copy of data in case submit errors and we need to revert
|
|
27
|
+
// Save a copy of data in case submit errors, and we need to revert
|
|
28
28
|
var preSubmitData = _objectSpread({}, data);
|
|
29
29
|
// Re-apply the patch to the page's formData.
|
|
30
30
|
// This should normally have no effect but will prevent issues
|
|
31
31
|
// with validation if formData happens to have been wiped.
|
|
32
32
|
formState.page.formData = _objectSpread(_objectSpread({}, formState.page.formData), patch);
|
|
33
|
-
// Check to see whether the action is able to proceed
|
|
34
|
-
// in the case of a submission will validate the fields in the page.
|
|
33
|
+
// Check to see whether the action is able to proceed
|
|
34
|
+
// which in the case of a submission will validate the fields in the page.
|
|
35
35
|
if (_helpers.default.canActionProceed(action, formState.page, validate.page)) {
|
|
36
36
|
patch = _helpers.default.cleanHiddenNestedData(patch, formState.page);
|
|
37
37
|
if (action.addToFormData) {
|
|
38
|
-
|
|
38
|
+
var operations = Array.isArray(action.addToFormData) ? action.addToFormData : [action.addToFormData];
|
|
39
|
+
operations.forEach(function (op) {
|
|
40
|
+
_utils.default.Data.setDataItem(formState.page.formData, op.field, op.value);
|
|
41
|
+
});
|
|
39
42
|
}
|
|
40
43
|
if (action.type === _models.PageAction.TYPES.NAVIGATE) {
|
|
41
44
|
_handlers.default.navigate(action, pageId, onPageChange);
|
|
@@ -71,7 +71,8 @@ jest.mock('./helpers', function () {
|
|
|
71
71
|
};
|
|
72
72
|
});
|
|
73
73
|
jest.mock('../../utils', function () {
|
|
74
|
-
|
|
74
|
+
var originalModule = jest.requireActual('../../utils');
|
|
75
|
+
return _objectSpread(_objectSpread({}, originalModule.default), {}, {
|
|
75
76
|
Format: {
|
|
76
77
|
formCalls: 0,
|
|
77
78
|
form: function form(_form, data, eventType) {
|
|
@@ -92,7 +93,7 @@ jest.mock('../../utils', function () {
|
|
|
92
93
|
this.CollectionPage.duplicateActiveEntryCalls = 0;
|
|
93
94
|
this.duplicateActiveEntryResult = true;
|
|
94
95
|
}
|
|
95
|
-
};
|
|
96
|
+
});
|
|
96
97
|
});
|
|
97
98
|
describe('components.FormRenderer.onPageAction', function () {
|
|
98
99
|
var MOCK_HOOKS = {
|
|
@@ -594,6 +595,41 @@ describe('components.FormRenderer.onPageAction', function () {
|
|
|
594
595
|
alpha: '123'
|
|
595
596
|
});
|
|
596
597
|
});
|
|
598
|
+
it('should work for an array of formData', function () {
|
|
599
|
+
var FORM_STATE = {
|
|
600
|
+
page: {
|
|
601
|
+
formData: {
|
|
602
|
+
testCollection: []
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
var ACTION = {
|
|
607
|
+
type: _models.PageAction.TYPES.NAVIGATE,
|
|
608
|
+
collection: 'testCollection',
|
|
609
|
+
addToFormData: [{
|
|
610
|
+
field: 'alpha',
|
|
611
|
+
value: '123'
|
|
612
|
+
}, {
|
|
613
|
+
field: 'beta.gamma',
|
|
614
|
+
value: '456'
|
|
615
|
+
}]
|
|
616
|
+
};
|
|
617
|
+
var CUSTOM_ARGS = _objectSpread(_objectSpread({}, ARGS), {}, {
|
|
618
|
+
formState: FORM_STATE,
|
|
619
|
+
action: ACTION
|
|
620
|
+
});
|
|
621
|
+
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
622
|
+
preActionChecks();
|
|
623
|
+
// Not doing the usual post-action checks here
|
|
624
|
+
// as a navigate action should stop at calling
|
|
625
|
+
// hooks.navigate.
|
|
626
|
+
expect(FORM_STATE.page.formData).toMatchObject({
|
|
627
|
+
alpha: '123',
|
|
628
|
+
beta: {
|
|
629
|
+
gamma: '456'
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
});
|
|
597
633
|
});
|
|
598
634
|
describe('recording patchLabel fields correctly when it is defined', function () {
|
|
599
635
|
var VALID_ACTIONS = Object.values(_models.PageAction.TYPES).filter(function (a) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _getFirstOf = _interopRequireDefault(require("./getFirstOf"));
|
|
4
4
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
-
describe('Utils.Operate.
|
|
5
|
+
describe('Utils.Operate.getFirstOf', function () {
|
|
6
6
|
var DATA = {
|
|
7
7
|
name: 'sam',
|
|
8
8
|
id: 1,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _setValueInFormData = _interopRequireDefault(require("./setValueInFormData"));
|
|
4
4
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
-
describe('Utils.Operate.
|
|
5
|
+
describe('Utils.Operate.setValueInFormData', function () {
|
|
6
6
|
var DATA = {
|
|
7
7
|
a: '1',
|
|
8
8
|
b: ['2', '3'],
|