@ukhomeoffice/cop-react-form-renderer 6.0.6-peter → 6.5.1-peter

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.
Files changed (72) hide show
  1. package/dist/components/CheckYourAnswers/CheckYourAnswers.scss +2 -2
  2. package/dist/components/CollectionPage/CollectionPage.js +8 -2
  3. package/dist/components/CollectionSummary/BannerStrip.js +3 -2
  4. package/dist/components/CollectionSummary/BannerStrip.scss +2 -2
  5. package/dist/components/CollectionSummary/BannerStrip.test.js +39 -4
  6. package/dist/components/CollectionSummary/CollectionSummary.js +82 -63
  7. package/dist/components/CollectionSummary/CollectionSummary.scss +1 -1
  8. package/dist/components/CollectionSummary/CollectionSummary.test.js +40 -80
  9. package/dist/components/CollectionSummary/Confirmation.scss +1 -1
  10. package/dist/components/CollectionSummary/RenderListView.js +24 -20
  11. package/dist/components/CollectionSummary/RenderListView.scss +10 -1
  12. package/dist/components/CollectionSummary/RenderListView.test.js +14 -4
  13. package/dist/components/CollectionSummary/SummaryCard.js +59 -38
  14. package/dist/components/CollectionSummary/SummaryCard.scss +2 -1
  15. package/dist/components/CollectionSummary/SummaryCard.test.js +193 -150
  16. package/dist/components/CollectionSummary/SummaryCardDetails.js +70 -13
  17. package/dist/components/CollectionSummary/SummaryCardDetails.scss +43 -6
  18. package/dist/components/CollectionSummary/SummaryCardDetails.test.js +174 -26
  19. package/dist/components/CollectionSummary/SummaryCardValidationContext.js +15 -5
  20. package/dist/components/CollectionSummary/SummaryCardValidationContext.test.js +5 -4
  21. package/dist/components/FormComponent/Collection.js +24 -17
  22. package/dist/components/FormComponent/Collection.test.js +138 -0
  23. package/dist/components/FormComponent/FormComponent.js +12 -0
  24. package/dist/components/FormPage/FormPage.scss +1 -1
  25. package/dist/components/FormRenderer/FormRenderer.js +7 -4
  26. package/dist/components/FormRenderer/FormRenderer.scss +1 -1
  27. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-airpax-after.json +429 -0
  28. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-airpax-before.json +449 -0
  29. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-airpax-form.json +15219 -0
  30. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-eab-2-data-after.json +516 -0
  31. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-eab-2-data-before.json +593 -0
  32. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-eab2-form.json +15219 -0
  33. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-mandec-data-after.json +84 -0
  34. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-mandec-data-before.json +98 -0
  35. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/cop-mandec-form.json +9158 -0
  36. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/test.json +1605 -0
  37. package/dist/components/FormRenderer/clear-uncompleted-routes/test-data/test2.json +205 -0
  38. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.js +69 -38
  39. package/dist/components/FormRenderer/helpers/clearOutUncompletedRoutes.test.js +30 -0
  40. package/dist/components/FormRenderer/helpers/deleteNodeByPath.js +8 -2
  41. package/dist/components/FormRenderer/onPageAction.js +6 -1
  42. package/dist/components/FormRenderer/onPageAction.test.js +18 -4
  43. package/dist/components/SummaryList/SummaryList.scss +2 -2
  44. package/dist/components/TaskList/TaskList.scss +1 -1
  45. package/dist/context/ValidationContext/ValidationContext.js +49 -5
  46. package/dist/context/ValidationContext/ValidationContext.test.js +16 -7
  47. package/dist/hooks/useRefData.js +1 -1
  48. package/dist/utils/CheckYourAnswers/showComponentCYA.js +1 -2
  49. package/dist/utils/CheckYourAnswers/showComponentCYA.test.js +5 -0
  50. package/dist/utils/CollectionPage/addCollectionPageEntry.js +1 -2
  51. package/dist/utils/CollectionPage/addCollectionPageEntry.test.js +4 -24
  52. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.js +13 -1
  53. package/dist/utils/CollectionPage/duplicateCollectionPageEntry.test.js +17 -2
  54. package/dist/utils/CollectionPage/getErrorsForCollection.js +55 -0
  55. package/dist/utils/CollectionPage/getErrorsForCollection.test.js +155 -0
  56. package/dist/utils/CollectionPage/getQuickEditPage.js +7 -1
  57. package/dist/utils/CollectionPage/index.js +2 -0
  58. package/dist/utils/CollectionPage/setCollectionPageData.js +9 -4
  59. package/dist/utils/CollectionPage/setCollectionPageData.test.js +18 -0
  60. package/dist/utils/Component/isEditable.js +1 -1
  61. package/dist/utils/Condition/meetsCondition.js +18 -0
  62. package/dist/utils/Condition/meetsCondition.test.js +100 -0
  63. package/dist/utils/Data/getOptions.js +10 -0
  64. package/dist/utils/Data/getOptions.test.js +73 -0
  65. package/dist/utils/Data/nestInRefdataOptions.js +49 -0
  66. package/dist/utils/Data/nestInRefdataOptions.test.js +236 -0
  67. package/dist/utils/Validate/validateContainer.js +3 -1
  68. package/dist/utils/Validate/validateContainer.test.js +33 -0
  69. package/dist/utils/Validate/validateEmail.js +1 -1
  70. package/dist/utils/Validate/validatePage.js +10 -1
  71. package/dist/utils/Validate/validatePage.test.js +69 -0
  72. package/package.json +4 -4
