@ukhomeoffice/cop-react-form-renderer 2.1.0 → 2.6.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.
Files changed (90) hide show
  1. package/dist/components/FormComponent/Container.test.js +250 -0
  2. package/dist/components/FormComponent/FormComponent.js +105 -21
  3. package/dist/components/FormComponent/FormComponent.test.js +67 -0
  4. package/dist/components/FormPage/FormPage.js +2 -1
  5. package/dist/components/FormRenderer/FormRenderer.js +105 -6
  6. package/dist/components/FormRenderer/FormRenderer.test.js +235 -0
  7. package/dist/components/FormRenderer/helpers/getNextPageId.js +3 -0
  8. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +6 -0
  9. package/dist/components/FormRenderer/helpers/getPage.js +1 -1
  10. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +18 -1
  11. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +44 -6
  12. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.js +50 -0
  13. package/dist/components/FormRenderer/helpers/getUpdatedSectionStates.test.js +122 -0
  14. package/dist/components/FormRenderer/helpers/index.js +7 -1
  15. package/dist/components/TaskList/Task.js +83 -0
  16. package/dist/components/TaskList/Task.test.js +112 -0
  17. package/dist/components/TaskList/TaskList.js +112 -0
  18. package/dist/components/TaskList/TaskList.scss +70 -0
  19. package/dist/components/TaskList/TaskList.stories.mdx +57 -0
  20. package/dist/components/TaskList/TaskList.test.js +223 -0
  21. package/dist/components/TaskList/TaskState.js +42 -0
  22. package/dist/components/TaskList/TaskState.test.js +99 -0
  23. package/dist/components/TaskList/index.js +13 -0
  24. package/dist/hooks/index.js +19 -1
  25. package/dist/hooks/useHooks.js +5 -1
  26. package/dist/json/taskList.json +228 -0
  27. package/dist/json/userProfile.data.json +2 -1
  28. package/dist/models/ComponentTypes.js +5 -1
  29. package/dist/models/FormTypes.js +2 -0
  30. package/dist/models/HubFormats.js +3 -1
  31. package/dist/models/PageAction.js +5 -0
  32. package/dist/models/TaskStates.js +41 -0
  33. package/dist/models/index.js +8 -0
  34. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +40 -0
  35. package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +257 -0
  36. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +9 -1
  37. package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +44 -0
  38. package/dist/utils/CheckYourAnswers/showComponentCYA.js +6 -0
  39. package/dist/utils/Component/cleanAttributes.js +1 -1
  40. package/dist/utils/Component/getComponent.js +26 -0
  41. package/dist/utils/Component/isEditable.js +1 -1
  42. package/dist/utils/Component/showComponent.js +2 -20
  43. package/dist/utils/Condition/index.js +19 -0
  44. package/dist/utils/Condition/meetsAllConditions.js +40 -0
  45. package/dist/utils/Condition/meetsAllConditions.test.js +62 -0
  46. package/dist/utils/{meetsCondition.js → Condition/meetsCondition.js} +0 -0
  47. package/dist/utils/Condition/meetsCondition.test.js +302 -0
  48. package/dist/utils/Condition/setupConditions.js +47 -0
  49. package/dist/utils/Condition/setupConditions.test.js +35 -0
  50. package/dist/utils/Container/getEditableComponents.js +38 -0
  51. package/dist/utils/Container/getEditableComponents.test.js +157 -0
  52. package/dist/utils/Container/index.js +22 -0
  53. package/dist/utils/Container/setupNesting.js +45 -0
  54. package/dist/utils/Container/setupNesting.test.js +92 -0
  55. package/dist/utils/Container/showContainer.js +61 -0
  56. package/dist/utils/Container/showContainer.test.js +128 -0
  57. package/dist/utils/Data/getDataPath.js +90 -0
  58. package/dist/utils/Data/getDataPath.test.js +52 -0
  59. package/dist/utils/Data/index.js +3 -0
  60. package/dist/utils/FormPage/getFormPage.js +4 -2
  61. package/dist/utils/FormPage/getFormPage.test.js +18 -7
  62. package/dist/utils/FormPage/getFormPages.test.js +5 -2
  63. package/dist/utils/FormPage/getPageActions.js +6 -0
  64. package/dist/utils/FormPage/index.js +0 -3
  65. package/dist/utils/FormPage/showFormPage.js +7 -27
  66. package/dist/utils/Hub/getFormHub.js +4 -0
  67. package/dist/utils/Hub/getFormHub.test.js +15 -4
  68. package/dist/utils/Validate/additional/index.js +55 -0
  69. package/dist/utils/Validate/additional/index.test.js +69 -0
  70. package/dist/utils/Validate/additional/mustBeAfter.js +37 -0
  71. package/dist/utils/Validate/additional/mustBeAfter.test.js +98 -0
  72. package/dist/utils/Validate/additional/mustBeBefore.js +35 -0
  73. package/dist/utils/Validate/additional/mustBeBefore.test.js +66 -0
  74. package/dist/utils/Validate/additional/mustBeInTheFuture.js +42 -0
  75. package/dist/utils/Validate/additional/mustBeInTheFuture.test.js +34 -0
  76. package/dist/utils/Validate/additional/mustBeInThePast.js +44 -0
  77. package/dist/utils/Validate/additional/mustBeInThePast.test.js +34 -0
  78. package/dist/utils/Validate/additional/utils.js +66 -0
  79. package/dist/utils/Validate/index.js +7 -1
  80. package/dist/utils/Validate/validateComponent.js +57 -0
  81. package/dist/utils/Validate/validateComponent.test.js +92 -2
  82. package/dist/utils/Validate/validateDate.js +155 -0
  83. package/dist/utils/Validate/validateDate.test.js +118 -0
  84. package/dist/utils/Validate/validatePage.js +6 -8
  85. package/dist/utils/Validate/validateTime.js +95 -0
  86. package/dist/utils/Validate/validateTime.test.js +61 -0
  87. package/dist/utils/index.js +6 -3
  88. package/package.json +3 -2
  89. package/dist/utils/FormPage/getEditableComponents.js +0 -28
  90. package/dist/utils/FormPage/getEditableComponents.test.js +0 -75
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _utils = require("./additional/utils");
9
+
10
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
11
+
12
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+
14
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
+
16
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
17
+
18
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
19
+
20
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
21
+
22
+ /**
23
+ * Checks if a time passed is a valid time.
24
+ * This will validate for missing components, invalid hour or minute components.
25
+ * EXAMPLE USE : const { message, propsInError } = validateTime('15:30')
26
+ *
27
+ * Note that an empty string is not considered invalid. You should use
28
+ * validateRequired (Validate.required) for that sort of validation.
29
+ *
30
+ * @param {string} time time as a string
31
+ * @returns an object with an error message and instructions for which parts of the time are in error
32
+ * or undefined for both if the time is valid
33
+ */
34
+ var validateTime = function validateTime(time) {
35
+ if (!time) {
36
+ return {
37
+ message: undefined,
38
+ propsInError: undefined
39
+ };
40
+ }
41
+
42
+ var formattedDate = (0, _utils.formattedTime)(time);
43
+
44
+ var _formattedDate$split = formattedDate.split(':'),
45
+ _formattedDate$split2 = _slicedToArray(_formattedDate$split, 2),
46
+ hour = _formattedDate$split2[0],
47
+ minute = _formattedDate$split2[1];
48
+
49
+ var intHour = parseInt(hour, 10);
50
+ var intMinute = parseInt(minute, 10);
51
+
52
+ if (hour.length === 0) {
53
+ return {
54
+ message: 'Time must include a hour',
55
+ propsInError: {
56
+ hour: true
57
+ }
58
+ };
59
+ }
60
+
61
+ if (intHour > 23 || intHour < 0) {
62
+ return {
63
+ message: 'Hour must be between 0 and 23',
64
+ propsInError: {
65
+ hour: true
66
+ }
67
+ };
68
+ }
69
+
70
+ if (minute.length === 0) {
71
+ return {
72
+ message: 'Time must include a minute',
73
+ propsInError: {
74
+ minute: true
75
+ }
76
+ };
77
+ }
78
+
79
+ if (intMinute > 59 || intMinute < 0) {
80
+ return {
81
+ message: 'Minute must be between 0 and 59',
82
+ propsInError: {
83
+ minute: true
84
+ }
85
+ };
86
+ }
87
+
88
+ return {
89
+ message: undefined,
90
+ propsInError: undefined
91
+ };
92
+ };
93
+
94
+ var _default = validateTime;
95
+ exports.default = _default;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ var _validateTime = _interopRequireDefault(require("./validateTime"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ describe('utils', function () {
8
+ describe('Validate', function () {
9
+ describe('time', function () {
10
+ test('should return no error when the value is an empty string', function () {
11
+ expect((0, _validateTime.default)('')).toEqual({
12
+ message: undefined,
13
+ propsInError: undefined
14
+ });
15
+ });
16
+ test('should return undefined if a time string is valid', function () {
17
+ var output = (0, _validateTime.default)('14:30');
18
+ expect(output).toEqual({
19
+ message: undefined,
20
+ propsInError: undefined
21
+ });
22
+ });
23
+ test('should return an error if no hour is given', function () {
24
+ var output = (0, _validateTime.default)(':30');
25
+ expect(output).toEqual({
26
+ message: 'Time must include a hour',
27
+ propsInError: {
28
+ hour: true
29
+ }
30
+ });
31
+ });
32
+ test('should return an error if the hour is not between 0 and 23', function () {
33
+ var output = (0, _validateTime.default)('35:30');
34
+ expect(output).toEqual({
35
+ message: 'Hour must be between 0 and 23',
36
+ propsInError: {
37
+ hour: true
38
+ }
39
+ });
40
+ });
41
+ test('should return an error if no minute is given', function () {
42
+ var output = (0, _validateTime.default)('14:');
43
+ expect(output).toEqual({
44
+ message: 'Time must include a minute',
45
+ propsInError: {
46
+ minute: true
47
+ }
48
+ });
49
+ });
50
+ test('should return an error if the minute is not between 0 and 59', function () {
51
+ var output = (0, _validateTime.default)('14:75');
52
+ expect(output).toEqual({
53
+ message: 'Minute must be between 0 and 59',
54
+ propsInError: {
55
+ minute: true
56
+ }
57
+ });
58
+ });
59
+ });
60
+ });
61
+ });
@@ -11,6 +11,10 @@ var _CheckYourAnswers = _interopRequireDefault(require("./CheckYourAnswers"));
11
11
 
12
12
  var _Component = _interopRequireDefault(require("./Component"));
13
13
 
14
+ var _Condition = _interopRequireDefault(require("./Condition"));
15
+
16
+ var _Container = _interopRequireDefault(require("./Container"));
17
+
14
18
  var _Data = _interopRequireDefault(require("./Data"));
15
19
 
16
20
  var _Format = _interopRequireDefault(require("./Format"));
@@ -19,8 +23,6 @@ var _FormPage = _interopRequireDefault(require("./FormPage"));
19
23
 
20
24
  var _Hub = _interopRequireDefault(require("./Hub"));
21
25
 
22
- var _meetsCondition = _interopRequireDefault(require("./meetsCondition"));
23
-
24
26
  var _Validate = _interopRequireDefault(require("./Validate"));
25
27
 
26
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -34,11 +36,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
34
36
  var Utils = _objectSpread({
35
37
  CheckYourAnswers: _CheckYourAnswers.default,
36
38
  Component: _Component.default,
39
+ Container: _Container.default,
37
40
  Data: _Data.default,
38
41
  Format: _Format.default,
39
42
  FormPage: _FormPage.default,
40
43
  Hub: _Hub.default,
41
- meetsCondition: _meetsCondition.default,
44
+ Condition: _Condition.default,
42
45
  Validate: _Validate.default
43
46
  }, _copReactComponents.Utils);
44
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "2.1.0",
3
+ "version": "2.6.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
@@ -16,8 +16,9 @@
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.1.2",
19
+ "@ukhomeoffice/cop-react-components": "1.2.0",
20
20
  "axios": "^0.21.1",
21
+ "dayjs": "^1.11.0",
21
22
  "govuk-frontend": "^3.13.0",
22
23
  "web-vitals": "^1.0.1"
23
24
  },
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _Component = _interopRequireDefault(require("../Component"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- /**
13
- * Gets all the editable components on a page.
14
- * @param {object} page The page to consider.
15
- * @returns An array of ONLY the editable components on a page.
16
- */
17
- var getEditableComponents = function getEditableComponents(page) {
18
- if (page && Array.isArray(page.components)) {
19
- return page.components.filter(function (c) {
20
- return _Component.default.editable(c);
21
- });
22
- }
23
-
24
- return [];
25
- };
26
-
27
- var _default = getEditableComponents;
28
- exports.default = _default;
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- var _getEditableComponents = _interopRequireDefault(require("./getEditableComponents"));
4
-
5
- var _isEditable = require("../Component/isEditable");
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- describe('utils', function () {
10
- describe('FormPage', function () {
11
- describe('getEditableComponents', function () {
12
- var HTML = {
13
- type: 'html',
14
- tagName: 'p',
15
- content: 'Alpha'
16
- };
17
- var INSET_TEXT = {
18
- type: 'inset-text',
19
- content: 'Bravo'
20
- };
21
- var HEADING = {
22
- type: 'heading',
23
- size: 'm',
24
- content: 'Charlie'
25
- };
26
- it('should return an empty array for a null page', function () {
27
- expect((0, _getEditableComponents.default)(null)).toEqual([]);
28
- });
29
- it('should return an empty array for a page with no components', function () {
30
- expect((0, _getEditableComponents.default)({
31
- components: []
32
- })).toEqual([]);
33
- });
34
- it('should return an empty array for a page with only non-editable components', function () {
35
- var COMPONENTS = [HTML, INSET_TEXT, HEADING];
36
- expect((0, _getEditableComponents.default)({
37
- components: COMPONENTS
38
- })).toEqual([]);
39
- });
40
-
41
- _isEditable.EDITABLE_TYPES.forEach(function (type) {
42
- it("should return just the \"".concat(type, "\" component if it exists in the components but no non-editable ones"), function () {
43
- var EDITABLE = {
44
- type: type
45
- };
46
- var COMPONENTS = [HTML, EDITABLE, INSET_TEXT, HEADING];
47
- expect((0, _getEditableComponents.default)({
48
- components: COMPONENTS
49
- })).toEqual([EDITABLE]);
50
- });
51
- });
52
-
53
- it('should return all editable components and no non-editable ones', function () {
54
- var COMPONENTS = [HTML, INSET_TEXT, HEADING];
55
-
56
- _isEditable.EDITABLE_TYPES.forEach(function (type) {
57
- COMPONENTS.push({
58
- type: type
59
- });
60
- });
61
-
62
- var RESULT = (0, _getEditableComponents.default)({
63
- components: COMPONENTS
64
- });
65
- expect(RESULT.length).toEqual(_isEditable.EDITABLE_TYPES.length);
66
-
67
- _isEditable.EDITABLE_TYPES.forEach(function (type) {
68
- expect(RESULT).toContainEqual({
69
- type: type
70
- });
71
- });
72
- });
73
- });
74
- });
75
- });