@ukhomeoffice/cop-react-form-renderer 4.16.0 → 4.16.1-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.
@@ -65,11 +65,17 @@ var Container = function Container(_ref) {
65
65
  };
66
66
 
67
67
  var shouldShow = function shouldShow(options) {
68
+ var full_path = "".concat(container.full_path || container.fieldId, ".").concat(options.fieldId);
69
+
68
70
  if (options.type === _models.ComponentTypes.CONTAINER) {
69
- return _utils.default.Container.show(options, formData);
71
+ return _utils.default.Container.show(_objectSpread(_objectSpread({}, options), {}, {
72
+ full_path: full_path
73
+ }), formData);
70
74
  }
71
75
 
72
- return _utils.default.Component.show(options, formData);
76
+ return _utils.default.Component.show(_objectSpread(_objectSpread({}, options), {}, {
77
+ full_path: full_path
78
+ }), formData);
73
79
  };
74
80
 
75
81
  var classes = _utils.default.classBuilder(DEFAULT_CLASS, [], container.className);
@@ -80,10 +86,12 @@ var Container = function Container(_ref) {
80
86
  }), container.components && container.components.filter(shouldShow).map(function (component, index) {
81
87
  var defaultValue = component.type === _models.ComponentTypes.FILE ? {} : '';
82
88
  var val = value ? value[component.fieldId] : defaultValue;
89
+ var full_path = "".concat(container.full_path || container.fieldId, ".").concat(component.fieldId);
83
90
  return /*#__PURE__*/_react.default.createElement(_FormComponent.default, _extends({
84
91
  key: index
85
92
  }, attrs, {
86
93
  component: _objectSpread(_objectSpread({}, component), {}, {
94
+ full_path: full_path,
87
95
  readonly: container.readonly ? true : component.readonly
88
96
  }),
89
97
  formData: formData,
@@ -80,7 +80,7 @@ describe('components.FormComponent.Container', function () {
80
80
  expect(label.tagName).toEqual('LABEL');
81
81
  expect(label.classList).toContain('govuk-label');
82
82
  expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
83
- expect(label.getAttribute('for')).toEqual(TEXT_ID);
83
+ expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
84
84
  hint = formGroup.childNodes[1];
85
85
  expect(hint.tagName).toEqual('SPAN');
86
86
  expect(hint.classList).toContain('govuk-hint');
@@ -88,7 +88,7 @@ describe('components.FormComponent.Container', function () {
88
88
  input = formGroup.childNodes[2];
89
89
  expect(input.tagName).toEqual('INPUT');
90
90
  expect(input.classList).toContain('govuk-input');
91
- expect(input.id).toEqual(TEXT_ID);
91
+ expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
92
92
  expect(input.value).toEqual(TEXT_VALUE);
93
93
 
94
94
  case 22:
@@ -137,7 +137,7 @@ describe('components.FormComponent.Container', function () {
137
137
  expect(label.tagName).toEqual('LABEL');
138
138
  expect(label.classList).toContain('govuk-label');
139
139
  expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
140
- expect(label.getAttribute('for')).toEqual(TEXT_ID);
140
+ expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(NESTED_ID, ".").concat(TEXT_ID));
141
141
  hint = formGroup.childNodes[1];
142
142
  expect(hint.tagName).toEqual('SPAN');
143
143
  expect(hint.classList).toContain('govuk-hint');
@@ -145,7 +145,7 @@ describe('components.FormComponent.Container', function () {
145
145
  input = formGroup.childNodes[2];
146
146
  expect(input.tagName).toEqual('INPUT');
147
147
  expect(input.classList).toContain('govuk-input');
148
- expect(input.id).toEqual(TEXT_ID);
148
+ expect(input.id).toEqual("".concat(ID, ".").concat(NESTED_ID, ".").concat(TEXT_ID));
149
149
  expect(input.value).toEqual(NESTED_TEXT_VALUE);
150
150
 
151
151
  case 25:
@@ -318,7 +318,7 @@ describe('components.FormComponent.Container', function () {
318
318
  expect(label.tagName).toEqual('LABEL');
319
319
  expect(label.classList).toContain('govuk-label');
320
320
  expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
321
- expect(label.getAttribute('for')).toEqual(TEXT_ID);
321
+ expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
322
322
  hint = formGroup.childNodes[1];
323
323
  expect(hint.tagName).toEqual('SPAN');
324
324
  expect(hint.classList).toContain('govuk-hint');
@@ -326,7 +326,7 @@ describe('components.FormComponent.Container', function () {
326
326
  input = formGroup.childNodes[2];
327
327
  expect(input.tagName).toEqual('INPUT');
328
328
  expect(input.classList).toContain('govuk-input');
329
- expect(input.id).toEqual(TEXT_ID);
329
+ expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
330
330
  expect(input.value).toEqual('');
331
331
 
332
332
  case 22:
@@ -400,7 +400,7 @@ describe('components.FormComponent.Container', function () {
400
400
  expect(label.tagName).toEqual('LABEL');
401
401
  expect(label.classList).toContain('govuk-label');
402
402
  expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
403
- expect(label.getAttribute('for')).toEqual(TEXT_ID);
403
+ expect(label.getAttribute('for')).toEqual("".concat(ID, ".").concat(TEXT_ID));
404
404
  hint = formGroup.childNodes[1];
405
405
  expect(hint.tagName).toEqual('SPAN');
406
406
  expect(hint.classList).toContain('govuk-hint');
@@ -410,7 +410,7 @@ describe('components.FormComponent.Container', function () {
410
410
 
411
411
  expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
412
412
 
413
- expect(input.id).toEqual(TEXT_ID);
413
+ expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
414
414
  expect(input.textContent).toEqual(TEXT_VALUE);
415
415
 
416
416
  case 22:
@@ -0,0 +1,79 @@
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;
@@ -0,0 +1,34 @@
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
+ });
@@ -0,0 +1,16 @@
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;
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _elevateErrors = _interopRequireDefault(require("./errors/elevateErrors"));
9
+
8
10
  var _validateComponent = _interopRequireDefault(require("./validateComponent"));
9
11
 
10
12
  var _additional = _interopRequireDefault(require("./additional"));
@@ -44,9 +46,9 @@ var validateContainer = function validateContainer(container, outerData, formDat
44
46
  });
45
47
  }
46
48
 
47
- return errors.filter(function (e) {
49
+ return (0, _elevateErrors.default)(errors.filter(function (e) {
48
50
  return !!e;
49
- });
51
+ }));
50
52
  };
51
53
 
52
54
  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.0",
3
+ "version": "4.16.1-alpha",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",