@ukhomeoffice/cop-react-form-renderer 6.15.16 → 6.16.0-beta
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/FormRenderer.js +16 -0
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +14 -17
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +0 -31
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutesUtils.js +35 -44
- package/package.json +2 -2
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-hidden-component-with-nested-questions-visible-elsewhere.json +0 -118
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-nested-answers-hidden-by-option-visible-elsewhere.json +0 -113
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/forms/form-page-nested-component.json +0 -26003
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-hidden-component-with-nested-questions-visible-elsewhere.json +0 -12
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-nested-answers-hidden-by-option-visible-elsewhere.json +0 -12
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/input/data-page-nested-component.json +0 -63
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-hidden-component-with-nested-questions-visible-elsewhere-removed.json +0 -11
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-nested-answers-hidden-by-option-visible-elsewhere-removed.json +0 -12
- package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/output/data-page-nested-component.json +0 -63
|
@@ -129,6 +129,17 @@ const InternalFormRenderer = _ref2 => {
|
|
|
129
129
|
validate
|
|
130
130
|
} = (0, _hooks.useValidation)();
|
|
131
131
|
|
|
132
|
+
// Set focus to header for accessibility, Screen reader to anounce the page heading
|
|
133
|
+
const setFocusToHeading = () => {
|
|
134
|
+
if (document) {
|
|
135
|
+
const header = Array.from(document.getElementsByTagName('h1')).pop();
|
|
136
|
+
if (header && document.activeElement !== header) {
|
|
137
|
+
header.setAttribute('tabIndex', '-1');
|
|
138
|
+
header.focus();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
132
143
|
// Need to set submission data when going back
|
|
133
144
|
window.onpopstate = e => {
|
|
134
145
|
var _formState$page;
|
|
@@ -192,6 +203,11 @@ const InternalFormRenderer = _ref2 => {
|
|
|
192
203
|
setHub(_utils.default.Hub.get(type, _hub, components, _objectSpread({}, data)));
|
|
193
204
|
}, [type, _hub, data, components, setHub]);
|
|
194
205
|
|
|
206
|
+
// Set focus to heading for accessibility
|
|
207
|
+
(0, _react.useEffect)(() => {
|
|
208
|
+
setFocusToHeading();
|
|
209
|
+
}, [formState]);
|
|
210
|
+
|
|
195
211
|
// Form state.
|
|
196
212
|
(0, _react.useEffect)(() => {
|
|
197
213
|
var _formState$page2;
|
|
@@ -42,7 +42,6 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
|
42
42
|
const createComponentMapsFromForm = (condensedPages, componentByIdMap, componentByFieldIdMap, formData) => {
|
|
43
43
|
const allComponents = new Map();
|
|
44
44
|
const componentsToKeep = {};
|
|
45
|
-
const unselectedOptionsNestedPaths = [];
|
|
46
45
|
const allCollections = new Map();
|
|
47
46
|
|
|
48
47
|
/*
|
|
@@ -69,14 +68,20 @@ const createComponentMapsFromForm = (condensedPages, componentByIdMap, component
|
|
|
69
68
|
var _component$data2;
|
|
70
69
|
component === null || component === void 0 || (_component$data2 = component.data) === null || _component$data2 === void 0 || (_component$data2 = _component$data2.options) === null || _component$data2 === void 0 || _component$data2.forEach(option => {
|
|
71
70
|
if (option.nested) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
// in container need to use the JPath for the data since the field that the component is looking at is nested in the container.
|
|
72
|
+
if (!(0, _optionIsSelected.default)((0, _getSourceData.default)(formData, path), option)) {
|
|
73
|
+
option.nested.forEach(nestedComponent => {
|
|
74
|
+
// delete hidden nested question payload items when the parent option is not selected
|
|
75
|
+
Utils.deleteNodeByPath(formData, Utils.getNestedQuestionPath(path, nestedComponent.fieldId));
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
// If the option is selected, then add any nested components to the allComponents list. If the nested block has a show_when, pass it down to the child questions
|
|
79
|
+
const blockShowWhen = option.show_when;
|
|
80
|
+
option.nested.forEach(nestedComponent => {
|
|
81
|
+
if (blockShowWhen) nestedComponent.show_when = blockShowWhen;
|
|
82
|
+
recursivelyMapFieldsAndDeleteHiddenNested(page, nestedComponent, Utils.getImmediateParent(path), allComponents, componentsToKeep, formData);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
80
85
|
}
|
|
81
86
|
});
|
|
82
87
|
}
|
|
@@ -95,14 +100,6 @@ const createComponentMapsFromForm = (condensedPages, componentByIdMap, component
|
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
102
|
});
|
|
98
|
-
// Now delete all the unselected options, if they are not used elsewhere
|
|
99
|
-
unselectedOptionsNestedPaths.forEach(path => {
|
|
100
|
-
if (componentsToKeep[path] > 1) {
|
|
101
|
-
componentsToKeep[path] -= 1;
|
|
102
|
-
} else {
|
|
103
|
-
Utils.deleteNodeByPath(formData, path);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
103
|
return {
|
|
107
104
|
allComponents,
|
|
108
105
|
componentsToKeep,
|
|
@@ -31,15 +31,9 @@ var _dataHiddenOptionsRemoved = _interopRequireDefault(require("../clear-uncompl
|
|
|
31
31
|
var _formHiddenComponentWithNestedQuestions = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-hidden-component-with-nested-questions.json"));
|
|
32
32
|
var _dataHiddenComponentWithNestedQuestions = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-hidden-component-with-nested-questions.json"));
|
|
33
33
|
var _dataHiddenComponentWithNestedQuestionsRemoved = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-hidden-component-with-nested-questions-removed.json"));
|
|
34
|
-
var _formHiddenComponentWithNestedQuestionsVisibleElsewhere = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-hidden-component-with-nested-questions-visible-elsewhere.json"));
|
|
35
|
-
var _dataHiddenComponentWithNestedQuestionsVisibleElsewhere = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-hidden-component-with-nested-questions-visible-elsewhere.json"));
|
|
36
|
-
var _dataHiddenComponentWithNestedQuestionsVisibleElsewhereRemoved = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-hidden-component-with-nested-questions-visible-elsewhere-removed.json"));
|
|
37
34
|
var _formNestedAnswersHiddenByOption = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-nested-answers-hidden-by-option.json"));
|
|
38
35
|
var _dataNestedAnswersHiddenByOption = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-nested-answers-hidden-by-option.json"));
|
|
39
36
|
var _dataNestedAnswersHiddenByOptionRemoved = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-nested-answers-hidden-by-option-removed.json"));
|
|
40
|
-
var _formNestedAnswersHiddenByOptionVisibleElsewhere = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-nested-answers-hidden-by-option-visible-elsewhere.json"));
|
|
41
|
-
var _dataNestedAnswersHiddenByOptionVisibleElsewhere = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-nested-answers-hidden-by-option-visible-elsewhere.json"));
|
|
42
|
-
var _dataNestedAnswersHiddenByOptionVisibleElsewhereRemoved = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-nested-answers-hidden-by-option-visible-elsewhere-removed.json"));
|
|
43
37
|
var _formHiddenPage = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-hidden-page.json"));
|
|
44
38
|
var _dataHiddenPage = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-hidden-page.json"));
|
|
45
39
|
var _dataHiddenPageRemoved = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-hidden-page-removed.json"));
|
|
@@ -105,9 +99,6 @@ var _copAirpaxCarrier = _interopRequireDefault(require("../clear-uncompleted-rou
|
|
|
105
99
|
var _formPageNestedRadioComponent = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-page-nested-radio-component.json"));
|
|
106
100
|
var _dataPageNestedRadioComponent = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-page-nested-radio-component.json"));
|
|
107
101
|
var _dataPageNestedRadioComponentRemoved = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-page-nested-radio-component-removed.json"));
|
|
108
|
-
var _formPageNestedComponent = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-page-nested-component.json"));
|
|
109
|
-
var _dataPageNestedComponent = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-page-nested-component.json"));
|
|
110
|
-
var _dataPageNestedComponent2 = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-page-nested-component.json"));
|
|
111
102
|
var _formVarianceBreach = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-variance-breach.json"));
|
|
112
103
|
var _copVarianceBreachWithUploadFiles = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/cop-variance-breach-with-upload-files.json"));
|
|
113
104
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -131,12 +122,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
131
122
|
|
|
132
123
|
// Nested questions within options inside a hidden component
|
|
133
124
|
|
|
134
|
-
// Nested questions within options inside a hidden component, but one nested path visible elsewhere
|
|
135
|
-
|
|
136
125
|
// Nested options inside a visible component, but answers don't align with option selected
|
|
137
126
|
|
|
138
|
-
// Nested options inside a visible component, answers don't align with option selected, but path visible elsewhere
|
|
139
|
-
|
|
140
127
|
// Hidden page
|
|
141
128
|
|
|
142
129
|
// Hidden page containing same component reused
|
|
@@ -256,24 +243,12 @@ describe('FormRenderer', () => {
|
|
|
256
243
|
const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
|
|
257
244
|
expect(result).toEqual(_dataHiddenComponentWithNestedQuestionsRemoved.default);
|
|
258
245
|
});
|
|
259
|
-
it('should NOT remove hidden component with nested questions in options when same path is visible elsewhere.', () => {
|
|
260
|
-
const submissionData = JSON.parse(JSON.stringify(_dataHiddenComponentWithNestedQuestionsVisibleElsewhere.default));
|
|
261
|
-
const form = JSON.parse(JSON.stringify(_formHiddenComponentWithNestedQuestionsVisibleElsewhere.default));
|
|
262
|
-
const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
|
|
263
|
-
expect(result).toEqual(_dataHiddenComponentWithNestedQuestionsVisibleElsewhereRemoved.default);
|
|
264
|
-
});
|
|
265
246
|
it('should remove answers associated with unselected options in a containerised component.', () => {
|
|
266
247
|
const submissionData = JSON.parse(JSON.stringify(_dataNestedAnswersHiddenByOption.default));
|
|
267
248
|
const form = JSON.parse(JSON.stringify(_formNestedAnswersHiddenByOption.default));
|
|
268
249
|
const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
|
|
269
250
|
expect(result).toEqual(_dataNestedAnswersHiddenByOptionRemoved.default);
|
|
270
251
|
});
|
|
271
|
-
it('should NOT remove answers associated with unselected options in a containerised component if component visible elsewhere.', () => {
|
|
272
|
-
const submissionData = JSON.parse(JSON.stringify(_dataNestedAnswersHiddenByOptionVisibleElsewhere.default));
|
|
273
|
-
const form = JSON.parse(JSON.stringify(_formNestedAnswersHiddenByOptionVisibleElsewhere.default));
|
|
274
|
-
const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
|
|
275
|
-
expect(result).toEqual(_dataNestedAnswersHiddenByOptionVisibleElsewhereRemoved.default);
|
|
276
|
-
});
|
|
277
252
|
it('should remove hidden page.', () => {
|
|
278
253
|
const submissionData = JSON.parse(JSON.stringify(_dataHiddenPage.default));
|
|
279
254
|
const form = JSON.parse(JSON.stringify(_formHiddenPage.default));
|
|
@@ -422,12 +397,6 @@ describe('FormRenderer', () => {
|
|
|
422
397
|
const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
|
|
423
398
|
expect(result).toEqual(_dataPageNestedRadioComponentRemoved.default);
|
|
424
399
|
});
|
|
425
|
-
it('should handle not removing the field if its used both nested option and a separate component.', () => {
|
|
426
|
-
const submissionData = JSON.parse(JSON.stringify(_dataPageNestedComponent.default));
|
|
427
|
-
const form = JSON.parse(JSON.stringify(_formPageNestedComponent.default));
|
|
428
|
-
const result = _index.default.clearOutUncompletedRoutes(true, form, submissionData);
|
|
429
|
-
expect(result).toEqual(_dataPageNestedComponent2.default);
|
|
430
|
-
});
|
|
431
400
|
});
|
|
432
401
|
});
|
|
433
402
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.toArray = exports.removeObjectWithOnlySingleIdField = exports.removeEmptyArraysAndUnusedCollectionIDs = exports.pruneCollectionEntry = exports.
|
|
6
|
+
exports.toArray = exports.removeObjectWithOnlySingleIdField = exports.removeEmptyArraysAndUnusedCollectionIDs = exports.pruneCollectionEntry = exports.isShowEntity = exports.getNestedQuestionPath = exports.getImmediateParent = exports.getDependencyObjectFromPath = exports.getDependencies = exports.findComponentDefinitionInForm = exports.deleteNodeByPath = exports.deleteNodeAndOptions = exports.deleteCorrespondingMetaInfo = exports.deleteComponentData = exports.addValue = void 0;
|
|
7
7
|
var _Condition = _interopRequireDefault(require("../../../utils/Condition"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
/* eslint-disable no-param-reassign */
|
|
@@ -85,6 +85,36 @@ const getNestedQuestionPath = (optionPath, nestedFieldId) => {
|
|
|
85
85
|
return parentPath ? "".concat(parentPath, ".").concat(nestedFieldId) : nestedFieldId;
|
|
86
86
|
};
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* If the component has options, go through each option removing the data for any nested fields.
|
|
90
|
+
* Required as nested options are in the payload at the same heirarchical level.
|
|
91
|
+
*
|
|
92
|
+
* There are occasions when a field shouldn't be removed from the payload, eg if a form is being used for 2 purposes
|
|
93
|
+
* eg the cop-reassign-task-to-rcc.json, and the field is only being hidden for display purposes. Allow these fields
|
|
94
|
+
* to be preserved with a property on the component.
|
|
95
|
+
|
|
96
|
+
* @param {Object} payload Javascript object from which the node will be deleted. Updated by the method.
|
|
97
|
+
* @param {String} path A string containing a decimal point delimited path specifying the node to delete.
|
|
98
|
+
* @param {Object} component The form component representing the path being deleted
|
|
99
|
+
* @return {void}, obj above updated.
|
|
100
|
+
*/
|
|
101
|
+
exports.getNestedQuestionPath = getNestedQuestionPath;
|
|
102
|
+
const deleteNodeAndOptions = (payload, path, component) => {
|
|
103
|
+
var _component$data;
|
|
104
|
+
if (component.preserveInPayload) return;
|
|
105
|
+
deleteNodeByPath(payload, path);
|
|
106
|
+
// If the component has options, go through each option removing the data for any nested fields. Required as nested options are in the payload at the same heirarchical level.
|
|
107
|
+
if (component !== null && component !== void 0 && (_component$data = component.data) !== null && _component$data !== void 0 && _component$data.options) {
|
|
108
|
+
var _component$data2;
|
|
109
|
+
component === null || component === void 0 || (_component$data2 = component.data) === null || _component$data2 === void 0 || (_component$data2 = _component$data2.options) === null || _component$data2 === void 0 || _component$data2.forEach(option => {
|
|
110
|
+
var _option$nested;
|
|
111
|
+
(_option$nested = option.nested) === null || _option$nested === void 0 || _option$nested.forEach(nested => {
|
|
112
|
+
deleteNodeByPath(payload, getNestedQuestionPath(path, nested.fieldId));
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
88
118
|
/**
|
|
89
119
|
* Pruning a collection payload may have resulted in objects that are only left with their 'id' field, which isn't data
|
|
90
120
|
* but added by the renderer to find the activeId. If so, remove these objects entirely as they have been pruned.
|
|
@@ -92,7 +122,7 @@ const getNestedQuestionPath = (optionPath, nestedFieldId) => {
|
|
|
92
122
|
* @param {Array} array Array of objects. Each object which has only 1 remaining field called 'id' should be removed.
|
|
93
123
|
* @return {void}, array above updated.
|
|
94
124
|
*/
|
|
95
|
-
exports.
|
|
125
|
+
exports.deleteNodeAndOptions = deleteNodeAndOptions;
|
|
96
126
|
const removeObjectWithOnlySingleIdField = array => {
|
|
97
127
|
for (let i = array.length - 1; i >= 0; i -= 1) {
|
|
98
128
|
const obj = array[i];
|
|
@@ -303,24 +333,6 @@ const removeEmptyArraysAndUnusedCollectionIDs = payload => {
|
|
|
303
333
|
}
|
|
304
334
|
};
|
|
305
335
|
|
|
306
|
-
/**
|
|
307
|
-
* Helper method to go through each option calling a passed in function for any nested fields.
|
|
308
|
-
* @param {Object} component The form component representing the path being deleted
|
|
309
|
-
* @param {Function} action The action to perform on each nested question. Varies for collections and non-collections
|
|
310
|
-
* @return {void}, obj above updated.
|
|
311
|
-
*/
|
|
312
|
-
exports.removeEmptyArraysAndUnusedCollectionIDs = removeEmptyArraysAndUnusedCollectionIDs;
|
|
313
|
-
const iterateOptions = (component, action) => {
|
|
314
|
-
var _component$data;
|
|
315
|
-
if (component !== null && component !== void 0 && (_component$data = component.data) !== null && _component$data !== void 0 && _component$data.options) {
|
|
316
|
-
var _component$data2;
|
|
317
|
-
component === null || component === void 0 || (_component$data2 = component.data) === null || _component$data2 === void 0 || (_component$data2 = _component$data2.options) === null || _component$data2 === void 0 || _component$data2.forEach(option => {
|
|
318
|
-
var _option$nested;
|
|
319
|
-
(_option$nested = option.nested) === null || _option$nested === void 0 || _option$nested.forEach(action);
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
|
|
324
336
|
/**
|
|
325
337
|
* Delete a component's payload item from the overall payload.
|
|
326
338
|
* A component can be defined in >1 places in the form spec. To cater for this,
|
|
@@ -336,23 +348,12 @@ const iterateOptions = (component, action) => {
|
|
|
336
348
|
* @param {*} component The component whose data we should attempt to delete
|
|
337
349
|
* @param {*} componentsToKeep A list of all components with a count of their number of uses in the form
|
|
338
350
|
*/
|
|
339
|
-
exports.
|
|
351
|
+
exports.removeEmptyArraysAndUnusedCollectionIDs = removeEmptyArraysAndUnusedCollectionIDs;
|
|
340
352
|
const deleteComponentData = (payload, path, component, componentsToKeep) => {
|
|
341
353
|
if (componentsToKeep[path] > 1) {
|
|
342
354
|
componentsToKeep[path] -= 1;
|
|
343
355
|
} else {
|
|
344
|
-
|
|
345
|
-
deleteNodeByPath(payload, path);
|
|
346
|
-
|
|
347
|
-
// If the component has options, go through each option removing the data for any nested fields. Required as nested options are in the payload at the same heirarchical level.
|
|
348
|
-
iterateOptions(component, nested => {
|
|
349
|
-
const nestedQuestionPath = getNestedQuestionPath(path, nested.fieldId);
|
|
350
|
-
if (componentsToKeep[nestedQuestionPath] > 1) {
|
|
351
|
-
componentsToKeep[nestedQuestionPath] -= 1;
|
|
352
|
-
} else {
|
|
353
|
-
deleteNodeByPath(payload, nestedQuestionPath);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
+
deleteNodeAndOptions(payload, path, component);
|
|
356
357
|
}
|
|
357
358
|
};
|
|
358
359
|
|
|
@@ -360,7 +361,6 @@ const deleteComponentData = (payload, path, component, componentsToKeep) => {
|
|
|
360
361
|
*
|
|
361
362
|
* Takes a single page collection payload object and removes the payload items specified in the componentsToPrune list
|
|
362
363
|
* as long as they don't appear in the componentsToKeep list.
|
|
363
|
-
*
|
|
364
364
|
* Additionally, if the component type is multifile, remove the corresponding data entries that will have been created
|
|
365
365
|
* in the meta section of the payload by the form renderer.
|
|
366
366
|
*
|
|
@@ -376,16 +376,7 @@ const pruneCollectionEntry = (pathsToKeep, componentsToPrune, collectionDataObje
|
|
|
376
376
|
if (component.type === "multifile") {
|
|
377
377
|
deleteCorrespondingMetaInfo(component, collectionDataObject, formData);
|
|
378
378
|
}
|
|
379
|
-
|
|
380
|
-
deleteNodeByPath(collectionDataObject, component.fieldId);
|
|
381
|
-
|
|
382
|
-
// If the component has options, go through each option removing the data for any nested fields. Required as nested options are in the payload at the same heirarchical level.
|
|
383
|
-
iterateOptions(component, nested => {
|
|
384
|
-
const nestedQuestionPath = getNestedQuestionPath(component.fieldId, nested.fieldId);
|
|
385
|
-
if (!pathsToKeep.has(nestedQuestionPath)) {
|
|
386
|
-
deleteNodeByPath(collectionDataObject, nestedQuestionPath);
|
|
387
|
-
}
|
|
388
|
-
});
|
|
379
|
+
deleteNodeAndOptions(collectionDataObject, component.fieldId, component);
|
|
389
380
|
}
|
|
390
381
|
});
|
|
391
382
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.16.0-beta",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"yalc-publish": "yarn compile-with-maps && cp -r src dist/src && yalc publish --push"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ukhomeoffice/cop-react-components": "
|
|
20
|
+
"@ukhomeoffice/cop-react-components": "5.0.0-delta",
|
|
21
21
|
"axios": "^0.23.0",
|
|
22
22
|
"dayjs": "^1.11.0",
|
|
23
23
|
"govuk-frontend": "^5.0.0",
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "example-form",
|
|
3
|
-
"cleanseHiddenData": true,
|
|
4
|
-
"version": "0.0.1",
|
|
5
|
-
"name": "example-form",
|
|
6
|
-
"title": "Example form",
|
|
7
|
-
"type": "form",
|
|
8
|
-
"components": [
|
|
9
|
-
{
|
|
10
|
-
"id": "alpha",
|
|
11
|
-
"fieldId": "alpha",
|
|
12
|
-
"label": "Alpha",
|
|
13
|
-
"type": "text"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"id": "bravo",
|
|
17
|
-
"fieldId": "bravo",
|
|
18
|
-
"label": "Bravo",
|
|
19
|
-
"type": "text"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"id": "person",
|
|
23
|
-
"fieldId": "person",
|
|
24
|
-
"type": "container",
|
|
25
|
-
"components": [
|
|
26
|
-
{
|
|
27
|
-
"id": "telephone_visible",
|
|
28
|
-
"fieldId": "telephone",
|
|
29
|
-
"label": "telephone_visible",
|
|
30
|
-
"type": "text"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"id": "telephoneKnown",
|
|
34
|
-
"fieldId": "telephoneKnown",
|
|
35
|
-
"type": "radios",
|
|
36
|
-
"data": {
|
|
37
|
-
"options": [
|
|
38
|
-
{
|
|
39
|
-
"value": "yes",
|
|
40
|
-
"label": "Yes",
|
|
41
|
-
"nested": [
|
|
42
|
-
{
|
|
43
|
-
"id": "telephone",
|
|
44
|
-
"fieldId": "telephone",
|
|
45
|
-
"type": "text",
|
|
46
|
-
"label": "Telephone",
|
|
47
|
-
"required": true
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"value": "no",
|
|
53
|
-
"label": "No"
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
},
|
|
57
|
-
"show_when": {
|
|
58
|
-
"op": "=",
|
|
59
|
-
"field": "bravo",
|
|
60
|
-
"value": "NOT-bravo-value"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"id": "name",
|
|
65
|
-
"fieldId": "name",
|
|
66
|
-
"label": "Name",
|
|
67
|
-
"type": "text"
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
"id": "gamma",
|
|
73
|
-
"fieldId": "gamma",
|
|
74
|
-
"label": "Gamma",
|
|
75
|
-
"type": "text"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"id": "epsilon",
|
|
79
|
-
"fieldId": "epsilon",
|
|
80
|
-
"label": "Epsilon",
|
|
81
|
-
"type": "text"
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
"pages": [
|
|
85
|
-
{
|
|
86
|
-
"id": "general",
|
|
87
|
-
"name": "general",
|
|
88
|
-
"title": "General information",
|
|
89
|
-
"components": [
|
|
90
|
-
{
|
|
91
|
-
"use": "alpha"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
"use": "bravo"
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
"use": "person"
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
"use": "gamma"
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
"use": "epsilon"
|
|
104
|
-
}
|
|
105
|
-
],
|
|
106
|
-
"actions": [
|
|
107
|
-
"submit",
|
|
108
|
-
{
|
|
109
|
-
"type": "cancel",
|
|
110
|
-
"page": "",
|
|
111
|
-
"validate": false,
|
|
112
|
-
"classModifiers": "secondary",
|
|
113
|
-
"label": "Cancel"
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
}
|
|
117
|
-
]
|
|
118
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "example-form",
|
|
3
|
-
"cleanseHiddenData": true,
|
|
4
|
-
"version": "0.0.1",
|
|
5
|
-
"name": "example-form",
|
|
6
|
-
"title": "Example form",
|
|
7
|
-
"type": "form",
|
|
8
|
-
"components": [
|
|
9
|
-
{
|
|
10
|
-
"id": "alpha",
|
|
11
|
-
"fieldId": "alpha",
|
|
12
|
-
"label": "Alpha",
|
|
13
|
-
"type": "text"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"id": "bravo",
|
|
17
|
-
"fieldId": "bravo",
|
|
18
|
-
"label": "Bravo",
|
|
19
|
-
"type": "text"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"id": "person",
|
|
23
|
-
"fieldId": "person",
|
|
24
|
-
"type": "container",
|
|
25
|
-
"components": [
|
|
26
|
-
{
|
|
27
|
-
"id": "telephone_visible",
|
|
28
|
-
"fieldId": "telephone",
|
|
29
|
-
"label": "telephone_visible",
|
|
30
|
-
"type": "text"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"id": "telephoneKnown",
|
|
34
|
-
"fieldId": "telephoneKnown",
|
|
35
|
-
"type": "radios",
|
|
36
|
-
"data": {
|
|
37
|
-
"options": [
|
|
38
|
-
{
|
|
39
|
-
"value": "yes",
|
|
40
|
-
"label": "Yes",
|
|
41
|
-
"nested": [
|
|
42
|
-
{
|
|
43
|
-
"id": "telephone",
|
|
44
|
-
"fieldId": "telephone",
|
|
45
|
-
"type": "text",
|
|
46
|
-
"label": "Telephone",
|
|
47
|
-
"required": true
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"value": "no",
|
|
53
|
-
"label": "No"
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"id": "name",
|
|
60
|
-
"fieldId": "name",
|
|
61
|
-
"label": "Name",
|
|
62
|
-
"type": "text"
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"id": "gamma",
|
|
68
|
-
"fieldId": "gamma",
|
|
69
|
-
"label": "Gamma",
|
|
70
|
-
"type": "text"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
"id": "epsilon",
|
|
74
|
-
"fieldId": "epsilon",
|
|
75
|
-
"label": "Epsilon",
|
|
76
|
-
"type": "text"
|
|
77
|
-
}
|
|
78
|
-
],
|
|
79
|
-
"pages": [
|
|
80
|
-
{
|
|
81
|
-
"id": "general",
|
|
82
|
-
"name": "general",
|
|
83
|
-
"title": "General information",
|
|
84
|
-
"components": [
|
|
85
|
-
{
|
|
86
|
-
"use": "alpha"
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
"use": "bravo"
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
"use": "person"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"use": "gamma"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
"use": "epsilon"
|
|
99
|
-
}
|
|
100
|
-
],
|
|
101
|
-
"actions": [
|
|
102
|
-
"submit",
|
|
103
|
-
{
|
|
104
|
-
"type": "cancel",
|
|
105
|
-
"page": "",
|
|
106
|
-
"validate": false,
|
|
107
|
-
"classModifiers": "secondary",
|
|
108
|
-
"label": "Cancel"
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
}
|