@ukhomeoffice/cop-react-form-renderer 4.19.1 → 4.19.2-alpha

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.
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -13,7 +15,11 @@ var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
13
15
 
14
16
  var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
15
17
 
16
- var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
18
+ var _showComponentCYA = _interopRequireWildcard(require("./showComponentCYA"));
19
+
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
23
 
18
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
25
 
@@ -34,6 +40,30 @@ var getEntryToCollectionRow = function getEntryToCollectionRow(page, onAction) {
34
40
  }];
35
41
  };
36
42
 
43
+ var setupContainerComponentsPath = function setupContainerComponentsPath(container) {
44
+ return _objectSpread(_objectSpread({}, container), {}, {
45
+ components: container.components.map(function (component) {
46
+ if (Array.isArray(component.components)) {
47
+ return _objectSpread(_objectSpread({}, component), {}, {
48
+ components: component.components.map(function (c) {
49
+ if (!_showComponentCYA.EXCLUDE_FROM_CYA.includes(c.type)) {
50
+ return _objectSpread(_objectSpread({}, c), !c.full_path && {
51
+ full_path: "".concat(component.full_path || "".concat(container.full_path, ".").concat(component.fieldId), ".").concat(c.fieldId)
52
+ });
53
+ }
54
+
55
+ return null;
56
+ }).filter(function (c) {
57
+ return !!c;
58
+ })
59
+ });
60
+ }
61
+
62
+ return component;
63
+ })
64
+ });
65
+ };
66
+
37
67
  var getContainerForItem = function getContainerForItem(collection, item, labelCount, full_path) {
38
68
  return {
39
69
  id: item.id,
@@ -77,6 +107,7 @@ var getCYARowsForCollection = function getCYARowsForCollection(page, collection,
77
107
  var labelCount = (collection.countOffset || 0) + index + 1;
78
108
  var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
79
109
  var container = getContainerForItem(collection, item, labelCount, full_path);
110
+ container = setupContainerComponentsPath(container, full_path);
80
111
  return [getTitleRowForItem(collection, item, page.id, labelCount, full_path)].concat((0, _getCYARowsForContainer.default)(page, container, item, onAction));
81
112
  }).filter(function (r) {
82
113
  return !!r;
@@ -196,4 +196,66 @@ describe('utils.CheckYourAnswers.getCYARowsForCollection', function () {
196
196
  value: 'Bravo'
197
197
  });
198
198
  });
199
+ it('should setup the full_path attribute for components within a container in a collection', function () {
200
+ var FORM_DATA = {
201
+ collection: [{
202
+ 'test-container': {
203
+ checkboxes1: 'Bravo',
204
+ checkboxes2: 'Charlie'
205
+ }
206
+ }]
207
+ };
208
+ var PAGE = {
209
+ id: 'page',
210
+ formData: FORM_DATA,
211
+ cya_link: {}
212
+ };
213
+ var COMPONENT_1 = {
214
+ id: 'checkboxes1',
215
+ fieldId: 'checkboxes1',
216
+ type: 'checkboxes',
217
+ label: 'Alpha'
218
+ };
219
+ var COMPONENT_2 = {
220
+ id: 'checkboxes2',
221
+ fieldId: 'checkboxes2',
222
+ type: 'checkboxes',
223
+ label: 'Bravo'
224
+ };
225
+ var CONTAINER = {
226
+ id: 'test-container',
227
+ fieldId: 'test-container',
228
+ type: 'container',
229
+ full_path: 'test-container',
230
+ components: [COMPONENT_1, COMPONENT_2]
231
+ };
232
+ var COLLECTION = {
233
+ id: 'collection',
234
+ fieldId: 'collection',
235
+ type: _models.ComponentTypes.COLLECTION,
236
+ countOffset: 0,
237
+ item: [CONTAINER],
238
+ value: FORM_DATA.collection,
239
+ formData: FORM_DATA
240
+ };
241
+
242
+ var ON_ACTION = function ON_ACTION() {};
243
+
244
+ var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
245
+ expect(ROWS.length).toEqual(3);
246
+ (0, _setupTests.expectObjectLike)(ROWS[1], {
247
+ pageId: PAGE.id,
248
+ fieldId: COMPONENT_1.fieldId,
249
+ full_path: "".concat(COLLECTION.fieldId, "[0].").concat(CONTAINER.fieldId, ".").concat(COMPONENT_1.fieldId),
250
+ key: COMPONENT_1.label,
251
+ value: 'Bravo'
252
+ });
253
+ (0, _setupTests.expectObjectLike)(ROWS[2], {
254
+ pageId: PAGE.id,
255
+ fieldId: COMPONENT_2.fieldId,
256
+ full_path: "".concat(COLLECTION.fieldId, "[0].").concat(CONTAINER.fieldId, ".").concat(COMPONENT_2.fieldId),
257
+ key: COMPONENT_2.label,
258
+ value: 'Charlie'
259
+ });
260
+ });
199
261
  });
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.EXCLUDE_FROM_CYA = void 0;
7
7
 
8
8
  var _models = require("../../models");
9
9
 
@@ -24,6 +24,8 @@ var EXCLUDE_FROM_CYA = [_models.ComponentTypes.HEADING, _models.ComponentTypes.H
24
24
  * @returns A boolean true if the component should show; otherwise false.
25
25
  */
26
26
 
27
+ exports.EXCLUDE_FROM_CYA = EXCLUDE_FROM_CYA;
28
+
27
29
  var showComponentCYA = function showComponentCYA(options, data) {
28
30
  if (!options) {
29
31
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.19.1",
3
+ "version": "4.19.2-alpha",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",