@ukhomeoffice/cop-react-form-renderer 5.77.4 → 5.78.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/components/CollectionSummary/SummaryCardDetails.js +22 -0
- package/dist/components/CollectionSummary/SummaryCardDetails.test.js +101 -14
- package/dist/components/SummaryList/SummaryList.js +2 -1
- package/dist/components/SummaryList/SummaryListHeadingRowWithAction.js +8 -3
- package/dist/utils/CheckYourAnswers/getComponentRowForCYA.js +1 -1
- package/package.json +2 -2
|
@@ -9,6 +9,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
10
10
|
var _models = require("../../models");
|
|
11
11
|
var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
|
|
12
|
+
var _getCYARowsForCollection = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARowsForCollection"));
|
|
12
13
|
var _getCYARowsForContainer = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARowsForContainer"));
|
|
13
14
|
var _showComponent = _interopRequireDefault(require("../../utils/Component/showComponent"));
|
|
14
15
|
var _Condition = _interopRequireDefault(require("../../utils/Condition"));
|
|
@@ -76,6 +77,27 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
76
77
|
}), classes, modEntry);
|
|
77
78
|
}));
|
|
78
79
|
}
|
|
80
|
+
if (component.type === _models.ComponentTypes.COLLECTION) {
|
|
81
|
+
var collectionRows = (0, _getCYARowsForCollection.default)(_objectSpread(_objectSpread({}, childPage), {}, {
|
|
82
|
+
formData: _objectSpread(_objectSpread({}, childPage.formData), entryData)
|
|
83
|
+
}), component, entryData[component.id]);
|
|
84
|
+
rowIndex += 1;
|
|
85
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
86
|
+
key: fieldId,
|
|
87
|
+
className: classes('field'),
|
|
88
|
+
style: {
|
|
89
|
+
'--column': columnIndex + 1,
|
|
90
|
+
'--row': rowIndex
|
|
91
|
+
}
|
|
92
|
+
}, collectionRows.map(function (subComponent) {
|
|
93
|
+
var _entryData$component$2;
|
|
94
|
+
// Put value for current subComponent at the top level
|
|
95
|
+
var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$2 = entryData[component.fieldId]) === null || _entryData$component$2 === void 0 ? void 0 : _entryData$component$2[subComponent.fieldId]));
|
|
96
|
+
return (0, _getComponentRowForCYA.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
|
|
97
|
+
label: subComponent.key
|
|
98
|
+
}), classes, modEntry);
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
79
101
|
rowIndex += 1;
|
|
80
102
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
81
103
|
key: fieldId,
|
|
@@ -156,6 +156,93 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
156
156
|
expect(section1Content.textContent).toContain('subThreeLabel');
|
|
157
157
|
expect(section1Content.textContent).toContain('charlie');
|
|
158
158
|
});
|
|
159
|
+
it('should render sections containing collections based on summaryLayout config', function () {
|
|
160
|
+
var CHILD_PAGES = [{
|
|
161
|
+
summaryLayout: {
|
|
162
|
+
sections: [{
|
|
163
|
+
title: 'Section 1',
|
|
164
|
+
columns: [{
|
|
165
|
+
fields: ['collectionComponent']
|
|
166
|
+
}]
|
|
167
|
+
}]
|
|
168
|
+
},
|
|
169
|
+
components: [{
|
|
170
|
+
fieldId: 'collectionComponent',
|
|
171
|
+
id: 'collectionComponent',
|
|
172
|
+
type: 'collection',
|
|
173
|
+
label: 'Collection',
|
|
174
|
+
labels: {
|
|
175
|
+
item: 'north'
|
|
176
|
+
},
|
|
177
|
+
item: [{
|
|
178
|
+
id: 'north',
|
|
179
|
+
fieldId: 'north',
|
|
180
|
+
type: 'text',
|
|
181
|
+
label: 'North',
|
|
182
|
+
required: true
|
|
183
|
+
}, {
|
|
184
|
+
id: 'east',
|
|
185
|
+
fieldId: 'east',
|
|
186
|
+
type: 'text',
|
|
187
|
+
label: 'East',
|
|
188
|
+
required: true
|
|
189
|
+
}, {
|
|
190
|
+
id: 'south',
|
|
191
|
+
fieldId: 'south',
|
|
192
|
+
type: 'text',
|
|
193
|
+
label: 'South',
|
|
194
|
+
required: true
|
|
195
|
+
}, {
|
|
196
|
+
id: 'west',
|
|
197
|
+
fieldId: 'west',
|
|
198
|
+
type: 'text',
|
|
199
|
+
label: 'West',
|
|
200
|
+
required: true
|
|
201
|
+
}]
|
|
202
|
+
}]
|
|
203
|
+
}];
|
|
204
|
+
var COLLECTION_ENTRY = {
|
|
205
|
+
summaryText: 'Full details',
|
|
206
|
+
collectionComponent: [{
|
|
207
|
+
north: 'Never',
|
|
208
|
+
east: 'Eat',
|
|
209
|
+
south: 'Shredded',
|
|
210
|
+
west: 'Wheat'
|
|
211
|
+
}]
|
|
212
|
+
};
|
|
213
|
+
var MASTER_PAGE = {
|
|
214
|
+
childPages: CHILD_PAGES
|
|
215
|
+
};
|
|
216
|
+
var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
217
|
+
masterPage: MASTER_PAGE,
|
|
218
|
+
childMasterPages: [],
|
|
219
|
+
formData: {},
|
|
220
|
+
entryData: COLLECTION_ENTRY
|
|
221
|
+
})),
|
|
222
|
+
container = _renderWithValidation3.container;
|
|
223
|
+
|
|
224
|
+
// Function to find an element by its text content
|
|
225
|
+
function getByTextContent(parent, text) {
|
|
226
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
227
|
+
return el.textContent === text;
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Check for section title
|
|
232
|
+
var section1Title = getByTextContent(container, 'Section 1');
|
|
233
|
+
expect(section1Title).not.toBeUndefined();
|
|
234
|
+
|
|
235
|
+
// All four subcomponents from the container should have labels and values displayed
|
|
236
|
+
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
237
|
+
expect(section1Content.textContent).toContain('North');
|
|
238
|
+
expect(section1Content.textContent).toContain('Never');
|
|
239
|
+
expect(section1Content.textContent).toContain('East');
|
|
240
|
+
expect(section1Content.textContent).toContain('Eat');
|
|
241
|
+
expect(section1Content.textContent).toContain('South');
|
|
242
|
+
expect(section1Content.textContent).toContain('Shredded');
|
|
243
|
+
expect(section1Content.textContent).toContain('West');
|
|
244
|
+
expect(section1Content.textContent).toContain('Wheat');
|
|
245
|
+
});
|
|
159
246
|
it('should render sections if they have show_when checks and pass them', function () {
|
|
160
247
|
var CHILD_PAGES = [{
|
|
161
248
|
summaryLayout: {
|
|
@@ -192,13 +279,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
192
279
|
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
193
280
|
showSection1: true
|
|
194
281
|
});
|
|
195
|
-
var
|
|
282
|
+
var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
196
283
|
masterPage: MASTER_PAGE,
|
|
197
284
|
childMasterPages: [],
|
|
198
285
|
formData: {},
|
|
199
286
|
entryData: CUSTOM_ENTRY
|
|
200
287
|
})),
|
|
201
|
-
container =
|
|
288
|
+
container = _renderWithValidation4.container;
|
|
202
289
|
|
|
203
290
|
// Function to find an element by its text content
|
|
204
291
|
function getByTextContent(parent, text) {
|
|
@@ -253,13 +340,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
253
340
|
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
254
341
|
showSection1: false
|
|
255
342
|
});
|
|
256
|
-
var
|
|
343
|
+
var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
257
344
|
masterPage: MASTER_PAGE,
|
|
258
345
|
childMasterPages: [],
|
|
259
346
|
formData: {},
|
|
260
347
|
entryData: CUSTOM_ENTRY
|
|
261
348
|
})),
|
|
262
|
-
container =
|
|
349
|
+
container = _renderWithValidation5.container;
|
|
263
350
|
|
|
264
351
|
// Function to find an element by its text content
|
|
265
352
|
function getByTextContent(parent, text) {
|
|
@@ -309,13 +396,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
309
396
|
var MASTER_PAGE = {
|
|
310
397
|
childPages: CHILD_PAGES
|
|
311
398
|
};
|
|
312
|
-
var
|
|
399
|
+
var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
313
400
|
masterPage: MASTER_PAGE,
|
|
314
401
|
childMasterPages: [],
|
|
315
402
|
formData: {},
|
|
316
403
|
entryData: ENTRY
|
|
317
404
|
})),
|
|
318
|
-
container =
|
|
405
|
+
container = _renderWithValidation6.container;
|
|
319
406
|
|
|
320
407
|
// Function to find an element by its text content
|
|
321
408
|
function getByTextContent(parent, text) {
|
|
@@ -376,7 +463,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
376
463
|
var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
|
|
377
464
|
showSection1: false
|
|
378
465
|
});
|
|
379
|
-
var
|
|
466
|
+
var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
380
467
|
masterPage: MASTER_PAGE,
|
|
381
468
|
childMasterPages: [],
|
|
382
469
|
formData: {
|
|
@@ -384,7 +471,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
384
471
|
},
|
|
385
472
|
entryData: CUSTOM_ENTRY
|
|
386
473
|
})),
|
|
387
|
-
container =
|
|
474
|
+
container = _renderWithValidation7.container;
|
|
388
475
|
|
|
389
476
|
// Function to find an element by its text content
|
|
390
477
|
function getByTextContent(parent, text) {
|
|
@@ -427,7 +514,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
427
514
|
var MASTER_PAGE = {
|
|
428
515
|
childPages: CHILD_PAGES
|
|
429
516
|
};
|
|
430
|
-
var
|
|
517
|
+
var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
431
518
|
masterPage: MASTER_PAGE,
|
|
432
519
|
childMasterPages: [],
|
|
433
520
|
formData: {
|
|
@@ -435,7 +522,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
435
522
|
},
|
|
436
523
|
entryData: ENTRY
|
|
437
524
|
})),
|
|
438
|
-
container =
|
|
525
|
+
container = _renderWithValidation8.container;
|
|
439
526
|
|
|
440
527
|
// Function to find an element by its text content
|
|
441
528
|
function getByTextContent(parent, text) {
|
|
@@ -493,13 +580,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
493
580
|
childPages: [].concat(CHILD_PAGES, CHILD_MASTER_PAGES)
|
|
494
581
|
};
|
|
495
582
|
var CHILD_COLLECTIONS = ['childCollection'];
|
|
496
|
-
var
|
|
583
|
+
var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
497
584
|
masterPage: MASTER_PAGE,
|
|
498
585
|
childCollections: CHILD_COLLECTIONS,
|
|
499
586
|
formData: {},
|
|
500
587
|
entryData: ENTRY
|
|
501
588
|
})),
|
|
502
|
-
container =
|
|
589
|
+
container = _renderWithValidation9.container;
|
|
503
590
|
|
|
504
591
|
// Function to find an element by its text content
|
|
505
592
|
function getByTextContent(parent, text) {
|
|
@@ -551,7 +638,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
551
638
|
var MASTER_PAGE = {
|
|
552
639
|
childPages: CHILD_PAGES
|
|
553
640
|
};
|
|
554
|
-
var
|
|
641
|
+
var _renderWithValidation10 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
555
642
|
masterPage: MASTER_PAGE,
|
|
556
643
|
childMasterPages: [],
|
|
557
644
|
formData: {},
|
|
@@ -559,7 +646,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
559
646
|
fieldA: 'notTheRightValue'
|
|
560
647
|
})
|
|
561
648
|
})),
|
|
562
|
-
container =
|
|
649
|
+
container = _renderWithValidation10.container;
|
|
563
650
|
|
|
564
651
|
// Function to find an element by its text content
|
|
565
652
|
function getByTextContent(parent, text) {
|
|
@@ -63,7 +63,8 @@ var SummaryList = function SummaryList(_ref) {
|
|
|
63
63
|
if (row.type === 'headingWithAction') {
|
|
64
64
|
return /*#__PURE__*/_react.default.createElement(_SummaryListHeadingRowWithAction.default, {
|
|
65
65
|
row: row,
|
|
66
|
-
classes: classes
|
|
66
|
+
classes: classes,
|
|
67
|
+
noChangeAction: noChangeAction
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
if (row.type === 'action') {
|
|
@@ -18,7 +18,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
18
18
|
|
|
19
19
|
var SummaryListHeadingRowWithAction = function SummaryListHeadingRowWithAction(_ref) {
|
|
20
20
|
var row = _ref.row,
|
|
21
|
-
classes = _ref.classes
|
|
21
|
+
classes = _ref.classes,
|
|
22
|
+
noChangeAction = _ref.noChangeAction;
|
|
22
23
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
23
24
|
className: classes('headingWithAction')
|
|
24
25
|
}, /*#__PURE__*/_react.default.createElement("td", {
|
|
@@ -26,7 +27,7 @@ var SummaryListHeadingRowWithAction = function SummaryListHeadingRowWithAction(_
|
|
|
26
27
|
colSpan: "2"
|
|
27
28
|
}, row.size === 's' && /*#__PURE__*/_react.default.createElement(_copReactComponents.SmallHeading, null, row.key), row.size === 'm' && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, row.key)), /*#__PURE__*/_react.default.createElement("td", {
|
|
28
29
|
className: "heading-action"
|
|
29
|
-
}, /*#__PURE__*/_react.default.createElement(_RowAction.default, {
|
|
30
|
+
}, !noChangeAction && /*#__PURE__*/_react.default.createElement(_RowAction.default, {
|
|
30
31
|
row: {
|
|
31
32
|
action: row.action
|
|
32
33
|
}
|
|
@@ -43,6 +44,10 @@ SummaryListHeadingRowWithAction.propTypes = {
|
|
|
43
44
|
aria_suffix: _propTypes.default.string,
|
|
44
45
|
onAction: _propTypes.default.func
|
|
45
46
|
})
|
|
46
|
-
}).isRequired
|
|
47
|
+
}).isRequired,
|
|
48
|
+
noChangeAction: _propTypes.default.bool
|
|
49
|
+
};
|
|
50
|
+
SummaryListHeadingRowWithAction.defaultProps = {
|
|
51
|
+
noChangeAction: false
|
|
47
52
|
};
|
|
48
53
|
var _default = exports.default = SummaryListHeadingRowWithAction;
|
|
@@ -25,7 +25,7 @@ var getComponentRowForCYA = function getComponentRowForCYA(page, component, cust
|
|
|
25
25
|
row: {
|
|
26
26
|
key: row.key,
|
|
27
27
|
value: /*#__PURE__*/_react.default.createElement(_Answer.default, {
|
|
28
|
-
value: row.value,
|
|
28
|
+
value: row.value || component.value,
|
|
29
29
|
component: row.component,
|
|
30
30
|
formData: modifiedPage.formData
|
|
31
31
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.78.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "3.21.0",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|