@ukhomeoffice/cop-react-form-renderer 5.91.0 → 5.91.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.
|
@@ -39,13 +39,44 @@ var interpolateOptions = function interpolateOptions(config, options) {
|
|
|
39
39
|
return n;
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns a list of options templated from a collection specified.
|
|
45
|
+
* config requires a item field with the templated options e.g
|
|
46
|
+
* "item": {
|
|
47
|
+
* "value": "${id}"
|
|
48
|
+
* "label": "${name}"
|
|
49
|
+
* "hint": "Select a person name"
|
|
50
|
+
* }
|
|
51
|
+
* @param {*} config
|
|
52
|
+
* @param {*} collectionName
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
var getCollectionOptions = function getCollectionOptions(config, collectionName) {
|
|
56
|
+
var collectionOptions = config.formData[collectionName].map(function (collection) {
|
|
57
|
+
return {
|
|
58
|
+
value: _copReactComponents.Utils.interpolateString(config.item.value, collection),
|
|
59
|
+
label: _copReactComponents.Utils.interpolateString(config.item.label, collection),
|
|
60
|
+
hint: _copReactComponents.Utils.interpolateString(config.item.hint, collection)
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
if (config.data.options) {
|
|
64
|
+
return [].concat(collectionOptions, config.data.options);
|
|
65
|
+
}
|
|
66
|
+
return collectionOptions;
|
|
67
|
+
};
|
|
42
68
|
var getOptions = function getOptions(config, callback) {
|
|
43
69
|
if (config) {
|
|
44
|
-
var _config$data, _config$
|
|
45
|
-
if (config
|
|
46
|
-
var
|
|
70
|
+
var _config$data, _config$data3, _config$data4;
|
|
71
|
+
if (config !== null && config !== void 0 && (_config$data = config.data) !== null && _config$data !== void 0 && _config$data.collection && config !== null && config !== void 0 && config.item) {
|
|
72
|
+
var _config$data2;
|
|
73
|
+
var combinedOptions = getCollectionOptions(config, config === null || config === void 0 || (_config$data2 = config.data) === null || _config$data2 === void 0 ? void 0 : _config$data2.collection);
|
|
47
74
|
return callback(interpolateOptions(config, combinedOptions));
|
|
48
75
|
}
|
|
76
|
+
if (config.options && config !== null && config !== void 0 && (_config$data3 = config.data) !== null && _config$data3 !== void 0 && _config$data3.options && config !== null && config !== void 0 && (_config$data4 = config.data) !== null && _config$data4 !== void 0 && _config$data4.url) {
|
|
77
|
+
var _combinedOptions = (0, _nestInRefdataOptions.default)(config.options, config.data.options);
|
|
78
|
+
return callback(interpolateOptions(config, _combinedOptions));
|
|
79
|
+
}
|
|
49
80
|
if (config.options) {
|
|
50
81
|
return callback(interpolateOptions(config, config.options));
|
|
51
82
|
}
|
|
@@ -46,6 +46,44 @@ describe('utils', function () {
|
|
|
46
46
|
expect(options).toEqual(CONFIG.data.options);
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
+
it('should get options from form data collection', function () {
|
|
50
|
+
var CONFIG = {
|
|
51
|
+
data: {
|
|
52
|
+
collection: "people"
|
|
53
|
+
},
|
|
54
|
+
item: {
|
|
55
|
+
/* eslint-disable no-template-curly-in-string */
|
|
56
|
+
label: "${name}",
|
|
57
|
+
value: "${name}",
|
|
58
|
+
hint: "${name}"
|
|
59
|
+
/* eslint-enable no-template-curly-in-string */
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
formData: {
|
|
63
|
+
people: [{
|
|
64
|
+
"name": "test"
|
|
65
|
+
}]
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
(0, _getOptions.default)(CONFIG, function (options) {
|
|
69
|
+
expect(options[0].hint).toEqual("test");
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it('should not show options if there is collection but not item data', function () {
|
|
73
|
+
var CONFIG = {
|
|
74
|
+
data: {
|
|
75
|
+
collection: "people"
|
|
76
|
+
},
|
|
77
|
+
formData: {
|
|
78
|
+
people: [{
|
|
79
|
+
"name": "test"
|
|
80
|
+
}]
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
(0, _getOptions.default)(CONFIG, function (options) {
|
|
84
|
+
expect(options).toEqual([]);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
49
87
|
it('should use the top-level options over those in the data property', function () {
|
|
50
88
|
var CONFIG = {
|
|
51
89
|
options: [{
|