Package not found. Please check the package name and try again.

@ukhomeoffice/cop-react-form-renderer 5.71.3 → 5.71.6

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.
@@ -10,6 +10,7 @@ var _react = _interopRequireWildcard(require("react"));
10
10
  var _hooks = require("../../hooks");
11
11
  var _PageAction = require("../../models/PageAction");
12
12
  var _elevateNestedComponents = _interopRequireDefault(require("../../utils/Component/elevateNestedComponents"));
13
+ var _getErrorsForCollection = _interopRequireDefault(require("../../utils/CollectionPage/getErrorsForCollection"));
13
14
  var _utils = _interopRequireDefault(require("../../utils"));
14
15
  var _getCYARow = _interopRequireDefault(require("../../utils/CheckYourAnswers/getCYARow"));
15
16
  var _Answer = _interopRequireDefault(require("../CheckYourAnswers/Answer"));
@@ -115,38 +116,8 @@ var CollectionSummary = function CollectionSummary(_ref) {
115
116
  return e.raisedBy === config.id;
116
117
  });
117
118
  }
118
- var allErrors = [];
119
- data.forEach(function (entry) {
120
- // Validation of a collection page uses the data from the
121
- // active entry, so here we have to set the active ID before
122
- // validating.
123
- var childPages = masterPage === null || masterPage === void 0 ? void 0 : masterPage.childPages.map(function (page) {
124
- return _objectSpread(_objectSpread({}, page), {}, {
125
- formData: _objectSpread(_objectSpread({}, formData), {}, _defineProperty({}, "".concat(config.collectionName.split('.').pop(), "ActiveId"), entry.id))
126
- });
127
- });
128
- var allPagesErrors = (childPages === null || childPages === void 0 ? void 0 : childPages.flatMap(function (page) {
129
- // Handle nested collections
130
- if (page.childPages) {
131
- return page.childPages.flatMap(function (nestedCollectionPage) {
132
- var pageErrors = _utils.default.Validate.page(nestedCollectionPage);
133
- return hooks.onValidate(nestedCollectionPage, pageErrors);
134
- });
135
- }
136
- var pageErrors = _utils.default.Validate.page(page);
137
- return hooks.onValidate(page, pageErrors);
138
- })) || [];
139
- // For each error we found, add the entryId so we know what Summary Card
140
- // we have to pass it to.
141
- var entryErrors = allPagesErrors.map(function (e) {
142
- return _objectSpread(_objectSpread({}, e), {}, {
143
- entryId: entry.id,
144
- showFor: config.id,
145
- raisedBy: config.id
146
- });
147
- });
148
- allErrors = allErrors.concat(entryErrors);
149
- });
119
+ var allErrors = (0, _getErrorsForCollection.default)(config, masterPage, formData, hooks);
120
+
150
121
  // We only queue allErrors if it's not empty to avoid
151
122
  // triggering a race condition with the 'data' memo
152
123
  // above.
@@ -92,65 +92,13 @@ describe('components.CollectionSummary.CollectionSummary', function () {
92
92
  expect(errorChecker.textContent).toContain('queuedErrors is an array of length 1');
93
93
  expect(errorChecker.textContent).toContain('testText is required');
94
94
  });
95
- it('should correctly queue errors found when validating entries with nested collections', function () {
96
- var FORM_DATA_NESTED = {
97
- testCollection: [{
98
- testDate: 'hello',
99
- child: [{
100
- randomField: 'hello'
101
- }]
102
- }]
103
- };
104
- var PAGES_NESTED = [{
105
- id: 'page1',
106
- collection: {
107
- name: 'testCollection'
108
- },
109
- components: [{
110
- id: 'testDate',
111
- fieldId: 'testDate',
112
- type: 'date'
113
- }],
114
- formData: FORM_DATA_NESTED
115
- }, {
116
- id: 'page2',
117
- collection: {
118
- name: 'testCollection.child'
119
- },
120
- components: [{
121
- id: 'testText',
122
- label: 'Nested Field',
123
- fieldId: 'testText',
124
- type: 'text',
125
- required: true
126
- }],
127
- formData: FORM_DATA_NESTED
128
- }];
129
- var ErrorCheckComponent = function ErrorCheckComponent() {
130
- var _useValidation2 = (0, _hooks.useValidation)(),
131
- queuedErrors = _useValidation2.queuedErrors;
132
- return /*#__PURE__*/_react.default.createElement("div", null, Array.isArray(queuedErrors) && "queuedErrors is an array of length ".concat(queuedErrors.length), (queuedErrors === null || queuedErrors === void 0 ? void 0 : queuedErrors.length) > 0 && queuedErrors.map(function (e) {
133
- return e.error;
134
- }));
135
- };
136
- var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(ErrorCheckComponent, null), /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
137
- config: CONFIG,
138
- formData: FORM_DATA_NESTED,
139
- onAction: ON_ACTION,
140
- pages: PAGES_NESTED
141
- }))),
142
- container = _renderWithValidation3.container;
143
- var errorChecker = container.children[0];
144
- expect(errorChecker.textContent).toContain('queuedErrors is an array of length 1');
145
- expect(errorChecker.textContent).toContain('Nested Field is required');
146
- });
147
95
  it('should render a confirmation when a SummaryCard\'s delete button is pressed', function () {
148
- var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
96
+ var _renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
149
97
  config: CONFIG,
150
98
  formData: FORM_DATA,
151
99
  onAction: ON_ACTION
152
100
  })),
