@ukhomeoffice/cop-react-form-renderer 5.56.1 → 5.58.0

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.
@@ -36,7 +36,9 @@ var BannerStrip = function BannerStrip(_ref) {
36
36
  id: bannerId,
37
37
  key: bannerId,
38
38
  className: classes('banner')
39
- }, _utils.default.interpolateString(banner, formData));
39
+ }, /*#__PURE__*/_react.default.createElement(_copReactComponents.Markup, {
40
+ content: _utils.default.interpolateString(banner, formData)
41
+ }));
40
42
  }
41
43
  return /*#__PURE__*/_react.default.createElement(_copReactComponents.Tag, {
42
44
  key: bannerId,
@@ -7,9 +7,13 @@
7
7
  padding: 0;
8
8
  margin: 0 0 govuk-spacing(1) 0;
9
9
  &__banner {
10
- @include govuk-font($size: 19, $weight: bold);
10
+ @include govuk-font($size: 19);
11
11
  display: inline-block;
12
12
  margin-right: govuk-spacing(2);
13
+
14
+ p {
15
+ margin: 0;
16
+ }
13
17
  }
14
18
  &__tag {
15
19
  @extend .govuk-tag;
@@ -64,11 +64,24 @@ var CollectionSummary = function CollectionSummary(_ref) {
64
64
  return _utils.default.CollectionPage.getData(config.collectionName, formData) || [];
65
65
  }, [formData]);
66
66
  var masterPage = (0, _react.useMemo)(function () {
67
- var newMasterPages = _utils.default.CollectionPage.mergePages(pages || []) || [];
68
- return newMasterPages.find(function (page) {
69
- var _page$collection;
70
- return ((_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name) === config.collectionName;
71
- });
67
+ var collectionNameParts = config.collectionName.split('.');
68
+ var childPages = _utils.default.CollectionPage.mergePages(pages || []) || [];
69
+ return collectionNameParts.reduce(function (acc, current, index) {
70
+ var _childPages$find;
71
+ var currentPath = index === 0 ? "".concat(acc).concat(current) : "".concat(acc, ".").concat(current);
72
+ if (index === collectionNameParts.length - 1) {
73
+ var _childPages;
74
+ return ((_childPages = childPages) === null || _childPages === void 0 ? void 0 : _childPages.find(function (p) {
75
+ var _p$collection;
76
+ return ((_p$collection = p.collection) === null || _p$collection === void 0 ? void 0 : _p$collection.name) === currentPath;
77
+ })) || null;
78
+ }
79
+ childPages = ((_childPages$find = childPages.find(function (p) {
80
+ var _p$collection2;
81
+ return ((_p$collection2 = p.collection) === null || _p$collection2 === void 0 ? void 0 : _p$collection2.name) === currentPath;
82
+ })) === null || _childPages$find === void 0 ? void 0 : _childPages$find.childPages) || null;
83
+ return currentPath;
84
+ }, "");
72
85
  }, [pages]);
73
86
  var validateEntries = function validateEntries() {
74
87
  var stored = [];
@@ -224,6 +237,7 @@ var CollectionSummary = function CollectionSummary(_ref) {
224
237
  return onChange(target);
225
238
  },
226
239
  parentCollectionName: config.collectionName.split('.').shift(),
240
+ childCollections: config.childCollections || [],
227
241
  formData: formData,
228
242
  classModifiers: entry === entryToDelete ? ['deleting-summary-card'] : [''],
229
243
  inError: errors.filter(function (e) {
@@ -260,7 +274,8 @@ CollectionSummary.propTypes = {
260
274
  confirmation: _propTypes.default.shape({
261
275
  message: _propTypes.default.string,
262
276
  label: _propTypes.default.string
263
- })
277
+ }),
278
+ childCollections: _propTypes.default.arrayOf(_propTypes.default.string)
264
279
  }).isRequired,
265
280
  onAction: _propTypes.default.func,
266
281
  onChange: _propTypes.default.func,
@@ -11,10 +11,10 @@ var _react = _interopRequireWildcard(require("react"));
11
11
  var _utils = _interopRequireDefault(require("../../utils"));
12
12
  var _getQuickEditPage = _interopRequireDefault(require("../../utils/CollectionPage/getQuickEditPage"));
13
13
  var _hooks = require("../../hooks");
14
- var _FormComponent = _interopRequireDefault(require("../FormComponent"));
15
14
  var _FormPage = _interopRequireDefault(require("../FormPage"));
16
15
  var _BannerStrip = _interopRequireDefault(require("./BannerStrip"));
17
16
  var _RenderListView = _interopRequireDefault(require("./RenderListView"));
17
+ var _SummaryCardDetails = _interopRequireDefault(require("./SummaryCardDetails"));
18
18
  require("./SummaryCard.scss");
19
19
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
20
20
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -44,7 +44,7 @@ var DEFAULT_DUPLICATE_BUTTON_LABEL = exports.DEFAULT_DUPLICATE_BUTTON_LABEL = 'D
44
44
  var DEFAULT_DETAILS_TITLE = exports.DEFAULT_DETAILS_TITLE = 'Full details';
45
45
  var DEFAULT_CHANGE_BUTTON_CLASS = exports.DEFAULT_CHANGE_BUTTON_CLASS = 'secondary';
46
46
  var SummaryCard = function SummaryCard(_ref) {
47
- var _config$changeAction2, _config$changeAction3, _config$duplicateActi, _config$deleteAction, _masterPage$childPage;
47
+ var _config$changeAction2, _config$changeAction3, _config$deleteAction, _config$duplicateActi;
48
48
  var id = _ref.id,
49
49
  entryData = _ref.entryData,
50
50
  config = _ref.config,
@@ -54,6 +54,7 @@ var SummaryCard = function SummaryCard(_ref) {
54
54
  onDuplicate = _ref.onDuplicate,
55
55
  onQuickEdit = _ref.onQuickEdit,
56
56
  parentCollectionName = _ref.parentCollectionName,
57
+ childCollections = _ref.childCollections,
57
58
  formData = _ref.formData,
58
59
  masterPage = _ref.masterPage,
59
60
  hideDetails = _ref.hideDetails,
@@ -180,19 +181,19 @@ var SummaryCard = function SummaryCard(_ref) {
180
181
  return onChange((_config$changeAction = config.changeAction) === null || _config$changeAction === void 0 ? void 0 : _config$changeAction.page, entryData.id);
181
182
  },
182
183
  classModifiers: ((_config$changeAction2 = config.changeAction) === null || _config$changeAction2 === void 0 ? void 0 : _config$changeAction2.classModifiers) || DEFAULT_CHANGE_BUTTON_CLASS
183
- }, ((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.label) || DEFAULT_CHANGE_BUTTON_LABEL), config.duplicateAction && typeof onDuplicate === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
184
- id: "".concat(id, ".duplicateButton"),
184
+ }, ((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.label) || DEFAULT_CHANGE_BUTTON_LABEL), config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
185
+ id: "".concat(id, ".deleteButton"),
185
186
  onClick: function onClick() {
186
- onDuplicate(entryData);
187
+ return onDelete(entryData);
187
188
  },
188
189
  classModifiers: "secondary"
189
- }, ((_config$duplicateActi = config.duplicateAction) === null || _config$duplicateActi === void 0 ? void 0 : _config$duplicateActi.label) || DEFAULT_DUPLICATE_BUTTON_LABEL), config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
190
- id: "".concat(id, ".deleteButton"),
190
+ }, ((_config$deleteAction = config.deleteAction) === null || _config$deleteAction === void 0 ? void 0 : _config$deleteAction.label) || DEFAULT_DELETE_BUTTON_LABEL), config.duplicateAction && typeof onDuplicate === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
191
+ id: "".concat(id, ".duplicateButton"),
191
192
  onClick: function onClick() {
192
- return onDelete(entryData);
193
+ onDuplicate(entryData);
193
194
  },
