@ukhomeoffice/cop-react-form-renderer 5.76.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 +13 -5
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +27 -0
- package/dist/utils/Component/elevateNestedComponents.js +2 -1
- package/dist/utils/Component/elevateNestedComponents.test.js +38 -0
- package/package.json +1 -1
|
@@ -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) {
|
|
@@ -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;
|
|
@@ -457,6 +457,33 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
457
457
|
key: 'Test text'
|
|
458
458
|
});
|
|
459
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
|
+
});
|
|
460
487
|
it('should default to a title size of small if one is not specified', function () {
|
|
461
488
|
var FORM_DATA = {
|
|
462
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
|
});
|