@ukhomeoffice/cop-react-form-renderer 4.19.2-alpha → 4.19.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.
@@ -1,7 +1,5 @@
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
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -15,11 +13,9 @@ var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
15
13
 
16
14
  var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
17
15
 
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); }
16
+ var _setupContainerComponentsPath = _interopRequireDefault(require("../Component/setupContainerComponentsPath"));
21
17
 
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; }
18
+ var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
23
19
 
24
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
21
 
@@ -40,30 +36,6 @@ var getEntryToCollectionRow = function getEntryToCollectionRow(page, onAction) {
40
36
  }];
41
37
  };
42
38
 
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
-
67
39
  var getContainerForItem = function getContainerForItem(collection, item, labelCount, full_path) {
68
40
  return {
69
41
  id: item.id,
@@ -107,7 +79,7 @@ var getCYARowsForCollection = function getCYARowsForCollection(page, collection,
107
79
  var labelCount = (collection.countOffset || 0) + index + 1;
108
80
  var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
109
81
  var container = getContainerForItem(collection, item, labelCount, full_path);
110
- container = setupContainerComponentsPath(container, full_path);
82
+ container = (0, _setupContainerComponentsPath.default)(container);
111
83
  return [getTitleRowForItem(collection, item, page.id, labelCount, full_path)].concat((0, _getCYARowsForContainer.default)(page, container, item, onAction));
112
84
  }).filter(function (r) {
113
85
  return !!r;
@@ -196,66 +196,4 @@ 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
- });
261
199
  });
@@ -15,6 +15,8 @@ var _getDefaultValue = _interopRequireDefault(require("./getDefaultValue"));
15
15
 
16
16
  var _isEditable = _interopRequireDefault(require("./isEditable"));
17
17
 
18
+ var _setupContainerComponentsPath = _interopRequireDefault(require("./setupContainerComponentsPath"));
19
+
18
20
  var _showComponent = _interopRequireDefault(require("./showComponent"));
19
21
 
20
22
  var _wrapInFormGroup = _interopRequireDefault(require("./wrapInFormGroup"));
@@ -27,6 +29,7 @@ var Component = {
27
29
  editable: _isEditable.default,
28
30
  elevateNested: _elevateNestedComponents.default,
29
31
  get: _getComponent.default,
32
+ setupContainerPaths: _setupContainerComponentsPath.default,
30
33
  show: _showComponent.default,
31
34
  wrap: _wrapInFormGroup.default
32
35
  };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _showComponentCYA = require("../CheckYourAnswers/showComponentCYA");
9
+
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
+
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
+
14
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+
16
+ var setupContainerComponentsPath = function setupContainerComponentsPath(container) {
17
+ return _objectSpread(_objectSpread({}, container), {}, {
18
+ components: container.components.map(function (component) {
19
+ if (Array.isArray(component.components)) {
20
+ return _objectSpread(_objectSpread({}, component), {}, {
21
+ components: component.components.map(function (c) {
22
+ if (!_showComponentCYA.EXCLUDE_FROM_CYA.includes(c.type)) {
23
+ return _objectSpread(_objectSpread({}, c), !c.full_path && {
24
+ full_path: "".concat(component.full_path || "".concat(container.full_path, ".").concat(component.fieldId), ".").concat(c.fieldId)
25
+ });
26
+ }
27
+
28
+ return null;
29
+ }).filter(function (c) {
30
+ return !!c;
31
+ })
32
+ });
33
+ }
34
+
35
+ return _objectSpread(_objectSpread({}, component), !component.full_path && {
36
+ full_path: "".concat(container.full_path || container.fieldId, ".").concat(component.fieldId)
37
+ });
38
+ })
39
+ });
40
+ };
41
+
42
+ var _default = setupContainerComponentsPath;
43
+ exports.default = _default;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ var _setupTests = require("../../setupTests");
4
+
5
+ var _setupContainerComponentsPath = _interopRequireDefault(require("./setupContainerComponentsPath"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ describe('utils.CheckYourAnswers.setupContainerComponentsPath', function () {
10
+ it('should setup the full_path attribute for components within a container', function () {
11
+ var COMPONENT_1 = {
12
+ id: 'checkboxes1',
13
+ fieldId: 'checkboxes1',
14
+ type: 'checkboxes',
15
+ label: 'Alpha'
16
+ };
17
+ var COMPONENT_2 = {
18
+ id: 'checkboxes2',
19
+ fieldId: 'checkboxes2',
20
+ type: 'checkboxes',
21
+ label: 'Bravo'
22
+ };
23
+ var CONTAINER = {
24
+ id: 'test-container',
25
+ fieldId: 'test-container',
26
+ type: 'container',
27
+ full_path: 'test-container',
28
+ components: [COMPONENT_1, COMPONENT_2]
29
+ };
30
+ var container = (0, _setupContainerComponentsPath.default)(CONTAINER);
31
+ (0, _setupTests.expectObjectLike)(container.components[0], {
32
+ id: COMPONENT_1.id,
33
+ fieldId: COMPONENT_1.fieldId,
34
+ full_path: "".concat(CONTAINER.fieldId, ".").concat(COMPONENT_1.fieldId),
35
+ type: COMPONENT_1.type,
36
+ label: COMPONENT_1.label
37
+ });
38
+ (0, _setupTests.expectObjectLike)(container.components[1], {
39
+ id: COMPONENT_2.id,
40
+ fieldId: COMPONENT_2.fieldId,
41
+ full_path: "".concat(CONTAINER.fieldId, ".").concat(COMPONENT_2.fieldId),
42
+ type: COMPONENT_2.type,
43
+ label: COMPONENT_2.label
44
+ });
45
+ });
46
+ it('should setup the full_path attribute for components when the container full_path property is missing', function () {
47
+ var COMPONENT_1 = {
48
+ id: 'checkboxes1',
49
+ fieldId: 'checkboxes1',
50
+ type: 'checkboxes',
51
+ label: 'Alpha'
52
+ };
53
+ var COMPONENT_2 = {
54
+ id: 'checkboxes2',
55
+ fieldId: 'checkboxes2',
56
+ type: 'checkboxes',
57
+ label: 'Bravo'
58
+ };
59
+ var CONTAINER = {
60
+ id: 'test-container',
61
+ fieldId: 'test-container',
62
+ type: 'container',
63
+ components: [COMPONENT_1, COMPONENT_2]
64
+ };
65
+ var container = (0, _setupContainerComponentsPath.default)(CONTAINER);
66
+ (0, _setupTests.expectObjectLike)(container.components[0], {
67
+ id: COMPONENT_1.id,
68
+ fieldId: COMPONENT_1.fieldId,
69
+ full_path: "".concat(CONTAINER.fieldId, ".").concat(COMPONENT_1.fieldId),
70
+ type: COMPONENT_1.type,
71
+ label: COMPONENT_1.label
72
+ });
73
+ (0, _setupTests.expectObjectLike)(container.components[1], {
74
+ id: COMPONENT_2.id,
75
+ fieldId: COMPONENT_2.fieldId,
76
+ full_path: "".concat(CONTAINER.fieldId, ".").concat(COMPONENT_2.fieldId),
77
+ type: COMPONENT_2.type,
78
+ label: COMPONENT_2.label
79
+ });
80
+ });
81
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.19.2-alpha",
3
+ "version": "4.19.2",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",