@ukhomeoffice/cop-react-form-renderer 4.56.1 → 4.59.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.
@@ -92,6 +92,19 @@ var getActionRows = function getActionRows(page, item, onAction, labelCount) {
92
92
  return actions;
93
93
  };
94
94
 
95
+ var getChangeActionForPage = function getChangeActionForPage(page, item, onAction) {
96
+ return function () {
97
+ var changeCallback = function changeCallback(data) {
98
+ data["".concat(page.collection.name, "ActiveId")] = item.id;
99
+ return data;
100
+ };
101
+
102
+ onAction({
103
+ pageId: page.id
104
+ }, changeCallback);
105
+ };
106
+ };
107
+
95
108
  var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onAction) {
96
109
  var _page$formData, _page$formData$page$c;
97
110
 
@@ -135,7 +148,8 @@ var getCYARowsForCollectionPage = function getCYARowsForCollectionPage(page, onA
135
148
  }
136
149
 
137
150
  var container = getContainerForPage(p, item, labelCount, full_path);
138
- var containerRows = (0, _getCYARowsForContainer.default)(p, container, item, undefined);
151
+ var rowChangeAction = getChangeActionForPage(p, item, onAction);
152
+ var containerRows = (0, _getCYARowsForContainer.default)(p, container, item, rowChangeAction);
139
153
  rows = rows.concat(containerRows);
140
154
  }
141
155
  });
@@ -21,11 +21,13 @@ var _mustBeLongerThan = _interopRequireDefault(require("./mustBeLongerThan"));
21
21
 
22
22
  var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
23
23
 
24
- var _mustEnterAtLeastOne = _interopRequireDefault(require("./mustEnterAtLeastOne"));
24
+ var _mustBeGreaterThan = _interopRequireDefault(require("./mustBeGreaterThan"));
25
+
26
+ var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
25
27
 
26
28
  var _mustBeNumbersOnly = _interopRequireDefault(require("./mustBeNumbersOnly"));
27
29
 
28
- var _mustBeLessThan = _interopRequireDefault(require("./mustBeLessThan"));
30
+ var _mustEnterAtLeastOne = _interopRequireDefault(require("./mustEnterAtLeastOne"));
29
31
 
30
32
  var _mustHaveLessThanDecimalPlaces = _interopRequireDefault(require("./mustHaveLessThanDecimalPlaces"));
31
33
 
@@ -46,6 +48,7 @@ var functions = {
46
48
  mustEnterAtLeastOne: _mustEnterAtLeastOne.default,
47
49
  mustBeNumbersOnly: _mustBeNumbersOnly.default,
48
50
  mustBeLessThan: _mustBeLessThan.default,
51
+ mustBeGreaterThan: _mustBeGreaterThan.default,
49
52
  mustHaveLessThanDecimalPlaces: _mustHaveLessThanDecimalPlaces.default,
50
53
  mustSelectOnlyOne: _mustSelectOnlyOne.default
51
54
  };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * @param {*} value - the value to check.