194
195
  classModifiers: "secondary"
195
- }, ((_config$deleteAction = config.deleteAction) === null || _config$deleteAction === void 0 ? void 0 : _config$deleteAction.label) || DEFAULT_DELETE_BUTTON_LABEL))), quickEdit && quickEditPage && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
196
+ }, ((_config$duplicateActi = config.duplicateAction) === null || _config$duplicateActi === void 0 ? void 0 : _config$duplicateActi.label) || DEFAULT_DUPLICATE_BUTTON_LABEL))), quickEdit && quickEditPage && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
196
197
  page: quickEditPage,
197
198
  onAction: function onAction(action, patch) {
198
199
  return _onAction(action, patch);
@@ -203,43 +204,11 @@ var SummaryCard = function SummaryCard(_ref) {
203
204
  }, !hideDetails && /*#__PURE__*/_react.default.createElement(_copReactComponents.Details, {
204
205
  summary: config.detailsTitle || DEFAULT_DETAILS_TITLE,
205
206
  className: "details"
206
- }, masterPage === null || masterPage === void 0 || (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.filter(function (p) {
207
- return _utils.default.FormPage.show(p, _objectSpread(_objectSpread({}, formData), entryData));
208
- }).map(function (childPage) {
209
- var _childPage$summaryLay;
210
- var allPageComponents = _utils.default.Component.elevateNested(childPage === null || childPage === void 0 ? void 0 : childPage.components, entryData);
211
- return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.sections.map(function (section) {
212
- var _section$fields;
213
- if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
214
- return null;
215
- }
216
- return /*#__PURE__*/_react.default.createElement("div", {
217
- key: section.title,
218
- className: classes('section')
219
- }, /*#__PURE__*/_react.default.createElement("h3", {
220
- className: classes('section-title')
221
- }, section.title), /*#__PURE__*/_react.default.createElement("div", {
222
- className: classes('section-content', "columns-".concat(section.columns))
223
- }, (_section$fields = section.fields) === null || _section$fields === void 0 ? void 0 : _section$fields.map(function (fieldId) {
224
- var component = allPageComponents.find(function (comp) {
225
- return comp.fieldId === fieldId;
226
- });
227
- return /*#__PURE__*/_react.default.createElement("div", {
228
- key: fieldId,
229
- className: classes('field')
230
- }, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
231
- component: _objectSpread(_objectSpread({}, component), {}, {
232
- hint: ''
233
- }),
234
- value: entryData[component === null || component === void 0 ? void 0 : component.fieldId],
235
- formData: entryData,
236
- wrap: true,
237
- readonly: true
238
- }));
239
- })));
240
- });
241
- }).filter(function (e) {
242
- return !!e;
207
+ }, /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
208
+ masterPage: masterPage,
209
+ childCollections: childCollections,
210
+ formData: formData,
211
+ entryData: entryData
243
212
  }))));
244
213
  };
245
214
  SummaryCard.propTypes = {
@@ -282,6 +251,7 @@ SummaryCard.propTypes = {
282
251
  onDuplicate: _propTypes.default.func,
283
252
  onQuickEdit: _propTypes.default.func,
284
253
  parentCollectionName: _propTypes.default.string.isRequired,
254
+ childCollections: _propTypes.default.arrayOf(_propTypes.default.string),
285
255
  formData: _propTypes.default.shape({}).isRequired,
286
256
  hideDetails: _propTypes.default.bool,
287
257
  inError: _propTypes.default.bool
@@ -292,6 +262,7 @@ SummaryCard.defaultProps = {
292
262
  onDelete: null,
293
263
  onDuplicate: null,
294
264
  onQuickEdit: null,
265
+ childCollections: [],
295
266
  hideDetails: false,
296
267
  inError: false
297
268
  };
@@ -71,7 +71,9 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
71
71
  }
72
72
 
73
73
  &__editpage {
74
- margin: 0 govuk-spacing(4)
74
+ margin: 0 govuk-spacing(4);
75
+ padding: govuk-spacing(4) govuk-spacing(4) 0;
76
+ background-color: #FFFFFF
75
77
  }
76
78
 
77
79
  &__body {
@@ -87,111 +89,6 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
87
89
  margin-bottom: 0;
88
90
  }
89
91
  }
