@ukhomeoffice/cop-react-form-renderer 5.74.0 → 5.74.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.
@@ -61,6 +61,17 @@ var SummaryCard = function SummaryCard(_ref) {
61
61
  formData = _ref.formData,
62
62
  masterPage = _ref.masterPage,
63
63
  hideDetails = _ref.hideDetails;
64
+ var summaryCardRef = (0, _react.useRef)(null);
65
+ var handleDuplicateAndScroll = function handleDuplicateAndScroll() {
66
+ onDuplicate(entryData);
67
+ var currentSummaryCard = summaryCardRef.current;
68
+ if (currentSummaryCard && currentSummaryCard.nextSibling) {
69
+ currentSummaryCard.nextSibling.scrollIntoView({
70
+ behavior: 'smooth',
71
+ block: 'start'
72
+ });
73
+ }
74
+ };
64
75
  var _useState = (0, _react.useState)(false),
65
76
  _useState2 = _slicedToArray(_useState, 2),
66
77
  quickEdit = _useState2[0],
@@ -159,6 +170,7 @@ var SummaryCard = function SummaryCard(_ref) {
159
170
  });
160
171
  }
161
172
  return /*#__PURE__*/_react.default.createElement("div", {
173
+ ref: summaryCardRef,
162
174
  className: classes(),
163
175
  id: id
164
176
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -207,7 +219,7 @@ var SummaryCard = function SummaryCard(_ref) {
207
219
  }, ((_config$deleteAction2 = config.deleteAction) === null || _config$deleteAction2 === void 0 ? void 0 : _config$deleteAction2.label) || DEFAULT_DELETE_BUTTON_LABEL), config.duplicateAction && typeof onDuplicate === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
208
220
  id: "".concat(id, ".duplicateButton"),
209
221
  onClick: function onClick() {
210
- onDuplicate(entryData);
222
+ handleDuplicateAndScroll();
211
223
  },
212
224
  classModifiers: "secondary",
213
225
  "aria-label": _utils.default.FormPage.getConditionalText((_config$duplicateActi = config.duplicateAction) === null || _config$duplicateActi === void 0 ? void 0 : _config$duplicateActi.aria_label, entryData),
@@ -44,11 +44,9 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
44
44
  return !!e;
45
45
  });
46
46
  }, [masterPage, childCollections]);
47
- var getSectionContent = function getSectionContent(section, components, childPage) {
47
+ var getSectionContent = function getSectionContent(columns, components, childPage) {
48
48
  var columnIndex = 0;
49
- return section.columns.filter(function (column) {
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 === section.columns.length - 1;
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': section.columns.length - 1
152
+ '--dividers': columns.length - 1
152
153
  }
153
- }, getSectionContent(section, allPageComponents, childPage)));
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 _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
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 = _renderWithValidation7.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 _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
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 = _renderWithValidation8.container;
562
+ container = _renderWithValidation9.container;
512
563
 
513
564
  // Function to find an element by its text content
514
565
  function getByTextContent(parent, text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.74.0",
3
+ "version": "5.74.2",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",