@ukhomeoffice/cop-react-form-renderer 3.5.2-alpha → 3.6.2

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.
@@ -101,7 +101,7 @@ var FormPage = function FormPage(_ref) {
101
101
  component: component,
102
102
  onChange: onPageChange,
103
103
  value: page.formData[component.fieldId] || patch[component.fieldId],
104
- formData: page.formData
104
+ formData: _objectSpread(_objectSpread({}, page.formData), patch)
105
105
  });
106
106
  }), /*#__PURE__*/_react.default.createElement(_PageActions.default, {
107
107
  actions: page.actions,
@@ -73,8 +73,7 @@ var FormRenderer = function FormRenderer(_ref) {
73
73
  className = _ref.className,
74
74
  hide_title = _ref.hide_title,
75
75
  summaryListClassModifiers = _ref.summaryListClassModifiers,
76
- noChangeAction = _ref.noChangeAction,
77
- newPageId = _ref.newPageId;
76
+ noChangeAction = _ref.noChangeAction;
78
77
  return /*#__PURE__*/_react.default.createElement(_context.HooksContextProvider, {
79
78
  overrides: hooks
80
79
  }, /*#__PURE__*/_react.default.createElement(_context.ValidationContextProvider, null, /*#__PURE__*/_react.default.createElement(InternalFormRenderer, {
@@ -90,8 +89,7 @@ var FormRenderer = function FormRenderer(_ref) {
90
89
  className: className,
91
90
  hide_title: hide_title,
92
91
  summaryListClassModifiers: summaryListClassModifiers,
93
- noChangeAction: noChangeAction,
94
- newPageId: newPageId
92
+ noChangeAction: noChangeAction
95
93
  })));
96
94
  };
97
95
 
@@ -111,8 +109,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
111
109
  className = _ref2.className,
112
110
  hide_title = _ref2.hide_title,
113
111
  summaryListClassModifiers = _ref2.summaryListClassModifiers,
114
- noChangeAction = _ref2.noChangeAction,
115
- newPageId = _ref2.newPageId;
112
+ noChangeAction = _ref2.noChangeAction;
116
113
 
117
114
  // Set up the initial states.
118
115
  var _useState = (0, _react.useState)({}),
@@ -180,10 +177,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
180
177
 
181
178
  (0, _react.useEffect)(function () {
182
179
  setPages(_utils.default.FormPage.getAll(_pages, components, _objectSpread({}, data)));
183
- }, [components, _pages, data, setPages]);
184
- (0, _react.useEffect)(function () {
185
- if (newPageId !== undefined) onPageChange(newPageId);
186
- }, [newPageId]); // Setup initial pageId.
180
+ }, [components, _pages, data, setPages]); // Setup initial pageId.
187
181
 
188
182
  (0, _react.useEffect)(function () {
189
183
  setPageId(function (prev) {
@@ -13,6 +13,10 @@ var _mustBeInThePast = _interopRequireDefault(require("./mustBeInThePast"));
13
13
 
14
14
  var _mustBeInTheFuture = _interopRequireDefault(require("./mustBeInTheFuture"));
15
15
 
16
+ var _mustBeLongerThan = _interopRequireDefault(require("./mustBeLongerThan"));
17
+
18
+ var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
19
+
16
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
21
 
18
22
  // Local imports
@@ -20,7 +24,9 @@ var functions = {
20
24
  mustBeAfter: _mustBeAfter.default,
21
25
  mustBeBefore: _mustBeBefore.default,
22
26
  mustBeInThePast: _mustBeInThePast.default,
23
- mustBeInTheFuture: _mustBeInTheFuture.default
27
+ mustBeInTheFuture: _mustBeInTheFuture.default,
28
+ mustBeLongerThan: _mustBeLongerThan.default,
29
+ mustBeShorterThan: _mustBeShorterThan.default
24
30
  };
25
31
 
26
32
  var additionalValidation = function additionalValidation(value, config) {
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * Function returns true if the string parameter is longer than a given length, false
10
+ * if it is not.
11
+ * @param {string} string - the string to check the length of.
12
+ * @param {number} config.value - the length that string.length must be greater than.
13
+ * @returns true if string.length is greater than config.value, false if not.
14
+ */
15
+ var mustBeLongerThan = function mustBeLongerThan(string, config) {
16
+ if (!string) {
17
+ // null, undefined and empty strings should be picked up by the required flag
18
+ // and not considered here as they would be valid for optional fields.
19
+ return true;
20
+ }
21
+
22
+ return string.length > config.value;
23
+ };
24
+
25
+ var _default = mustBeLongerThan;
26
+ exports.default = _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _mustBeLongerThan = _interopRequireDefault(require("./mustBeLongerThan"));
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('mustBeLongerThan', function () {
11
+ test('should return true given a string longer than the given length', function () {
12
+ var result = (0, _mustBeLongerThan.default)('test', {
13
+ value: 3
14
+ });
15
+ expect(result).toEqual(true);
16
+ });
17
+ test('should return false given a string shorter than the given length', function () {
18
+ var result = (0, _mustBeLongerThan.default)('to', {
19
+ value: 3
20
+ });
21
+ expect(result).toEqual(false);
22
+ });
23
+ test('should return false given a string equal to the given length', function () {
24
+ var result = (0, _mustBeLongerThan.default)('dog', {
25
+ value: 3
26
+ });
27
+ expect(result).toEqual(false);
28
+ });
29
+ test('should return true when string is undefined', function () {
30
+ var result = (0, _mustBeLongerThan.default)(undefined, {
31
+ value: 3
32
+ });
33
+ expect(result).toEqual(true);
34
+ });
35
+ test('should return true when string is empty', function () {
36
+ var result = (0, _mustBeLongerThan.default)('', {
37
+ value: 3
38
+ });
39
+ expect(result).toEqual(true);
40
+ });
41
+ test('should return true when string is null', function () {
42
+ var result = (0, _mustBeLongerThan.default)(null, {
43
+ value: 3
44
+ });
45
+ expect(result).toEqual(true);
46
+ });
47
+ });
48
+ });
49
+ });
50
+ });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ * Function returns true if the string parameter is shorter than a given length, false
10
+ * if it is not.
11
+ * @param {string} string - the string to check the length of.
12
+ * @param {number} config.value - the length that string.length must be less than.
13
+ * @returns true if string.length is greater than config.value, false if not.
14
+ */
15
+ var mustBeShorterThan = function mustBeShorterThan(string, config) {
16
+ if (!string) {
17
+ // null, undefined and empty strings should be picked up by the required flag
18
+ // and not considered here as they would be valid for optional fields.
19
+ return true;
20
+ }
21
+
22
+ return string.length < config.value;
23
+ };
24
+
25
+ var _default = mustBeShorterThan;
26
+ exports.default = _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _mustBeShorterThan = _interopRequireDefault(require("./mustBeShorterThan"));
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('mustBeShorterThan', function () {
11
+ test('should return true given a string shorter than the given length', function () {
12
+ var result = (0, _mustBeShorterThan.default)('to', {
13
+ value: 3
14
+ });
15
+ expect(result).toEqual(true);
16
+ });
17
+ test('should return false given a string longer than the given length', function () {
18
+ var result = (0, _mustBeShorterThan.default)('test', {
19
+ value: 3
20
+ });
21
+ expect(result).toEqual(false);
22
+ });
23
+ test('should return false given a string equal to the given length', function () {
24
+ var result = (0, _mustBeShorterThan.default)('dog', {
25
+ value: 3
26
+ });
27
+ expect(result).toEqual(false);
28
+ });
29
+ test('should return true when string is undefined', function () {
30
+ var result = (0, _mustBeShorterThan.default)(undefined, {
31
+ value: 3
32
+ });
33
+ expect(result).toEqual(true);
34
+ });
35
+ test('should return true when string is empty', function () {
36
+ var result = (0, _mustBeShorterThan.default)('', {
37
+ value: 3
38
+ });
39
+ expect(result).toEqual(true);
40
+ });
41
+ test('should return true when string is null', function () {
42
+ var result = (0, _mustBeShorterThan.default)(null, {
43
+ value: 3
44
+ });
45
+ expect(result).toEqual(true);
46
+ });
47
+ });
48
+ });
49
+ });
50
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "3.5.2-alpha",
3
+ "version": "3.6.2",
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": "1.9.0",
19
+ "@ukhomeoffice/cop-react-components": "1.9.5",
20
20
  "axios": "^0.21.1",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^3.13.0",