@ukhomeoffice/cop-react-form-renderer 5.75.0 → 5.77.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/utils/CheckYourAnswers/getCYARowsForCollectionPage.js +16 -8
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +69 -0
- package/dist/utils/Component/elevateNestedComponents.js +2 -1
- package/dist/utils/Component/elevateNestedComponents.test.js +38 -0
- package/package.json +1 -1
|
@@ -56,7 +56,7 @@ var getTitleRowForItem = function getTitleRowForItem(page, item, pageId, labelCo
|
|
|
56
56
|
size: page.collection.titleSize || 's'
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
|
-
var getHeadingRow = function getHeadingRow(config, pageId, labelCount, changeAction) {
|
|
59
|
+
var getHeadingRow = function getHeadingRow(config, pageId, labelCount, changeAction, item) {
|
|
60
60
|
if (config.text === '') {
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
@@ -64,7 +64,7 @@ var getHeadingRow = function getHeadingRow(config, pageId, labelCount, changeAct
|
|
|
64
64
|
pageId: pageId,
|
|
65
65
|
fieldId: "heading".concat(labelCount),
|
|
66
66
|
full_path: "heading".concat(labelCount),
|
|
67
|
-
key: config.text,
|
|
67
|
+
key: _copReactComponents.Utils.interpolateString(config.text, item),
|
|
68
68
|
type: changeAction === null ? 'heading' : 'headingWithAction',
|
|
69
69
|
size: config.size || 's',
|
|
70
70
|
action: changeAction === null ? null : {
|
|
@@ -73,14 +73,18 @@ var getHeadingRow = function getHeadingRow(config, pageId, labelCount, changeAct
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
-
var getCollectionNameHeading = function getCollectionNameHeading(page, titleName) {
|
|
76
|
+
var getCollectionNameHeading = function getCollectionNameHeading(page, titleName, config, changeAction) {
|
|
77
77
|
return {
|
|
78
78
|
pageId: page.id,
|
|
79
79
|
fieldId: "".concat(page.collection.name, "Title"),
|
|
80
80
|
full_path: "".concat(page.collection.name, "Title"),
|
|
81
|
-
key: titleName.charAt(0).toUpperCase() + titleName.slice(1),
|
|
82
|
-
type: 'heading',
|
|
83
|
-
size: 'm'
|
|
81
|
+
key: (config === null || config === void 0 ? void 0 : config.text) || titleName.charAt(0).toUpperCase() + titleName.slice(1),
|
|
82
|
+
type: changeAction == null ? 'heading' : 'headingWithAction',
|
|
83
|
+
size: (config === null || config === void 0 ? void 0 : config.size) || 'm',
|
|
84
|
+
action: changeAction === null ? null : {
|
|
85
|
+
onAction: changeAction,
|
|
86
|
+
label: 'Change'
|
|
87
|
+
}
|
|
84
88
|
};
|
|
85
89
|
};
|
|
86
90
|
var getActionRows = function getActionRows(page, item, onAction, labelCount) {
|
|
@@ -159,7 +163,7 @@ var getCYARowsForChildPages = function getCYARowsForChildPages(childPages, item,
|
|
|
159
163
|
var changeAction = getChangeActionForPage(childPage, onAction, activeIds);
|
|
160
164
|
if (childPage.collection.heading) {
|
|
161
165
|
var headingAction = childPage.collection.heading.changeLink ? changeAction : null;
|
|
162
|
-
var headingRow = getHeadingRow(childPage.collection.heading, childPage.id, labelCount, headingAction);
|
|
166
|
+
var headingRow = getHeadingRow(childPage.collection.heading, childPage.id, labelCount, headingAction, item);
|
|
163
167
|
rows = rows.concat(headingRow);
|
|
164
168
|
}
|
|
165
169
|
var container = getContainerForPage(childPage, item, labelCount, fullPath);
|
|
@@ -191,7 +195,11 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
|
|
|
191
195
|
}
|
|
192
196
|
var rows = [];
|
|
193
197
|
if (!page.collection.hideNameFromCYA) {
|
|
194
|
-
|
|
198
|
+
var _page$collection$coll;
|
|
199
|
+
var headingChangeAction = (_page$collection$coll = page.collection.collectionHeading) !== null && _page$collection$coll !== void 0 && _page$collection$coll.changeLinkPage ? getChangeActionForPage({
|
|
200
|
+
id: page.collection.collectionHeading.changeLinkPage
|
|
201
|
+
}, onAction, activeIds) : null;
|
|
202
|
+
rows.push(getCollectionNameHeading(page, collectionName, page.collection.collectionHeading, headingChangeAction));
|
|
195
203
|
}
|
|
196
204
|
var itemIndex = 0;
|
|
197
205
|
var result = Array.isArray(page.collection.onlyShowActiveEntryOnCYA) ? (0, _meetsAllConditions.default)(page.collection.onlyShowActiveEntryOnCYA, data) : page.collection.onlyShowActiveEntryOnCYA;
|
|
@@ -415,6 +415,75 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
415
415
|
key: 'Test text'
|
|
416
416
|
});
|
|
417
417
|
});
|
|
418
|
+
it('should allow interpolation of custom headings', function () {
|
|
419
|
+
var FORM_DATA = {
|
|
420
|
+
collection: [{
|
|
421
|
+
id: '01',
|
|
422
|
+
testText: 'value'
|
|
423
|
+
}]
|
|
424
|
+
};
|
|
425
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
426
|
+
formData: FORM_DATA,
|
|
427
|
+
childPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
428
|
+
collection: _objectSpread(_objectSpread({}, PAGES[0].collection), {}, {
|
|
429
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
430
|
+
heading: {
|
|
431
|
+
size: 'm',
|
|
432
|
+
text: 'interpolated text: ${testText}'
|
|
433
|
+
}
|
|
434
|
+
})
|
|
435
|
+
})]
|
|
436
|
+
});
|
|
437
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
438
|
+
expect(ROWS.length).toEqual(7);
|
|
439
|
+
expect(ROWS[0]).toMatchObject({
|
|
440
|
+
type: 'heading',
|
|
441
|
+
key: 'Collection'
|
|
442
|
+
});
|
|
443
|
+
expect(ROWS[1]).toMatchObject({
|
|
444
|
+
type: 'heading',
|
|
445
|
+
key: 'Collection entry 1'
|
|
446
|
+
});
|
|
447
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
448
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
449
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
450
|
+
expect(ROWS[5]).toMatchObject({
|
|
451
|
+
type: 'heading',
|
|
452
|
+
key: 'interpolated text: value',
|
|
453
|
+
size: 'm'
|
|
454
|
+
});
|
|
455
|
+
expect(ROWS[6]).toMatchObject({
|
|
456
|
+
value: 'value',
|
|
457
|
+
key: 'Test text'
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
it('should alow configuration of collection name headings', function () {
|
|
461
|
+
var FORM_DATA = {
|
|
462
|
+
collection: [{
|
|
463
|
+
id: '01',
|
|
464
|
+
testText: 'value'
|
|
465
|
+
}]
|
|
466
|
+
};
|
|
467
|
+
var PAGE = _objectSpread(_objectSpread({}, MASTER_PAGE), {}, {
|
|
468
|
+
formData: FORM_DATA,
|
|
469
|
+
collection: _objectSpread(_objectSpread({}, MASTER_PAGE.collection), {}, {
|
|
470
|
+
collectionHeading: {
|
|
471
|
+
text: 'Custom collection heading',
|
|
472
|
+
size: 'm',
|
|
473
|
+
changeLinkPage: PAGES[0].id
|
|
474
|
+
}
|
|
475
|
+
}),
|
|
476
|
+
childPages: [_objectSpread(_objectSpread({}, PAGES[0]), {}, {
|
|
477
|
+
collection: _objectSpread({}, PAGES[0].collection)
|
|
478
|
+
})]
|
|
479
|
+
});
|
|
480
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null, null, FORM_DATA);
|
|
481
|
+
expect(ROWS.length).toEqual(6);
|
|
482
|
+
expect(ROWS[0]).toMatchObject({
|
|
483
|
+
type: 'headingWithAction',
|
|
484
|
+
key: 'Custom collection heading'
|
|
485
|
+
});
|
|
486
|
+
});
|
|
418
487
|
it('should default to a title size of small if one is not specified', function () {
|
|
419
488
|
var FORM_DATA = {
|
|
420
489
|
collection: [{
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _Data = _interopRequireDefault(require("../Data"));
|
|
8
|
+
var _optionIsSelected = _interopRequireDefault(require("./optionIsSelected"));
|
|
8
9
|
var _showComponent = _interopRequireDefault(require("./showComponent"));
|
|
9
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
11
|
/**
|
|
@@ -45,7 +46,7 @@ var elevateNestedComponents = function elevateNestedComponents(components, data)
|
|
|
45
46
|
// selected, then add its nested components to the array.
|
|
46
47
|
var sourceData = (data === null || data === void 0 ? void 0 : data[component.id]) || _Data.default.getSource(data, component.full_path);
|
|
47
48
|
// If the specific option wasn't shown we shouldn't elevate anything nested under it
|
|
48
|
-
if (Array.isArray(option.nested) && sourceData
|
|
49
|
+
if (Array.isArray(option.nested) && (0, _optionIsSelected.default)(sourceData, option) && (0, _showComponent.default)(option, data)) {
|
|
49
50
|
allComponents = allComponents.concat(option.nested);
|
|
50
51
|
}
|
|
51
52
|
});
|
|
@@ -263,4 +263,42 @@ describe('utils.Component.elevateNestedComponents', function () {
|
|
|
263
263
|
};
|
|
264
264
|
expect((0, _elevateNestedComponents.default)(COMPONENTS, DATA)).toEqual([].concat(COMPONENTS));
|
|
265
265
|
});
|
|
266
|
+
it('should return the original array with elevated nested components that are defined using refdata_match when they are visible', function () {
|
|
267
|
+
var COMPONENTS = [{
|
|
268
|
+
id: 'textComp'
|
|
269
|
+
}, {
|
|
270
|
+
id: 'checkboxComp',
|
|
271
|
+
data: {
|
|
272
|
+
options: [{
|
|
273
|
+
label: 'Yes',
|
|
274
|
+
value: 'yes',
|
|
275
|
+
id: 99
|
|
276
|
+
}, {
|
|
277
|
+
label: 'No',
|
|
278
|
+
value: 'no',
|
|
279
|
+
id: 100
|
|
280
|
+
}, {
|
|
281
|
+
nested: [{
|
|
282
|
+
id: 'nestedOne'
|
|
283
|
+
}, {
|
|
284
|
+
id: 'nestedTwo'
|
|
285
|
+
}],
|
|
286
|
+
refdata_match: {
|
|
287
|
+
id: 99
|
|
288
|
+
}
|
|
289
|
+
}]
|
|
290
|
+
}
|
|
291
|
+
}];
|
|
292
|
+
var DATA = {
|
|
293
|
+
checkboxComp: [{
|
|
294
|
+
value: 'yes',
|
|
295
|
+
id: 99
|
|
296
|
+
}]
|
|
297
|
+
};
|
|
298
|
+
expect((0, _elevateNestedComponents.default)(COMPONENTS, DATA)).toEqual([].concat(COMPONENTS, [{
|
|
299
|
+
id: 'nestedOne'
|
|
300
|
+
}, {
|
|
301
|
+
id: 'nestedTwo'
|
|
302
|
+
}]));
|
|
303
|
+
});
|
|
266
304
|
});
|