153
- container = _renderWithValidation4.container;
101
+ container = _renderWithValidation3.container;
154
102
  var summary = checkSetup(container);
155
103
  expect(summary.children.length).toEqual(2);
156
104
  var card = summary.children[0];
@@ -174,12 +122,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
174
122
  title: 'Title'
175
123
  }
176
124
  };
177
- var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
125
+ var _renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
178
126
  config: CONFIG_WITH_BUTTON,
179
127
  formData: FORM_DATA,
180
128
  onAction: ON_ACTION
181
129
  })),
182
- container = _renderWithValidation5.container;
130
+ container = _renderWithValidation4.container;
183
131
  var summary = checkSetup(container);
184
132
  expect(summary.children.length).toEqual(3); // The button and a card for each item.
185
133
  expect(summary.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
@@ -198,12 +146,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
198
146
  title: 'Title'
199
147
  }
200
148
  };
201
- var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
149
+ var _renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
202
150
  config: CONFIG_WITH_BUTTON,
203
151
  formData: FORM_DATA,
204
152
  onAction: ON_ACTION
205
153
  })),
206
- container = _renderWithValidation6.container;
154
+ container = _renderWithValidation5.container;
207
155
  var summary = checkSetup(container);
208
156
  expect(summary.children.length).toEqual(3); // The button and a card for each item.
209
157
  expect(summary.children[0].id).toEqual("".concat(CONFIG_WITH_BUTTON.fieldId, ".addButton"));
@@ -211,12 +159,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
211
159
  expect(summary.children[0].tagName).toEqual('BUTTON');
212
160
  });
213
161
  it('should apply the expected class name to the summary card when delete button is pressed', function () {
214
- var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
162
+ var _renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
215
163
  config: CONFIG,
216
164
  formData: FORM_DATA,
217
165
  onAction: ON_ACTION
218
166
  })),
219
- container = _renderWithValidation7.container;
167
+ container = _renderWithValidation6.container;
220
168
  var summary = checkSetup(container);
221
169
  expect(summary.children.length).toEqual(2);
222
170
  var card = summary.children[0];
@@ -227,12 +175,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
227
175
  expect(card.className).toContain('deleting-summary-card');
228
176
  });
229
177
  it('should focus on the delete button in the confirmation panel', function () {
230
- var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
178
+ var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
231
179
  config: CONFIG,
232
180
  formData: FORM_DATA,
233
181
  onAction: ON_ACTION
234
182
  })),
235
- container = _renderWithValidation8.container;
183
+ container = _renderWithValidation7.container;
236
184
  var summary = checkSetup(container);
237
185
  expect(summary.children.length).toEqual(2);
238
186
  var card = summary.children[0];
@@ -243,12 +191,12 @@ describe('components.CollectionSummary.CollectionSummary', function () {
243
191
  expect(document.activeElement).toEqual(confirmButton);
244
192
  });
245
193
  it('should have the role "alert" in the confirmation panel', function () {
246
- var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
194
+ var _renderWithValidation8 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
247
195
  config: CONFIG,
248
196
  formData: FORM_DATA,
249
197
  onAction: ON_ACTION
250
198
  })),
251
- container = _renderWithValidation9.container;
199
+ container = _renderWithValidation8.container;
252
200
  var summary = checkSetup(container);
253
201
  expect(summary.children.length).toEqual(2);
254
202
  var card = summary.children[0];