@@ -7,7 +7,10 @@ exports.default = exports.DEFAULT_CLASS = void 0;
7
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _utils = _interopRequireDefault(require("../../utils"));
10
+ var _models = require("../../models");
10
11
  var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
12
+ var _getCYARowsForContainer = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARowsForContainer"));
13
+ var _showComponent = _interopRequireDefault(require("../../utils/Component/showComponent"));
11
14
  require("./SummaryCardDetails.scss");
12
15
  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
16
  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; }
@@ -40,13 +43,75 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
40
43
  return !!e;
41
44
  });
42
45
  }, [masterPage, childCollections]);
46
+ var getSectionContent = function getSectionContent(section, components, childPage) {
47
+ var columnIndex = 0;
48
+ return section.columns.flatMap(function (column, index) {
49
+ var _column$fields;
50
+ var rowIndex = 0;
51
+ 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) {
53
+ return comp.fieldId === fieldId;
54
+ });
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);
60
+ rowIndex += 1;
61
+ return /*#__PURE__*/_react.default.createElement("div", {
62
+ key: fieldId,
63
+ className: classes('field'),
64
+ style: {
65
+ '--column': columnIndex + 1,
66
+ '--row': rowIndex
67
+ }
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));
86
+ }).filter(function (e) {
87
+ return !!e;
88
+ });
89
+ // If the column that's just been generated has anything in it
90
+ // then we stick a divider on it's right side. The divider isn't
91
+ // passed rowIndex as it spans all rows. columnIndex is incremented
92
+ // twice to account for the divider column too.
93
+ var lastColumn = index === section.columns.length - 1;
94
+ if (!lastColumn && columnContent.length !== 0) {
95
+ columnIndex += 2;
96
+ return [].concat(columnContent, [/*#__PURE__*/_react.default.createElement("div", {
97
+ key: "divider".concat(columnIndex),
98
+ className: classes('divider'),
99
+ style: {
100
+ '--column': columnIndex
101
+ }
102
+ })]);
103
+ }
104
+ return columnContent;
105
+ }).filter(function (e) {
106
+ return !!e;
107
+ });
108
+ };
43
109
  return (masterPage === null || masterPage === void 0 || (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.filter(function (p) {
44
110
  return _utils.default.FormPage.show(p, _objectSpread(_objectSpread({}, formData), entryData));
45
111
  }).map(function (childPage) {
46
112
  var _childPage$summaryLay;
47
113
  var allPageComponents = _utils.default.Component.elevateNested(childPage === null || childPage === void 0 ? void 0 : childPage.components, entryData);
48
114
  return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.sections.map(function (section) {
49
- var _section$fields;
50
115
  if (section.show_when && !_utils.default.Condition.meetsAll(section.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
51
116
  return null;
52
117
  }
@@ -76,19 +141,11 @@ var SummaryCardDetails = function SummaryCardDetails(_ref) {
76
141
  }, !hideChildSectionTitles && /*#__PURE__*/_react.default.createElement("h3", {
77
142
  className: classes('section-title')
78
143
  }, 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
- if (!component) {
85
- return null;
144
+ className: classes('section-content'),
145
+ style: {
146
+ '--dividers': section.columns.length - 1
86
147
  }
87
- return /*#__PURE__*/_react.default.createElement("div", {
88
- key: fieldId,
89
- className: classes('field')
90
- }, (0, _getComponentRowForCYA.default)(childPage, component, classes, entryData));
91
- })));
148
+ }, getSectionContent(section, allPageComponents, childPage)));
92
149
  });
