@ukhomeoffice/cop-react-form-renderer 6.15.8-charlie → 6.15.8

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.
@@ -144,21 +144,10 @@ const InternalFormRenderer = _ref2 => {
144
144
  setGoingBack(true);
145
145
  hooks.onGoingBack(e.state ? e.state : null);
146
146
  if (components && pages && data && (_formState$page = formState.page) !== null && _formState$page !== void 0 && _formState$page.formData && pagePoint === undefined) {
147
- var _submissionData$formS;
148
147
  const submissionData = _utils.default.Format.form({
149
148
  pages,
150
149
  components
151
150
  }, _objectSpread(_objectSpread({}, data), formState.page.formData), _models.EventTypes.SUBMIT);
152
- if (submissionData !== null && submissionData !== void 0 && (_submissionData$formS = submissionData.formStatus) !== null && _submissionData$formS !== void 0 && _submissionData$formS.taskPage) {
153
- const object = submissionData.formStatus.tasks;
154
- Object.keys(object).forEach(key => {
155
- const value = object[key];
156
- if (value.currentPage && !value.complete) {
157
- delete object[key].currentPage;
158
- }
159
- });
160
- delete submissionData.formStatus.taskPage;
161
- }
162
151
  setData(submissionData);
163
152
  }
164
153
  };