90
-
91
- &__section {
92
- border-bottom: 2px solid #A9A9A9;
93
-
94
- &-title {
95
- font-weight: bold;
96
- margin: govuk-spacing(2) 0 govuk-spacing(6) 0;
97
- }
98
-
99
- &-content {
100
- display: flex;
101
- flex-wrap: wrap;
102
- gap: govuk-spacing(2);
103
-
104
- .hods-form-summary-card__field {
105
- box-sizing: border-box;
106
- margin-bottom: govuk-spacing(4);
107
-
108
- .govuk-label,
109
- .govuk-fieldset__legend {
110
- font-weight: bold;
111
- margin-bottom: govuk-spacing(1) !important;
112
-
113
- &::after {
114
- content: " :";
115
- }
116
- }
117
-
118
- div.govuk-form-group div:has(img){
119
- display: flex;
120
- flex-wrap: wrap;
121
-
122
- .hods-readonly.hods-readonly--success {
123
- font-size: 0;
124
- line-height: 0;
125
-
126
- .cop-upload-preview__thumb {
127
- display: inline-block;
128
- margin-right: govuk-spacing(1);
129
- }
130
- }
131
-
132
- }
133
- }
134
-
135
- &--columns-1,
136
- &--columns-2,
137
- &--columns-3 {
138
- position: relative;
139
- margin-bottom: govuk-spacing(1);
140
-
141
- &::before {
142
- content: "";
143
- position: absolute;
144
- top: 0;
145
- width: 2px;
146
- height: 100%;
147
- background-color: #A9A9A9;
148
- left: 0;
149
- }
150
- }
151
-
152
- &--columns-2 {
153
- &::after {
154
- content: "";
155
- position: absolute;
156
- top: 0;
157
- width: 2px;
158
- height: 100%;
159
- background-color: #A9A9A9;
160
- left: 50%;
161
- }
162
-
163
- .hods-form-summary-card__field {
164
- flex: 0 0 calc(50% - 10px);
165
- }
166
- }
167
-
168
- &--columns-3 {
169
- &::after {
170
- content: "";
171
- position: absolute;
172
- top: 0;
173
- left: 33.333%;
174
- width: 2px;
175
- height: 100%;
176
- background-color: #A9A9A9;
177
- }
178
-
179
- .hods-form-summary-card__field {
180
- flex: 0 0 calc(33.333% - 10px);
181
-
182
- &:nth-child(2)::after {
183
- content: "";
184
- position: absolute;
185
- top: 0;
186
- right: 33.333%;
187
- width: 2px;
188
- height: 100%;
189
- background-color: #A9A9A9;
190
- }
191
- }
192
- }
193
- }
194
- }
195
92
  }
196
93
 
197
94
  @media (max-width: 640px) {
@@ -208,45 +105,5 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
208
105
  margin-top: govuk-spacing(2);
209
106
  }
210
107
  }
211
-
212
- &__section {
213
- &-content {
214
- display: block;
215
-
216
- .hods-form-summary-card__field {
217
- width: 100%;
218
- }
219
-
220
- .hods-form-summary-card__field:nth-child(2)::after {
221
- display: none;
222
- }
223
-
224
- &--columns-2,
225
- &--columns-3 {
226
- position: relative;
227
- margin-bottom: govuk-spacing(1);
228
-
229
- &::before {
230
- content: '';
231
- position: absolute;
232
- top: 0;
233
- width: 2px;
234
- height: 100%;
235
- background-color: #A9A9A9;
236
- left: 0;
237
- }
238
-
239
- &::after {
240
- display: none;
241
- }
242
- }
243
-
244
- &--columns-3 {
245
- .hods-form-summary-card__field:nth-child(2)::after {
246
- content: none;
247
- }
248
- }
249
- }
250
- }
251
108
  }
252
109
  }
@@ -1366,247 +1366,4 @@ describe('components.CollectionSummary.SummaryCard', function () {
1366
1366
  expect(detailsComponent).toBeNull();
1367
1367
  });
1368
1368
  });
