@ukhomeoffice/cop-react-form-renderer 5.91.0 → 5.92.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.
@@ -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$data2;
45
- if (config.options && config !== null && config !== void 0 && (_config$data = config.data) !== null && _config$data !== void 0 && _config$data.options && config !== null && config !== void 0 && (_config$data2 = config.data) !== null && _config$data2 !== void 0 && _config$data2.url) {
46
- var combinedOptions = (0, _nestInRefdataOptions.default)(config.options, config.data.options);
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: [{
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  // eslint-disable-next-line no-control-regex
8
8
  // const EMAIL_REGEX = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/i;
9
9
  var HODS_EMAIL_REGEX = /^[a-z0-9._\-']+@(digital\.)?homeoffice.gov.uk$/i;
10
+ var JMSC_EMAIL_REGEX = /^[a-z0-9._\-']+@jmsc.gov.uk$/i;
10
11
 
11
12
  /**
12
13
  * Validates an email address, ensuring it is in the correct domain and
@@ -26,7 +27,7 @@ var validateEmail = function validateEmail(value) {
26
27
  if (!!value) {
27
28
  var name = label ? label.toLowerCase() : 'email address';
28
29
  if (typeof value === 'string') {
29
- if (HODS_EMAIL_REGEX.test(value)) {
30
+ if (HODS_EMAIL_REGEX.test(value) || JMSC_EMAIL_REGEX.test(value)) {
30
31
  return undefined;
31
32
  }
32
33
  }
@@ -14,6 +14,9 @@ describe('utils', function () {
14
14
  it('should return no error when the value is a valid .gov.uk address', function () {
15
15
  expect((0, _validateEmail.default)('alpha@homeoffice.gov.uk', LABEL)).toBeUndefined();
16
16
  });
17
+ it('should return no error when the value is a valid jmsc.gov.uk address', function () {
18
+ expect((0, _validateEmail.default)('alpha@jmsc.gov.uk', LABEL)).toBeUndefined();
19
+ });
17
20
  it('should return no error when the value is a capitalised digital.homeoffice.gov.uk address', function () {
18
21
  expect((0, _validateEmail.default)('ALPHA.BRAVO@DIGITAL.HOMEOFFICE.GOV.UK', LABEL)).toBeUndefined();
19
22
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.91.0",
3
+ "version": "5.92.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",