@@ -0,0 +1,200 @@
1
+ {
2
+ "name": "cop-addABorderEvent",
3
+ "title": "Add a border event",
4
+ "type": "form",
5
+ "components":[],
6
+ "pages": [
7
+ {
8
+ "id": "vehicle-owner-details",
9
+ "name": "vehicle-owner-details",
10
+ "title": "Vehicle owner details",
11
+ "show_when": [
12
+ {
13
+ "field": "driverOwnVehicle",
14
+ "op": "=",
15
+ "value": "noSomeoneElseOwns"
16
+ },
17
+ {
18
+ "field": "modeOfTransport.id",
19
+ "op": "eq",
20
+ "value": 9
21
+ },
22
+ {
23
+ "field": "whatHappened",
24
+ "op": "in",
25
+ "values": [
26
+ "roroItems",
27
+ "sams",
28
+ "peopleHidingTrailer",
29
+ "peopleHidingVehicle",
30
+ "unsecuredGoods"
31
+ ]
32
+ }
33
+ ],
34
+ "components": [
35
+ {
36
+ "id": "otherVehicleOwner",
37
+ "fieldId": "otherVehicleOwner",
38
+ "type": "container",
39
+ "show_on_cya": true,
40
+ "components": [
41
+ {
42
+ "id": "fullName",
43
+ "fieldId": "fullName",
44
+ "type": "text",
45
+ "label": "Full name",
46
+ "required": true,
47
+ "custom_errors": [
48
+ {
49
+ "type": "required",
50
+ "message": "Enter the full name of the owner"
51
+ }
52
+ ],
53
+ "additionalValidation": [
54
+ {
55
+ "function": "mustBeShorterThan",
56
+ "value": 256,
57
+ "message": "Full name must be 255 characters or less"
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ "id": "vehicleOwnerAddress",
63
+ "fieldId": "vehicleOwnerAddress",
64
+ "label": "Do you have an address for the owner?",
65
+ "cya_label": "Do you have an address for the owner?",
66
+ "type": "radios",
67
+ "required": true,
68
+ "custom_errors": [
69
+ {
70
+ "type": "required",
71
+ "message": "Select whether you have an address for the owner"
72
+ }
73
+ ],
74
+ "data": {
75
+ "options": [
76
+ {
77
+ "label": "Yes - a UK address",
78
+ "value": "Yes",
79
+ "nested": [
80
+ {
81
+ "id": "ukAddress",
82
+ "fieldId": "ukAddress",
83
+ "hint": "Enter part of the address and select a result",
84
+ "type": "addressLookup",
85
+ "label": "Search UK address",
86
+ "cya_label": "Address",
87
+ "required": true,
88
+ "isEditable": true
89
+ }
90
+ ]
91
+ },
92
+ {
93
+ "label": "Yes - a non-UK address",
94
+ "value": "no",
95
+ "nested": [
96
+ {
97
+ "id": "nonUkAddressText",
98
+ "fieldId": "nonUkAddressText",
99
+ "type": "textarea",
100
+ "label": "International address",
101
+ "cya_label": "Address",
102
+ "required": true,
103
+ "custom_errors": [
104
+ {
105
+ "type": "required",
106
+ "message": "Enter an international address"
107
+ }
108
+ ],
109
+ "additionalValidation": [
110
+ {
111
+ "function": "mustBeShorterThan",
112
+ "value": "1001",
113
+ "message": "International address must be 1000 characters or less"
114
+ }
115
+ ]
116
+ },
117
+ {
118
+ "id": "country",
119
+ "fieldId": "country",
120
+ "type": "autocomplete",
121
+ "showAllValues": true,
122
+ "label": "Country",
123
+ "required": true,
124
+ "custom_errors": [
125
+ {
126
+ "type": "required",
127
+ "message": "Select a country"
128
+ }
129
+ ],
130
+ "item": {
131
+ "value": "id",
132
+ "label": "name",
133
+ "format": "${iso31661alpha3} - ${name}"
134
+ },
135
+ "data": {
136
+ "url": "refdata/v2/entities/country?sort=name.asc&mode=dataOnly&validDateTime=true&filter=id=neq.234&select=id,name,iso31661alpha3"
137
+ }
138
+ }
139
+ ]
140
+ },
141
+ {
142
+ "label": "No",
143
+ "value": "false"
144
+ }
145
+ ]
146
+ }
147
+ },
148
+ {
149
+ "id": "telephoneNumber",
150
+ "fieldId": "telephoneNumber",
151
+ "type": "text",
152
+ "label": "Telephone number",
153
+ "hint": "For international numbers include the country code",
154
+ "pattern": "^[\\+]?[\\s\\d]+$",
155
+ "additionalValidation": [
156
+ {
157
+ "function": "mustBeShorterThan",
158
+ "value": 16,
159
+ "message": "Telephone number must be 15 characters or less"
160
+ }
161
+ ],
162
+ "custom_errors": [
163
+ {
164
+ "type": "pattern",
165
+ "message": "Telephone number can only contain a + symbol at the start and numbers"
166
+ }
167
+ ]
168
+ },
169
+ {
170
+ "id": "emailAddress",
171
+ "fieldId": "emailAddress",
172
+ "type": "text",
173
+ "label": "Email address",
174
+ "additionalValidation": [
175
+ {
176
+ "function": "mustBeShorterThan",
177
+ "value": 101,
178
+ "message": "Email address must be 100 characters or less"
179
+ }
180
+ ]
181
+ }
182
+ ]
183
+ }
184
+ ],
185
+ "actions": [
186
+ {
187
+ "type": "saveAndContinue",
188
+ "page": "vehicle-details-cya"
189
+ },
190
+ "saveAndReturn"
191
+ ],
192
+ "cya_link": {
193
+ "page": "vehicle-owner-details",
194
+ "singleChangeLink": true,
195
+ "aria_suffix": "Vehicle owner details"
196
+ }
197
+ }
198
+ ]
199
+ }
200
+
@@ -0,0 +1,45 @@
1
+ {
2
+ "id": "8d4674c4-1adb-11f0-a7ba-620783054865",
3
+ "businessKey": "DEV-20250416-1142",
4
+ "port": {
5
+ "id": 1639,
6
+ "name": "Dover",
7
+ "sea": true,
8
+ "air": false,
9
+ "land": false,
10
+ "rail": false,
11
+ "countryid": 234,
12
+ "iata": null,
13
+ "value": "1639",
14
+ "label": "Dover",
15
+ "hint": ""
16
+ },
17
+ "modeOfTransport": {
18
+ "id": 9,
19
+ "mode": "RoRo Tourist",
20
+ "modecode": "rorotour",
21
+ "crossingtype": [
22
+ "sea"
23
+ ],
24
+ "value": "RoRo Tourist",
25
+ "label": "RoRo Tourist"
26
+ },
27
+ "whatHappened": "peopleHidingVehicle",
28
+ "formInstanceId": "5b3b4c37-df21-4e61-bffe-3034c55d4429",
29
+ "driverOwnVehicle": "noSomeoneElseOwns",
30
+ "otherVehicleOwner": {
31
+ "vehicleOwnerAddress": "no",
32
+ "fullName": "Robert Flecher",
33
+ "telephoneNumber": "07835442994",
34
+ "emailAddress": "robrotheram@gmail.com",
35
+ "nonUkAddressText": "Dickinson St",
36
+ "country": {
37
+ "id": 211,
38
+ "name": "Sudan (the)",
39
+ "iso31661alpha3": "SDN",
40
+ "value": "211",
41
+ "label": "Sudan (the)",
42
+ "hint": ""
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "id": "8d4674c4-1adb-11f0-a7ba-620783054865",
3
+ "businessKey": "DEV-20250416-1142",
4
+ "port": {
5
+ "id": 1639,
6
+ "name": "Dover",
7
+ "sea": true,
8
+ "air": false,
9
+ "land": false,
10
+ "rail": false,
11
+ "countryid": 234,
12
+ "iata": null,
13
+ "value": "1639",
14
+ "label": "Dover",
15
+ "hint": ""
16
+ },
17
+ "modeOfTransport": {
18
+ "id": 9,
19
+ "mode": "RoRo Tourist",
20
+ "modecode": "rorotour",
21
+ "crossingtype": [
22
+ "sea"
23
+ ],
24
+ "value": "RoRo Tourist",
25
+ "label": "RoRo Tourist"
26
+ },
27
+ "whatHappened": "peopleHidingVehicle",
28
+ "formInstanceId": "5b3b4c37-df21-4e61-bffe-3034c55d4429",
29
+ "driverOwnVehicle": "noSomeoneElseOwns",
30
+ "otherVehicleOwner": {
31
+ "vehicleOwnerAddress": "no",
32
+ "fullName": "Robert Flecher",
33
+ "telephoneNumber": "07835442994",
34
+ "emailAddress": "robrotheram@gmail.com",
35
+ "nonUkAddressText": "Dickinson St",
36
+ "country": {
37
+ "id": 211,
38
+ "name": "Sudan (the)",
39
+ "iso31661alpha3": "SDN",
40
+ "value": "211",
41
+ "label": "Sudan (the)",
42
+ "hint": ""
43
+ }
44
+ }
45
+ }
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _mergeCollectionPages = _interopRequireDefault(require("../../../utils/CollectionPage/mergeCollectionPages"));
8
8
  var Utils = _interopRequireWildcard(require("./clearOutUncompletedRoutesUtils"));
9
9
  var _optionIsSelected = _interopRequireDefault(require("../../../utils/Component/optionIsSelected"));
10
+ var _getSourceData = _interopRequireDefault(require("../../../utils/Data/getSourceData"));
10
11
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
12
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -67,7 +68,8 @@ const createComponentMapsFromForm = (condensedPages, componentByIdMap, component
67
68
  var _component$data2;
68
69
  component === null || component === void 0 || (_component$data2 = component.data) === null || _component$data2 === void 0 || (_component$data2 = _component$data2.options) === null || _component$data2 === void 0 || _component$data2.forEach(option => {
69
70
  if (option.nested) {
70
- if (!(0, _optionIsSelected.default)(formData[component.id], option)) {
71
+ // in container need to use the JPath for the data since the field that the component is looking at is nested in the container.
72
+ if (!(0, _optionIsSelected.default)((0, _getSourceData.default)(formData, path), option)) {
71
73
  option.nested.forEach(nestedComponent => {
72
74
  // delete hidden nested question payload items when the parent option is not selected
73
75
  Utils.deleteNodeByPath(formData, Utils.getNestedQuestionPath(path, nestedComponent.fieldId));
@@ -93,6 +93,9 @@ var _copAirpaxRemovePhotosAfter = _interopRequireDefault(require("../clear-uncom
93
93
  var _copAirpaxChangeWhatHappenedBefore = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/cop-airpax-change-what-happened-before.json"));
94
94
  var _copAirpaxChangeWhatHappenedAfter = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/cop-airpax-change-what-happened-after.json"));
95
95
  var _copAirpaxCarrier = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/cop-airpax-carrier.json"));
96
+ var _formPageNestedRadioComponent = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/forms/form-page-nested-radio-component.json"));
97
+ var _dataPageNestedRadioComponent = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/input/data-page-nested-radio-component.json"));
98
+ var _dataPageNestedRadioComponentRemoved = _interopRequireDefault(require("../clear-uncompleted-routes/test-data/output/data-page-nested-radio-component-removed.json"));
96
99
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
97
100
  // Hidden component
98
101
 
@@ -160,6 +163,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
160
163
 
161
164
  // Carrier not removed
162
165
 
166
+ // Form with no componets but componet listed in page.
167
+
163
168
  describe('FormRenderer', () => {
164
169
  describe('helpers', () => {
165
170
  describe('clearOutUncompletedRoutes', () => {
@@ -365,6 +370,12 @@ describe('FormRenderer', () => {
365
370
  const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
366
371
  expect(result).toEqual(_copAirpaxChangeWhatHappenedAfter.default);
367
372
  });
373
+ it('should handle nested option in container componet defined in the page.', () => {
374
+ const submissionData = JSON.parse(JSON.stringify(_dataPageNestedRadioComponent.default));
375
+ const form = JSON.parse(JSON.stringify(_formPageNestedRadioComponent.default));
376
+ const result = _index.default.clearOutUncompletedRoutes(form, submissionData);
377
+ expect(result).toEqual(_dataPageNestedRadioComponentRemoved.default);
378
+ });
368
379
  });
369
380
  });
370
381
  });
@@ -30,12 +30,6 @@ const getCurrentTaskState = function (_ref) {
30
30
  if (currentPage) {
31
31
  return _models.TaskStates.TYPES.IN_PROGRESS;
32
32
  }
33
- // If the user has clicked on the back link (see FormRenderer.jsx window.onpopstate event handler)
34
- // the task will be incomplete and the currentPage deleted
35
- // and the task state should be recognised as 'In progress'.
36
- if (complete !== undefined && !complete && currentPage === undefined) {
37
- return _models.TaskStates.TYPES.IN_PROGRESS;
38
- }
39
33
  return defaultState;
40
34
  };
41
35
 
@@ -115,26 +115,6 @@ describe('components.FormRenderer.helpers.getUpdatedSectionStates', () => {
115
115
  expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.IN_PROGRESS);
116
116
  expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
117
117
  });
118
- it("should set tasks to '".concat(_models.TaskStates.TYPES.IN_PROGRESS, "' if they have no current page and are not complete"), () => {
119
- const SECTIONS = [{
120
- name: 'Add event details',
121
- tasks: [{
122
- name: 'Date, location and mode details',
123
- pages: ['eventDate', 'eventMode']
124
- }, {
125
- name: 'Officer and agency details',
126
- pages: ['officeDetails']
127
- }]
128
- }];
129
- const TASKS = {
130
- 'Date, location and mode details': {
131
- complete: false
132
- }
133
- };
134
- const updatedSections = (0, _getUpdatedSectionStates.default)(SECTIONS, TASKS);
135
- expect(updatedSections[0].tasks[0].state).toEqual(_models.TaskStates.TYPES.IN_PROGRESS);
136
- expect(updatedSections[0].tasks[1].state).toEqual(_models.TaskStates.TYPES.CANNOT_START_YET);
137
- });
138
118
  it("should set the status of any tasks in a section with a failed show_when to '".concat(_models.TaskStates.TYPES.SKIPPED, "'"), () => {
139
119
  const SECTIONS = [{
140
120
  name: 'Add event details',
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "6.15.8-charlie",
3
+ "version": "6.15.8",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",
7
7
  "test": "react-scripts test",
8
8
  "test:coverage": "yarn test --coverage --watchAll=false",
9
9
  "lint": "eslint --ext .js,.jsx src",
10
+ "lint:fix": "eslint --ext .js,.jsx src --fix",
10
11
  "storybook:start": "start-storybook --docs -s src/assets --no-manager-cache -p 6007",
11
12
  "storybook:build": "build-storybook --docs -s src/assets",
12
13
  "storybook": "yarn storybook:start",