@ukhomeoffice/cop-react-form-renderer 6.0.1-peter → 6.0.4-peter
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/FormComponent/FormComponent.js +1 -0
- package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +30 -11
- package/dist/components/FormRenderer/onPageAction.js +6 -5
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +4 -2
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +79 -0
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _showComponent = _interopRequireDefault(require("../../../utils/Component/showComponent"));
|
|
8
8
|
var _mergeCollectionPages = _interopRequireDefault(require("../../../utils/CollectionPage/mergeCollectionPages"));
|
|
9
9
|
var _deleteNodeByPath = _interopRequireDefault(require("./deleteNodeByPath"));
|
|
10
|
+
var _optionIsSelected = _interopRequireDefault(require("../../../utils/Component/optionIsSelected"));
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
/* eslint-disable no-param-reassign */
|
|
12
13
|
|
|
@@ -18,6 +19,19 @@ var recurseCheckForHiddenComponents = function recurseCheckForHiddenComponents(c
|
|
|
18
19
|
(_component$components = component.components) === null || _component$components === void 0 || _component$components.forEach(function (c) {
|
|
19
20
|
recurseCheckForHiddenComponents(c, formData, path, candidateComponentForDeletion);
|
|
20
21
|
});
|
|
22
|
+
} else if ((0, _showComponent.default)(component, formData)) {
|
|
23
|
+
var _component$data;
|
|
24
|
+
if (component !== null && component !== void 0 && (_component$data = component.data) !== null && _component$data !== void 0 && _component$data.options) {
|
|
25
|
+
var _component$data2;
|
|
26
|
+
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(function (option) {
|
|
27
|
+
if (!(0, _optionIsSelected.default)(formData[component.id], option) && option.nested) {
|
|
28
|
+
option.nested.forEach(function (nested) {
|
|
29
|
+
path = nested.fieldId;
|
|
30
|
+
candidateComponentForDeletion.set(path, component);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
21
35
|
} else if (!(0, _showComponent.default)(component, formData)) {
|
|
22
36
|
candidateComponentForDeletion.set(path, component);
|
|
23
37
|
}
|
|
@@ -106,19 +120,24 @@ var clearOutUncompletedRoutes = function clearOutUncompletedRoutes(form, formDat
|
|
|
106
120
|
var componentsUsedInVisiblePagesIds = [];
|
|
107
121
|
condensedPages === null || condensedPages === void 0 || condensedPages.forEach(function (page) {
|
|
108
122
|
var _page$collection;
|
|
109
|
-
if ((_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
if (page !== null && page !== void 0 && (_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name) {
|
|
124
|
+
var _page$collection2;
|
|
125
|
+
var collectionDatas = formData[page === null || page === void 0 || (_page$collection2 = page.collection) === null || _page$collection2 === void 0 ? void 0 : _page$collection2.name];
|
|
126
|
+
if (collectionDatas) {
|
|
127
|
+
collectionDatas.forEach(function (collectionData) {
|
|
128
|
+
var _page$childPages;
|
|
129
|
+
/* eslint-disable consistent-return */
|
|
130
|
+
(_page$childPages = page.childPages) === null || _page$childPages === void 0 || _page$childPages.forEach(function (childPage) {
|
|
131
|
+
if (childPage.deleteCollectionWhenHidden) {
|
|
132
|
+
if (childPage && !(0, _showComponent.default)(childPage, collectionData) || childPage && !(0, _showComponent.default)(childPage, formData)) {
|
|
133
|
+
delete formData[childPage.collection.name];
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
117
136
|
}
|
|
118
|
-
|
|
119
|
-
|
|
137
|
+
deleteHiddenComponent(childPage, form, collectionData, formData);
|
|
138
|
+
});
|
|
120
139
|
});
|
|
121
|
-
}
|
|
140
|
+
}
|
|
122
141
|
} else {
|
|
123
142
|
markComponentsForDeletion(page, form, formData, candidateComponentForDeletion, componentsUsedInVisiblePagesIds);
|
|
124
143
|
}
|
|
@@ -56,7 +56,6 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
56
56
|
_handlers.default.navigate(action, pageId, onPageChange);
|
|
57
57
|
setSubmitting(false);
|
|
58
58
|
} else {
|
|
59
|
-
var baseData = _objectSpread(_objectSpread(_objectSpread({}, data), patch), formState.page.formData);
|
|
60
59
|
var pageUpdate = function pageUpdate(next) {
|
|
61
60
|
return onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, next));
|
|
62
61
|
};
|
|
@@ -108,12 +107,14 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
108
107
|
setData(submissionData);
|
|
109
108
|
}
|
|
110
109
|
;
|
|
110
|
+
var formPagesAndComponents = {
|
|
111
|
+
pages: pages,
|
|
112
|
+
components: components
|
|
113
|
+
};
|
|
111
114
|
if (action.type === _models.PageAction.TYPES.SUBMIT) {
|
|
112
|
-
_helpers.default.clearOutUncompletedRoutes(
|
|
113
|
-
pages: pages,
|
|
114
|
-
components: components
|
|
115
|
-
}, submissionData);
|
|
115
|
+
_helpers.default.clearOutUncompletedRoutes(formPagesAndComponents, submissionData);
|
|
116
116
|
}
|
|
117
|
+
|
|
117
118
|
// In case of hub-and-spoke if patchLabel has changed then
|
|
118
119
|
// save name and value to variables for call to onSubmit hook
|
|
119
120
|
var changedFieldName;
|
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
8
|
var _models = require("../../models");
|
|
9
9
|
var _addShowWhen = _interopRequireDefault(require("../Component/addShowWhen"));
|
|
10
|
+
var _meetsAllConditions = _interopRequireDefault(require("../Condition/meetsAllConditions"));
|
|
10
11
|
var _showFormPageCYA = _interopRequireDefault(require("../FormPage/showFormPageCYA"));
|
|
11
12
|
var _getCYACollectionDeleteAction = _interopRequireDefault(require("./getCYACollectionDeleteAction"));
|
|
12
13
|
var _getCYACollectionChangeAction = _interopRequireDefault(require("./getCYACollectionChangeAction"));
|
|
@@ -157,7 +158,7 @@ var getCYARowsForChildPages = function getCYARowsForChildPages(childPages, item,
|
|
|
157
158
|
}
|
|
158
159
|
var container = getContainerForPage(childPage, item, labelCount, fullPath);
|
|
159
160
|
var rowChangeAction = getChangeActionForPage(childPage, onAction, activeIds);
|
|
160
|
-
var containerRows = (0, _getCYARowsForContainer.default)(childPage, container, item, rowChangeAction, fnOverride);
|
|
161
|
+
var containerRows = (0, _getCYARowsForContainer.default)(childPage, container, _objectSpread(_objectSpread({}, childPage.formData), item), rowChangeAction, fnOverride);
|
|
161
162
|
rows = rows.concat(containerRows);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
@@ -188,7 +189,8 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
|
|
|
188
189
|
rows.push(getCollectionNameHeading(page, collectionName));
|
|
189
190
|
}
|
|
190
191
|
var itemIndex = 0;
|
|
191
|
-
|
|
192
|
+
var result = Array.isArray(page.collection.onlyShowActiveEntryOnCYA) ? (0, _meetsAllConditions.default)(page.collection.onlyShowActiveEntryOnCYA, data) : page.collection.onlyShowActiveEntryOnCYA;
|
|
193
|
+
if (result) {
|
|
192
194
|
var activeEntry = collectionData.find(function (entry, index) {
|
|
193
195
|
itemIndex = index;
|
|
194
196
|
return entry.id === activeId;
|
|
@@ -170,6 +170,41 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
170
170
|
key: 'Test date'
|
|
171
171
|
});
|
|
172
172
|
});
|
|
173
|
+
it('should use values from top-level formData if they don\'t exist in the item', function () {
|
|
174
|
+
var FORM_DATA = {
|
|
175
|
+
testText: 'value',
|
|
176
|
+
collection: [{
|
|
177
|
+
id: '01'
|
|
178
|
+
}]
|
|
179
|
+
};
|
|
180
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
181
|
+
childPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
182
|
+
formData: FORM_DATA
|
|
183
|
+
}), PAGES[1]],
|
|
184
|
+
formData: FORM_DATA
|
|
185
|
+
});
|
|
186
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
187
|
+
expect(ROWS.length).toEqual(7); // Title row + component row for each item
|
|
188
|
+
expect(ROWS[0]).toMatchObject({
|
|
189
|
+
type: 'heading',
|
|
190
|
+
key: 'Collection'
|
|
191
|
+
});
|
|
192
|
+
expect(ROWS[1]).toMatchObject({
|
|
193
|
+
type: 'heading',
|
|
194
|
+
key: 'Collection entry 1'
|
|
195
|
+
});
|
|
196
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
197
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
198
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
199
|
+
expect(ROWS[5]).toMatchObject({
|
|
200
|
+
value: 'value',
|
|
201
|
+
key: 'Test text'
|
|
202
|
+
});
|
|
203
|
+
expect(ROWS[6]).toMatchObject({
|
|
204
|
+
value: '',
|
|
205
|
+
key: 'Test date'
|
|
206
|
+
});
|
|
207
|
+
});
|
|
173
208
|
it('should return correctly formatted rows for only the active entry when page.collection.onlyShowActiveEntryOnCYA is defined', function () {
|
|
174
209
|
var FORM_DATA = {
|
|
175
210
|
collectionActiveId: '02',
|
|
@@ -209,6 +244,50 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
209
244
|
key: 'Test date'
|
|
210
245
|
});
|
|
211
246
|
});
|
|
247
|
+
it('should return correctly formatted rows for only the active entry when page.collection.onlyShowActiveEntryOnCYA is an array', function () {
|
|
248
|
+
var FORM_DATA = {
|
|
249
|
+
text: 'blue',
|
|
250
|
+
collectionActiveId: '02',
|
|
251
|
+
collection: [{
|
|
252
|
+
id: '01',
|
|
253
|
+
testText: 'value'
|
|
254
|
+
}, {
|
|
255
|
+
id: '02',
|
|
256
|
+
testText: 'value'
|
|
257
|
+
}]
|
|
258
|
+
};
|
|
259
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
260
|
+
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
261
|
+
onlyShowActiveEntryOnCYA: [{
|
|
262
|
+
field: 'text',
|
|
263
|
+
op: 'eq',
|
|
264
|
+
value: 'blue'
|
|
265
|
+
}]
|
|
266
|
+
}),
|
|
267
|
+
formData: FORM_DATA
|
|
268
|
+
});
|
|
269
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
270
|
+
expect(ROWS.length).toEqual(7); // Title row + component row for only the active item.
|
|
271
|
+
expect(ROWS[0]).toMatchObject({
|
|
272
|
+
type: 'heading',
|
|
273
|
+
key: 'Collection'
|
|
274
|
+
});
|
|
275
|
+
expect(ROWS[1]).toMatchObject({
|
|
276
|
+
type: 'heading',
|
|
277
|
+
key: 'Collection entry 2'
|
|
278
|
+
});
|
|
279
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
280
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
281
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
282
|
+
expect(ROWS[5]).toMatchObject({
|
|
283
|
+
value: 'value',
|
|
284
|
+
key: 'Test text'
|
|
285
|
+
});
|
|
286
|
+
expect(ROWS[6]).toMatchObject({
|
|
287
|
+
value: '',
|
|
288
|
+
key: 'Test date'
|
|
289
|
+
});
|
|
290
|
+
});
|
|
212
291
|
it('should exclude components that should not be shown', function () {
|
|
213
292
|
var FD = {
|
|
214
293
|
collection: [{
|