@ukhomeoffice/cop-react-form-renderer 6.15.11-alpha → 6.15.12-alpha

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.
@@ -76,6 +76,12 @@ const FormComponent = _ref => {
76
76
 
77
77
  // eslint-disable-next-line no-param-reassign
78
78
  target = (0, _helpers.addLabel)(target, component, data);
79
+ if (component.type === _models.ComponentTypes.SELECT && target.value === '') {
80
+ // eslint-disable-next-line no-param-reassign
81
+ target.value = null;
82
+ // eslint-disable-next-line no-param-reassign
83
+ target.label = null;
84
+ }
79
85
  onChange({
80
86
  target
81
87
  });
@@ -10,13 +10,14 @@ exports.default = void 0;
10
10
  * @returns The updated target.
11
11
  */
12
12
  const addLabel = (paramTarget, component, data) => {
13
+ var _target$value;
13
14
  const target = paramTarget;
14
15
  // target.value can be an object in which case use value in object attribute
15
- const value = typeof target.value === 'object' ? target.value.value : target.value;
16
+ const value = typeof target.value === 'object' ? (_target$value = target.value) === null || _target$value === void 0 ? void 0 : _target$value.value : target.value;
16
17
  // find the reference data item using the value
17
18
  const item = data.find(e => String(e.id) === value);
18
19
  // if item is null it means that the target.value can be used as a label otherwise use item.label
19
- target.label = item === undefined ? target.value : item.label;
20
+ target.label = item === undefined ? target.value || '' : item.label;
20
21
  target.component = component.cya_label;
21
22
  return target;
22
23
  };
@@ -19,6 +19,8 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
19
19
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
20
20
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
21
21
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
22
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
23
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
22
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
23
25
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } // Global imports
24
26
  // Local imports.
@@ -67,20 +69,31 @@ const FormPage = _ref => {
67
69
  target
68
70
  } = _ref2;
69
71
  const formPage = page;
70
- if (target.value == null) {
72
+ const {
73
+ value
74
+ } = target;
75
+ if (!value) {
71
76
  delete formPage.formData[target.name];
72
77
  setPatch(prev => {
73
- const data = prev;
74
- return delete data[target.name];
78
+ const _target$name = target.name,
79
+ {
80
+ [_target$name]: removedValue
81
+ } = prev,
82
+ newState = _objectWithoutProperties(prev, [_target$name].map(_toPropertyKey));
83
+ return newState;
75
84
  });
76
85
  setPatchLabel(prev => {
77
- const data = prev;
78
- return delete data[target.component];
86
+ const _target$component = target.component,
87
+ {
88
+ [_target$component]: removedValue
89
+ } = prev,
90
+ newState = _objectWithoutProperties(prev, [_target$component].map(_toPropertyKey));
91
+ return newState;
79
92
  });
80
93
  } else {
81
- formPage.formData[target.name] = target.value;
94
+ formPage.formData[target.name] = value;
82
95
  setPatch(prev => _objectSpread(_objectSpread({}, prev), {}, {
83
- [target.name]: target.value
96
+ [target.name]: value
84
97
  }));
85
98
  setPatchLabel(prev => _objectSpread(_objectSpread({}, prev), {}, {
86
99
  [target.component]: target.label
@@ -337,5 +337,58 @@ describe('components.FormPage', () => {
337
337
  }));
338
338
  expect(ON_ACTION_CALLS.length).toEqual(0);
339
339
  });
340
+ it('removed field from the form data when the value is set to null', () => {
341
+ const AUTOCOMPLETE = {
342
+ id: 'autocomplete',
343
+ fieldId: 'autocomplete',
344
+ label: 'autocomplete',
345
+ hint: '',
346
+ type: 'autocomplete',
347
+ required: true,
348
+ source: [{
349
+ id: 'a',
350
+ name: 'apple'
351
+ }, {
352
+ id: 'b',
353
+ name: 'banana'
354
+ }, {
355
+ id: 'c',
356
+ name: 'cherry'
357
+ }, {
358
+ id: 'd',
359
+ name: 'DURIAN'
360
+ }],
361
+ disabled: false
362
+ };
363
+ const page = {
364
+ id: 'page1',
365
+ title: 'Page title',
366
+ label: 'Page label',
367
+ components: [AUTOCOMPLETE],
368
+ formData: {
369
+ autocomplete: 'autocomplete value example'
370
+ },
371
+ actions: []
372
+ };
373
+ const onChangeMock = jest.fn();
374
+ const {
375
+ getByLabelText
376
+ } = (0, _setupTests.renderWithValidation)(/*#__PURE__*/_react2.default.createElement(_FormPage.default, {
377
+ page: page,
378
+ fromTarget: true,
379
+ onAction: onChangeMock,
380
+ onChange: onChangeMock
381
+ }));
382
+ const input = getByLabelText('autocomplete');
383
+ _react.fireEvent.change(input, {
384
+ target: {
385
+ name: 'autocomplete',
386
+ value: '',
387
+ component: 'autocomplete'
388
+ }
389
+ });
390
+ const updatedState = onChangeMock.mock.calls.pop()[0];
391
+ expect(updatedState.autocomplete).toBeUndefined();
392
+ });
340
393
  });
