@ukhomeoffice/cop-react-form-renderer 5.76.0 → 5.77.2
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 -6
- package/dist/utils/CheckYourAnswers/getCYARowsForCollectionPage.test.js +103 -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) {
|
|
@@ -163,7 +167,9 @@ var getCYARowsForChildPages = function getCYARowsForChildPages(childPages, item,
|
|
|
163
167
|
rows = rows.concat(headingRow);
|
|
164
168
|
}
|
|
165
169
|
var container = getContainerForPage(childPage, item, labelCount, fullPath);
|
|
166
|
-
var containerRows = (0, _getCYARowsForContainer.default)(
|
|
170
|
+
var containerRows = (0, _getCYARowsForContainer.default)(_objectSpread(_objectSpread({}, childPage), {}, {
|
|
171
|
+
formData: _objectSpread(_objectSpread({}, childPage.formData), item)
|
|
172
|
+
}), container, _objectSpread(_objectSpread({}, childPage.formData), item), changeAction, fnOverride);
|
|
167
173
|
rows = rows.concat(containerRows);
|
|
168
174
|
}
|
|
169
175
|
}
|
|
@@ -191,7 +197,11 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
|
|
|
191
197
|
}
|
|
192
198
|
var rows = [];
|
|
193
199
|
if (!page.collection.hideNameFromCYA) {
|
|
194
|
-
|
|
200
|
+
var _page$collection$coll;
|
|
201
|
+
var headingChangeAction = (_page$collection$coll = page.collection.collectionHeading) !== null && _page$collection$coll !== void 0 && _page$collection$coll.changeLinkPage ? getChangeActionForPage({
|
|
202
|
+
id: page.collection.collectionHeading.changeLinkPage
|
|
203
|
+
}, onAction, activeIds) : null;
|
|
204
|
+
rows.push(getCollectionNameHeading(page, collectionName, page.collection.collectionHeading, headingChangeAction));
|
|
195
205
|
}
|
|
196
206
|
var itemIndex = 0;
|
|
197
207
|
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: [{
|
|
@@ -654,4 +681,80 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
|
|
|
654
681
|
key: 'Test text'
|
|
655
682
|
});
|
|
656
683
|
});
|
|
684
|
+
it('should create rows for the Collection component correctly', function () {
|
|
685
|
+
var FORM_DATA = {
|
|
686
|
+
collection: [{
|
|
687
|
+
id: '01',
|
|
688
|
+
testCollection: [{
|
|
689
|
+
testText: 'collection value'
|
|
690
|
+
}],
|
|
691
|
+
otherComp: 'one'
|
|
692
|
+
}]
|
|
693
|
+
};
|
|
694
|
+
var COLLECTION_COMP = {
|
|
695
|
+
id: 'testCollection',
|
|
696
|
+
fieldId: 'testCollection',
|
|
697
|
+
label: 'Test collection',
|
|
698
|
+
type: 'collection',
|
|
699
|
+
item: [{
|
|
700
|
+
id: 'testText',
|
|
701
|
+
fieldId: 'testText',
|
|
702
|
+
type: 'text',
|
|
703
|
+
label: 'Some nice text'
|
|
704
|
+
}],
|
|
705
|
+
show_when: [{
|
|
706
|
+
field: 'otherComp',
|
|
707
|
+
op: 'eq',
|
|
708
|
+
value: 'one'
|
|
709
|
+
}]
|
|
710
|
+
};
|
|
711
|
+
var MASTER_PAGE_WITH_COLLECTION = {
|
|
712
|
+
id: 'page1',
|
|
713
|
+
collection: {
|
|
714
|
+
name: 'collection',
|
|
715
|
+
labels: {
|
|
716
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
717
|
+
item: 'Collection entry ${index}'
|
|
718
|
+
},
|
|
719
|
+
actions: [{
|
|
720
|
+
type: 'change'
|
|
721
|
+
}, {
|
|
722
|
+
type: 'remove',
|
|
723
|
+
label: 'custom remove label'
|
|
724
|
+
}, {
|
|
725
|
+
type: 'change',
|
|
726
|
+
label: 'custom change label',
|
|
727
|
+
page: 'confirmDelete'
|
|
728
|
+
}]
|
|
729
|
+
},
|
|
730
|
+
childPages: [{
|
|
731
|
+
id: 'page1',
|
|
732
|
+
collection: {
|
|
733
|
+
name: 'collection'
|
|
734
|
+
},
|
|
735
|
+
components: [COLLECTION_COMP]
|
|
736
|
+
}],
|
|
737
|
+
formData: FORM_DATA
|
|
738
|
+
};
|
|
739
|
+
var ROWS = (0, _getCYARowsForCollectionPage.default)(MASTER_PAGE_WITH_COLLECTION, null, null, FORM_DATA);
|
|
740
|
+
expect(ROWS.length).toEqual(7); // Title row + component row for each item
|
|
741
|
+
expect(ROWS[0]).toMatchObject({
|
|
742
|
+
type: 'heading',
|
|
743
|
+
key: 'Collection'
|
|
744
|
+
});
|
|
745
|
+
expect(ROWS[1]).toMatchObject({
|
|
746
|
+
type: 'heading',
|
|
747
|
+
key: 'Collection entry 1'
|
|
748
|
+
});
|
|
749
|
+
expect(ROWS[2].action.label).toEqual('Change');
|
|
750
|
+
expect(ROWS[3].action.label).toEqual('custom remove label');
|
|
751
|
+
expect(ROWS[4].action.label).toEqual('custom change label');
|
|
752
|
+
expect(ROWS[5]).toMatchObject({
|
|
753
|
+
key: 'Item 1'
|
|
754
|
+
});
|
|
755
|
+
expect(ROWS[6]).toMatchObject({
|
|
756
|
+
value: 'collection value',
|
|
757
|
+
key: 'Some nice text'
|
|
758
|
+
});
|
|
759
|
+
});
|
|
657
760
|
});
|
|
@@ -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
|
});
|