@ukhomeoffice/cop-react-form-renderer 4.19.0 → 4.19.1

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.
@@ -19,38 +19,55 @@ var getComponentToUse = function getComponentToUse(toUse, formComponents) {
19
19
  return fc.id === firstId;
20
20
  }));
21
21
 
22
+ var component = wrapper;
22
23
  var parent = wrapper;
23
24
 
24
25
  var _loop = function _loop() {
25
26
  var id = path.shift();
26
27
 
27
- if (Array.isArray(parent.components)) {
28
+ if (Array.isArray(component.components)) {
28
29
  // Filter the parent components down to just the one referenced
29
30
  // by the current id.
31
+ parent = component;
30
32
  parent.components = parent.components.filter(function (c) {
31
33
  return c.id === id;
32
34
  });
33
35
 
34
36
  if (parent.components.length > 0) {
35
37
  // Make the found child the parent so we can iterate.
36
- parent = parent.components[0];
38
+ component = parent.components[0];
37
39
  } else {
38
40
  // If no child was found, there can be no parent.
39
- parent = undefined;
41
+ component = undefined;
40
42
  }
41
43
  } else {
42
44
  // We cannot find the child with this id if there are no child
43
45
  // components on this parent.
44
- parent = undefined;
46
+ component = undefined;
45
47
  }
46
48
  };
47
49
 
48
- while (parent && path.length > 0) {
50
+ while (component && path.length > 0) {
49
51
  _loop();
52
+ }
53
+
54
+ if (component) {
55
+ component = _objectSpread(_objectSpread(_objectSpread({}, component), toUse), {}, {
56
+ cya_label: component.label || component.cya_label,
57
+ fieldId: toUse.fieldId || component.fieldId
58
+ });
59
+
60
+ if (parent && parent.id !== component.id) {
61
+ parent.components[0] = component;
62
+ } else {
63
+ wrapper = component;
64
+ }
65
+
66
+ return wrapper;
50
67
  } // If we missed a nested reference along the way, don't return the wrapper.
51
68
 
52
69
 
53
- return parent ? wrapper : undefined;
70
+ return undefined;
54
71
  };
55
72
  /**
56
73
  * Use an existing component from the formComponents, overriding any properties
@@ -66,11 +83,7 @@ var useComponent = function useComponent(toUse, formComponents) {
66
83
  var component = getComponentToUse(toUse, formComponents);
67
84
 
68
85
  if (component) {
69
- var fieldId = toUse.fieldId || component.fieldId;
70
- return _objectSpread(_objectSpread(_objectSpread({}, component), toUse), {}, {
71
- cya_label: component.label || component.cya_label,
72
- fieldId: fieldId
73
- });
86
+ return component;
74
87
  }
75
88
  }
76
89
 
@@ -142,11 +142,12 @@ describe('utils', function () {
142
142
  var TO_USE = {
143
143
  use: ID
144
144
  };
145
- expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({
146
- use: ID
147
- }, CONTAINER), {}, {
148
- cya_label: CONTAINER.label,
149
- components: [ZULU // Foxtrot is not included
145
+ expect((0, _useComponent.default)(TO_USE, FORM_COMPONENTS)).toEqual(_objectSpread(_objectSpread({}, CONTAINER), {}, {
146
+ components: [_objectSpread(_objectSpread({
147
+ use: ID
148
+ }, ZULU), {}, {
149
+ cya_label: ZULU.label
150
+ }) // Foxtrot is not included
150
151
  ]
151
152
  }));
152
153
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.19.0",
3
+ "version": "4.19.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",