@ukhomeoffice/cop-react-form-renderer 4.16.2-alpha → 4.16.3

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.
@@ -17,6 +17,8 @@ var _getCYACollectionDeleteAction = _interopRequireDefault(require("./getCYAColl
17
17
 
18
18
  var _getCYACollectionChangeAction = _interopRequireDefault(require("./getCYACollectionChangeAction"));
19
19
 
20
+ var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
21
+
20
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
23
 
22
24
  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; }
@@ -34,12 +36,18 @@ var getContainerForPage = function getContainerForPage(page, item, labelCount, f
34
36
  required: true,
35
37
  full_path: full_path,
36
38
  components: allComponents.map(function (component) {
37
- return _objectSpread(_objectSpread({}, component), {}, {
38
- label: _copReactComponents.Utils.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
39
- index: labelCount
40
- })),
41
- full_path: "".concat(full_path, ".").concat(component.fieldId)
42
- });
39
+ if ((0, _showComponentCYA.default)(component, item)) {
40
+ return _objectSpread(_objectSpread({}, component), {}, {
41
+ label: _copReactComponents.Utils.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
42
+ index: labelCount
43
+ })),
44
+ full_path: "".concat(full_path, ".").concat(component.fieldId)
45
+ });
46
+ }
47
+
48
+ return undefined;
49
+ }).filter(function (c) {
50
+ return c;
43
51
  })
44
52
  };
45
53
  };
@@ -121,4 +121,50 @@ describe('utils.CheckYourAnswers.getCYARowsForCollectionPage', function () {
121
121
  expect(ROWS[9].value).toEqual('value');
122
122
  expect(ROWS[9].key).toEqual('Test text');
123
123
  });
124
+ it('should exclude components that should not be shown', function () {
125
+ var FD = {
126
+ collection: [{
127
+ id: '01',
128
+ otherField: 'yes',
129
+ testText: 'testing'
130
+ }, {
131
+ id: '02',
132
+ otherField: 'no',
133
+ testText: 'testing'
134
+ }]
135
+ };
136
+ var C = {
137
+ id: 'testText',
138
+ fieldId: 'testText',
139
+ label: 'Test text',
140
+ type: 'text',
141
+ show_when: {
142
+ field: "otherField",
143
+ op: "!=",
144
+ value: "no"
145
+ }
146
+ };
147
+ var P = {
148
+ id: 'page1',
149
+ collection: {
150
+ name: 'collection'
151
+ },
152
+ title: 'Collection',
153
+ components: [C]
154
+ };
155
+
156
+ var PAGE = _objectSpread(_objectSpread({}, P), {}, {
157
+ formData: FD
158
+ });
159
+
160
+ var ROWS = (0, _getCYARowsForCollectionPage.default)(PAGE, null);
161
+ expect(ROWS.length).toEqual(3); // Title row + single component as other should fail show check
162
+
163
+ expect(ROWS[0].type).toEqual('title');
164
+ expect(ROWS[0].key).toEqual('Item 1');
165
+ expect(ROWS[1].value).toEqual('testing');
166
+ expect(ROWS[1].key).toEqual('Test text');
167
+ expect(ROWS[2].type).toEqual('title');
168
+ expect(ROWS[2].key).toEqual('Item 2');
169
+ });
124
170
  });
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _elevateErrors = _interopRequireDefault(require("./errors/elevateErrors"));
9
-
10
8
  var _validateComponent = _interopRequireDefault(require("./validateComponent"));
11
9
 
12
10
  var _additional = _interopRequireDefault(require("./additional"));
@@ -53,9 +51,9 @@ var validateContainer = function validateContainer(container, outerData, formDat
53
51
  });
54
52
  }
55
53
 
56
- return (0, _elevateErrors.default)(errors.filter(function (e) {
54
+ return errors.flat(1).filter(function (e) {
57
55
  return !!e;
58
- }));
56
+ });
59
57
  };
60
58
 
61
59
  var _default = validateContainer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.16.2-alpha",
3
+ "version": "4.16.3",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -1,79 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- /**
9
- * Iterates over an array of errors and brings any nested
10
- * error that should be displayed into the top level array.
11
- *
12
- * e.g.
13
- * [
14
- * null,
15
- * null,
16
- * [
17
- * { error },
18
- * { error },
19
- * { error },
20
- * ]
21
- * ]
22
- *
23
- * This allows us to have containers components, whose components are children
24
- * containers and those children container components are also made up of
25
- * containers.
26
- *
27
- * e.g.
28
- * {
29
- * "type": "container",
30
- * "components": [
31
- * {
32
- * "type": "any-type"
33
- * },
34
- * {
35
- * "type": "container",
36
- * "components": [
37
- * {
38
- * "type": "any-type"
39
- * },
40
- * {
41
- * "type": "container",
42
- * "components": [
43
- * {
44
- * "type": "container",
45
- * "components":[]
46
- * }
47
- * ]
48
- * }
49
- * ]
50
- * }
51
- * ]
52
- * }
53
- *
54
- *
55
- * @param {*} errors A array of nested arrays containing errors.
56
- * @returns An array containing error objects or an empty array when no errors are found.
57
- */
58
- var elevateErrors = function elevateErrors(errors) {
59
- var nestedErrors = [];
60
-
61
- var getError = function getError(errors) {
62
- errors.forEach(function (error) {
63
- if (error) {
64
- if (Array.isArray(error)) {
65
- getError(error);
66
- } else {
67
- // Must be an error if not an array
68
- nestedErrors.push(error);
69
- }
70
- }
71
- });
72
- };
73
-
74
- getError(errors);
75
- return nestedErrors;
76
- };
77
-
78
- var _default = elevateErrors;
79
- exports.default = _default;
@@ -1,34 +0,0 @@
1
- "use strict";
2
-
3
- var _elevateErrors = _interopRequireDefault(require("./elevateErrors"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
- describe('utils.Validate.ElevateErrors', function () {
8
- it('should get nested errors wrapped within multiple arrays', function () {
9
- var nestedErrors = [[undefined, undefined, [[{
10
- "type": 'This Alpha error is required'
11
- }, [{
12
- "type": 'This Bravo error is required'
13
- }, [[], {
14
- "type": 'This Charlie error is required'
15
- }]]]]]];
16
- expect((0, _elevateErrors.default)(nestedErrors)).toHaveLength(3);
17
- expect((0, _elevateErrors.default)(nestedErrors)).toMatchObject([{
18
- "type": 'This Alpha error is required'
19
- }, {
20
- "type": 'This Bravo error is required'
21
- }, {
22
- "type": 'This Charlie error is required'
23
- }]);
24
- });
25
- it('should get the single error within an array', function () {
26
- var nestedErrors = [[{
27
- "type": 'This Alpha error is required'
28
- }]];
29
- expect((0, _elevateErrors.default)(nestedErrors)).toHaveLength(1);
30
- expect((0, _elevateErrors.default)(nestedErrors)).toMatchObject([{
31
- "type": 'This Alpha error is required'
32
- }]);
33
- });
34
- });
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _elevateErrors = _interopRequireDefault(require("./elevateErrors"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- var Errors = {
13
- elevate: _elevateErrors.default
14
- };
15
- var _default = Errors;
16
- exports.default = _default;