@ukhomeoffice/cop-react-form-renderer 4.13.0 → 4.13.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.
|
@@ -25,12 +25,23 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
25
|
|
|
26
26
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
27
27
|
|
|
28
|
+
var setupChildrenJSX = function setupChildrenJSX(options, config) {
|
|
29
|
+
options.forEach(function (option) {
|
|
30
|
+
if (!Array.isArray(option.nested)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
option.children = getChildrenJsx(config, option.nested);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
28
37
|
/**
|
|
29
38
|
* Separate function for each component type for the sake of
|
|
30
39
|
* code clarity - having the additional bits and pieces in the
|
|
31
40
|
* switch statement increases the cyclomatic complexity and
|
|
32
41
|
* makes it much harder to follow what's going on.
|
|
33
42
|
*/
|
|
43
|
+
|
|
44
|
+
|
|
34
45
|
var getAutocomplete = function getAutocomplete(config) {
|
|
35
46
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
36
47
|
|
|
@@ -48,6 +59,7 @@ var getCheckboxes = function getCheckboxes(config) {
|
|
|
48
59
|
options = val;
|
|
49
60
|
});
|
|
50
61
|
|
|
62
|
+
setupChildrenJSX(options, config);
|
|
51
63
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
52
64
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Checkboxes, _extends({}, attrs, {
|
|
53
65
|
options: options
|
|
@@ -106,13 +118,7 @@ var getRadios = function getRadios(config) {
|
|
|
106
118
|
options = val;
|
|
107
119
|
});
|
|
108
120
|
|
|
109
|
-
options
|
|
110
|
-
if (!Array.isArray(option.nested)) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
option.children = getChildrenJsx(config, option.nested);
|
|
115
|
-
});
|
|
121
|
+
setupChildrenJSX(options, config);
|
|
116
122
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
117
123
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.Radios, _extends({}, attrs, {
|
|
118
124
|
options: options
|
|
@@ -79,6 +79,7 @@ var validateComponent = function validateComponent(component, outerData, formDat
|
|
|
79
79
|
error = message;
|
|
80
80
|
break;
|
|
81
81
|
|
|
82
|
+
case _models.ComponentTypes.CHECKBOXES:
|
|
82
83
|
case _models.ComponentTypes.RADIOS:
|
|
83
84
|
var nestedErrors = [];
|
|
84
85
|
(_component$data$optio = component.data.options) === null || _component$data$optio === void 0 ? void 0 : _component$data$optio.forEach(function (option) {
|
|
@@ -200,19 +200,19 @@ describe('utils.Validate.Component', function () {
|
|
|
200
200
|
});
|
|
201
201
|
});
|
|
202
202
|
describe('when the component has a nested component', function () {
|
|
203
|
-
it('should return no error when the radio component contains nested components without errors', function () {
|
|
203
|
+
it.each([['radios', 'text'], ['checkboxes', 'text']])('should return no error when the radio component contains nested components without errors', function (parentType, nestedType) {
|
|
204
204
|
var NESTED_ID = 'nestedId';
|
|
205
205
|
var NESTED_VALUE = 'nestedValue';
|
|
206
206
|
|
|
207
207
|
var FORMDATA = _defineProperty({}, NESTED_ID, NESTED_VALUE);
|
|
208
208
|
|
|
209
209
|
var COMPONENT = {
|
|
210
|
-
type:
|
|
210
|
+
type: parentType,
|
|
211
211
|
id: 'a',
|
|
212
212
|
data: {
|
|
213
213
|
options: [{
|
|
214
214
|
nested: [{
|
|
215
|
-
type:
|
|
215
|
+
type: nestedType,
|
|
216
216
|
fieldId: NESTED_ID,
|
|
217
217
|
id: NESTED_ID,
|
|
218
218
|
required: true
|
|
@@ -222,16 +222,16 @@ describe('utils.Validate.Component', function () {
|
|
|
222
222
|
};
|
|
223
223
|
expect((0, _validateComponent.default)(COMPONENT, undefined, FORMDATA)).toBeUndefined();
|
|
224
224
|
});
|
|
225
|
-
it('should return an error when the radio component contains nested components with errors', function () {
|
|
225
|
+
it.each([['radios', 'text'], ['checkboxes', 'text']])('should return an error when the radio component contains nested components with errors', function (parentType, nestedType) {
|
|
226
226
|
var NESTED_ID = 'nestedId';
|
|
227
227
|
var FORMDATA = {};
|
|
228
228
|
var COMPONENT = {
|
|
229
|
-
type:
|
|
229
|
+
type: parentType,
|
|
230
230
|
id: 'a',
|
|
231
231
|
data: {
|
|
232
232
|
options: [{
|
|
233
233
|
nested: [{
|
|
234
|
-
type:
|
|
234
|
+
type: nestedType,
|
|
235
235
|
fieldId: NESTED_ID,
|
|
236
236
|
id: NESTED_ID,
|
|
237
237
|
required: true
|
|
@@ -244,10 +244,10 @@ describe('utils.Validate.Component', function () {
|
|
|
244
244
|
error: "Field is required"
|
|
245
245
|
}]);
|
|
246
246
|
});
|
|
247
|
-
it('should return no error when a non selected radio component contains nested components with errors', function () {
|
|
247
|
+
it.each([['radios'], ['checkboxes']])('should return no error when a non selected radio component contains nested components with errors', function (type) {
|
|
248
248
|
var NESTED_ID = 'nestedId';
|
|
249
249
|
var COMPONENT = {
|
|
250
|
-
type:
|
|
250
|
+
type: type,
|
|
251
251
|
id: 'a',
|
|
252
252
|
data: {
|
|
253
253
|
options: [{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.1-alpha",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "2.2.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "2.2.3-alpha",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|