@@ -268,14 +216,14 @@ describe('components.CollectionSummary.CollectionSummary', function () {
268
216
  displayFields: ['testText']
269
217
  }
270
218
  });
271
- var _renderWithValidation10 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
219
+ var _renderWithValidation9 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
272
220
  config: listViewConfig,
273
221
  formData: FORM_DATA,
274
222
  onAction: ON_ACTION,
275
223
  pages: PAGES
276
224
  })),
277
- container = _renderWithValidation10.container,
278
- getByText = _renderWithValidation10.getByText;
225
+ container = _renderWithValidation9.container,
226
+ getByText = _renderWithValidation9.getByText;
279
227
  var summary = checkSetup(container);
280
228
  expect(summary.children.length).toEqual(2);
281
229
  var card = summary.children[0];
@@ -300,14 +248,14 @@ describe('components.CollectionSummary.CollectionSummary', function () {
300
248
  message: 'Test confirmation message with index number ${index}'
301
249
  }
302
250
  });
303
- var _renderWithValidation11 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
251
+ var _renderWithValidation10 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_CollectionSummary.default, {
304
252
  config: listViewConfig,
305
253
  formData: FORM_DATA,
306
254
  onAction: ON_ACTION,
307
255
  pages: PAGES
308
256
  })),
309
- container = _renderWithValidation11.container,
310
- getByText = _renderWithValidation11.getByText;
257
+ container = _renderWithValidation10.container,
258
+ getByText = _renderWithValidation10.getByText;
311
259
  var summary = checkSetup(container);
312
260
  expect(summary.children.length).toEqual(2);
313
261
  var card = summary.children[0];
@@ -9,6 +9,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _utils = _interopRequireDefault(require("../../utils"));
11
11
  var _getComponentRowForCYA = _interopRequireDefault(require("../../utils/CheckYourAnswers/getComponentRowForCYA"));
12
+ var _Condition = _interopRequireDefault(require("../../utils/Condition"));
12
13
  require("./RenderListView.scss");
13
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
15
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
@@ -80,7 +81,10 @@ var RenderListView = function RenderListView(_ref) {
80
81
  return _utils.default.Component.elevateNested([component], entryData);
81
82
  }).flat().filter(Boolean);