93
150
  }).filter(function (e) {
94
151
  return !!e;
@@ -36,9 +36,12 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
36
36
  border-bottom: 2px solid #E9EBED;
37
37
 
38
38
  &-content {
39
- display: flex;
40
- flex-wrap: wrap;
39
+ display: grid;
40
+ grid-template-columns: repeat(var(--dividers), 1fr 2px) 1fr;
41
+ grid-auto-rows: minmax(100px, 1fr);
41
42
  gap: govuk-spacing(2);
43
+ position: relative;
44
+ margin-bottom: govuk-spacing(1);
42
45
 
43
46
  .hods-form-summary-card__field {
44
47
  box-sizing: border-box;
@@ -61,6 +64,7 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
61
64
  }
62
65
  }
63
66
 
67
+ /*
64
68
  &--columns-1,
65
69
  &--columns-2,
66
70
  &--columns-3 {
@@ -79,6 +83,9 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
79
83
  }
80
84
 
81
85
  &--columns-2 {
86
+ display: grid;
87
+ grid-template-columns: repeat(2, 1fr);
88
+
82
89
  &::after {
83
90
  content: "";
84
91
  position: absolute;
@@ -89,12 +96,13 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
89
96
  left: 50%;
90
97
  }
91
98
 
92
- .hods-form-summary-card-details__field {
93
- flex: 0 0 calc(50% - 10px);
94
- }
99
+
95
100
  }
96
101
 
97
102
  &--columns-3 {
103
+ display: grid;
104
+ grid-template-columns: repeat(2, 1fr);
105
+
98
106
  &::after {
99
107
  content: "";
100
108
  position: absolute;
@@ -106,7 +114,10 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
106
114
  }
107
115
 
108
116
  .hods-form-summary-card-details__field {
109
- flex: 0 0 calc(33.333% - 10px);
117
+ grid-column-start: var("--column");
118
+ grid-column-end: var("--column");
119
+ grid-row-start: var("--row");
120
+ grid-row-end: var("--row");
110
121
 
111
122
  &:nth-child(2)::after {
112
123
  content: "";
@@ -119,6 +130,23 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
119
130
  }
120
131
  }
121
132
  }
133
+ */
134
+
135
+ .hods-form-summary-card-details__field {
136
+ grid-column-start: var(--column);
137
+ grid-column-end: var(--column);
138
+ grid-row-start: var(--row);
139
+ grid-row-end: var(--row);
140
+ }
141
+
142
+ .hods-form-summary-card-details__divider {
143
+ position: absolute;
144
+ height: 100%;
145
+ width: 100%;
146
+ background-color: #E9EBED;
147
+ grid-column-start: var(--column);
148
+ grid-column-end: var(--column);
149
+ }
122
150
  }
123
151
  }
124
152
  }
@@ -137,6 +165,15 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
137
165
  display: none;
138
166
  }
139
167
 
168
+ .hods-form-summary-card-details__divider {
169
+ position: absolute;
170
+ height: 0%;
171
+ width: 0%;
172
+ background-color: #E9EBED;
173
+ grid-column-start: var(--column);
174
+ grid-column-end: var(--column);
175
+ }
176
+
140
177
  &--columns-2,
