@ukhomeoffice/cop-react-form-renderer 4.19.0 → 4.19.2-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.
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +32 -1
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +62 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +3 -1
- package/dist/utils/FormPage/useComponent.js +24 -11
- package/dist/utils/FormPage/useComponent.test.js +6 -5
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -13,7 +15,11 @@ var _getCYAAction = _interopRequireDefault(require("./getCYAAction"));
|
|
|
13
15
|
|
|
14
16
|
var _getCYARowsForContainer = _interopRequireDefault(require("./getCYARowsForContainer"));
|
|
15
17
|
|
|
16
|
-
var _showComponentCYA =
|
|
18
|
+
var _showComponentCYA = _interopRequireWildcard(require("./showComponentCYA"));
|
|
19
|
+
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
+
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
23
|
|
|
18
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
25
|
|
|
@@ -34,6 +40,30 @@ var getEntryToCollectionRow = function getEntryToCollectionRow(page, onAction) {
|
|
|
34
40
|
}];
|
|
35
41
|
};
|
|
36
42
|
|
|
43
|
+
var setupContainerComponentsPath = function setupContainerComponentsPath(container) {
|
|
44
|
+
return _objectSpread(_objectSpread({}, container), {}, {
|
|
45
|
+
components: container.components.map(function (component) {
|
|
46
|
+
if (Array.isArray(component.components)) {
|
|
47
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
48
|
+
components: component.components.map(function (c) {
|
|
49
|
+
if (!_showComponentCYA.EXCLUDE_FROM_CYA.includes(c.type)) {
|
|
50
|
+
return _objectSpread(_objectSpread({}, c), !c.full_path && {
|
|
51
|
+
full_path: "".concat(component.full_path || "".concat(container.full_path, ".").concat(component.fieldId), ".").concat(c.fieldId)
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
}).filter(function (c) {
|
|
57
|
+
return !!c;
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return component;
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
37
67
|
var getContainerForItem = function getContainerForItem(collection, item, labelCount, full_path) {
|
|
38
68
|
return {
|
|
39
69
|
id: item.id,
|
|
@@ -77,6 +107,7 @@ var getCYARowsForCollection = function getCYARowsForCollection(page, collection,
|
|
|
77
107
|
var labelCount = (collection.countOffset || 0) + index + 1;
|
|
78
108
|
var full_path = "".concat(collection.full_path || collection.fieldId, "[").concat(index, "]");
|
|
79
109
|
var container = getContainerForItem(collection, item, labelCount, full_path);
|
|
110
|
+
container = setupContainerComponentsPath(container, full_path);
|
|
80
111
|
return [getTitleRowForItem(collection, item, page.id, labelCount, full_path)].concat((0, _getCYARowsForContainer.default)(page, container, item, onAction));
|
|
81
112
|
}).filter(function (r) {
|
|
82
113
|
return !!r;
|
|
@@ -196,4 +196,66 @@ describe('utils.CheckYourAnswers.getCYARowsForCollection', function () {
|
|
|
196
196
|
value: 'Bravo'
|
|
197
197
|
});
|
|
198
198
|
});
|
|
199
|
+
it('should setup the full_path attribute for components within a container in a collection', function () {
|
|
200
|
+
var FORM_DATA = {
|
|
201
|
+
collection: [{
|
|
202
|
+
'test-container': {
|
|
203
|
+
checkboxes1: 'Bravo',
|
|
204
|
+
checkboxes2: 'Charlie'
|
|
205
|
+
}
|
|
206
|
+
}]
|
|
207
|
+
};
|
|
208
|
+
var PAGE = {
|
|
209
|
+
id: 'page',
|
|
210
|
+
formData: FORM_DATA,
|
|
211
|
+
cya_link: {}
|
|
212
|
+
};
|
|
213
|
+
var COMPONENT_1 = {
|
|
214
|
+
id: 'checkboxes1',
|
|
215
|
+
fieldId: 'checkboxes1',
|
|
216
|
+
type: 'checkboxes',
|
|
217
|
+
label: 'Alpha'
|
|
218
|
+
};
|
|
219
|
+
var COMPONENT_2 = {
|
|
220
|
+
id: 'checkboxes2',
|
|
221
|
+
fieldId: 'checkboxes2',
|
|
222
|
+
type: 'checkboxes',
|
|
223
|
+
label: 'Bravo'
|
|
224
|
+
};
|
|
225
|
+
var CONTAINER = {
|
|
226
|
+
id: 'test-container',
|
|
227
|
+
fieldId: 'test-container',
|
|
228
|
+
type: 'container',
|
|
229
|
+
full_path: 'test-container',
|
|
230
|
+
components: [COMPONENT_1, COMPONENT_2]
|
|
231
|
+
};
|
|
232
|
+
var COLLECTION = {
|
|
233
|
+
id: 'collection',
|
|
234
|
+
fieldId: 'collection',
|
|
235
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
236
|
+
countOffset: 0,
|
|
237
|
+
item: [CONTAINER],
|
|
238
|
+
value: FORM_DATA.collection,
|
|
239
|
+
formData: FORM_DATA
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
var ON_ACTION = function ON_ACTION() {};
|
|
243
|
+
|
|
244
|
+
var ROWS = (0, _getCYARowsForCollection.default)(PAGE, COLLECTION, FORM_DATA.collection, ON_ACTION);
|
|
245
|
+
expect(ROWS.length).toEqual(3);
|
|
246
|
+
(0, _setupTests.expectObjectLike)(ROWS[1], {
|
|
247
|
+
pageId: PAGE.id,
|
|
248
|
+
fieldId: COMPONENT_1.fieldId,
|
|
249
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(CONTAINER.fieldId, ".").concat(COMPONENT_1.fieldId),
|
|
250
|
+
key: COMPONENT_1.label,
|
|
251
|
+
value: 'Bravo'
|
|
252
|
+
});
|
|
253
|
+
(0, _setupTests.expectObjectLike)(ROWS[2], {
|
|
254
|
+
pageId: PAGE.id,
|
|
255
|
+
fieldId: COMPONENT_2.fieldId,
|
|
256
|
+
full_path: "".concat(COLLECTION.fieldId, "[0].").concat(CONTAINER.fieldId, ".").concat(COMPONENT_2.fieldId),
|
|
257
|
+
key: COMPONENT_2.label,
|
|
258
|
+
value: 'Charlie'
|
|
259
|
+
});
|
|
260
|
+
});
|
|
199
261
|
});
|
|
@@ -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;
|
|
@@ -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(
|
|
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
|
-
|
|
38
|
+
component = parent.components[0];
|
|
37
39
|
} else {
|
|
38
40
|
// If no child was found, there can be no parent.
|
|
39
|
-
|
|
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
|
-
|
|
46
|
+
component = undefined;
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
while (
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
});
|