@ukhomeoffice/cop-react-form-renderer 4.22.4-beta → 4.22.4

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.
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _models = require("../../models");
9
9
 
10
+ var _elevateNestedComponents = _interopRequireDefault(require("../Component/elevateNestedComponents"));
11
+
10
12
  var _getCYARow = _interopRequireDefault(require("./getCYARow"));
11
13
 
12
14
  var _getCYARowsForCollection = _interopRequireDefault(require("./getCYARowsForCollection"));
@@ -23,7 +25,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
23
25
 
24
26
  var getCYARowsForContainer = function getCYARowsForContainer(page, container, formData, onAction) {
25
27
  if ((0, _showComponentCYA.default)(container, page.formData)) {
26
- return container.components.filter(function (c) {
28
+ var allComponents = (0, _elevateNestedComponents.default)(container.components, formData);
29
+ return allComponents.filter(function (c) {
27
30
  return (0, _showComponentCYA.default)(c, page.formData);
28
31
  }).flatMap(function (component) {
29
32
  var fd = formData ? formData[component.fieldId] : undefined;
@@ -320,4 +320,51 @@ describe('utils.CheckYourAnswers.getCYARowsForContainer', function () {
320
320
  checkTitleRow(1, ROWS[2]);
321
321
  checkValueRow(1, ROWS[3], 'Charlie');
322
322
  });
323
+ it('should get the appropriate number for rows components with nested components inside a container', function () {
324
+ var FORM_DATA = {
325
+ container: {
326
+ a: 'B',
327
+ nested: 'Bravo'
328
+ }
329
+ };
330
+ var PAGE = {
331
+ id: 'page',
332
+ formData: FORM_DATA,
333
+ cya_link: {}
334
+ };
335
+ var NESTED_COMPONENT = {
336
+ id: 'nested',
337
+ fieldId: 'nested',
338
+ type: _models.ComponentTypes.TEXT
339
+ };
340
+ var COMPONENT = {
341
+ type: 'radios',
342
+ id: 'a',
343
+ fieldId: 'a',
344
+ label: 'Alpha',
345
+ data: {
346
+ options: [{
347
+ value: 'B',
348
+ label: 'B',
349
+ nested: [NESTED_COMPONENT]
350
+ }, {
351
+ value: 'A',
352
+ label: 'A'
353
+ }]
354
+ }
355
+ };
356
+ var CONTAINER = {
357
+ id: 'container',
358
+ fieldId: 'container',
359
+ type: _models.ComponentTypes.CONTAINER,
360
+ components: [COMPONENT],
361
+ value: FORM_DATA.container,
362
+ formData: FORM_DATA
363
+ };
364
+
365
+ var ON_ACTION = function ON_ACTION() {};
366
+
367
+ var ROWS = (0, _getCYARowsForContainer.default)(PAGE, CONTAINER, FORM_DATA.container, ON_ACTION);
368
+ expect(ROWS.length).toEqual(2);
369
+ });
323
370
  });
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _Data = _interopRequireDefault(require("../Data"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
8
12
  /**
9
13
  * Iterates over an array of components and brings any nested
10
14
  * components that should be visible into the top level array.
@@ -40,7 +44,9 @@ var elevateNestedComponents = function elevateNestedComponents(components, data)
40
44
  (_component$data = component.data) === null || _component$data === void 0 ? void 0 : (_component$data$optio = _component$data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.forEach(function (option) {
41
45
  // If this option has nested components and is
42
46
  // selected, then add its nested components to the array.
43
- if (Array.isArray(option.nested) && data[component.id] === option.value) {
47
+ var sourceData = (data === null || data === void 0 ? void 0 : data[component.id]) || _Data.default.getSource(data, component.full_path);
48
+
49
+ if (Array.isArray(option.nested) && sourceData === option.value) {
44
50
  allComponents = allComponents.concat(option.nested);
45
51
  }
46
52
  });
@@ -89,4 +89,36 @@ describe('utils.Component.elevateNestedComponents', function () {
89
89
  id: 'nestedTwo'
90
90
  }]));
91
91
  });
92
+ it('should return the original array with elevated nested components when a component has a full_path', function () {
93
+ var COMPONENTS = [{
94
+ id: 'textComp'
95
+ }, {
96
+ id: 'radiosComp',
97
+ data: {
98
+ options: [{
99
+ label: 'Yes',
100
+ value: 'yes',
101
+ nested: [{
102
+ id: 'nestedOne'
103
+ }, {
104
+ id: 'nestedTwo'
105
+ }]
106
+ }, {
107
+ label: 'No',
108
+ value: 'no'
109
+ }]
110
+ },
111
+ full_path: 'component.radiosComp'
112
+ }];
113
+ var DATA = {
114
+ component: {
115
+ radiosComp: 'yes'
116
+ }
117
+ };
118
+ expect((0, _elevateNestedComponents.default)(COMPONENTS, DATA)).toEqual([].concat(COMPONENTS, [{
119
+ id: 'nestedOne'
120
+ }, {
121
+ id: 'nestedTwo'
122
+ }]));
123
+ });
92
124
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.22.4-beta",
3
+ "version": "4.22.4",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",