141
178
  &--columns-3 {
142
179
  position: relative;
@@ -38,12 +38,16 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
38
38
  summaryLayout: {
39
39
  sections: [{
40
40
  title: 'Section 1',
41
- columns: 2,
42
- fields: ['fieldA', 'fieldB']
41
+ columns: [{
42
+ fields: ['fieldA']
43
+ }, {
44
+ fields: ['fieldB']
45
+ }]
43
46
  }, {
44
47
  title: 'Section 2',
45
- columns: 1,
46
- fields: ['fieldC']
48
+ columns: [{
49
+ fields: ['fieldC']
50
+ }]
47
51
  }]
48
52
  },
49
53
  components: [{
@@ -82,13 +86,86 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
82
86
  var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
83
87
  expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
84
88
  });
89
+ it('should render sections containing containers based on summaryLayout config', function () {
90
+ var CHILD_PAGES = [{
91
+ summaryLayout: {
92
+ sections: [{
93
+ title: 'Section 1',
94
+ columns: [{
95
+ fields: ['containerComponent']
96
+ }]
97
+ }]
98
+ },
99
+ components: [{
100
+ fieldId: 'containerComponent',
101
+ type: 'container',
102
+ label: 'container',
103
+ components: [{
104
+ fieldId: 'subOne',
105
+ label: 'subOneLabel'
106
+ }, {
107
+ fieldId: 'subTwo',
108
+ label: 'subTwoLabel'
109
+ }, {
110
+ fieldId: 'subThree',
111
+ label: 'subThreeLabel'
112
+ }]
113
+ }]
114
+ }];
115
+ var CONTAINER_ENTRY = {
116
+ id: '001',
117
+ bannerText: 'A banner',
118
+ titleText: 'A title',
119
+ detailsText: 'Some details',
120
+ index: 0,
121
+ summaryText: 'Full details',
122
+ containerComponent: {
123
+ subOne: 'alpha',
124
+ subTwo: 'bravo',
125
+ subThree: 'charlie'
126
+ }
127
+ };
128
+ var MASTER_PAGE = {
129
+ childPages: CHILD_PAGES
130
+ };
131
+ var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
132
+ masterPage: MASTER_PAGE,
133
+ childMasterPages: [],
134
+ formData: {},
135
+ entryData: CONTAINER_ENTRY
136
+ })),
137
+ container = _renderWithValidation2.container;
138
+
139
+ // Function to find an element by its text content
140
+ function getByTextContent(parent, text) {
141
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
142
+ return el.textContent === text;
143
+ });
144
+ }
145
+
146
+ // Check for section title
147
+ var section1Title = getByTextContent(container, 'Section 1');
148
+ expect(section1Title).not.toBeUndefined();
149
+
150
+ // All three subcomponents from the container should have labels and values displayed
151
+ var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
152
+ expect(section1Content.textContent).toContain('subOneLabel');
153
+ expect(section1Content.textContent).toContain('alpha');
154
+ expect(section1Content.textContent).toContain('subTwoLabel');
155
+ expect(section1Content.textContent).toContain('bravo');
156
+ expect(section1Content.textContent).toContain('subThreeLabel');
157
+ expect(section1Content.textContent).toContain('charlie');
158
+ });
85
159
  it('should render sections if they have show_when checks and pass them', function () {
86
160
  var CHILD_PAGES = [{
87
161
  summaryLayout: {
88
162
  sections: [{
89
163
  title: 'Section 1',
90
- columns: 2,
91
- fields: ['fieldA', 'fieldB'],
164
+ columns: [{
165
+ fields: ['fieldA']
166
+ }, {
167
+ fields: ['fieldB']
168
+ }],
92
169
  show_when: [{
93
170
  field: 'showSection1',
94
171
  op: "=",
@@ -96,8 +173,9 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
96
173
  }]
97
174
  }, {
98
175
  title: 'Section 2',
99
- columns: 1,
100
- fields: ['fieldC']
176
+ columns: [{
177
+ fields: ['fieldC']
178
+ }]
101
179
  }]
102
180
  },
103
181
  components: [{
@@ -114,13 +192,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
114
192
  var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
115
193
  showSection1: true
116
194
  });
117
- var _renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
195
+ var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
118
196
  masterPage: MASTER_PAGE,
119
197
  childMasterPages: [],
120
198
  formData: {},
121
199
  entryData: CUSTOM_ENTRY
122
200
  })),
123
- container = _renderWithValidation2.container;
201
+ container = _renderWithValidation3.container;
124
202
 
125
203
  // Function to find an element by its text content
126
204
  function getByTextContent(parent, text) {
@@ -144,8 +222,11 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
144
222
  summaryLayout: {
145
223
  sections: [{
146
224
  title: 'Section 1',
147
- columns: 2,
148
- fields: ['fieldA', 'fieldB'],
225
+ columns: [{
226
+ fields: ['fieldA']
227
+ }, {
228
+ fields: ['fieldB']
229
+ }],
149
230
  show_when: [{
150
231
  field: 'showSection1',
151
232
  op: "=",
@@ -153,8 +234,9 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
153
234
  }]
154
235
  }, {
155
236
  title: 'Section 2',
156
- columns: 1,
157
- fields: ['fieldC']
237
+ columns: [{
238
+ fields: ['fieldC']
239
+ }]
158
240
  }]
159
241
  },
160
242
  components: [{
@@ -171,13 +253,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
171
253
  var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
172
254
  showSection1: false
173
255
  });
174
- var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
256
+ var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
175
257
  masterPage: MASTER_PAGE,
176
258
  childMasterPages: [],
177
259
  formData: {},
178
260
  entryData: CUSTOM_ENTRY
179
261
  })),
