@ukhomeoffice/cop-react-form-renderer 5.72.0 → 5.73.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.
@@ -92,7 +92,7 @@ var RenderListView = function RenderListView(_ref) {
92
92
  var component = elevatedComponents.find(function (comp) {
93
93
  return comp.fieldId === fieldId;
94
94
  });
95
- if (!component || !_Condition.default.meetsAll(component, _objectSpread(_objectSpread({}, childPage.formData), entryData))) {
95
+ if (!component) {
96
96
  return null;
97
97
  }
98
98
  return (0, _getComponentRowForCYA.default)(childPage, component, listClass, entryData);
@@ -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
  });
@@ -10,6 +10,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
10
  /**
11
11
  * @param {*} value - the value to check.
12
12
  * @param {string} config.collectionPath - the path to the collection within formData
13
+ * @param {string} config.caseInsensitive - true to ignore case, assumes string values
13
14
  * @param {object} component - the component definition
14
15
  * @param {object} formData - the current form data
15
16
  * @returns true if components value is not the same in any other entry in the collection
@@ -28,6 +29,9 @@ var mustBeUniqueInCollection = function mustBeUniqueInCollection(value, config,
28
29
  return false;
29
30
  }
30
31
  ;
32
+ if (config.caseInsensitive && typeof value === 'string' && typeof entry[component.id] === 'string') {
33
+ return entry[component.id].toUpperCase() === value.toUpperCase();
34
+ }
31
35
  return entry[component.id] === value;
32
36
  });
33
37
  return !result;
@@ -121,6 +121,42 @@ describe('utils', function () {
121
121
  }), COMPONENT_NESTED, FORM_DATA);
122
122
  expect(result).toBeFalsy();
123
123
  });
124
+ test('should return true if other entries have the same value for this field in a different case', function () {
125
+ var FORM_DATA = {
126
+ namesActiveId: 2,
127
+ names: [{
128
+ id: 1,
129
+ firstName: 'ALPHA'
130
+ }, {
131
+ id: 2,
132
+ firstName: 'alpha'
133
+ }, {
134
+ id: 3,
135
+ firstName: 'bravo'
136
+ }]
137
+ };
138
+ var result = (0, _mustBeUniqueInCollection.default)('alpha', CONFIG, COMPONENT, FORM_DATA);
139
+ expect(result).toBeTruthy();
140
+ });
141
+ test('should return false if other entries have the same value for this field in a different case and caseInsensitive is true', function () {
142
+ var FORM_DATA = {
143
+ namesActiveId: 2,
144
+ names: [{
145
+ id: 1,
146
+ firstName: 'ALPHA'
147
+ }, {
148
+ id: 2,
149
+ firstName: 'alpha'
150
+ }, {
151
+ id: 3,
152
+ firstName: 'bravo'
153
+ }]
154
+ };
155
+ var result = (0, _mustBeUniqueInCollection.default)('alpha', _objectSpread(_objectSpread({}, CONFIG), {}, {
156
+ caseInsensitive: true
157
+ }), COMPONENT, FORM_DATA);
158
+ expect(result).toBeFalsy();
159
+ });
124
160
  });
125
161
  });
126
162
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.72.0",
3
+ "version": "5.73.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",