1369
- describe('SummaryLayout config behavior', function () {
1370
- it('should render sections and fields based on summaryLayout config', function () {
1371
- var CHILD_PAGES = [{
1372
- summaryLayout: {
1373
- sections: [{
1374
- title: 'Section 1',
1375
- columns: 2,
1376
- fields: ['fieldA', 'fieldB']
1377
- }, {
1378
- title: 'Section 2',
1379
- columns: 1,
1380
- fields: ['fieldC']
1381
- }]
1382
- },
1383
- components: [{
1384
- fieldId: 'fieldA'
1385
- }, {
1386
- fieldId: 'fieldB'
1387
- }, {
1388
- fieldId: 'fieldC'
1389
- }]
1390
- }];
1391
- var CONFIG = {
1392
- title: 'Title'
1393
- };
1394
- var _renderWithValidation36 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1395
- id: ID,
1396
- entryData: ENTRY,
1397
- config: CONFIG,
1398
- parentCollectionName: "parent",
1399
- pages: CHILD_PAGES,
1400
- formData: {},
1401
- masterPage: {
1402
- childPages: CHILD_PAGES
1403
- }
1404
- })),
1405
- container = _renderWithValidation36.container;
1406
-
1407
- // Function to find an element by its text content
1408
- function getByTextContent(parent, text) {
1409
- return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
1410
- return el.textContent === text;
1411
- });
1412
- }
1413
-
1414
- // Check for section titles
1415
- var section1Title = getByTextContent(container, 'Section 1');
1416
- var section2Title = getByTextContent(container, 'Section 2');
1417
- expect(section1Title).not.toBeUndefined();
1418
- expect(section2Title).not.toBeUndefined();
1419
- var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
1420
- expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
1421
- var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
1422
- expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
1423
- });
1424
- it('should render sections if they have show_when checks and pass them', function () {
1425
- var CHILD_PAGES = [{
1426
- summaryLayout: {
1427
- sections: [{
1428
- title: 'Section 1',
1429
- columns: 2,
1430
- fields: ['fieldA', 'fieldB'],
1431
- show_when: [{
1432
- field: 'showSection1',
1433
- op: "=",
1434
- value: true
1435
- }]
1436
- }, {
1437
- title: 'Section 2',
1438
- columns: 1,
1439
- fields: ['fieldC']
1440
- }]
1441
- },
1442
- components: [{
1443
- fieldId: 'fieldA'
1444
- }, {
1445
- fieldId: 'fieldB'
1446
- }, {
1447
- fieldId: 'fieldC'
1448
- }]
1449
- }];
1450
- var CONFIG = {
1451
- title: 'Title'
1452
- };
1453
- var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
1454
- showSection1: true
1455
- });
1456
- var _renderWithValidation37 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1457
- id: ID,
1458
- entryData: CUSTOM_ENTRY,
1459
- config: CONFIG,
1460
- parentCollectionName: "parent",
1461
- pages: CHILD_PAGES,
1462
- formData: {},
1463
- masterPage: {
1464
- childPages: CHILD_PAGES
1465
- }
1466
- })),
1467
- container = _renderWithValidation37.container;
1468
-
1469
- // Function to find an element by its text content
1470
- function getByTextContent(parent, text) {
1471
- return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
1472
- return el.textContent === text;
1473
- });
1474
- }
1475
-
1476
- // Check for section titles
1477
- var section1Title = getByTextContent(container, 'Section 1');
1478
- var section2Title = getByTextContent(container, 'Section 2');
1479
- expect(section1Title).not.toBeUndefined();
1480
- expect(section2Title).not.toBeUndefined();
1481
- var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
1482
- expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
1483
- var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
1484
- expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
1485
- });
1486
- it('should not render sections if they have show_when checks and fail them', function () {
1487
- var CHILD_PAGES = [{
1488
- summaryLayout: {
1489
- sections: [{
1490
- title: 'Section 1',
1491
- columns: 2,
1492
- fields: ['fieldA', 'fieldB'],
1493
- show_when: [{
1494
- field: 'showSection1',
1495
- op: "=",
1496
- value: true
1497
- }]
1498
- }, {
1499
- title: 'Section 2',
1500
- columns: 1,
1501
- fields: ['fieldC']
1502
- }]
1503
- },
1504
- components: [{
1505
- fieldId: 'fieldA'
1506
- }, {
1507
- fieldId: 'fieldB'
1508
- }, {
1509
- fieldId: 'fieldC'
1510
- }]
1511
- }];
1512
- var CONFIG = {
1513
- title: 'Title'
1514
- };
1515
- var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
1516
- showSection1: false
1517
- });
1518
- var _renderWithValidation38 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1519
- id: ID,
1520
- entryData: CUSTOM_ENTRY,
1521
- config: CONFIG,
1522
- parentCollectionName: "parent",
1523
- pages: CHILD_PAGES,
1524
- formData: {},
1525
- masterPage: {
1526
- childPages: CHILD_PAGES
1527
- }
1528
- })),
1529
- container = _renderWithValidation38.container;
1530
-
1531
- // Function to find an element by its text content
1532
- function getByTextContent(parent, text) {
1533
- return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
1534
- return el.textContent === text;
1535
- });
1536
- }
1537
-
1538
- // Check for section titles
1539
- var section1Title = getByTextContent(container, 'Section 1');
1540
- var section2Title = getByTextContent(container, 'Section 2');
1541
- expect(section1Title).toBeUndefined();
1542
- expect(section2Title).not.toBeUndefined();
1543
- var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
1544
- expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
1545
- });
1546
- it('should not render sections on pages that fail show_when checks', function () {
1547
- var CHILD_PAGES = [{
1548
- show_when: [{
1549
- field: 'testField',
1550
- op: '=',
1551
- value: true
1552
- }],
1553
- summaryLayout: {
1554
- sections: [{
1555
- title: 'Section 1',
1556
- columns: 2,
1557
- fields: ['fieldA', 'fieldB'],
1558
- show_when: [{
1559
- field: 'showSection1',
1560
- op: "=",
1561
- value: true
1562
- }]
1563
- }, {
1564
- title: 'Section 2',
1565
- columns: 1,
1566
- fields: ['fieldC']
1567
- }]
1568
- },
1569
- components: [{
1570
- fieldId: 'fieldA'
1571
- }, {
1572
- fieldId: 'fieldB'
1573
- }, {
1574
- fieldId: 'fieldC'
1575
- }]
1576
- }];
1577
- var CONFIG = {
1578
- title: 'Title'
1579
- };
1580
- var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
1581
- showSection1: false
1582
- });
1583
- var _renderWithValidation39 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
1584
- id: ID,
1585
- entryData: CUSTOM_ENTRY,
1586
- config: CONFIG,
1587
- parentCollectionName: "parent",
1588
- pages: CHILD_PAGES,
1589
- formData: {
1590
- testField: false
1591
- },
1592
- masterPage: {
1593
- childPages: CHILD_PAGES
1594
- }
1595
- })),
1596
- container = _renderWithValidation39.container;
1597
-
1598
- // Function to find an element by its text content
1599
- function getByTextContent(parent, text) {
1600
- return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
1601
- return el.textContent === text;
1602
- });
1603
- }
1604
-
1605
- // Check for section titles
1606
- var section1Title = getByTextContent(container, 'Section 1');
1607
- var section2Title = getByTextContent(container, 'Section 2');
1608
- expect(section1Title).toBeUndefined();
1609
- expect(section2Title).toBeUndefined();
1610
- });
1611
- });
1612
1369
  });
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.DEFAULT_CLASS = void 0;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _utils = _interopRequireDefault(require("../../utils"));
10
+ var _FormComponent = _interopRequireDefault(require("../FormComponent"));
11
+ require("./SummaryCardDetails.scss");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
20
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // Global imports.
21
+ // Local imports.
22
+ // Styles.
23
+ var DEFAULT_CLASS = exports.DEFAULT_CLASS = 'hods-form-summary-card-details';
24
+ var SummaryCardDetails = function SummaryCardDetails(_ref) {
25
+ var _masterPage$childPage;
26
+ var masterPage = _ref.masterPage,
27
+ childCollections = _ref.childCollections,
28
+ formData = _ref.formData,
29
+ entryData = _ref.entryData,
30
+ classModifiers = _ref.classModifiers,
31
+ hideChildSectionTitles = _ref.hideChildSectionTitles;
32
+ var classes = _utils.default.classBuilder(DEFAULT_CLASS, classModifiers);
33
+ var childMasterPages = (0, _react.useMemo)(function () {
34
+ return childCollections.map(function (childName) {
35
+ return masterPage.childPages.find(function (page) {
36
+ var _page$collection;
37
+ return ((_page$collection = page.collection) === null || _page$collection === void 0 ? void 0 : _page$collection.name) === childName;
38
+ });
39
+ }).filter(function (e) {
40
+ return !!e;
41
+ });
42
+ }, [masterPage, childCollections]);
43
+ return (masterPage === null || masterPage === void 0 || (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.filter(function (p) {
44
+ return _utils.default.FormPage.show(p, _objectSpread(_objectSpread({}, formData), entryData));
45
+ }).map(function (childPage) {
46
+ var _childPage$summaryLay;
47
+ var allPageComponents = _utils.default.Component.elevateNested(childPage === null || childPage === void 0 ? void 0 : childPage.components, entryData);
48
+ return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.sections.map(function (section) {
49
+ var _section$fields;
50
+ if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
51
+ return null;
52
+ }
53
+ if (section.type === 'childCollection') {
54
+ var childMasterPage = childMasterPages.find(function (p) {
55
+ return p.collection.name === section.collectionName;
56
+ });
57
+ var childFormData = entryData[section.collectionName.split('.').pop()] || [];
58
+ if (childMasterPage && childFormData.length > 0) {
59
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h3", {
60
+ className: classes('section-title')
61
+ }, section.title), childFormData.map(function (entry) {
62
+ return /*#__PURE__*/_react.default.createElement(SummaryCardDetails, {
63
+ masterPage: childMasterPage,
64
+ childMasterPages: [],
65
+ formData: _objectSpread(_objectSpread(_objectSpread({}, formData), entryData), entry),
66
+ entryData: entry,
67
+ hideChildSectionTitles: true
68
+ });
69
+ }));
70
+ }
71
+ return null;
72
+ }
73
+ return /*#__PURE__*/_react.default.createElement("div", {
74
+ key: section.title,
75
+ className: classes('section')
76
+ }, !hideChildSectionTitles && /*#__PURE__*/_react.default.createElement("h3", {
77
+ className: classes('section-title')
78
+ }, section.title), /*#__PURE__*/_react.default.createElement("div", {
79
+ className: classes('section-content', "columns-".concat(section.columns))
80
+ }, (_section$fields = section.fields) === null || _section$fields === void 0 ? void 0 : _section$fields.map(function (fieldId) {
81
+ var component = allPageComponents.find(function (comp) {
82
+ return comp.fieldId === fieldId;
83
+ });
84
+ return /*#__PURE__*/_react.default.createElement("div", {
85
+ key: fieldId,
86
+ className: classes('field')
87
+ }, /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
88
+ component: _objectSpread(_objectSpread({}, component), {}, {
89
+ hint: ''
90
+ }),
91
+ value: entryData[component === null || component === void 0 ? void 0 : component.fieldId],
92
+ formData: entryData,
93
+ wrap: true,
94
+ readonly: true
95
+ }));
96
+ })));
97
+ });
98
+ }).filter(function (e) {
99
+ return !!e;
100
+ })) || null;
101
+ };
102
+ SummaryCardDetails.propTypes = {
103
+ childCollections: _propTypes.default.arrayOf(_propTypes.default.string),
104
+ masterPage: _propTypes.default.shape({
105
+ childPages: _propTypes.default.arrayOf(_propTypes.default.shape({})).isRequired
106
+ }).isRequired,
107
+ formData: _propTypes.default.shape({}).isRequired,
108
+ entryData: _propTypes.default.shape({}).isRequired,
109
+ classModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
110
+ hideChildSectionTitles: _propTypes.default.bool
111
+ };
112
+ SummaryCardDetails.defaultProps = {
113
+ childCollections: [],
114
+ classModifiers: null,
115
+ hideChildSectionTitles: false
116
+ };
117
+ var _default = exports.default = SummaryCardDetails;
@@ -0,0 +1,158 @@
1
+ $govuk-font-family: 'Roboto', arial, sans-serif;
2
+
3
+ @import "node_modules/govuk-frontend/govuk/_base";
4
+
5
+ .govuk-grid-column-two-thirds:has(.hods-form-summary-card-details) {
6
+ width: 100% !important;
7
+ }
8
+
9
+ .hods-form-summary-card-details {
10
+ &__section {
11
+ border-bottom: 2px solid #E9EBED;
12
+
13
+ &-title {
14
+ font-weight: bold;
15
+ margin: govuk-spacing(2) 0 govuk-spacing(6) 0;
16
+ }
17
+
18
+ &-content {
19
+ display: flex;
20
+ flex-wrap: wrap;
21
+ gap: govuk-spacing(2);
22
+
23
+ .hods-form-summary-card-details__field {
24
+ box-sizing: border-box;
25
+ margin-bottom: govuk-spacing(4);
26
+
27
+ .govuk-label,
28
+ .govuk-fieldset__legend {
29
+ font-weight: bold;
30
+ margin-bottom: govuk-spacing(1) !important;
31
+
32
+ &::after {
33
+ content: " :";
34
+ }
35
+ }
36
+
37
+ div.govuk-form-group div:has(img){
38
+ display: flex;
39
+ flex-wrap: wrap;
40
+
41
+ .hods-readonly.hods-readonly--success {
42
+ font-size: 0;
43
+ line-height: 0;
44
+
45
+ .cop-upload-preview__thumb {
46
+ display: inline-block;
47
+ margin-right: govuk-spacing(1);
48
+ }
49
+ }
50
+
51
+ }
52
+ }
53
+
54
+ &--columns-1,
55
+ &--columns-2,
56
+ &--columns-3 {
57
+ position: relative;
58
+ margin-bottom: govuk-spacing(1);
59
+
60
+ &::before {
61
+ content: "";
62
+ position: absolute;
63
+ top: 0;
64
+ width: 2px;
65
+ height: 100%;
66
+ background-color: #E9EBED;
67
+ left: 0;
68
+ }
69
+ }
70
+
71
+ &--columns-2 {
72
+ &::after {
73
+ content: "";
74
+ position: absolute;
75
+ top: 0;
76
+ width: 2px;
77
+ height: 100%;
78
+ background-color: #E9EBED;
79
+ left: 50%;
80
+ }
81
+
82
+ .hods-form-summary-card-details__field {
83
+ flex: 0 0 calc(50% - 10px);
84
+ }
85
+ }
86
+
87
+ &--columns-3 {
88
+ &::after {
89
+ content: "";
90
+ position: absolute;
91
+ top: 0;
92
+ left: 33.333%;
93
+ width: 2px;
94
+ height: 100%;
95
+ background-color: #E9EBED;
96
+ }
97
+
98
+ .hods-form-summary-card-details__field {
99
+ flex: 0 0 calc(33.333% - 10px);
100
+
101
+ &:nth-child(2)::after {
102
+ content: "";
103
+ position: absolute;
104
+ top: 0;
105
+ right: 33.333%;
106
+ width: 2px;
107
+ height: 100%;
108
+ background-color: #E9EBED;
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ @media (max-width: 640px) {
117
+ .hods-form-summary-card-details {
118
+ &__section {
119
+ &-content {
120
+ display: block;
121
+
122
+ .hods-form-summary-card-details__field {
123
+ width: 100%;
124
+ }
125
+
126
+ .hods-form-summary-card-details__field:nth-child(2)::after {
127
+ display: none;
128
+ }
129
+
130
+ &--columns-2,
131
+ &--columns-3 {
132
+ position: relative;
133
+ margin-bottom: govuk-spacing(1);
134
+
135
+ &::before {
136
+ content: '';
137
+ position: absolute;
138
+ top: 0;
139
+ width: 2px;
140
+ height: 100%;
141
+ background-color: #A9A9A9;
142
+ left: 0;
143
+ }
144
+
145
+ &::after {
146
+ display: none;
147
+ }
148
+ }
149
+
150
+ &--columns-3 {
151
+ .hods-form-summary-card-details__field:nth-child(2)::after {
152
+ content: none;
153
+ }
154
+ }
155
+ }
156
+ }
157
+ }
158
+ }
@@ -0,0 +1,319 @@
1
+ "use strict";
2
+
3
+ var _react = _interopRequireDefault(require("react"));
4
+ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
5
+ var _setupTests = require("../../setupTests");
6
+ var _SummaryCardDetails = _interopRequireWildcard(require("./SummaryCardDetails"));
7
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
8
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
15
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } // Global imports.
16
+ // Local imports.
17
+ describe('components.CollectionSummary.SummaryCardDetails', function () {
18
+ var classes = _copReactComponents.Utils.classBuilder(_SummaryCardDetails.DEFAULT_CLASS, [], '');
19
+ var ENTRY = {
20
+ id: '001',
21
+ bannerText: 'A banner',
22
+ titleText: 'A title',
23
+ detailsText: 'Some details',
24
+ index: 0,
25
+ summaryText: 'Full details',
26
+ childCollection: [{
27
+ id: '001',
28
+ childField1: 'alpha',
29
+ childField2: 'bravo'
30
+ }, {
31
+ id: '002',
32
+ childField1: 'alpha',
33
+ childField2: 'bravo'
34
+ }]
35
+ };
36
+ it('should render sections and fields based on summaryLayout config', function () {
37
+ var CHILD_PAGES = [{
38
+ summaryLayout: {
39
+ sections: [{
40
+ title: 'Section 1',
41
+ columns: 2,
42
+ fields: ['fieldA', 'fieldB']
43
+ }, {
44
+ title: 'Section 2',
45
+ columns: 1,
46
+ fields: ['fieldC']
47
+ }]
48
+ },
49
+ components: [{
50
+ fieldId: 'fieldA'
51
+ }, {
52
+ fieldId: 'fieldB'
53
+ }, {
54
+ fieldId: 'fieldC'
55
+ }]
56
+ }];
57
+ var MASTER_PAGE = {
58
+ childPages: CHILD_PAGES
59
+ };
60
+ var _renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
61
+ masterPage: MASTER_PAGE,
62
+ childMasterPages: [],
63
+ formData: {},
64
+ entryData: ENTRY
65
+ })),
66
+ container = _renderWithValidation.container;
67
+
68
+ // Function to find an element by its text content
69
+ function getByTextContent(parent, text) {
70
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
71
+ return el.textContent === text;
72
+ });
73
+ }
74
+
75
+ // Check for section titles
76
+ var section1Title = getByTextContent(container, 'Section 1');
77
+ var section2Title = getByTextContent(container, 'Section 2');
78
+ expect(section1Title).not.toBeUndefined();
79
+ expect(section2Title).not.toBeUndefined();
80
+ var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
81
+ expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
82
+ var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
83
+ expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
84
+ });
85
+ it('should render sections if they have show_when checks and pass them', function () {
86
+ var CHILD_PAGES = [{
87
+ summaryLayout: {
88
+ sections: [{
89
+ title: 'Section 1',
90
+ columns: 2,
91
+ fields: ['fieldA', 'fieldB'],
92
+ show_when: [{
93
+ field: 'showSection1',
94
+ op: "=",
95
+ value: true
96
+ }]
97
+ }, {
98
+ title: 'Section 2',
99
+ columns: 1,
100
+ fields: ['fieldC']
101
+ }]
102
+ },
103
+ components: [{
104
+ fieldId: 'fieldA'
105
+ }, {
106
+ fieldId: 'fieldB'
107
+ }, {
108
+ fieldId: 'fieldC'
109
+ }]
110
+ }];
111
+ var MASTER_PAGE = {
112
+ childPages: CHILD_PAGES
113
+ };
114
+ var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
115
+ showSection1: true
116
+ });
117
+ var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
118
+ masterPage: MASTER_PAGE,
119
+ childMasterPages: [],
120
+ formData: {},
121
+ entryData: CUSTOM_ENTRY
122
+ })),
123
+ container = _renderWithValidation2.container;
124
+
125
+ // Function to find an element by its text content
126
+ function getByTextContent(parent, text) {
127
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
128
+ return el.textContent === text;
129
+ });
130
+ }
131
+
132
+ // Check for section titles
133
+ var section1Title = getByTextContent(container, 'Section 1');
134
+ var section2Title = getByTextContent(container, 'Section 2');
135
+ expect(section1Title).not.toBeUndefined();
136
+ expect(section2Title).not.toBeUndefined();
137
+ var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
138
+ expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
139
+ var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
140
+ expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
141
+ });
142
+ it('should not render sections if they have show_when checks and fail them', function () {
143
+ var CHILD_PAGES = [{
144
+ summaryLayout: {
145
+ sections: [{
146
+ title: 'Section 1',
147
+ columns: 2,
148
+ fields: ['fieldA', 'fieldB'],
149
+ show_when: [{
150
+ field: 'showSection1',
151
+ op: "=",
152
+ value: true
153
+ }]
154
+ }, {
155
+ title: 'Section 2',
156
+ columns: 1,
157
+ fields: ['fieldC']
158
+ }]
159
+ },
160
+ components: [{
161
+ fieldId: 'fieldA'
162
+ }, {
163
+ fieldId: 'fieldB'
164
+ }, {
165
+ fieldId: 'fieldC'
166
+ }]
167
+ }];
168
+ var MASTER_PAGE = {
169
+ childPages: CHILD_PAGES
170
+ };
171
+ var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
172
+ showSection1: false
173
+ });
174
+ var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
175
+ masterPage: MASTER_PAGE,
176
+ childMasterPages: [],
177
+ formData: {},
178
+ entryData: CUSTOM_ENTRY
179
+ })),
180
+ container = _renderWithValidation3.container;
181
+
182
+ // Function to find an element by its text content
183
+ function getByTextContent(parent, text) {
184
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
185
+ return el.textContent === text;
186
+ });
187
+ }
188
+
189
+ // Check for section titles
190
+ var section1Title = getByTextContent(container, 'Section 1');
191
+ var section2Title = getByTextContent(container, 'Section 2');
192
+ expect(section1Title).toBeUndefined();
193
+ expect(section2Title).not.toBeUndefined();
194
+ var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
195
+ expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
196
+ });
197
+ it('should not render sections on pages that fail show_when checks', function () {
198
+ var CHILD_PAGES = [{
199
+ show_when: [{
200
+ field: 'testField',
201
+ op: '=',
202
+ value: true
203
+ }],
204
+ summaryLayout: {
205
+ sections: [{
206
+ title: 'Section 1',
207
+ columns: 2,
208
+ fields: ['fieldA', 'fieldB'],
209
+ show_when: [{
210
+ field: 'showSection1',
211
+ op: "=",
212
+ value: true
213
+ }]
214
+ }, {
215
+ title: 'Section 2',
216
+ columns: 1,
217
+ fields: ['fieldC']
218
+ }]
219
+ },
220
+ components: [{
221
+ fieldId: 'fieldA'
222
+ }, {
223
+ fieldId: 'fieldB'
224
+ }, {
225
+ fieldId: 'fieldC'
226
+ }]
227
+ }];
228
+ var MASTER_PAGE = {
229
+ childPages: CHILD_PAGES
230
+ };
231
+ var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
232
+ showSection1: false
233
+ });
234
+ var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
235
+ masterPage: MASTER_PAGE,
236
+ childMasterPages: [],
237
+ formData: {
238
+ testField: false
239
+ },
240
+ entryData: CUSTOM_ENTRY
241
+ })),
242
+ container = _renderWithValidation4.container;
243
+
244
+ // Function to find an element by its text content
245
+ function getByTextContent(parent, text) {
246
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
247
+ return el.textContent === text;
248
+ });
249
+ }
250
+
251
+ // Check for section titles
252
+ var section1Title = getByTextContent(container, 'Section 1');
253
+ var section2Title = getByTextContent(container, 'Section 2');
254
+ expect(section1Title).toBeUndefined();
255
+ expect(section2Title).toBeUndefined();
256
+ });
257
+ it('should render child collections', function () {
258
+ var CHILD_MASTER_PAGES = [{
259
+ collection: {
260
+ name: 'childCollection'
261
+ },
262
+ childPages: [{
263
+ components: [{
264
+ fieldId: 'childField1'
265
+ }, {
266
+ fieldId: 'childField2'
267
+ }],
268
+ summaryLayout: {
269
+ sections: [{
270
+ title: 'Hidden Title',
271
+ columns: 2,
272
+ fields: ['childfield1', 'childfield2']
273
+ }]
274
+ }
275
+ }]
276
+ }];
277
+ var CHILD_PAGES = [{
278
+ summaryLayout: {
279
+ sections: [{
280
+ type: 'childCollection',
281
+ collectionName: 'childCollection',
282
+ title: 'Children'
283
+ }]
284
+ },
285
+ components: [{
286
+ fieldId: 'fieldA'
287
+ }, {
288
+ fieldId: 'fieldB'
289
+ }, {
290
+ fieldId: 'fieldC'
291
+ }]
292
+ }];
293
+ var MASTER_PAGE = {
294
+ childPages: [].concat(CHILD_PAGES, CHILD_MASTER_PAGES)
295
+ };
296
+ var CHILD_COLLECTIONS = ['childCollection'];
297
+ var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
298
+ masterPage: MASTER_PAGE,
299
+ childCollections: CHILD_COLLECTIONS,
300
+ formData: {},
301
+ entryData: ENTRY
302
+ })),
303
+ container = _renderWithValidation5.container;
304
+
305
+ // Function to find an element by its text content
306
+ function getByTextContent(parent, text) {
307
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
308
+ return el.textContent === text;
309
+ });
310
+ }
311
+ var childCollectionSectionTitle = getByTextContent(container, 'Children');
312
+ expect(childCollectionSectionTitle).not.toBeUndefined();
313
+ var childSectionTitles = getByTextContent(container, 'Hidden Title');
314
+ expect(childSectionTitles).toBeUndefined(); // Individual section title for child collections should be hidden.
315
+
316
+ var childFields = container.querySelectorAll(".".concat(classes('field')));
317
+ expect(childFields.length).toEqual(4); // Two for each entry in the child collection.
318
+ });
319
+ });
@@ -166,6 +166,7 @@ var FormComponent = function FormComponent(_ref) {
166
166
  options: options,
167
167
  value: value,
168
168
  onChange: onComponentChangeExtended,
169
+ onTopLevelChange: onTopLevelChange,
169
170
  formData: formData,
170
171
  onAction: onAction,
171
172
  submitting: submitting
@@ -84,7 +84,7 @@ var nestUnderParent = function nestUnderParent(childPage, masterPages) {
84
84
  */
85
85
  var mergeCollectionPages = function mergeCollectionPages(pages) {
86
86
  var masterPages = {};
87
- return pages.map(function (page) {
87
+ var pagesWithMasters = pages.map(function (page) {
88
88
  var _page$collection;
89
89
  if (page !== null && page !== void 0 && (_page$collection = page.collection) !== null && _page$collection !== void 0 && _page$collection.name) {
90
90
  if (!masterPages[page.collection.name]) {
@@ -92,10 +92,7 @@ var mergeCollectionPages = function mergeCollectionPages(pages) {
92
92
  // we kick one off using this page as a template.
93
93
  var newMasterPage = createMasterPage(page);
94
94
  masterPages[page.collection.name] = newMasterPage;
95
- // We check if the new master page belongs to a child collection,
96
- // if so then nest it under the parent master page and remove from
97
- // the pages array. If not then treat it as a top-level collection.
98
- return nestUnderParent(newMasterPage, masterPages) ? null : newMasterPage;
95
+ return newMasterPage;
99
96
  }
100
97
  // If a master page already exists for this collection.name
101
98
  // then we just merge this page into it and remove this page
@@ -107,5 +104,17 @@ var mergeCollectionPages = function mergeCollectionPages(pages) {
107
104
  }).filter(function (page) {
108
105
  return !!page;
109
106
  });
107
+ // We nest any child master pages under their parents here to
108
+ // ensure that all parent master pages have been created by the
109
+ // above code first.
110
+ return pagesWithMasters.map(function (page) {
111
+ var _page$collection2;
112
+ if ((_page$collection2 = page.collection) !== null && _page$collection2 !== void 0 && _page$collection2.masterPage) {
113
+ return nestUnderParent(page, masterPages) ? null : page;
114
+ }
115
+ return page;
116
+ }).filter(function (e) {
117
+ return !!e;
118
+ });
110
119
  };
111
120
  var _default = exports.default = mergeCollectionPages;
@@ -49,7 +49,7 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
49
49
  childPages: PAGES
50
50
  });
51
51
  });
52
- it('should correctly merge and nested child collection pages under their parents', function () {
52
+ it('should correctly merge and nest child collection pages under their parents', function () {
53
53
  var PAGES = [{
54
54
  id: 'page1',
55
55
  collection: {
@@ -95,6 +95,53 @@ describe('utils.CollectionPage.mergeCollectionPages', function () {
95
95
  }]
96
96
  });
97
97
  });
98
+ it('should correctly merge and nest child collection pages under their parents, even if the child pages are created first', function () {
99
+ var PAGES = [{
100
+ id: 'page1',
101
+ collection: {
102
+ name: 'parent.child'
103
+ },
104
+ components: [TEXT_COMP]
105
+ }, {
106
+ id: 'page2',
107
+ collection: {
108
+ name: 'parent.child'
109
+ },
110
+ components: [DATE_COMP]
111
+ }, {
112
+ id: 'page3',
113
+ collection: {
114
+ name: 'parent'
115
+ },
116
+ components: [DATE_COMP]
117
+ }, {
118
+ id: 'page4',
119
+ collection: {
120
+ name: 'parent'
121
+ },
122
+ components: [DATE_COMP]
123
+ }];
124
+ var RESULT = (0, _mergeCollectionPages.default)(PAGES);
125
+ expect(RESULT.length).toEqual(1); // One master page for parent collection.
126
+ expect(RESULT[0].childPages.length).toEqual(3); // Two normal pages and the child collection's master page.
127
+ expect(RESULT[0]).toMatchObject({
128
+ id: 'page3',
129
+ collection: {
130
+ name: 'parent',
131
+ masterPage: true
132
+ },
133
+ formData: {},
134
+ childPages: [PAGES[2], PAGES[3], {
135
+ id: 'page1',
136
+ collection: {
137
+ name: 'parent.child',
138
+ masterPage: true
139
+ },
140
+ formData: {},
141
+ childPages: [PAGES[0], PAGES[1]]
142
+ }]
143
+ });
144
+ });
98
145
  it('should leave non-collection pages unaffected', function () {
99
146
  var PAGES = [{
100
147
  id: 'page1',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.56.1",
3
+ "version": "5.58.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",