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

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.
@@ -13,6 +13,8 @@ var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
13
13
 
14
14
  var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
15
15
 
16
+ var _setupContainerComponentsPath = _interopRequireDefault(require("../Component/setupContainerComponentsPath"));
17
+
16
18
  var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
17
19
 
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -77,6 +79,7 @@ var getCYARowsForCollection = function getCYARowsForCollection(page, collection,
77
79
  var labelCount = (collection.countOffset || 0) + index + 1;
78
80
  var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
79
81
  var container = getContainerForItem(collection, item, labelCount, full_path);
82
+ container = (0, _setupContainerComponentsPath.default)(container);
80
83
  return [getTitleRowForItem(collection, item, page.id, labelCount, full_path)].concat((0, _getCYARowsForContainer.default)(page, container, item, onAction));
81
84
  }).filter(function (r) {
82
85
  return !!r;
@@ -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;
@@ -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.1",
3
+ "version": "4.19.2-beta",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",