@ukhomeoffice/cop-react-form-renderer 4.19.4 → 4.20.0
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.
|
@@ -9,6 +9,8 @@ var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
|
9
9
|
|
|
10
10
|
var _getSourceData = _interopRequireDefault(require("./getSourceData"));
|
|
11
11
|
|
|
12
|
+
var _setDataItem = _interopRequireDefault(require("./setDataItem"));
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
|
|
14
16
|
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; }
|
|
@@ -17,28 +19,35 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
17
19
|
|
|
18
20
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
21
|
|
|
20
|
-
var setDefaultDateValue = function setDefaultDateValue(date, data) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} else {
|
|
24
|
-
data[date.fieldId] = date.defaultValue;
|
|
25
|
-
}
|
|
22
|
+
var setDefaultDateValue = function setDefaultDateValue(date, data, fullPath) {
|
|
23
|
+
var val = date.defaultValue === 'today' ? (0, _dayjs.default)().format('DD-MM-YYYY') : date.defaultValue;
|
|
24
|
+
(0, _setDataItem.default)(data, "".concat(fullPath).concat(date.fieldId), val);
|
|
26
25
|
};
|
|
27
26
|
/**
|
|
28
|
-
* This currently will not work for collections
|
|
27
|
+
* This currently will not work for collections.
|
|
29
28
|
* If support is required it will need to be added.
|
|
30
29
|
*/
|
|
31
30
|
|
|
32
31
|
|
|
33
|
-
var setupDefaultValue = function setupDefaultValue(component, data) {
|
|
34
|
-
|
|
32
|
+
var setupDefaultValue = function setupDefaultValue(component, data, fullPath) {
|
|
33
|
+
var componentFullPath = "".concat(fullPath).concat(component.fieldId);
|
|
34
|
+
|
|
35
|
+
if (component.type === 'container') {
|
|
36
|
+
var _component$components;
|
|
37
|
+
|
|
38
|
+
(_component$components = component.components) === null || _component$components === void 0 ? void 0 : _component$components.forEach(function (comp) {
|
|
39
|
+
setupDefaultValue(comp, data, "".concat(componentFullPath, "."));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (component.defaultValue && !(0, _getSourceData.default)(data, componentFullPath)) {
|
|
35
44
|
switch (component.type) {
|
|
36
45
|
case 'date':
|
|
37
|
-
setDefaultDateValue(component, data);
|
|
46
|
+
setDefaultDateValue(component, data, fullPath);
|
|
38
47
|
break;
|
|
39
48
|
|
|
40
49
|
default:
|
|
41
|
-
data
|
|
50
|
+
(0, _setDataItem.default)(data, componentFullPath, component.defaultValue);
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
|
|
@@ -53,7 +62,7 @@ var setupDefaultValue = function setupDefaultValue(component, data) {
|
|
|
53
62
|
|
|
54
63
|
var setupDefaultValuesForComponents = function setupDefaultValuesForComponents(components, data) {
|
|
55
64
|
components.forEach(function (component) {
|
|
56
|
-
return setupDefaultValue(component, data);
|
|
65
|
+
return setupDefaultValue(component, data, '');
|
|
57
66
|
});
|
|
58
67
|
};
|
|
59
68
|
|
|
@@ -62,7 +71,7 @@ var setupPageDefaultValues = function setupPageDefaultValues(pages, data) {
|
|
|
62
71
|
page.components.filter(function (c) {
|
|
63
72
|
return !c.use;
|
|
64
73
|
}).forEach(function (component) {
|
|
65
|
-
return setupDefaultValue(component, data);
|
|
74
|
+
return setupDefaultValue(component, data, '');
|
|
66
75
|
});
|
|
67
76
|
});
|
|
68
77
|
};
|
|
@@ -271,6 +271,74 @@ describe('utils', function () {
|
|
|
271
271
|
pageField: 'EXISTING_VALUE'
|
|
272
272
|
});
|
|
273
273
|
});
|
|
274
|
+
it('should handle default values of components within containers', function () {
|
|
275
|
+
var PAGES = [{
|
|
276
|
+
components: [{
|
|
277
|
+
fieldId: 'firstContainer',
|
|
278
|
+
type: 'container',
|
|
279
|
+
components: [{
|
|
280
|
+
fieldId: 'firstDate',
|
|
281
|
+
type: 'date',
|
|
282
|
+
defaultValue: '01-01-1999'
|
|
283
|
+
}, {
|
|
284
|
+
fieldId: 'secondContainer',
|
|
285
|
+
type: 'container',
|
|
286
|
+
components: [{
|
|
287
|
+
fieldId: 'secondDate',
|
|
288
|
+
type: 'date',
|
|
289
|
+
defaultValue: '01-01-2000'
|
|
290
|
+
}]
|
|
291
|
+
}]
|
|
292
|
+
}]
|
|
293
|
+
}];
|
|
294
|
+
var RESULT = (0, _setupFormData.default)(PAGES, [], {});
|
|
295
|
+
expect(RESULT).toEqual({
|
|
296
|
+
firstContainer: {
|
|
297
|
+
firstDate: '01-01-1999',
|
|
298
|
+
secondContainer: {
|
|
299
|
+
secondDate: '01-01-2000'
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
it('should ignore default values of components within containers when they already have a value in data', function () {
|
|
305
|
+
var PAGES = [{
|
|
306
|
+
components: [{
|
|
307
|
+
fieldId: 'firstContainer',
|
|
308
|
+
type: 'container',
|
|
309
|
+
components: [{
|
|
310
|
+
fieldId: 'firstDate',
|
|
311
|
+
type: 'date',
|
|
312
|
+
defaultValue: '01-01-1999'
|
|
313
|
+
}, {
|
|
314
|
+
fieldId: 'secondContainer',
|
|
315
|
+
type: 'container',
|
|
316
|
+
components: [{
|
|
317
|
+
fieldId: 'secondDate',
|
|
318
|
+
type: 'date',
|
|
319
|
+
defaultValue: '01-01-2000'
|
|
320
|
+
}]
|
|
321
|
+
}]
|
|
322
|
+
}]
|
|
323
|
+
}];
|
|
324
|
+
var DATA = {
|
|
325
|
+
firstContainer: {
|
|
326
|
+
firstDate: '01-01-1000',
|
|
327
|
+
secondContainer: {
|
|
328
|
+
secondDate: '01-01-1000'
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var RESULT = (0, _setupFormData.default)(PAGES, [], DATA);
|
|
333
|
+
expect(RESULT).toEqual({
|
|
334
|
+
firstContainer: {
|
|
335
|
+
firstDate: '01-01-1000',
|
|
336
|
+
secondContainer: {
|
|
337
|
+
secondDate: '01-01-1000'
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
});
|
|
274
342
|
});
|
|
275
343
|
});
|
|
276
344
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.20.0",
|
|
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.3.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "2.3.3",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|