@ukhomeoffice/cop-react-form-renderer 5.73.1 → 5.74.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.
|
@@ -293,7 +293,10 @@ var CollectionSummary = function CollectionSummary(_ref) {
|
|
|
293
293
|
label: config.addButton.label || DEFAULT_ADD_BUTTON_LABEL,
|
|
294
294
|
page: config.addButton.page,
|
|
295
295
|
type: _PageAction.PageActionTypes.COLLECTION_ADD,
|
|
296
|
-
classModifiers: ['secondary']
|
|
296
|
+
classModifiers: ['secondary'],
|
|
297
|
+
customAction: {
|
|
298
|
+
type: config.addButton.customAction
|
|
299
|
+
}
|
|
297
300
|
},
|
|
298
301
|
onAction: onAction
|
|
299
302
|
}));
|
|
@@ -305,7 +308,10 @@ CollectionSummary.propTypes = {
|
|
|
305
308
|
collectionName: _propTypes.default.string.isRequired,
|
|
306
309
|
addButton: _propTypes.default.shape({
|
|
307
310
|
label: _propTypes.default.string,
|
|
308
|
-
page: _propTypes.default.string.isRequired
|
|
311
|
+
page: _propTypes.default.string.isRequired,
|
|
312
|
+
customAction: _propTypes.default.shape({
|
|
313
|
+
type: _propTypes.default.string
|
|
314
|
+
})
|
|
309
315
|
}),
|
|
310
316
|
card: _propTypes.default.shape({
|
|
311
317
|
banners: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({})])),
|
|
@@ -44,11 +44,9 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
44
44
|
return !!e;
|
|
45
45
|
});
|
|
46
46
|
}, [masterPage, childCollections]);
|
|
47
|
-
var getSectionContent = function getSectionContent(
|
|
47
|
+
var getSectionContent = function getSectionContent(columns, components, childPage) {
|
|
48
48
|
var columnIndex = 0;
|
|
49
|
-
return
|
|
50
|
-
return _Condition.default.meetsAll(column, _objectSpread(_objectSpread({}, childPage.formData), entryData));
|
|
51
|
-
}).flatMap(function (column, index) {
|
|
49
|
+
return columns.flatMap(function (column, index) {
|
|
52
50
|
var _column$fields;
|
|
53
51
|
var rowIndex = 0;
|
|
54
52
|
var columnContent = (_column$fields = column.fields) === null || _column$fields === void 0 ? void 0 : _column$fields.flatMap(function (fieldId) {
|
|
@@ -95,7 +93,7 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
95
93
|
// then we stick a divider on it's right side. The divider isn't
|
|
96
94
|
// passed rowIndex as it spans all rows. columnIndex is incremented
|
|
97
95
|
// twice to account for the divider column too.
|
|
98
|
-
var lastColumn = index ===
|
|
96
|
+
var lastColumn = index === columns.length - 1;
|
|
99
97
|
if (!lastColumn && columnContent.length !== 0) {
|
|
100
98
|
columnIndex += 2;
|
|
101
99
|
return [].concat(columnContent, [/*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -140,6 +138,9 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
140
138
|
}
|
|
141
139
|
return null;
|
|
142
140
|
}
|
|
141
|
+
var columns = section.columns.filter(function (column) {
|
|
142
|
+
return _Condition.default.meetsAll(column, _objectSpread(_objectSpread({}, childPage.formData), entryData));
|
|
143
|
+
});
|
|
143
144
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
144
145
|
key: section.title,
|
|
145
146
|
className: classes('section')
|
|
@@ -148,9 +149,9 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
|
|
|
148
149
|
}, section.title), /*#__PURE__*/_react.default.createElement("div", {
|
|
149
150
|
className: classes('section-content'),
|
|
150
151
|
style: {
|
|
151
|
-
'--dividers':
|
|
152
|
+
'--dividers': columns.length - 1
|
|
152
153
|
}
|
|
153
|
-
}, getSectionContent(
|
|
154
|
+
}, getSectionContent(columns, allPageComponents, childPage)));
|
|
154
155
|
});
|
|
155
156
|
}).filter(function (e) {
|
|
156
157
|
return !!e;
|
|
@@ -399,6 +399,57 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
399
399
|
expect(section1Title).toBeUndefined();
|
|
400
400
|
expect(section2Title).toBeUndefined();
|
|
401
401
|
});
|
|
402
|
+
it('should not render columns that fail show_when checks', function () {
|
|
403
|
+
var CHILD_PAGES = [{
|
|
404
|
+
summaryLayout: {
|
|
405
|
+
sections: [{
|
|
406
|
+
title: 'Section 1',
|
|
407
|
+
columns: [{
|
|
408
|
+
fields: ['fieldA'],
|
|
409
|
+
show_when: [{
|
|
410
|
+
field: 'showSection1',
|
|
411
|
+
op: '=',
|
|
412
|
+
value: true
|
|
413
|
+
}]
|
|
414
|
+
}, {
|
|
415
|
+
fields: ['fieldB']
|
|
416
|
+
}]
|
|
417
|
+
}]
|
|
418
|
+
},
|
|
419
|
+
components: [{
|
|
420
|
+
fieldId: 'fieldA',
|
|
421
|
+
label: 'fieldA'
|
|
422
|
+
}, {
|
|
423
|
+
fieldId: 'fieldB',
|
|
424
|
+
label: 'fieldB'
|
|
425
|
+
}]
|
|
426
|
+
}];
|
|
427
|
+
var MASTER_PAGE = {
|
|
428
|
+
childPages: CHILD_PAGES
|
|
429
|
+
};
|
|
430
|
+
var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
431
|
+
masterPage: MASTER_PAGE,
|
|
432
|
+
childMasterPages: [],
|
|
433
|
+
formData: {
|
|
434
|
+
testField: false
|
|
435
|
+
},
|
|
436
|
+
entryData: ENTRY
|
|
437
|
+
})),
|
|
438
|
+
container = _renderWithValidation7.container;
|
|
439
|
+
|
|
440
|
+
// Function to find an element by its text content
|
|
441
|
+
function getByTextContent(parent, text) {
|
|
442
|
+
return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
|
|
443
|
+
return el.textContent === text;
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Check for section titles
|
|
448
|
+
var section1Title = getByTextContent(container, 'Section 1');
|
|
449
|
+
expect(section1Title).toBeDefined();
|
|
450
|
+
var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
|
|
451
|
+
expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
|
|
452
|
+
});
|
|
402
453
|
it('should render child collections', function () {
|
|
403
454
|
var CHILD_MASTER_PAGES = [{
|
|
404
455
|
collection: {
|
|
@@ -442,13 +493,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
442
493
|
childPages: [].concat(CHILD_PAGES, CHILD_MASTER_PAGES)
|
|
443
494
|
};
|
|
444
495
|
var CHILD_COLLECTIONS = ['childCollection'];
|
|
445
|
-
var
|
|
496
|
+
var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
446
497
|
masterPage: MASTER_PAGE,
|
|
447
498
|
childCollections: CHILD_COLLECTIONS,
|
|
448
499
|
formData: {},
|
|
449
500
|
entryData: ENTRY
|
|
450
501
|
})),
|
|
451
|
-
container =
|
|
502
|
+
container = _renderWithValidation8.container;
|
|
452
503
|
|
|
453
504
|
// Function to find an element by its text content
|
|
454
505
|
function getByTextContent(parent, text) {
|
|
@@ -500,7 +551,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
500
551
|
var MASTER_PAGE = {
|
|
501
552
|
childPages: CHILD_PAGES
|
|
502
553
|
};
|
|
503
|
-
var
|
|
554
|
+
var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
|
|
504
555
|
masterPage: MASTER_PAGE,
|
|
505
556
|
childMasterPages: [],
|
|
506
557
|
formData: {},
|
|
@@ -508,7 +559,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
|
|
|
508
559
|
fieldA: 'notTheRightValue'
|
|
509
560
|
})
|
|
510
561
|
})),
|
|
511
|
-
container =
|
|
562
|
+
container = _renderWithValidation9.container;
|
|
512
563
|
|
|
513
564
|
// Function to find an element by its text content
|
|
514
565
|
function getByTextContent(parent, text) {
|