341
394
  });
@@ -189,6 +189,17 @@ const InternalFormRenderer = _ref2 => {
189
189
  setFormState(_helpers.default.getFormState(pageId, pages, hub));
190
190
  }, [pages, hub, pageId, setFormState, type, goingBack, data, formState.page]);
191
191
 
192
+ // page rendered page
193
+ (0, _react.useEffect)(() => {
194
+ if (document) {
195
+ const element = document.getElementsByTagName("h1")[0];
196
+ if (element) {
197
+ element.setAttribute("tabIndex", "-1");
198
+ element.focus();
199
+ }
200
+ }
201
+ }, [formState.page]);
202
+
192
203
  // Call the onFormLoad hook just when this component first renders.
193
204
  (0, _react.useEffect)(() => {
194
205
  setPagePoint(undefined);
@@ -0,0 +1,445 @@
1
+ {
2
+ "cya": {
3
+ "actions": [
4
+ {
5
+ "type": "submit",
6
+ "label": "Submit",
7
+ "validate": true
8
+ }
9
+ ],
10
+ "confirm": [
11
+ {
12
+ "title": "Task kept with NCC",
13
+ "message": [
14
+ "<h2 class='govuk-heading-m'>What happens next</h2>",
15
+ "<p class='govuk-body'>Review the task by ${reviewTimeP} on ${reviewDateP}.</p>",
16
+ "<p class='govuk-body'>To view the task, go to <a href='/tms/open-tasks'>open NCC tasks</a>. You can track updates in the task's timeline.</p>",
17
+ "<p class='govuk-body'><a href='/'>Go to homepage</a></p>",
18
+ "<p class='govuk-body'><a href='https://lssiprod.service-now.com/ess?id=take_survey&type_id=e0e2125b1bdd1110f8655946464bcbf7'>What do you think of this service?</a></p>"
19
+ ],
20
+ "show_when": [
21
+ {
22
+ "op": "=",
23
+ "field": "assignWhere",
24
+ "value": "NCC"
25
+ }
26
+ ]
27
+ },
28
+ {
29
+ "title": "Task assigned to RCC",
30
+ "message": [
31
+ "<h2 class='govuk-heading-m'>What happens next</h2>",
32
+ "<p>This task will automatically close at 23:59 on ${autoClose} - the day after the event date.</p>",
33
+ "<p>To view the task, go to <a href='/tms/open-tasks'>open NCC tasks</a>. You can track updates in the task's timeline.</p>",
34
+ "<p>You can only work on the task when it is assigned to NCC.</p>",
35
+ "<p><a href='/'>Go to homepage</a></p>",
36
+ "<p><a href='https://lssiprod.service-now.com/ess?id=take_survey&type_id=e0e2125b1bdd1110f8655946464bcbf7'>What do you think of this service?</a></p>"
37
+ ],
38
+ "show_when": [
39
+ {
40
+ "type": "and",
41
+ "conditions": [
42
+ {
43
+ "op": "=",
44
+ "field": "assignWhere",
45
+ "value": "RCC"
46
+ },
47
+ {
48
+ "op": "=",
49
+ "field": "responseNeeded",
50
+ "value": "No"
51
+ }
52
+ ]
53
+ }
54
+ ]
55
+ },
56
+ {
57
+ "title": "Task assigned to RCC",
58
+ "message": [
59
+ "<h2 class='govuk-heading-m'>What happens next</h2>",
60
+ "<p class='govuk-body'>You set a review date of ${reviewTimeP} on ${reviewDateP}.</p>",
61
+ "<p class='govuk-body'>To view the task, go to <a href='/tms/open-tasks'>open NCC tasks</a>. You can track updates in the task's timeline.</p>",
62
+ "<p class='govuk-body'>You can only work on the task when it is assigned to NCC.</p>",
63
+ "<p class='govuk-body'><a href='/'>Go to homepage</a></p>",
64
+ "<p class='govuk-body'><a href='https://lssiprod.service-now.com/ess?id=take_survey&type_id=e0e2125b1bdd1110f8655946464bcbf7'>What do you think of this service?</a></p>"
65
+ ],
66
+ "show_when": [
67
+ {
68
+ "type": "and",
69
+ "conditions": [
70
+ {
71
+ "op": "=",
72
+ "field": "assignWhere",
73
+ "value": "RCC"
74
+ },
75
+ {
76
+ "op": "=",
77
+ "field": "responseNeeded",
78
+ "value": "Yes"
79
+ }
80
+ ]
81
+ }
82
+ ]
83
+ },
84
+ {
85
+ "title": "Task assigned to RCC",
86
+ "message": [
87
+ "<h2 class='govuk-heading-m'>What happens next</h2>",
88
+ "<p class='govuk-body'>RCC will review this task.</p>",
89
+ "<p class='govuk-body'><a href='/'>Go to homepage</a></p>",
90
+ "<p class='govuk-body'><a href='https://lssiprod.service-now.com/ess?id=take_survey&type_id=e0e2125b1bdd1110f8655946464bcbf7'>What do you think of this service?</a></p>"
91
+ ],
92
+ "show_when": [
93
+ {
94
+ "type": "and",
95
+ "conditions": [
96
+ {
97
+ "op": "!includes",
98
+ "field": "keycloakContext.groups",
99
+ "value": "/BFNCC"
100
+ }
101
+ ]
102
+ }
103
+ ]
104
+ }
105
+ ],
106
+ "insertDateTime": true
107
+ },
108
+ "name": "cop-reassign-task-to-rcc",
109
+ "type": "cya",
110
+ "pages": [
111
+ {
112
+ "id": "assignTask",
113
+ "name": "assignTask",
114
+ "title": "Assign Task",
115
+ "actions": [
116
+ {
117
+ "page": "assignTaskToRCC",
118
+ "type": "next",
119
+ "label": "Continue",
120
+ "validate": true,
121
+ "show_when": {
122
+ "type": "or",
123
+ "conditions": [
124
+ {
125
+ "op": "=",
126
+ "field": "assignWhere",
127
+ "value": "RCC"
128
+ }
129
+ ]
130
+ }
131
+ },
132
+ {
133
+ "page": "reviewDateAndTime",
134
+ "type": "saveAndNavigate",
135
+ "label": "Continue",
136
+ "validate": true,
137
+ "show_when": {
138
+ "type": "or",
139
+ "conditions": [
140
+ {
141
+ "op": "!=",
142
+ "field": "assignWhere",
143
+ "value": "RCC"
144
+ }
145
+ ]
146
+ }
147
+ }
148
+ ],
149
+ "cya_link": {},
150
+ "show_when": [
151
+ {
152
+ "op": "includes",
153
+ "field": "keycloakContext.groups",
154
+ "value": "/BFNCC"
155
+ }
156
+ ],
157
+ "components": [
158
+ {
159
+ "use": "assignWhere"
160
+ }
161
+ ]
162
+ },
163
+ {
164
+ "id": "assignTaskToRCC",
165
+ "name": "assignTaskToRCC",
166
+ "title": "Assign task to RCC",
167
+ "actions": [
168
+ {
169
+ "type": "next",
170
+ "label": "Continue",
171
+ "validate": true
172
+ }
173
+ ],
174
+ "cya_link": {},
175
+ "show_when": {
176
+ "conditions": [
177
+ {
178
+ "op": "=",
179
+ "field": "assignWhere",
180
+ "value": "RCC"
181
+ }
182
+ ]
183
+ },
184
+ "components": [
185
+ {
186
+ "use": "regionalCommandCentre",
187
+ "show_when": {
188
+ "type": "and",
189
+ "conditions": [
190
+ {
191
+ "op": "!=",
192
+ "field": "definitionKey",
193
+ "value": "cop-variance-breach-v2"
194
+ }
195
+ ]
196
+ }
197
+ },
198
+ {
199
+ "use": "regionalCommandCentreDisplay",
200
+ "show_when": {
201
+ "type": "or",
202
+ "conditions": [
203
+ {
204
+ "op": "=",
205
+ "field": "definitionKey",
206
+ "value": "cop-variance-breach-v2"
207
+ }
208
+ ]
209
+ }
210
+ },
211
+ {
212
+ "use": "responseNeeded",
213
+ "show_when": {
214
+ "type": "or",
215
+ "conditions": [
216
+ {
217
+ "op": "includes",
218
+ "field": "keycloakContext.groups",
219
+ "value": "/BFNCC"
220
+ }
221
+ ]
222
+ }
223
+ },
224
+ {
225
+ "use": "assignMessage"
226
+ }
227
+ ],
228
+ "operations": [
229
+ {
230
+ "field": "reviewDateTime",
231
+ "function": "deleteValueInFormData",
232
+ "run_when": {
233
+ "field": "responseNeeded",
234
+ "condition": "changes"
235
+ },
236
+ "component": " "
237
+ }
238
+ ]
239
+ },
240
+ {
241
+ "id": "reviewDateAndTime",
242
+ "name": "reviewDateAndTime",
243
+ "title": "Set a review date and time",
244
+ "actions": [
245
+ {
246
+ "type": "next",
247
+ "label": "Continue",
248
+ "validate": true
249
+ }
250
+ ],
251
+ "cya_link": {},
252
+ "show_when": [
253
+ {
254
+ "type": "or",
255
+ "conditions": [
256
+ {
257
+ "op": "=",
258
+ "field": "responseNeeded",
259
+ "value": "Yes"
260
+ },
261
+ {
262
+ "op": "=",
263
+ "field": "assignWhere",
264
+ "value": "NCC"
265
+ }
266
+ ]
267
+ }
268
+ ],
269
+ "components": [
270
+ {
271
+ "use": "reviewDateTime"
272
+ },
273
+ {
274
+ "use": "responseNeeded",
275
+ "label": "",
276
+ "value": "Yes",
277
+ "hidden": true,
278
+ "required": true,
279
+ "show_on_cya": false,
280
+ "defaultValue": "Yes"
281
+ }
282
+ ]
283
+ }
284
+ ],
285
+ "title": "Assign task to RCC",
286
+ "components": [
287
+ {
288
+ "id": "assignMessage",
289
+ "type": "textarea",
290
+ "label": "Message",
291
+ "fieldId": "assignMessage",
292
+ "cya_link": {},
293
+ "required": true,
294
+ "custom_errors": [
295
+ {
296
+ "type": "required",
297
+ "message": "Enter a message"
298
+ }
299
+ ]
300
+ },
301
+ {
302
+ "id": "assignWhere",
303
+ "data": {
304
+ "options": [
305
+ {
306
+ "hint": "Set a review date and time.",
307
+ "label": "Keep task with NCC",
308
+ "value": "NCC"
309
+ },
310
+ {
311
+ "hint": "Either set a review date and time or set the task to automatically close.",
312
+ "label": "Assign task to RCC",
313
+ "value": "RCC"
314
+ }
315
+ ]
316
+ },
317
+ "type": "radios",
318
+ "label": " ",
319
+ "fieldId": "assignWhere",
320
+ "preserveInPayload": true,
321
+ "required": true,
322
+ "cya_label": "Assign task",
323
+ "custom_errors": [
324
+ {
325
+ "type": "required",
326
+ "message": "Select where you want to assign this task"
327
+ }
328
+ ],
329
+ "showAllValues": "true"
330
+ },
331
+ {
332
+ "id": "regionalCommandCentre",
333
+ "data": {
334
+ "url": "${environmentContext.referenceDataUrl}/v2/entities/branch?mode=dataOnly&filter=directorateid.eq=2&filter=code=in.(BFSEEU,BFHROW,BFSOUTH,BFNORTH,BFCENT)"
335
+ },
336
+ "hint": "Type to search",
337
+ "item": {
338
+ "label": "name",
339
+ "value": "id"
340
+ },
341
+ "type": "autocomplete",
342
+ "label": "Regional Command Centre",
343
+ "fieldId": "regionalCommandCentre",
344
+ "required": true,
345
+ "cya_label": "RCC",
346
+ "custom_errors": [
347
+ {
348
+ "type": "required",
349
+ "message": "Select a Regional Command Centre"
350
+ }
351
+ ],
352
+ "showAllValues": true
353
+ },
354
+ {
355
+ "id": "regionalCommandCentreDisplay",
356
+ "data": {
357
+ "url": "${environmentContext.referenceDataUrl}/v2/entities/branch?mode=dataOnly&filter=directorateid.eq=2&filter=code=in.(BFSEEU,BFHROW,BFSOUTH,BFNORTH,BFCENT)"
358
+ },
359
+ "item": {
360
+ "label": "name",
361
+ "value": "id"
362
+ },
363
+ "type": "autocomplete",
364
+ "label": "Regional Command Centre",
365
+ "fieldId": "regionalCommandCentre",
366
+ "disabled": true,
367
+ "required": true,
368
+ "cya_label": "RCC",
369
+ "showAllValues": true
370
+ },
371
+ {
372
+ "id": "reviewDateTime",
373
+ "type": "container",
374
+ "label": " ",
375
+ "fieldId": "reviewDateTime",
376
+ "required": true,
377
+ "components": [
378
+ {
379
+ "type": "html",
380
+ "content": "The review date and time will display on the open NCC tasks screen."
381
+ },
382
+ {
383
+ "id": "reviewDate",
384
+ "hint": "For example, 20 2 2023.",
385
+ "type": "date",
386
+ "label": "Review date",
387
+ "fieldId": "reviewDate",
388
+ "cya_link": {},
389
+ "required": true,
390
+ "custom_errors": [
391
+ {
392
+ "type": "required",
393
+ "message": "Enter a review date"
394
+ }
395
+ ],
396
+ "additionalValidation": [
397
+ {
398
+ "message": "Review date must be today or in the future",
399
+ "function": "mustBeInTheFuture",
400
+ "todayAllowed": true
401
+ }
402
+ ]
403
+ },
404
+ {
405
+ "id": "reviewTime",
406
+ "hint": "Use 24-hour. For example, 19:45.",
407
+ "type": "time",
408
+ "label": "Review time",
409
+ "fieldId": "reviewTime",
410
+ "cya_link": {},
411
+ "required": true,
412
+ "custom_errors": [
413
+ {
414
+ "type": "required",
415
+ "message": "Enter a review time"
416
+ }
417
+ ]
418
+ }
419
+ ]
420
+ },
421
+ {
422
+ "id": "responseNeeded",
423
+ "data": {
424
+ "options": [
425
+ {
426
+ "hint": "Set a review date for the task.",
427
+ "label": "Yes",
428
+ "value": "Yes"
429
+ },
430
+ {
431
+ "hint": "The task will automatically close at 23:59 on ${autoClose} - the day after the event date.",
432
+ "label": "No",
433
+ "value": "No"
434
+ }
435
+ ]
436
+ },
437
+ "type": "radios",
438
+ "label": "Do you need a response?",
439
+ "fieldId": "responseNeeded",
440
+ "required": true,
441
+ "showAllValues": "true"
442
+ }
443
+ ],
444
+ "version": "7b941ec0bb281e2b93ba32058b81e1a88f0f0a9a"
445
+ }