10
+ * @param {number} config.value - the value must be greater than config.value.
11
+ * @returns true if value is greater than config.value, false if not.
12
+ */
13
+ var mustBeGreaterThan = function mustBeGreaterThan(value, config) {
14
+ if (!value) {
15
+ // null, undefined and empty strings should be picked up by the required flag
16
+ // and not considered here as they would be valid for optional fields.
17
+ return true;
18
+ }
19
+
20
+ var finalValue = typeof value === 'string' ? value.replace(/,/g, '') : value;
21
+ return parseFloat(finalValue) > config.value;
22
+ };
23
+
24
+ var _default = mustBeGreaterThan;
25
+ exports.default = _default;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ var _mustBeGreaterThan = _interopRequireDefault(require("./mustBeGreaterThan"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ describe('utils', function () {
8
+ describe('Validate', function () {
9
+ describe('additional', function () {
10
+ describe('mustBeGreaterThan', function () {
11
+ test('should return true given a number greater than 10', function () {
12
+ var result = (0, _mustBeGreaterThan.default)('11', {
13
+ value: 10
14
+ });
15
+ expect(result).toEqual(true);
16
+ });
17
+ test('should return false if provided value less than or equal to 10', function () {
18
+ var result1 = (0, _mustBeGreaterThan.default)('9', {
19
+ value: 10
20
+ });
21
+ expect(result1).toBeFalsy();
22
+ var result2 = (0, _mustBeGreaterThan.default)('10', {
23
+ value: 10
24
+ });
25
+ expect(result2).toBeFalsy();
26
+ });
27
+ test('should correctly handle numbers with commas in', function () {
28
+ var result1 = (0, _mustBeGreaterThan.default)('999,999,999.99', {
29
+ value: 1000000000
30
+ });
31
+ expect(result1).toEqual(false);
32
+ var result2 = (0, _mustBeGreaterThan.default)('1,000,000,123', {
33
+ value: 1000000000
34
+ });
35
+ expect(result2).toEqual(true);
36
+ });
37
+ test('should return true when string is undefined', function () {
38
+ var result = (0, _mustBeGreaterThan.default)(undefined, {
39
+ value: 10
40
+ });
41
+ expect(result).toEqual(true);
42
+ });
43
+ test('should return true when string is empty', function () {
44
+ var result = (0, _mustBeGreaterThan.default)('', {
45
+ value: 10
46
+ });
47
+ expect(result).toEqual(true);
48
+ });
49
+ test('should return true when string is null', function () {
50
+ var result = (0, _mustBeGreaterThan.default)(null, {
51
+ value: 10
52
+ });
53
+ expect(result).toEqual(true);
54
+ });
55
+ });
56
+ });
57
+ });
58
+ });
@@ -6,18 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  /**
9
- * @param {string} string - the string to check value.
10
- * @param {number} config.value - the string.value must be equal or less than config.value.
11
- * @returns true if sting value is equal to or less then config.value, false if not.
9
+ * @param {*} value - the value to check.
10
+ * @param {number} config.value - the value must be equal or less than config.value.
11
+ * @returns true if value is equal to or less then config.value, false if not.
12
12
  */
13
- var mustBeLessThan = function mustBeLessThan(string, config) {
14
- if (!string) {
13
+ var mustBeLessThan = function mustBeLessThan(value, config) {
14
+ if (!value) {
15
15
  // null, undefined and empty strings should be picked up by the required flag
16
16
  // and not considered here as they would be valid for optional fields.
17
17
  return true;
18
18
  }
19
19
 
20
- return parseFloat(string) < config.value;
20
+ var finalValue = typeof value === 'string' ? value.replace(/,/g, '') : value;
21
+ return parseFloat(finalValue) < config.value;
21
22
  };
22
23
 
23
24
  var _default = mustBeLessThan;
@@ -7,7 +7,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
7
7
  describe('utils', function () {
8
8
  describe('Validate', function () {
9
9
  describe('additional', function () {
10
- describe('mustBeShorterThan', function () {
10
+ describe('mustBeLessThan', function () {
11
11
  test('should return true given a number equal to or less than 1000000000', function () {
12
12
  var result = (0, _mustBeLessThan.default)(999999999.999, {
13
13
  value: 1000000000
@@ -20,6 +20,16 @@ describe('utils', function () {
20
20
  });
21
21
  expect(result).toBeFalsy();
22
22
  });
23
+ test('should correctly handle numbers with commas in', function () {
24
+ var result1 = (0, _mustBeLessThan.default)('999,999,999.99', {
25
+ value: 1000000000
26
+ });
27
+ expect(result1).toEqual(true);
28
+ var result2 = (0, _mustBeLessThan.default)('1,000,000,123', {
29
+ value: 1000000000
30
+ });
31
+ expect(result2).toEqual(false);
32
+ });
23
33
  test('should return true when string is undefined', function () {
24
34
  var result = (0, _mustBeLessThan.default)(undefined, {
25
35
  value: 3
@@ -6,18 +6,21 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
 
8
8
  /**
9
- * @returns true if number pass the regex, false if not.
9
+ * Checks if a string contains only numberical characters.
10
+ * An optional flag in config can be used to allow commas.
11
+ * @param {*} value The value to check for only numerical characters.
12
+ * @param {object} config The config of the validation check.
13
+ * @returns true if value passes the regex, false if not.
10
14
  */
11
- var mustBeNumbersOnly = function mustBeNumbersOnly(number) {
12
- var numbersOnlyRegex = /^[0-9]*\.?[0-9]*$/;
13
-
14
- if (!number) {
15
+ var mustBeNumbersOnly = function mustBeNumbersOnly(value, config) {
16
+ if (!value) {
15
17
  // null, undefined and empty numbers should be picked up by the required flag
16
18
  // and not considered here as they would be valid for optional fields.
17
19
  return true;
18
20
  }
19
21
 
20
- return numbersOnlyRegex.test(number);
22
+ var regex = config !== null && config !== void 0 && config.allowCommas ? /^[0-9,]*\.?[0-9]*$/ : /^[0-9]*\.?[0-9]*$/;
23
+ return regex.test(value);
21
24
  };
22
25
 
23
26
  var _default = mustBeNumbersOnly;
@@ -16,10 +16,18 @@ describe('utils', function () {
16
16
  var result = (0, _mustBeNumbersOnly.default)('123456.123');
17
17
  expect(result).toEqual(true);
18
18
  });
19
- test('should return false if given number contains letters', function () {
20
- var result = (0, _mustBeNumbersOnly.default)('123124Hello');
19
+ test('should return false if given number contains commas and config does not allow them', function () {
20
+ var CONFIG = {};
21
+ var result = (0, _mustBeNumbersOnly.default)('1,234', CONFIG);
21
22
  expect(result).toEqual(false);
22
23
  });
24
+ test('should return true if given number contains commas and config allows them', function () {
25
+ var CONFIG = {
26
+ allowCommas: true
27
+ };
28
+ var result = (0, _mustBeNumbersOnly.default)('1,234', CONFIG);
29
+ expect(result).toEqual(true);
30
+ });
23
31
  test('should return true when string is undefined', function () {
24
32
  var result = (0, _mustBeNumbersOnly.default)(undefined);
25
33
  expect(result).toEqual(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.56.1",
3
+ "version": "4.59.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",