82
83
  return (_childPage$summaryLay = childPage.summaryLayout) === null || _childPage$summaryLay === void 0 || (_childPage$summaryLay = _childPage$summaryLay.sections) === null || _childPage$summaryLay === void 0 ? void 0 : _childPage$summaryLay.flatMap(function (section) {
83
- var summaryFields = section.columns.flatMap(function (column) {
84
+ var filteredColumns = section.columns.filter(function (column) {
85
+ return _Condition.default.meetsAll(column, _objectSpread(_objectSpread({}, childPage.formData), entryData));
86
+ });
87
+ var summaryFields = filteredColumns.flatMap(function (column) {
84
88
  return column.fields || [];
85
89
  });
86
90
  if (summaryFields.length) {
@@ -88,7 +92,7 @@ var RenderListView = function RenderListView(_ref) {
88
92
  var component = elevatedComponents.find(function (comp) {
89
93
  return comp.fieldId === fieldId;
90
94
  });
91
- if (!component) {
95
+ if (!component || !_Condition.default.meetsAll(component, _objectSpread(_objectSpread({}, childPage.formData), entryData))) {
92
96
  return null;
93
97
  }
94
98
  return (0, _getComponentRowForCYA.default)(childPage, component, listClass, entryData);
@@ -19,6 +19,7 @@ describe('components.CollectionSummary.RenderListView', function () {
19
19
  label: 'Value 3',
20
20
  value: 'Value 3'
21
21
  },
22
+ condition: 'test',
22
23
  index: 0
23
24
  };
24
25
  var MASTER_PAGE = {
@@ -26,7 +27,12 @@ describe('components.CollectionSummary.RenderListView', function () {
26
27
  summaryLayout: {
27
28
  sections: [{
28
29
  columns: [{
29
- fields: ['item1', 'item2', 'item3']
30
+ fields: ['item1', 'item2', 'item3'],
31
+ show_when: {
32
+ field: "condition",
33
+ op: "in",
34
+ values: ["test"]
35
+ }
30
36
  }]
31
37
  }]
32
38
  },
@@ -67,8 +67,8 @@ var SummaryCard = function SummaryCard(_ref) {
67
67
  setQuickEdit = _useState2[1];
68
68
  var classes = _copReactComponents.Utils.classBuilder(DEFAULT_CLASS, classModifiers, config.className);
69
69
  var quickEditPage = (0, _react.useMemo)(function () {
70
- return config.quickEdit ? (0, _getQuickEditPage.default)(masterPage, entryData) : null;
71
- }, [masterPage, config, entryData, quickEdit]);
70
+ return config.quickEdit ? (0, _getQuickEditPage.default)(masterPage, formData, entryData) : null;
71
+ }, [masterPage, config, formData, entryData, quickEdit]);
72
72
 
73
73
  // The validation context used here is a custom one for Summary Cards,
74
74
  // not the standard context. See SummaryCardValidationContext.jsx.
@@ -40,7 +40,15 @@ var duplicateCollectionPageEntry = function duplicateCollectionPageEntry(collect
40
40
  fieldsToIgnore.forEach(function (field) {
41
41
  return delete newEntry[field];
42
42
  });
43
- collectionData.push(newEntry);
43
+ var insertionIndex = collectionData.findIndex(function (entry) {
44
+ return entry.id === entryId;
45
+ }) + 1;
46
+ if (insertionIndex === -1) {
47
+ collectionData.push(newEntry);
48
+ } else {
49
+ collectionData.splice(insertionIndex, 0, newEntry);
50
+ }
51
+
44
52
  // eslint-disable-next-line no-param-reassign
45
53
  formData["".concat(collectionName.split('.').pop(), "ActiveId")] = newEntry.id;
46
54
  return newEntryId;
@@ -24,6 +24,26 @@ describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
24
24
  expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")]).toBeTruthy();
25
25
  expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")] === '1').toBeFalsy();
26
26
  });
27
+ it('should put the new entry under the original one', function () {
28
+ var _FORM_DATA2;
29
+ var FORM_DATA = (_FORM_DATA2 = {}, _defineProperty(_FORM_DATA2, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA2, COLLECTION_NAME, [{
30
+ id: '1',
31
+ value: 'value1'
32
+ }, {
33
+ id: '2',
34
+ value: 'value2'
35
+ }, {
36
+ id: '3',
37
+ value: 'value1'
38
+ }]), _FORM_DATA2);
39
+ (0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '1');
40
+ expect(FORM_DATA[COLLECTION_NAME].length).toEqual(4);
41
+ expect(FORM_DATA[COLLECTION_NAME][1].value).toEqual(FORM_DATA[COLLECTION_NAME][0].value);
42
+ expect(FORM_DATA[COLLECTION_NAME][1].id).toBeTruthy();
43
+ expect(FORM_DATA[COLLECTION_NAME][1].id === '1').toBeFalsy();
44
+ expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")]).toBeTruthy();
45
+ expect(FORM_DATA["".concat(COLLECTION_NAME, "ActiveId")] === '1').toBeFalsy();
46
+ });
27
47
  it('should duplicate entries in nested collections correctly', function () {
28
48
  var FORM_DATA = {
29
49
  parentsActiveId: '2',
@@ -54,8 +74,8 @@ describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
54
74
  expect((0, _getCollectionPageActiveId.default)('parents.children', FORM_DATA) === '2').toBeFalsy();
55
75
  });
56
76
  it('should ignore fields in the fieldToIgnore array', function () {
57
- var _FORM_DATA2;
58
- var FORM_DATA = (_FORM_DATA2 = {}, _defineProperty(_FORM_DATA2, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA2, COLLECTION_NAME, [OBJ]), _FORM_DATA2);
77
+ var _FORM_DATA3;
78
+ var FORM_DATA = (_FORM_DATA3 = {}, _defineProperty(_FORM_DATA3, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA3, COLLECTION_NAME, [OBJ]), _FORM_DATA3);
59
79
  ;
60
80
  var FIELDS_TO_IGNORE = ['value'];
61
81
  (0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '1', FIELDS_TO_IGNORE);
@@ -66,8 +86,8 @@ describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
66
86
  expect(FORM_DATA[COLLECTION_NAME][1].value).toBeUndefined();
67
87
  });
68
88
  it('should add fields from the fieldsToAdd object', function () {
69
- var _FORM_DATA3;
70
- var FORM_DATA = (_FORM_DATA3 = {}, _defineProperty(_FORM_DATA3, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA3, COLLECTION_NAME, [OBJ]), _FORM_DATA3);
89
+ var _FORM_DATA4;
90
+ var FORM_DATA = (_FORM_DATA4 = {}, _defineProperty(_FORM_DATA4, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA4, COLLECTION_NAME, [OBJ]), _FORM_DATA4);
71
91
  ;
72
92
  var FIELDS_TO_ADD = {
73
93
  addedKey: 'addedValue'
@@ -81,8 +101,8 @@ describe('utils.CollectionPage.duplicateCollectionPageEntry', function () {
81
101
  expect(FORM_DATA[COLLECTION_NAME][1].addedKey).toEqual('addedValue');
82
102
  });
83
103
  it('should do nothing if an entry with the given id does not exist', function () {
84
- var _FORM_DATA4, _expect$toEqual;
85
- var FORM_DATA = (_FORM_DATA4 = {}, _defineProperty(_FORM_DATA4, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA4, COLLECTION_NAME, [OBJ]), _FORM_DATA4);
104
+ var _FORM_DATA5, _expect$toEqual;
105
+ var FORM_DATA = (_FORM_DATA5 = {}, _defineProperty(_FORM_DATA5, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_FORM_DATA5, COLLECTION_NAME, [OBJ]), _FORM_DATA5);
86
106
  ;
87
107
  (0, _duplicateCollectionPageEntry.default)(COLLECTION_NAME, FORM_DATA, '0');
88
108
  expect(FORM_DATA).toEqual((_expect$toEqual = {}, _defineProperty(_expect$toEqual, "".concat(COLLECTION_NAME, "ActiveId"), '1'), _defineProperty(_expect$toEqual, COLLECTION_NAME, [OBJ]), _expect$toEqual));
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _ = _interopRequireDefault(require(".."));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
14
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
15
+ var getErrorsForCollection = function getErrorsForCollection(config, masterPage, formData, hooks) {
16
+ var activeIds = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
17
+ if (!masterPage) {
18
+ return [];
19
+ }
20
+ // Get data for current collection
21
+ var collectionData = _.default.CollectionPage.getData(masterPage.collection.name, masterPage.formData) || [];
22
+ var allErrors = [];
23
+
24
+ // Loop over each entry in the collection data
25
+ collectionData.forEach(function (entry) {
26
+ var _masterPage$childPage;
27
+ // eslint-disable-next-line no-param-reassign
28
+ activeIds = _objectSpread(_objectSpread({}, activeIds), {}, _defineProperty({}, "".concat(masterPage.collection.name.split('.').pop(), "ActiveId"), entry.id));
29
+
30
+ // Loop over child pages and validate each one
31
+ var allPagesErrors = (_masterPage$childPage = masterPage.childPages) === null || _masterPage$childPage === void 0 ? void 0 : _masterPage$childPage.flatMap(function (page) {
32
+ var pageWithIds = _objectSpread(_objectSpread({}, page), {}, {
33
+ formData: _objectSpread(_objectSpread({}, formData), activeIds)
34
+ });
35
+
36
+ // Handle nested collections
37
+ if (page.childPages) {
38
+ return getErrorsForCollection(config, pageWithIds, formData, hooks, activeIds);
39
+ }
40
+ var pageErrors = _.default.Validate.page(pageWithIds);
41
+ return hooks.onValidate(pageWithIds, pageErrors);
42
+ });
43
+
44
+ // For each error add the entryId so we know what Summary Card we have to pass it to.
45
+ allErrors = allErrors.concat(allPagesErrors.map(function (e) {
46
+ return _objectSpread(_objectSpread({}, e), {}, {
47
+ entryId: entry.id,
48
+ showFor: config.id,
49
+ raisedBy: config.id
50
+ });
51
+ }));
52
+ });
53
+ return allErrors;
54
+ };
55
+ var _default = exports.default = getErrorsForCollection;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ var _getErrorsForCollection = _interopRequireDefault(require("./getErrorsForCollection"));
4
+ var _models = require("../../models");
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+ describe('Utils.CollectionPage.getErrorsForCollection', function () {
7
+ var HOOKS = {
8
+ onValidate: function onValidate(_, errors) {
9
+ return errors;
10
+ }
11
+ };
12
+ var CONFIG = {
13
+ id: 'testId'
14
+ };
15
+ var FORM_DATA = {
16
+ collection: [{
17
+ id: 22,
18
+ item1: 'blue',
19
+ child: [{
20
+ id: 11,
21
+ item4: 'red'
22
+ }]
23
+ }]
24
+ };
25
+ var FORM_DATA_MISSING_TOP = {
26
+ collection: [{
27
+ id: 22,
28
+ item2: 'blue',
29
+ child: [{
30
+ id: 11,
31
+ item4: 'red'
32
+ }]
33
+ }]
34
+ };
35
+ var FORM_DATA_MISSING_NESTED = {
36
+ collection: [{
37
+ id: 22,
38
+ item1: 'blue',
39
+ child: [{
40
+ id: 11,
41
+ item9: 'red'
42
+ }]
43
+ }]
44
+ };
45
+ var FORM_DATA_MISSING_BOTH = {
46
+ collection: [{
47
+ id: 22,
48
+ item9: 'blue',
49
+ child: [{
50
+ id: 11,
51
+ item9: 'red'
52
+ }]
53
+ }]
54
+ };
55
+ var MASTER_PAGE = {
56
+ id: 'masterPage',
57
+ collection: {
58
+ name: 'collection',
59
+ masterPage: true
60
+ },
61
+ formData: FORM_DATA,
62
+ childPages: [{
63
+ id: 'page1',
64
+ collection: {
65
+ name: 'collection'
66
+ },
67
+ formData: FORM_DATA,
68
+ components: [{
69
+ id: 'item1',
70
+ fieldId: 'item1',
71
+ label: 'Item 1',
72
+ required: true,
73
+ type: _models.ComponentTypes.TEXT
74
+ }, {
75
+ id: 'item2',
76
+ fieldId: 'item2',
77
+ label: 'Item 2',
78
+ type: _models.ComponentTypes.TEXT
79
+ }]
80
+ }]
81
+ };
82
+ var MASTER_PAGE_WITH_NESTED = {
83
+ id: 'masterPage',
84
+ collection: {
85
+ name: 'collection',
86
+ masterPage: true
87
+ },
88
+ formData: FORM_DATA,
89
+ childPages: [{
90
+ id: 'page1',
91
+ collection: {
92
+ name: 'collection'
93
+ },
94
+ formData: FORM_DATA,
95
+ components: [{
96
+ id: 'item1',
97
+ fieldId: 'item1',
98
+ label: 'Item 1',
99
+ required: true,
100
+ type: _models.ComponentTypes.TEXT
101
+ }, {
102
+ id: 'item2',
103
+ fieldId: 'item2',
104
+ label: 'Item 2',
105
+ type: _models.ComponentTypes.TEXT
106
+ }]
107
+ }, {
108
+ id: 'page2',
109
+ formData: FORM_DATA,
110
+ collection: {
111
+ name: 'collection.child',
112
+ masterPage: true
113
+ },
114
+ childPages: [{
115
+ id: 'nestedPage',
116
+ formData: FORM_DATA,
117
+ collection: {
118
+ name: 'collection.child'
119
+ },
120
+ components: [{
121
+ id: 'item4',
122
+ fieldId: 'item4',
123
+ label: 'Item 4',
124
+ required: true,
125
+ type: _models.ComponentTypes.TEXT
126
+ }, {
127
+ id: 'item5',
128
+ fieldId: 'item5',
129
+ label: 'Item 5',
130
+ type: _models.ComponentTypes.TEXT
131
+ }]
132
+ }]
133
+ }]
134
+ };
135
+ it('should return nothing for a master page without errors', function () {
136
+ var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE, FORM_DATA, HOOKS);
137
+ expect(errors.length).toEqual(0);
138
+ });
139
+ it('should return erorrs for a master page with errors', function () {
140
+ var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE, FORM_DATA_MISSING_TOP, HOOKS);
141
+ expect(errors.length).toEqual(1);
142
+ });
143
+ it('should return nothing for a master page with a nested master page without errors', function () {
144
+ var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE_WITH_NESTED, FORM_DATA, HOOKS);
145
+ expect(errors.length).toEqual(0);
146
+ });
147
+ it('should return errors for a master page with a nested master page without errors', function () {
148
+ var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE_WITH_NESTED, FORM_DATA_MISSING_NESTED, HOOKS);
149
+ expect(errors.length).toEqual(1);
150
+ });
151
+ it('should return errors for a master page with errors with a nested master page with errors', function () {
152
+ var errors = (0, _getErrorsForCollection.default)(CONFIG, MASTER_PAGE_WITH_NESTED, FORM_DATA_MISSING_BOTH, HOOKS);
153
+ expect(errors.length).toEqual(2);
154
+ });
155
+ });
@@ -50,16 +50,17 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
50
50
  * editable or not.
51
51
  *
52
52
  * @param {object} masterPage The master page for the collection.
53
+ * @param {object} formData The top-level formData object.
53
54
  * @param {object} entryData The data for the current collection entry.
54
55
  * @returns Page suitble for rendering in a QuickEdit
55
56
  */
56
- var getQuickEditPage = function getQuickEditPage(masterPage, entryData) {
57
+ var getQuickEditPage = function getQuickEditPage(masterPage, formData, entryData) {
57
58
  if (!masterPage) {
58
59
  return null;
59
60
  }
60
61
  var fullComponents = [];
61
62
  masterPage.childPages.forEach(function (page) {
62
- if (!page.summaryQuickEdit || !(0, _showFormPage.default)(page, _objectSpread(_objectSpread({}, page.formData), entryData))) {
63
+ if (!page.summaryQuickEdit || !(0, _showFormPage.default)(page, _objectSpread(_objectSpread({}, formData), entryData))) {
63
64
  return;
64
65
  }
65
66
  page.summaryQuickEdit.forEach(function (quickEditComponent) {
@@ -81,7 +82,7 @@ var getQuickEditPage = function getQuickEditPage(masterPage, entryData) {
81
82
  // that as a specific test for when the component should be quick
82
83
  // editable - it doesn't get spread to the merged object.
83
84
  if (quickEditComponent.show_when) {
84
- if ((0, _meetsAllConditions.default)(quickEditComponent.show_when, _objectSpread(_objectSpread({}, page.formData), entryData))) {
85
+ if ((0, _meetsAllConditions.default)(quickEditComponent.show_when, _objectSpread(_objectSpread({}, formData), entryData))) {
85
86
  fullComponents.push(_objectSpread(_objectSpread({}, mergedComponent), {}, {
86
87
  show_when: originalComponent.show_when || []
87
88
  }));
@@ -93,7 +94,9 @@ var getQuickEditPage = function getQuickEditPage(masterPage, entryData) {
93
94
  });
94
95
 
95
96
  // Put components and actions onto page object
96
- var pageToReturn = _objectSpread({}, masterPage.childPages[0]);
97
+ var pageToReturn = _objectSpread(_objectSpread({}, masterPage.childPages[0]), {}, {
98
+ formData: formData
99
+ });
97
100
  pageToReturn.components = fullComponents;
98
101
  pageToReturn.actions = [{
99
102
  type: 'save',
@@ -9,6 +9,15 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
9
9
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
10
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
11
  describe('Utils.CollectionPage.getQuickEditPage', function () {
12
+ var FORM_DATA = {
13
+ items: [{
14
+ id: '123',
15
+ testText1: 'value 1',
16
+ testText2: 'value 2',
17
+ conditionText: 'true',
18
+ testText3: 'value 3'
19
+ }]
20
+ };
12
21
  var MASTER_PAGE = {
13
22
  childPages: [{
14
23
  id: 'firstPage',
@@ -44,15 +53,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
44
53
  fieldId: 'testText2',
45
54
  required: true
46
55
  }],
47
- formData: {
48
- items: [{
49
- id: '123',
50
- testText1: 'value 1',
51
- testText2: 'value 2',
52
- conditionText: 'true',
53
- testText3: 'value 3'
54
- }]
55
- },
56
+ formData: FORM_DATA,
56
57
  summaryQuickEdit: [{
57
58
  use: "testText2",
58
59
  show_when: {
@@ -69,15 +70,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
69
70
  fieldId: 'testText3',
70
71
  required: true
71
72
  }],
72
- formData: {
73
- items: [{
74
- id: '123',
75
- testText1: 'value 1',
76
- testText2: 'value 2',
77
- conditionText: 'true',
78
- testText3: 'value 3'
79
- }]
80
- },
73
+ formData: FORM_DATA,
81
74
  summaryQuickEdit: ["testText3"]
82
75
  }]
83
76
  };
@@ -103,15 +96,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
103
96
  fieldId: 'testText3',
104
97
  required: true
105
98
  }],
106
- formData: {
107
- items: [{
108
- id: '123',
109
- testText1: 'value 1',
110
- testText2: 'value 2',
111
- conditionText: 'true',
112
- testText3: 'value 3'
113
- }]
114
- },
99
+ formData: FORM_DATA,
115
100
  actions: [{
116
101
  type: 'save',
117
102
  label: 'Save',
@@ -131,7 +116,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
131
116
  testText3: 'value 3'
132
117
  };
133
118
  it('should return a quick edit page', function () {
134
- var createdPage = (0, _getQuickEditPage.default)(MASTER_PAGE, ENTRY_DATA);
119
+ var createdPage = (0, _getQuickEditPage.default)(MASTER_PAGE, FORM_DATA, ENTRY_DATA);
135
120
  expect(createdPage).toMatchObject(EXPECTED_OUTPUT);
136
121
  });
137
122
  it('should return a quick edit page without components that fail the quick edit show_when', function () {
@@ -144,7 +129,7 @@ describe('Utils.CollectionPage.getQuickEditPage', function () {
144
129
  var CUSTOM_ENTRY_DATA = _objectSpread(_objectSpread({}, ENTRY_DATA), {}, {
145
130
  conditionText: 'false'
146
131
  });
147
- var createdPage = (0, _getQuickEditPage.default)(MASTER_PAGE, CUSTOM_ENTRY_DATA);
132
+ var createdPage = (0, _getQuickEditPage.default)(MASTER_PAGE, FORM_DATA, CUSTOM_ENTRY_DATA);
148
133
  expect(createdPage).toMatchObject(CUSTOM_OUTPUT);
149
134
  });
150
135
  });
@@ -10,6 +10,7 @@ var _duplicateCollectionPageEntry = _interopRequireDefault(require("./duplicateC
10
10
  var _getCollectionPageActiveId = _interopRequireDefault(require("./getCollectionPageActiveId"));
11
11
  var _getCollectionPageActiveIndex = _interopRequireDefault(require("./getCollectionPageActiveIndex"));
12
12
  var _getCollectionPageData = _interopRequireDefault(require("./getCollectionPageData"));
13
+ var _getErrorsForCollection = _interopRequireDefault(require("./getErrorsForCollection"));
13
14
  var _mergeCollectionPages = _interopRequireDefault(require("./mergeCollectionPages"));
14
15
  var _removeCollectionPageEntry = _interopRequireDefault(require("./removeCollectionPageEntry"));
15
16
  var _setCollectionPageData = _interopRequireDefault(require("./setCollectionPageData"));
@@ -23,6 +24,7 @@ var CollectionPage = {
23
24
  getActiveId: _getCollectionPageActiveId.default,
24
25
  getActiveIndex: _getCollectionPageActiveIndex.default,
25
26
  getData: _getCollectionPageData.default,
27
+ getErrorsForCollection: _getErrorsForCollection.default,
26
28
  mergePages: _mergeCollectionPages.default,
27
29
  removeEntry: _removeCollectionPageEntry.default,
28
30
  setData: _setCollectionPageData.default
@@ -7,7 +7,7 @@ exports.default = exports.EDITABLE_TYPES = void 0;
7
7
  var _models = require("../../models");
8
8
  // Local imports
9
9
 
10
- var EDITABLE_TYPES = exports.EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.MULTI_FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
10
+ var EDITABLE_TYPES = exports.EDITABLE_TYPES = [_models.ComponentTypes.AUTOCOMPLETE, _models.ComponentTypes.CALCULATION, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.COLLECTION_SUMMARY, _models.ComponentTypes.DATE, _models.ComponentTypes.EMAIL, _models.ComponentTypes.FILE, _models.ComponentTypes.MULTI_FILE, _models.ComponentTypes.PHONE_NUMBER, _models.ComponentTypes.RADIOS, _models.ComponentTypes.SELECT, _models.ComponentTypes.TEXT, _models.ComponentTypes.TEXT_AREA, _models.ComponentTypes.TIME];
11
11
  var isEditable = function isEditable(options) {
12
12
  return EDITABLE_TYPES.includes(options === null || options === void 0 ? void 0 : options.type) || (options === null || options === void 0 ? void 0 : options.isEditable) || false;
13
13
  };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  // eslint-disable-next-line no-control-regex
8
8
  // const EMAIL_REGEX = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/i;
9
- var HODS_EMAIL_REGEX = /^[a-z0-9._-]+@(digital\.)?homeoffice.gov.uk$/i;
9
+ var HODS_EMAIL_REGEX = /^[a-z0-9._\-']+@(digital\.)?homeoffice.gov.uk$/i;
10
10
 
11
11
  /**
12
12
  * Validates an email address, ensuring it is in the correct domain and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.71.3",
3
+ "version": "5.71.6",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",