@ukhomeoffice/cop-react-form-renderer 5.78.2 → 5.80.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.
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _models = require("../../../models");
|
|
8
|
-
var SHOULD_HAVE_FIELDSET = [_models.ComponentTypes.RADIOS, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE];
|
|
8
|
+
var SHOULD_HAVE_FIELDSET = [_models.ComponentTypes.RADIOS, _models.ComponentTypes.CHECKBOXES, _models.ComponentTypes.DATE, _models.ComponentTypes.TIME];
|
|
9
9
|
var _default = exports.default = function _default(component) {
|
|
10
10
|
return component.fieldset || SHOULD_HAVE_FIELDSET.includes(component.type);
|
|
11
11
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
8
|
+
var _getCollectionPageActiveIndex = _interopRequireDefault(require("../CollectionPage/getCollectionPageActiveIndex"));
|
|
9
|
+
var _getSourceData = _interopRequireDefault(require("../Data/getSourceData"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
// Global imports.
|
|
12
|
+
|
|
13
|
+
// Local imports.
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Finds a field within data and returns its length
|
|
17
|
+
* @param {object} config The config of the operation.
|
|
18
|
+
* @param {string} config.target The path to the target field. If the path
|
|
19
|
+
* goes through a collection this can be specified as 'collectionName[]'
|
|
20
|
+
* and this function will use the active entry within that collection.
|
|
21
|
+
* @param {object} data A page's formData.
|
|
22
|
+
* @returns The length of a field if found or 0
|
|
23
|
+
*/
|
|
24
|
+
var getLength = function getLength(config, data) {
|
|
25
|
+
if (!config || !data) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Replace any instances of 'collectionName[]' with 'collectionName[activeIndex]'
|
|
30
|
+
var pathParts = config.target.split('.');
|
|
31
|
+
var updatedPath = '';
|
|
32
|
+
pathParts.forEach(function (part) {
|
|
33
|
+
if (updatedPath !== '') {
|
|
34
|
+
updatedPath += '.';
|
|
35
|
+
}
|
|
36
|
+
if (part.slice(-2) === '[]') {
|
|
37
|
+
var collectionName = part.slice(0, -2);
|
|
38
|
+
var activeIndex = (0, _getCollectionPageActiveIndex.default)(collectionName, data);
|
|
39
|
+
updatedPath += "".concat(collectionName, "[").concat(activeIndex, "]");
|
|
40
|
+
} else {
|
|
41
|
+
updatedPath += part;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Get the field and return its length
|
|
46
|
+
var targetPath = _copReactComponents.Utils.interpolateString(updatedPath, data);
|
|
47
|
+
var target = (0, _getSourceData.default)(data, targetPath);
|
|
48
|
+
return (target === null || target === void 0 ? void 0 : target.length) || 0;
|
|
49
|
+
};
|
|
50
|
+
var _default = exports.default = getLength;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getLength = _interopRequireDefault(require("./getLength"));
|
|
4
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5
|
+
describe('Utils.Operate.getLength', function () {
|
|
6
|
+
it('returns null if config is not defined', function () {
|
|
7
|
+
expect((0, _getLength.default)(null, {})).toEqual(null);
|
|
8
|
+
});
|
|
9
|
+
it('returns null if data is not defined', function () {
|
|
10
|
+
expect((0, _getLength.default)({}, null)).toEqual(null);
|
|
11
|
+
});
|
|
12
|
+
it('returns the length of a top level string', function () {
|
|
13
|
+
var CONFIG = {
|
|
14
|
+
target: 'alpha'
|
|
15
|
+
};
|
|
16
|
+
var DATA = {
|
|
17
|
+
alpha: 'abcdef'
|
|
18
|
+
};
|
|
19
|
+
expect((0, _getLength.default)(CONFIG, DATA)).toEqual(6);
|
|
20
|
+
});
|
|
21
|
+
it('returns the length of a top level array', function () {
|
|
22
|
+
var CONFIG = {
|
|
23
|
+
target: 'alpha'
|
|
24
|
+
};
|
|
25
|
+
var DATA = {
|
|
26
|
+
alpha: [{
|
|
27
|
+
test: 'test'
|
|
28
|
+
}, {
|
|
29
|
+
test: 'test'
|
|
30
|
+
}, {
|
|
31
|
+
test: 'test'
|
|
32
|
+
}, {
|
|
33
|
+
test: 'test'
|
|
34
|
+
}]
|
|
35
|
+
};
|
|
36
|
+
expect((0, _getLength.default)(CONFIG, DATA)).toEqual(4);
|
|
37
|
+
});
|
|
38
|
+
it('returns 0 if the field cannot be found', function () {
|
|
39
|
+
var CONFIG = {
|
|
40
|
+
target: 'alpha'
|
|
41
|
+
};
|
|
42
|
+
var DATA = {
|
|
43
|
+
beta: [{
|
|
44
|
+
test: 'test'
|
|
45
|
+
}, {
|
|
46
|
+
test: 'test'
|
|
47
|
+
}, {
|
|
48
|
+
test: 'test'
|
|
49
|
+
}, {
|
|
50
|
+
test: 'test'
|
|
51
|
+
}]
|
|
52
|
+
};
|
|
53
|
+
expect((0, _getLength.default)(CONFIG, DATA)).toEqual(0);
|
|
54
|
+
});
|
|
55
|
+
it('returns the length of a field not on the top level', function () {
|
|
56
|
+
var CONFIG = {
|
|
57
|
+
target: 'alpha.beta'
|
|
58
|
+
};
|
|
59
|
+
var DATA = {
|
|
60
|
+
alphaActiveId: 3,
|
|
61
|
+
alpha: {
|
|
62
|
+
beta: 'qwerty'
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
expect((0, _getLength.default)(CONFIG, DATA)).toEqual(6);
|
|
66
|
+
});
|
|
67
|
+
it('returns the length of an array nested under an array', function () {
|
|
68
|
+
var CONFIG = {
|
|
69
|
+
target: 'alpha[].beta'
|
|
70
|
+
};
|
|
71
|
+
var DATA = {
|
|
72
|
+
alphaActiveId: 3,
|
|
73
|
+
alpha: [{
|
|
74
|
+
id: 1,
|
|
75
|
+
beta: ['test']
|
|
76
|
+
}, {
|
|
77
|
+
id: 2,
|
|
78
|
+
beta: ['test', 'test']
|
|
79
|
+
}, {
|
|
80
|
+
id: 3,
|
|
81
|
+
beta: ['test', 'test', 'test']
|
|
82
|
+
}, {
|
|
83
|
+
id: 4,
|
|
84
|
+
beta: ['test', 'test', 'test', 'test']
|
|
85
|
+
}]
|
|
86
|
+
};
|
|
87
|
+
expect((0, _getLength.default)(CONFIG, DATA)).toEqual(3);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -12,6 +12,7 @@ var _setValueInFormData = _interopRequireDefault(require("./setValueInFormData")
|
|
|
12
12
|
var _shouldRun = _interopRequireDefault(require("./shouldRun"));
|
|
13
13
|
var _setDataItem = _interopRequireDefault(require("../Data/setDataItem"));
|
|
14
14
|
var _getFirstOf = _interopRequireDefault(require("./getFirstOf"));
|
|
15
|
+
var _getLength = _interopRequireDefault(require("./getLength"));
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
// Global imports.
|
|
17
18
|
|
|
@@ -22,6 +23,7 @@ var functions = {
|
|
|
22
23
|
getIndexOfMatchingValueIn: _getIndexOfMatchingValueIn.default,
|
|
23
24
|
persistValueInFormData: _persistValueInFormData.default,
|
|
24
25
|
setValueInFormData: _setValueInFormData.default,
|
|
26
|
+
getLength: _getLength.default,
|
|
25
27
|
getFirstOf: _getFirstOf.default
|
|
26
28
|
};
|
|
27
29
|
var doOperation = function doOperation(config, data, onChange) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.80.1",
|
|
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": "3.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "3.22.0",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|