180
- container = _renderWithValidation3.container;
262
+ container = _renderWithValidation4.container;
181
263
 
182
264
  // Function to find an element by its text content
183
265
  function getByTextContent(parent, text) {
@@ -194,6 +276,65 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
194
276
  var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
195
277
  expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
196
278
  });
279
+ it('should not render components that fail show_when checks', function () {
280
+ var CHILD_PAGES = [{
281
+ summaryLayout: {
282
+ sections: [{
283
+ title: 'Section 1',
284
+ columns: [{
285
+ fields: ['fieldA']
286
+ }, {
287
+ fields: ['fieldB']
288
+ }]
289
+ }, {
290
+ title: 'Section 2',
291
+ columns: [{
292
+ fields: ['fieldC']
293
+ }]
294
+ }]
295
+ },
296
+ components: [{
297
+ fieldId: 'fieldA'
298
+ }, {
299
+ fieldId: 'fieldB',
300
+ show_when: [{
301
+ field: 'fieldA',
302
+ op: '=',
303
+ value: 'notTheRightValue'
304
+ }]
305
+ }, {
306
+ fieldId: 'fieldC'
307
+ }]
308
+ }];
309
+ var MASTER_PAGE = {
310
+ childPages: CHILD_PAGES
311
+ };
312
+ var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
313
+ masterPage: MASTER_PAGE,
314
+ childMasterPages: [],
315
+ formData: {},
316
+ entryData: ENTRY
317
+ })),
318
+ container = _renderWithValidation5.container;
319
+
320
+ // Function to find an element by its text content
321
+ function getByTextContent(parent, text) {
322
+ return Array.from(parent.getElementsByClassName(classes('section-title'))).find(function (el) {
323
+ return el.textContent === text;
324
+ });
325
+ }
326
+
327
+ // Check for section titles
328
+ var section1Title = getByTextContent(container, 'Section 1');
329
+ var section2Title = getByTextContent(container, 'Section 2');
330
+ expect(section1Title).not.toBeUndefined();
331
+ expect(section2Title).not.toBeUndefined();
332
+ var section1Content = section1Title.parentNode.querySelector(".".concat(classes('section-content')));
333
+ expect(section1Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1); // Just Field A, Field B should be hidden.
334
+
335
+ var section2Content = section2Title.parentNode.querySelector(".".concat(classes('section-content')));
336
+ expect(section2Content.querySelectorAll(".".concat(classes('field'))).length).toEqual(1);
337
+ });
197
338
  it('should not render sections on pages that fail show_when checks', function () {
198
339
  var CHILD_PAGES = [{
199
340
  show_when: [{
@@ -204,8 +345,11 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
204
345
  summaryLayout: {
205
346
  sections: [{
206
347
  title: 'Section 1',
207
- columns: 2,
208
- fields: ['fieldA', 'fieldB'],
348
+ columns: [{
349
+ fields: ['fieldA']
350
+ }, {
351
+ fields: ['fieldB']
352
+ }],
209
353
  show_when: [{
210
354
  field: 'showSection1',
211
355
  op: "=",
@@ -213,8 +357,9 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
213
357
  }]
214
358
  }, {
215
359
  title: 'Section 2',
216
- columns: 1,
217
- fields: ['fieldC']
360
+ columns: [{
361
+ fields: ['fieldC']
362
+ }]
218
363
  }]
219
364
  },
220
365
  components: [{
@@ -231,7 +376,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
231
376
  var CUSTOM_ENTRY = _objectSpread(_objectSpread({}, ENTRY), {}, {
232
377
  showSection1: false
233
378
  });
234
- var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
379
+ var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
235
380
  masterPage: MASTER_PAGE,
236
381
  childMasterPages: [],
237
382
  formData: {
@@ -239,7 +384,7 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
239
384
  },
240
385
  entryData: CUSTOM_ENTRY
241
386
  })),
242
- container = _renderWithValidation4.container;
387
+ container = _renderWithValidation6.container;
243
388
 
244
389
  // Function to find an element by its text content
245
390
  function getByTextContent(parent, text) {
@@ -268,8 +413,11 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
268
413
  summaryLayout: {
269
414
  sections: [{
270
415
  title: 'Hidden Title',
271
- columns: 2,
272
- fields: ['childfield1', 'childfield2']
416
+ columns: [{
417
+ fields: ['childfield1']
418
+ }, {
419
+ fields: ['childfield2']
420
+ }]
273
421
  }]
274
422
  }
275
423
  }]
@@ -294,13 +442,13 @@ describe('components.CollectionSummary.SummaryCardDetails', function () {
294
442
  childPages: [].concat(CHILD_PAGES, CHILD_MASTER_PAGES)
295
443
  };
296
444
  var CHILD_COLLECTIONS = ['childCollection'];
297
- var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
445
+ var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_SummaryCardDetails.default, {
298
446
  masterPage: MASTER_PAGE,
299
447
  childCollections: CHILD_COLLECTIONS,
300
448
  formData: {},
301
449
  entryData: ENTRY
302
450
  })),
303
- container = _renderWithValidation5.container;
451
+ container = _renderWithValidation7.container;
304
452
 
305
453
  // Function to find an element by its text content
306
454
  function getByTextContent(parent, text) {
@@ -7,8 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _propTypes = _interopRequireDefault(require("prop-types"));
10
- var _utils = _interopRequireDefault(require("../../utils"));
11
10
  var _ValidationContext = require("../../context/ValidationContext");
11
+ var _hooks = require("../../hooks");
12
+ var _utils = _interopRequireDefault(require("../../utils"));
12
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14
  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); }
14
15
  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; }
@@ -22,7 +23,11 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /* eslint-
22
23
  var SummaryCardValidationContextProvider = function SummaryCardValidationContextProvider(_ref) {
23
24
  var entryId = _ref.entryId,
24
25
  topLevelErrors = _ref.topLevelErrors,
26
+ clearTopLevelErrorsForCard = _ref.clearTopLevelErrorsForCard,
25
27
  children = _ref.children;
28
+ var _useHooks = (0, _hooks.useHooks)(),
29
+ hooks = _useHooks.hooks;
30
+
26
31
  // Errors raised from the Collection Summary.
27
32
  var initialErrors = topLevelErrors.filter(function (e) {
28
33
  return e.entryId === entryId;
@@ -38,8 +43,10 @@ var SummaryCardValidationContextProvider = function SummaryCardValidationContext
38
43
  setErrors(null);
39
44
  };
40
45
  var addErrors = function addErrors(addedErrors) {
41
- var newErrors = errors !== null && errors !== void 0 ? errors : [];
42
- setErrors(newErrors.concat(addedErrors));
46
+ setErrors(function (prev) {
47
+ var newErrors = prev !== null && prev !== void 0 ? prev : [];
48
+ return newErrors.concat(addedErrors);
49
+ });
43
50
  };
44
51
 
45
52
  // This validate is only used by the Quick Edit page
@@ -47,8 +54,9 @@ var SummaryCardValidationContextProvider = function SummaryCardValidationContext
47
54
  var validate = {
48
55
  page: function page(_page) {
49
56
  var pageErrors = _utils.default.Validate.page(_page);
50
- setErrors(pageErrors);
51
- return pageErrors;
57
+ var allErrors = hooks.onValidate(_page, pageErrors);
58
+ setErrors(allErrors);
59
+ return allErrors;
52
60
  }
53
61
  };
54
62
  return /*#__PURE__*/_react.default.createElement(_ValidationContext.ValidationContext.Provider, {
@@ -56,6 +64,7 @@ var SummaryCardValidationContextProvider = function SummaryCardValidationContext
56
64
  addErrors: addErrors,
57
65
  errors: errors === null ? [].concat(initialErrors) : errors,
58
66
  resetQuickEditErrors: resetQuickEditErrors,
67
+ clearTopLevelErrorsForCard: clearTopLevelErrorsForCard,
59
68
  validate: validate
60
69
  }
61
70
  }, children);
