@ukhomeoffice/cop-react-form-renderer 5.73.0 → 5.74.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.
@@ -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({})])),
@@ -11,6 +11,7 @@ var _models = require("../../models");
11
11
  var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
12
12
  var _getCYARowsForContainer = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARowsForContainer"));
13
13
  var _showComponent = _interopRequireDefault(require("../../utils/Component/showComponent"));
14
+ var _Condition = _interopRequireDefault(require("../../utils/Condition"));
14
15
  require("./SummaryCardDetails.scss");
15
16
  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); }
16
17
  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; }
@@ -45,18 +46,38 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
45
46
  }, [masterPage, childCollections]);
46
47
  var getSectionContent = function getSectionContent(section, components, childPage) {
47
48
  var columnIndex = 0;
48
- return section.columns.flatMap(function (column, index) {
49
+ return section.columns.filter(function (column) {
50
+ return _Condition.default.meetsAll(column, _objectSpread(_objectSpread({}, childPage.formData), entryData));
51
+ }).flatMap(function (column, index) {
49
52
  var _column$fields;
50
53
  var rowIndex = 0;
51
54
  var columnContent = (_column$fields = column.fields) === null || _column$fields === void 0 ? void 0 : _column$fields.flatMap(function (fieldId) {
52
- var component = components.find(function (comp) {
55
+ var componentMatches = components.filter(function (comp) {
53
56
  return comp.fieldId === fieldId;
54
57
  });
55
- if (!component || !(0, _showComponent.default)(component, _objectSpread(_objectSpread({}, childPage.formData), entryData))) {
56
- return null;
57
- }
58
- if (component.type === _models.ComponentTypes.CONTAINER) {
59
- var containerRows = (0, _getCYARowsForContainer.default)(childPage, component, entryData);
58
+ return componentMatches.map(function (component) {
59
+ if (!component || !(0, _showComponent.default)(component, _objectSpread(_objectSpread({}, childPage.formData), entryData))) {
60
+ return null;
61
+ }
62
+ if (component.type === _models.ComponentTypes.CONTAINER) {
63
+ var containerRows = (0, _getCYARowsForContainer.default)(childPage, component, entryData);
64
+ rowIndex += 1;
65
+ return /*#__PURE__*/_react.default.createElement("div", {
66
+ key: fieldId,
67
+ className: classes('field'),
68
+ style: {
69
+ '--column': columnIndex + 1,
70
+ '--row': rowIndex
71
+ }
72
+ }, containerRows.map(function (subComponent) {
73
+ var _entryData$component$;
74
+ // Put value for current subcomponent at top level
75
+ var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$ = entryData[component.fieldId]) === null || _entryData$component$ === void 0 ? void 0 : _entryData$component$[subComponent.fieldId]));
76
+ return (0, _getComponentRowForCYA.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
77
+ label: subComponent.key
78
+ }), classes, modEntry);
79
+ }));
80
+ }
60
81
  rowIndex += 1;
61
82
  return /*#__PURE__*/_react.default.createElement("div", {
62
83
  key: fieldId,
@@ -65,24 +86,8 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
65
86
  '--column': columnIndex + 1,
66
87
  '--row': rowIndex
67
88
  }
68
- }, containerRows.map(function (subComponent) {
69
- var _entryData$component$;
70
- // Put value for current subcomponent at top level
71
- var modEntry = _objectSpread(_objectSpread({}, entryData), _defineProperty({}, subComponent.fieldId, (_entryData$component$ = entryData[component.fieldId]) === null || _entryData$component$ === void 0 ? void 0 : _entryData$component$[subComponent.fieldId]));
72
- return (0, _getComponentRowForCYA.default)(childPage, _objectSpread(_objectSpread({}, subComponent), {
73
- label: subComponent.key
74
- }), classes, modEntry);
75
- }));
76
- }
77
- rowIndex += 1;
78
- return /*#__PURE__*/_react.default.createElement("div", {
79
- key: fieldId,
80
- className: classes('field'),
81
- style: {
82
- '--column': columnIndex + 1,
83
- '--row': rowIndex
84
- }
85
- }, (0, _getComponentRowForCYA.default)(childPage, component, classes, entryData));
89
+ }, (0, _getComponentRowForCYA.default)(childPage, component, classes, entryData));
90
+ });
86
91
  }).filter(function (e) {
87
92
  return !!e;
88
93
  });
@@ -464,4 +464,61 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
464
464
  var childFields = container.querySelectorAll(".".concat(classes('section')));
465
465
  expect(childFields.length).toEqual(2); // One for each entry in the child collection.
466
466
  });
467
+
468
+ it('should render components if a component with the same ID has already failed a show_when', function () {
469
+ var CHILD_PAGES = [{
470
+ summaryLayout: {
471
+ sections: [{
472
+ title: 'Section 1',
473
+ columns: [{
474
+ fields: ['fieldA']
475
+ }, {
476
+ fields: ['fieldB']
477
+ }]
478
+ }]
479
+ },
480
+ components: [{
481
+ fieldId: 'fieldA'
482
+ }, {
483
+ fieldId: 'fieldB',
484
+ label: 'first',
485
+ show_when: [{
486
+ field: 'fieldA',
487
+ op: '=',
488
+ value: 'notTheRightValue'
489
+ }]
490
+ }, {
491
+ fieldId: 'fieldB',
492
+ label: 'second',
493
+ show_when: [{
494
+ field: 'fieldA',
495
+ op: '!=',
496
+ value: 'notTheRightValue'
497
+ }]
498
+ }]
499
+ }];
500
+ var MASTER_PAGE = {
501
+ childPages: CHILD_PAGES
502
+ };
503
+ var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
504
+ masterPage: MASTER_PAGE,
505
+ childMasterPages: [],
506
+ formData: {},
507
+ entryData: _objectSpread(_objectSpread({}, ENTRY), {}, {
508
+ fieldA: 'notTheRightValue'
509
+ })
510
+ })),
511
+ container = _renderWithValidation8.container;
512
+
513
+ // Function to find an element by its text content
514
+ function getByTextContent(parent, text) {
515
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
516
+ return el.textContent === text;
517
+ });
518
+ }
519
+ var section1Title = getByTextContent(container, 'Section 1');
520
+ expect(section1Title).not.toBeUndefined();
521
+ var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
522
+ expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(2);
523
+ });
467
524
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.73.0",
3
+ "version": "5.74.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",