@ukhomeoffice/cop-react-form-renderer 1.0.0 → 2.0.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 (57) hide show
  1. package/dist/components/FormPage/FormPage.js +8 -2
  2. package/dist/components/FormPage/FormPage.test.js +2 -2
  3. package/dist/components/FormRenderer/FormRenderer.js +26 -10
  4. package/dist/components/FormRenderer/handlers/getPageId.js +1 -10
  5. package/dist/components/FormRenderer/handlers/getPageId.test.js +5 -31
  6. package/dist/components/FormRenderer/handlers/handlers.test.js +2 -2
  7. package/dist/components/FormRenderer/helpers/getNextPageId.js +33 -26
  8. package/dist/components/FormRenderer/helpers/getNextPageId.test.js +89 -7
  9. package/dist/components/FormRenderer/helpers/getSubmissionStatus.js +27 -0
  10. package/dist/components/FormRenderer/helpers/getSubmissionStatus.test.js +209 -0
  11. package/dist/components/FormRenderer/helpers/index.js +4 -1
  12. package/dist/components/PageActions/PageActions.stories.mdx +1 -1
  13. package/dist/components/PageActions/PageActions.test.js +2 -2
  14. package/dist/components/SummaryList/RowAction.js +1 -1
  15. package/dist/components/SummaryList/RowAction.test.js +6 -6
  16. package/dist/components/SummaryList/SummaryList.js +1 -1
  17. package/dist/components/SummaryList/helpers/getRowActionAttributes.js +2 -2
  18. package/dist/components/SummaryList/helpers/getRowActionAttributes.test.js +4 -4
  19. package/dist/json/areYouACivilServant.json +7 -0
  20. package/dist/json/firstForm.json +94 -0
  21. package/dist/json/grade.json +108 -0
  22. package/dist/json/saveAndContinue.json +98 -0
  23. package/dist/json/team.json +17351 -0
  24. package/dist/json/userProfile.data.json +14 -0
  25. package/dist/json/userProfile.json +276 -0
  26. package/dist/models/ComponentTypes.js +4 -0
  27. package/dist/utils/CheckYourAnswers/getCYAAction.js +24 -3
  28. package/dist/utils/CheckYourAnswers/getCYAAction.test.js +62 -15
  29. package/dist/utils/CheckYourAnswers/getCYARow.js +8 -2
  30. package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -5
  31. package/dist/utils/Component/getComponent.js +24 -0
  32. package/dist/utils/Component/getComponentTests/getComponent.autocomplete.test.js +75 -0
  33. package/dist/utils/Component/getComponentTests/getComponent.checkboxes.test.js +129 -0
  34. package/dist/utils/Component/getComponentTests/getComponent.date.test.js +129 -0
  35. package/dist/utils/Component/getComponentTests/getComponent.email.test.js +80 -0
  36. package/dist/utils/Component/getComponentTests/getComponent.heading.test.js +33 -0
  37. package/dist/utils/Component/getComponentTests/getComponent.html.test.js +45 -0
  38. package/dist/utils/Component/getComponentTests/getComponent.insetText.test.js +31 -0
  39. package/dist/utils/Component/getComponentTests/getComponent.phoneNumber.test.js +80 -0
  40. package/dist/utils/Component/getComponentTests/getComponent.radios.test.js +125 -0
  41. package/dist/utils/Component/getComponentTests/getComponent.text.test.js +80 -0
  42. package/dist/utils/Component/getComponentTests/getComponent.textarea.test.js +76 -0
  43. package/dist/utils/Component/getComponentTests/getComponent.unknown.test.js +14 -0
  44. package/dist/utils/Component/isEditable.js +1 -1
  45. package/dist/utils/Data/refDataToOptions.js +4 -0
  46. package/dist/utils/Data/refDataToOptions.test.js +30 -0
  47. package/dist/utils/FormPage/getEditableComponents.js +28 -0
  48. package/dist/utils/FormPage/getEditableComponents.test.js +75 -0
  49. package/dist/utils/FormPage/getFormPage.js +5 -1
  50. package/dist/utils/FormPage/getPageActions.js +66 -0
  51. package/dist/utils/FormPage/getPageActions.test.js +89 -0
  52. package/dist/utils/FormPage/index.js +7 -1
  53. package/dist/utils/FormPage/showFormPage.js +81 -0
  54. package/dist/utils/FormPage/showFormPage.test.js +131 -0
  55. package/dist/utils/Validate/validateComponent.js +4 -2
  56. package/package.json +9 -5
  57. package/dist/utils/Component/getComponent.test.js +0 -361