@@ -64,6 +73,7 @@ var _default = exports.default = SummaryCardValidationContextProvider;
64
73
  SummaryCardValidationContextProvider.propTypes = {
65
74
  entryId: _propTypes.default.string.isRequired,
66
75
  topLevelErrors: _propTypes.default.arrayOf(_propTypes.default.shape({})),
76
+ clearTopLevelErrorsForCard: _propTypes.default.func.isRequired,
67
77
  children: _propTypes.default.node
68
78
  };
69
79
  SummaryCardValidationContextProvider.defaultProps = {
@@ -6,6 +6,7 @@ var _copReactComponents = require("@ukhomeoffice/cop-react-components");
6
6
  var _react2 = _interopRequireWildcard(require("react"));
7
7
  var _propTypes = _interopRequireDefault(require("prop-types"));
8
8
  var _hooks = require("../../hooks");
9
+ var _context3 = require("../../context");
9
10
  var _SummaryCardValidationContext = _interopRequireDefault(require("./SummaryCardValidationContext"));
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
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); }
@@ -36,10 +37,10 @@ describe('context.SummaryCardValidationContext', function () {
36
37
  return _regeneratorRuntime().wrap(function _callee$(_context) {
37
38
  while (1) switch (_context.prev = _context.next) {
38
39
  case 0:
39
- _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
40
+ _render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_context3.HooksContextProvider, null, /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
40
41
  entryId: "123",
41
42
  topLevelErrors: []
42
- }, /*#__PURE__*/_react2.default.createElement(TestComponent, null))), container = _render.container;
43
+ }, /*#__PURE__*/_react2.default.createElement(TestComponent, null)))), container = _render.container;
43
44
  expect(container.childNodes.length).toEqual(4);
44
45
  expect(container.textContent).toContain('addErrors is a function');
45
46
  expect(container.textContent).toContain('resetQuickEditErrors is a function');
@@ -72,10 +73,10 @@ describe('context.SummaryCardValidationContext', function () {
72
73
  id: 'testid',
73
74
  error: 'error message four'
74
75
  }];
75
- _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
76
+ _render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_context3.HooksContextProvider, null, /*#__PURE__*/_react2.default.createElement(_SummaryCardValidationContext.default, {
76
77
  entryId: "123",
77
78
  topLevelErrors: TOP_LEVEL_ERRORS
78
- }, /*#__PURE__*/_react2.default.createElement(TestComponent, null))), container = _render2.container;
79
+ }, /*#__PURE__*/_react2.default.createElement(TestComponent, null)))), container = _render2.container;
79
80
  expect(container.childNodes.length).toEqual(5);
80
81
  expect(container.textContent).toContain('addErrors is a function');
81
82
  expect(container.textContent).toContain('resetQuickEditErrors is a function');