@@ -13,6 +13,8 @@ var _getFormState = _interopRequireDefault(require("./getFormState"));
13
13
 
14
14
  var _getNextPageId = _interopRequireDefault(require("./getNextPageId"));
15
15
 
16
+ var _getSubmissionStatus = _interopRequireDefault(require("./getSubmissionStatus"));
17
+
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
18
20
  // Local imports
@@ -20,7 +22,8 @@ var helpers = {
20
22
  canActionProceed: _canActionProceed.default,
21
23
  canCYASubmit: _canCYASubmit.default,
22
24
  getFormState: _getFormState.default,
23
- getNextPageId: _getNextPageId.default
25
+ getNextPageId: _getNextPageId.default,
26
+ getSubmissionStatus: _getSubmissionStatus.default
24
27
  };
25
28
  exports.helpers = helpers;
26
29
  var _default = helpers;
@@ -43,7 +43,7 @@ Renders the buttons at the bottom of a Page.
43
43
  <Canvas>
44
44
  <Story name="Custom action">
45
45
  {() => {
46
- const ACTIONS = [{ type: 'navigate', url: '/profile', label: 'Go to profile' }];
46
+ const ACTIONS = [{ type: 'navigate', page: 'profile', label: 'Go to profile' }];
47
47
  const ON_ACTION = (action, patch, onError) => {
48
48
  console.log('action invoked', action, patch);
49
49
  };
@@ -87,7 +87,7 @@ describe('components', function () {
87
87
  case 0:
88
88
  ACTIONS = [{
89
89
  type: 'navigate',
90
- url: '/alpha',
90
+ page: 'alpha',
91
91
  label: 'Alpha'
92
92
  }];
93
93
  _render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_PageActions.default, {
@@ -121,7 +121,7 @@ describe('components', function () {
121
121
  case 0:
122
122
  NAVIGATE = {
123
123
  type: _models.PageAction.TYPES.NAVIGATE,
124
- url: '/alpha',
124
+ page: 'alpha',
125
125
  label: 'Alpha'
126
126
  };
127
127
  ACTIONS = [NAVIGATE, _models.PageAction.TYPES.SUBMIT];
@@ -56,7 +56,7 @@ RowAction.propTypes = {
56
56
  row: _propTypes.default.shape({
57
57
  action: _propTypes.default.shape({
58
58
  label: _propTypes.default.string.isRequired,
59
- href: _propTypes.default.string,
59
+ page: _propTypes.default.string,
60
60
  aria_suffix: _propTypes.default.string,
61
61
  onAction: _propTypes.default.func
62
62
  })
@@ -23,10 +23,10 @@ describe('components', function () {
23
23
  expect(container.childNodes.length).toEqual(0);
24
24
  });
25
25
  it('should handle a row with an href in the action', function () {
26
- var HREF = 'http://alpha.homeoffice.gov.uk';
26
+ var PAGE = 'alpha';
27
27
  var ROW = {
28
28
  action: {
29
- href: HREF,
29
+ page: PAGE,
30
30
  label: 'Change'
31
31
  }
32
32
  };
@@ -38,14 +38,14 @@ describe('components', function () {
38
38
 
39
39
  var link = container.childNodes[0];
40
40
  expect(link.tagName).toEqual('A');
41
- expect(link.getAttribute('href')).toEqual(HREF);
41
+ expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
42
42
  expect(link.textContent).toEqual(ROW.action.label);
43
43
  });
44
44
  it('should render an aria_suffix appropriately', function () {
45
- var HREF = 'http://alpha.homeoffice.gov.uk';
45
+ var PAGE = 'alpha';
46
46
  var ROW = {
47
47
  action: {
48
- href: HREF,
48
+ page: PAGE,
49
49
  label: 'Change',
50
50
  aria_suffix: 'the thing'
51
51
  }
@@ -58,7 +58,7 @@ describe('components', function () {
58
58
 
59
59
  var link = container.childNodes[0];
60
60
  expect(link.tagName).toEqual('A');
61
- expect(link.getAttribute('href')).toEqual(HREF);
61
+ expect(link.getAttribute('href')).toEqual("/".concat(PAGE));
62
62
  expect(link.textContent).toEqual("".concat(ROW.action.label, " ").concat(ROW.action.aria_suffix));
63
63
  });
64
64
  it('should handle a row with an onAction in the action', function () {
@@ -62,7 +62,7 @@ SummaryList.propTypes = {
62
62
  key: _propTypes.default.string.isRequired,
63
63
  value: _propTypes.default.any,
64
64
  action: _propTypes.default.shape({
65
- href: _propTypes.default.string,
65
+ page: _propTypes.default.string,
66
66
  label: _propTypes.default.string,
67
67
  aria_suffix: _propTypes.default.string,
68
68
  onAction: _propTypes.default.func
@@ -13,9 +13,9 @@ var getRowActionAttributes = function getRowActionAttributes(row) {
13
13
  return row.action.onAction(row);
14
14
  }
15
15
  };
16
- } else {
16
+ } else if (row.action.page) {
17
17
  return {
18
- href: row.action.href
18
+ href: "/".concat(row.action.page)
19
19
  };
20
20
  }
21
21
  }
@@ -20,15 +20,15 @@ describe('components', function () {
20
20
  };
21
21
  expect((0, _getRowActionAttributes.default)(ROW)).toEqual({});
22
22
  });
23
- it('should handle a row with an href', function () {
24
- var HREF = 'http://alpha.homeoffice.gov.uk';
23
+ it('should handle a row with a page', function () {
24
+ var PAGE = 'alpha';
25
25
  var ROW = {
26
26
  action: {
27
- href: HREF
27
+ page: PAGE
28
28
  }
29
29
  };
30
30
  expect((0, _getRowActionAttributes.default)(ROW)).toEqual({
31
- href: HREF
31
+ href: "/".concat(PAGE)
32
32
  });
33
33
  });
34
34
  it('should handle a row with an onAction function', function () {
@@ -0,0 +1,7 @@
1
+ {
2
+ "data": [
3
+ { "id": "yes", "name": "Yes" },
4
+ { "id": "no-contractor", "name": "No, I'm a contractor" },
5
+ { "id": "no-agency", "name": "No, I'm agency staff" }
6
+ ]
7
+ }
@@ -0,0 +1,94 @@
1
+ {
2
+ "id": "firstForm",
3
+ "version": "1",
4
+ "name": "firstForm",
5
+ "title": "First form",
6
+ "type": "cya",
7
+ "components": [
8
+ {
9
+ "id": "firstName",
10
+ "fieldId": "firstName",
11
+ "label": "First name",
12
+ "type": "text",
13
+ "required": true
14
+ },
15
+ {
16
+ "id": "surname",
17
+ "fieldId": "surname",
18
+ "label": "Last name",
19
+ "type": "text",
20
+ "required": true
21
+ },
22
+ {
23
+ "id": "age",
24
+ "fieldId": "age",
25
+ "label": "Your age",
26
+ "type": "text",
27
+ "required": true
28
+ }
29
+ ],
30
+ "pages": [
31
+ {
32
+ "id": "before",
33
+ "name": "before",
34
+ "title": "Before you start",
35
+ "components": [
36
+ "This is a sample form to prove out the mechanism for save and continue.",
37
+ "When you click on the Start button, a new business key should be generated for this form.",
38
+ {
39
+ "type": "inset-text",
40
+ "content": "Generating a business key is non-reversible and cancelling the form creation will leave a gap."
41
+ },
42
+ "If you are happy to proceed, click start now."
43
+ ],
44
+ "actions": [
45
+ { "type": "navigate", "page": "firstName", "start": true, "label": "Start now" }
46
+ ],
47
+ "show_on_cya": false
48
+ },
49
+ {
50
+ "id": "firstName",
51
+ "name": "firstName",
52
+ "title": "Enter first name",
53
+ "components": [
54
+ { "use": "firstName", "label": "" }
55
+ ],
56
+ "actions": [ "saveAndContinue", "saveAndReturn" ],
57
+ "cya_link": {
58
+ "page": "firstName",
59
+ "aria_suffix": "your first name"
60
+ }
61
+ },
62
+ {
63
+ "id": "surname",
64
+ "name": "surname",
65
+ "title": "Enter surname",
66
+ "components": [
67
+ { "use": "surname", "label": "" }
68
+ ],
69
+ "actions": [ "saveAndContinue", "saveAndReturn" ],
70
+ "cya_link": {
71
+ "page": "surname",
72
+ "aria_suffix": "your surname"
73
+ }
74
+ },
75
+ {
76
+ "id": "age",
77
+ "name": "age",
78
+ "title": "Enter age",
79
+ "components": [
80
+ { "use": "age", "label": "" }
81
+ ],
82
+ "actions": [ "saveAndContinue", "saveAndReturn" ],
83
+ "cya_link": {
84
+ "page": "age",
85
+ "aria_suffix": "your first name"
86
+ }
87
+ }
88
+ ],
89
+ "cya": {
90
+ "actions": [
91
+ { "type": "submit", "label": "Submit", "validate": true }
92
+ ]
93
+ }
94
+ }
@@ -0,0 +1,108 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "373979c1-2360-46be-b712-0409ac068059",
5
+ "name": "SCS4",
6
+ "parentgradetypeid": null,
7
+ "validfrom": "2019-01-01T00:01:00.000Z",
8
+ "validto": null,
9
+ "updatedby": null
10
+ },
11
+ {
12
+ "id": "36c80dfe-0aae-455b-9445-2e1c09dcafdc",
13
+ "name": "SCS3",
14
+ "parentgradetypeid": "373979c1-2360-46be-b712-0409ac068059",
15
+ "validfrom": "2019-01-01T00:01:00.000Z",
16
+ "validto": null,
17
+ "updatedby": null
18
+ },
19
+ {
20
+ "id": "1b041cda-b151-4769-b76a-d42d67b0b960",
21
+ "name": "Senior Director / SCS2",
22
+ "parentgradetypeid": "36c80dfe-0aae-455b-9445-2e1c09dcafdc",
23
+ "validfrom": "2019-01-01T00:01:00.000Z",
24
+ "validto": null,
25
+ "updatedby": null
26
+ },
27
+ {
28
+ "id": "172de41d-f7b0-4be9-b7e8-0cf4f1a1342f",
29
+ "name": "Director / SCS1",
30
+ "parentgradetypeid": "1b041cda-b151-4769-b76a-d42d67b0b960",
31
+ "validfrom": "2019-01-01T00:01:00.000Z",
32
+ "validto": null,
33
+ "updatedby": null
34
+ },
35
+ {
36
+ "id": "39e18b45-0358-4a45-83ec-5a70b74641e8",
37
+ "name": "Deputy Director / Grade 6",
38
+ "parentgradetypeid": "172de41d-f7b0-4be9-b7e8-0cf4f1a1342f",
39
+ "validfrom": "2019-01-01T00:01:00.000Z",
40
+ "validto": null,
41
+ "updatedby": null
42
+ },
43
+ {
44
+ "id": "44855085-a36b-42e5-b805-f4ebe209ecf2",
45
+ "name": "Assistant Director / Grade 7",
46
+ "parentgradetypeid": "39e18b45-0358-4a45-83ec-5a70b74641e8",
47
+ "validfrom": "2019-01-01T00:01:00.000Z",
48
+ "validto": null,
49
+ "updatedby": null
50
+ },
51
+ {
52
+ "id": "4fad1115-7d12-4b6f-8d8a-97dbe469a346",
53
+ "name": "Senior Officer / Senior Executive Officer",
54
+ "parentgradetypeid": "44855085-a36b-42e5-b805-f4ebe209ecf2",
55
+ "validfrom": "2019-01-01T00:01:00.000Z",
56
+ "validto": null,
57
+ "updatedby": null
58
+ },
59
+ {
60
+ "id": "b512288d-95e3-4f60-ad4c-4cdfab68d841",
61
+ "name": "Higher Officer / Higher Executive Officer",
62
+ "parentgradetypeid": "4fad1115-7d12-4b6f-8d8a-97dbe469a346",
63
+ "validfrom": "2019-01-01T00:01:00.000Z",
64
+ "validto": null,
65
+ "updatedby": null
66
+ },
67
+ {
68
+ "id": "1c140011-46ad-4a5d-af25-e80a6fcdcdba",
69
+ "name": "Officer / Executive Officer",
70
+ "parentgradetypeid": "b512288d-95e3-4f60-ad4c-4cdfab68d841",
71
+ "validfrom": "2019-01-01T00:01:00.000Z",
72
+ "validto": null,
73
+ "updatedby": null
74
+ },
75
+ {
76
+ "id": "02de92d8-aad1-4663-a37f-a87012f60f1b",
77
+ "name": "Assistant Officer / Administrative Officer",
78
+ "parentgradetypeid": "1c140011-46ad-4a5d-af25-e80a6fcdcdba",
79
+ "validfrom": "2019-01-01T00:01:00.000Z",
80
+ "validto": null,
81
+ "updatedby": null
82
+ },
83
+ {
84
+ "id": "9910a29d-7fbb-451d-8729-f39f4373bbcc",
85
+ "name": "Assistant Office / Messenger",
86
+ "parentgradetypeid": "02de92d8-aad1-4663-a37f-a87012f60f1b",
87
+ "validfrom": "2019-01-01T00:01:00.000Z",
88
+ "validto": null,
89
+ "updatedby": null
90
+ },
91
+ {
92
+ "id": "073b92f8-7208-4026-a090-906c276079f1",
93
+ "name": "Contractor",
94
+ "parentgradetypeid": null,
95
+ "validfrom": "2019-01-01T00:01:00.000Z",
96
+ "validto": null,
97
+ "updatedby": null
98
+ },
99
+ {
100
+ "id": "c27cf914-0b97-4c4e-bb2d-2ae4b886baa5",
101
+ "name": "Agency Staff",
102
+ "parentgradetypeid": null,
103
+ "validfrom": "2019-01-01T00:01:00.000Z",
104
+ "validto": null,
105
+ "updatedby": null
106
+ }
107
+ ]
108
+ }
@@ -0,0 +1,98 @@
1
+ {
2
+ "id": "saveAndContinue",
3
+ "version": "1",
4
+ "name": "saveAndContinue",
5
+ "title": "Save and continue example",
6
+ "type": "hub-and-spoke",
7
+ "components": [
8
+ {
9
+ "id": "firstName",
10
+ "fieldId": "firstName",
11
+ "label": "First name",
12
+ "type": "text",
13
+ "required": true
14
+ },
15
+ {
16
+ "id": "surname",
17
+ "fieldId": "surname",
18
+ "label": "Last name",
19
+ "type": "text",
20
+ "required": true
21
+ },
22
+ {
23
+ "id": "email",
24
+ "fieldId": "email",
25
+ "label": "Your email address",
26
+ "type": "email",
27
+ "required": true
28
+ },
29
+ {
30
+ "id": "location",
31
+ "fieldId": "location",
32
+ "label": "Incident location",
33
+ "type": "text",
34
+ "required": true
35
+ },
36
+ {
37
+ "id": "when",
38
+ "fieldId": "when",
39
+ "label": "Incident date and start time",
40
+ "type": "text",
41
+ "required": true
42
+ },
43
+ {
44
+ "id": "seizedItems",
45
+ "fieldId": "seizedItems",
46
+ "type": "collection",
47
+ "required": true,
48
+ "components": [
49
+ { "use": "type" },
50
+ { "use": "description" },
51
+ {
52
+ "id": "status",
53
+ "fieldId": "status",
54
+ "label": "What is the seized status of this item?",
55
+ "type": "radios",
56
+ "required": true
57
+ }
58
+ ],
59
+ "_description": "Required means at least 1 item"
60
+ }
61
+ ],
62
+ "pages": [
63
+ {
64
+ "id": "details",
65
+ "name": "details",
66
+ "title": "Your details",
67
+ "components": [
68
+ { "use": "firstName" },
69
+ { "use": "surname" },
70
+ { "use": "email" }
71
+ ],
72
+ "actions": [
73
+ { "type": "saveDraft", "validate": true, "label": "Save and continue" },
74
+ { "type": "saveAndReturn", "validate": true, "label": "Save and return later", "classModifiers": "secondary" }
75
+ ],
76
+ "cya_link": {
77
+ "page": "details",
78
+ "aria_suffix": "your details"
79
+ }
80
+ },
81
+ {
82
+ "id": "where-and-when",
83
+ "name": "where-and-when",
84
+ "title": "Where and when",
85
+ "components": [
86
+ { "use": "location" },
87
+ { "use": "when" }
88
+ ],
89
+ "actions": ["submit"],
90
+ "cya_link": {
91
+ "page": "where-and-when",
92
+ "aria_suffix": "where and when"
93
+ }
94
+ }
95
+ ],
96
+ "hub": { "format": "CYA" },
97
+ "cya": {}
98
+ }