@ukhomeoffice/cop-react-form-renderer 3.11.1-alpha → 3.15.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.
@@ -67,7 +67,9 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
67
67
  hide_title = _ref.hide_title,
68
68
  summaryListClassModifiers = _ref.summaryListClassModifiers,
69
69
  noChangeAction = _ref.noChangeAction,
70
- groups = _ref.groups;
70
+ groups = _ref.groups,
71
+ sections = _ref.sections,
72
+ type = _ref.type;
71
73
 
72
74
  var _useState = (0, _react.useState)([]),
73
75
  _useState2 = _slicedToArray(_useState, 2),
@@ -145,7 +147,31 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
145
147
  key: "heading"
146
148
  }, title), errors && errors.length > 0 && /*#__PURE__*/_react.default.createElement(_copReactComponents.ErrorSummary, {
147
149
  errors: errors
148
- }), pages && pages.map(function (page, pageIndex, array) {
150
+ }), type === 'task-list-cya' && pages.length > 0 && sections && sections.map(function (section) {
151
+ return section.tasks.map(function (task) {
152
+ var filterPages = pages.filter(function (page) {
153
+ return task.pages.some(function (p) {
154
+ return p === page.name;
155
+ });
156
+ });
157
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h3", {
158
+ className: "govuk-heading-m govuk-!-margin-top-8 govuk-!-margin-bottom-0"
159
+ }, filterPages.length > 0 && task.name), filterPages.map(function (page, pageIndex, array) {
160
+ var hideActionButtons;
161
+ isGroup(page.id) ? hideActionButtons = true : hideActionButtons = noChangeAction;
162
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, {
163
+ key: pageIndex
164
+ }, !hide_page_titles && page.title && !isGroup(page.id) && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("h4", {
165
+ className: "govuk-heading-m govuk-!-margin-top-6 govuk-!-margin-bottom-5"
166
+ }, _utils.default.interpolateString(page.title, page.formData))), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
167
+ rows: page.rows,
168
+ classModifiers: summaryListClassModifiers,
169
+ noChangeAction: hideActionButtons,
170
+ isGroup: isGroup(page.id)
171
+ }));
172
+ }));
173
+ });
174
+ }), type !== 'task-list-cya' && pages && pages.map(function (page, pageIndex, array) {
149
175
  var pageMarginBottom = isLastPage(pageIndex) || isGroup(array[pageIndex].id) || isGroup(array[pageIndex + 1].id) ? DEFAULT_MARGIN_BOTTOM : listMarginBottom;
150
176
  var currentGroup;
151
177
  isGroup(page.id) && (currentGroup = getGroupForPage(page.id));
@@ -181,7 +207,16 @@ CheckYourAnswers.propTypes = {
181
207
  hide_actions: _propTypes.default.bool,
182
208
  hide_title: _propTypes.default.bool,
183
209
  summaryListClassModifiers: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
184
- noChangeAction: _propTypes.default.bool
210
+ noChangeAction: _propTypes.default.bool,
211
+ sections: _propTypes.default.arrayOf(_propTypes.default.shape({
212
+ name: _propTypes.default.string.isRequired,
213
+ tasks: _propTypes.default.arrayOf(_propTypes.default.shape({
214
+ name: _propTypes.default.string.isRequired,
215
+ pages: _propTypes.default.array.isRequired,
216
+ state: _propTypes.default.string.isRequired
217
+ })).isRequired
218
+ })),
219
+ type: _propTypes.default.string
185
220
  };
186
221
  CheckYourAnswers.defaultProps = {
187
222
  title: DEFAULT_TITLE,
@@ -189,7 +224,8 @@ CheckYourAnswers.defaultProps = {
189
224
  hide_actions: false,
190
225
  hide_title: false,
191
226
  summaryListClassModifiers: null,
192
- noChangeAction: false
227
+ noChangeAction: false,
228
+ sections: []
193
229
  };
194
230
  var _default = CheckYourAnswers;
195
231
  exports.default = _default;
@@ -1,21 +1,15 @@
1
1
  <!-- Global imports -->
2
2
 
3
3
  import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
4
- import {
5
- Details,
6
- Heading,
7
- Link,
8
- Tag,
9
- } from '@ukhomeoffice/cop-react-components';
4
+ import { Details, Heading, Link, Tag } from '@ukhomeoffice/cop-react-components';
10
5
  import withMock from 'storybook-addon-mock';
11
6
 
12
7
  <!-- Local imports -->
13
-
8
+ import { HooksContextProvider, ValidationContextProvider } from '../../context';
14
9
  import Utils from '../../utils';
15
10
  import CheckYourAnswers from './CheckYourAnswers';
16
11
 
17
12
  <!-- JSON documents -->
18
-
19
13
  import CIVIL_SERVANT from '../../json/areYouACivilServant.json';
20
14
  import GRADE from '../../json/grade.json';
21
15
  import TEAMS from '../../json/team.json';
@@ -84,11 +78,15 @@ Renders the **Check your answers** screen for a form.
84
78
  console.log('row action invoked', page);
85
79
  };
86
80
  return (
87
- <CheckYourAnswers
88
- pages={PAGES}
89
- onAction={ON_ACTION}
90
- onRowAction={ON_ROW_ACTION}
91
- />
81
+ <HooksContextProvider>
82
+ <ValidationContextProvider>
83
+ <CheckYourAnswers
84
+ pages={PAGES}
85
+ onAction={ON_ACTION}
86
+ onRowAction={ON_ROW_ACTION}
87
+ />
88
+ </ValidationContextProvider>
89
+ </HooksContextProvider>
92
90
  );
93
91
  }}
94
92
  </Story>
@@ -146,12 +144,16 @@ Renders the **Check your answers** screen for a form.
146
144
  console.log('row action invoked', page);
147
145
  };
148
146
  return (
149
- <CheckYourAnswers
150
- pages={PAGES}
151
- hide_page_titles={true}
152
- onAction={ON_ACTION}
153
- onRowAction={ON_ROW_ACTION}
154
- />
147
+ <HooksContextProvider>
148
+ <ValidationContextProvider>
149
+ <CheckYourAnswers
150
+ pages={PAGES}
151
+ hide_page_titles={true}
152
+ onAction={ON_ACTION}
153
+ onRowAction={ON_ROW_ACTION}
154
+ />
155
+ </ValidationContextProvider>
156
+ </HooksContextProvider>
155
157
  );
156
158
  }}
157
159
  </Story>
@@ -200,13 +202,17 @@ Renders the **Check your answers** screen for a form.
200
202
  console.log('row action invoked', page);
201
203
  };
202
204
  return (
203
- <CheckYourAnswers
204
- pages={PAGES}
205
- hide_page_titles={true}
206
- actions={ACTIONS}
207
- onAction={ON_ACTION}
208
- onRowAction={ON_ROW_ACTION}
209
- />
205
+ <HooksContextProvider>
206
+ <ValidationContextProvider>
207
+ <CheckYourAnswers
208
+ pages={PAGES}
209
+ hide_page_titles={true}
210
+ actions={ACTIONS}
211
+ onAction={ON_ACTION}
212
+ onRowAction={ON_ROW_ACTION}
213
+ />
214
+ </ValidationContextProvider>
215
+ </HooksContextProvider>
210
216
  );
211
217
  }}
212
218
  </Story>
@@ -258,15 +264,19 @@ Renders the **Check your answers** screen for a form.
258
264
  console.log('row action invoked', page);
259
265
  };
260
266
  return (
261
- <CheckYourAnswers
262
- pages={PAGES}
263
- hide_page_titles={true}
264
- onAction={ON_ACTION}
265
- onRowAction={ON_ROW_ACTION}
266
- hide_title={true}
267
- summaryListClassModifiers='no-border'
268
- noChangeAction={true}
269
- />
267
+ <HooksContextProvider>
268
+ <ValidationContextProvider>
269
+ <CheckYourAnswers
270
+ pages={PAGES}
271
+ hide_page_titles={true}
272
+ onAction={ON_ACTION}
273
+ onRowAction={ON_ROW_ACTION}
274
+ hide_title={true}
275
+ summaryListClassModifiers='no-border'
276
+ noChangeAction={true}
277
+ />
278
+ </ValidationContextProvider>
279
+ </HooksContextProvider>
270
280
  );
271
281
  }}
272
282
  </Story>
@@ -320,13 +330,17 @@ Renders the **Check your answers** screen for a form.
320
330
  console.log('row action invoked', page);
321
331
  };
322
332
  return (
323
- <CheckYourAnswers
324
- pages={PAGES}
325
- hide_page_titles={false}
326
- onAction={ON_ACTION}
327
- onRowAction={ON_ROW_ACTION}
328
- groups={CYA.groups}
329
- />
333
+ <HooksContextProvider>
334
+ <ValidationContextProvider>
335
+ <CheckYourAnswers
336
+ pages={PAGES}
337
+ hide_page_titles={false}
338
+ onAction={ON_ACTION}
339
+ onRowAction={ON_ROW_ACTION}
340
+ groups={CYA.groups}
341
+ />
342
+ </ValidationContextProvider>
343
+ </HooksContextProvider>
330
344
  );
331
345
  }}
332
346
  </Story>
@@ -359,33 +373,37 @@ Renders the **Check your answers** screen for a form.
359
373
  ],
360
374
  }}>
361
375
  {() => {
362
- const DATA = Utils.Data.setupForm(
363
- GROUP.pages,
364
- GROUP.components,
365
- GROUP_DATA
366
- );
367
- const PAGES = Utils.FormPage.getAll(
368
- GROUP.pages,
369
- GROUP.components,
370
- { ...DATA }
371
- );
372
- const ACTIONS = GROUP.cya.actions;
373
- const ON_ACTION = (action, patch, onError) => {
374
- console.log('action invoked', action, patch);
375
- };
376
- const ON_ROW_ACTION = (page) => {
377
- console.log('row action invoked', page);
378
- };
379
- return (
380
- <CheckYourAnswers
381
- pages={PAGES}
382
- hide_page_titles={true}
383
- actions={ACTIONS}
384
- onAction={ON_ACTION}
385
- onRowAction={ON_ROW_ACTION}
386
- />
387
- );
388
- }}
376
+ const DATA = Utils.Data.setupForm(
377
+ GROUP.pages,
378
+ GROUP.components,
379
+ GROUP_DATA
380
+ );
381
+ const PAGES = Utils.FormPage.getAll(
382
+ GROUP.pages,
383
+ GROUP.components,
384
+ { ...DATA }
385
+ );
386
+ const ACTIONS = GROUP.cya.actions;
387
+ const ON_ACTION = (action, patch, onError) => {
388
+ console.log('action invoked', action, patch);
389
+ };
390
+ const ON_ROW_ACTION = (page) => {
391
+ console.log('row action invoked', page);
392
+ };
393
+ return (
394
+ <HooksContextProvider>
395
+ <ValidationContextProvider>
396
+ <CheckYourAnswers
397
+ pages={PAGES}
398
+ hide_page_titles={true}
399
+ actions={ACTIONS}
400
+ onAction={ON_ACTION}
401
+ onRowAction={ON_ROW_ACTION}
402
+ />
403
+ </ValidationContextProvider>
404
+ </HooksContextProvider>
405
+ );
406
+ }}
389
407
  </Story>
390
408
  </Canvas>
391
409
 
@@ -384,25 +384,37 @@ describe('components', function () {
384
384
  }
385
385
  }, _callee12);
386
386
  })));
387
- it('Show answers from multiple address fields into in one DL', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
388
- var DATA, GROUP_PAGES, cya, groupedComponent, keyGroup, valueGroup, changeButtonDiv, changeButton;
387
+ it('should show task list in CYA style', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
388
+ var sections, taskHeading1, namesPageHeading, taskHeading2, gradePageHeading;
389
389
  return regeneratorRuntime.wrap(function _callee14$(_context14) {
390
390
  while (1) {
391
391
  switch (_context14.prev = _context14.next) {
392
392
  case 0:
393
- DATA = _utils.default.Data.setupForm(_group.default.pages, _group.default.components, _groupData.default);
394
- GROUP_PAGES = _utils.default.FormPage.getAll(_group.default.pages, _group.default.components, _objectSpread({}, DATA));
395
- _context14.next = 4;
393
+ sections = [{
394
+ name: 'These are your tasks',
395
+ tasks: [{
396
+ name: 'Task 1',
397
+ state: 'complete',
398
+ pages: ['names']
399
+ }, {
400
+ name: 'Task 2',
401
+ state: 'complete',
402
+ pages: ['grade']
403
+ }]
404
+ }];
405
+ _context14.next = 3;
396
406
  return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
397
407
  return regeneratorRuntime.wrap(function _callee13$(_context13) {
398
408
  while (1) {
399
409
  switch (_context13.prev = _context13.next) {
400
410
  case 0:
401
411
  (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
402
- pages: GROUP_PAGES,
412
+ pages: PAGES,
403
413
  onRowAction: ON_ROW_ACTION,
404
414
  onAction: ON_ACTION,
405
- hide_title: true
415
+ hide_title: true,
416
+ sections: sections,
417
+ type: "task-list-cya"
406
418
  }), container);
407
419
 
408
420
  case 1:
@@ -413,6 +425,63 @@ describe('components', function () {
413
425
  }, _callee13);
414
426
  })));
415
427
 
428
+ case 3:
429
+ taskHeading1 = container.childNodes[0].childNodes[0];
430
+ expect(taskHeading1.tagName).toEqual('H3');
431
+ expect(taskHeading1.textContent).toEqual('Task 1');
432
+ expect(taskHeading1.classList).toContain("govuk-!-margin-top-8");
433
+ expect(taskHeading1.classList).toContain("govuk-!-margin-bottom-0");
434
+ namesPageHeading = container.childNodes[0].childNodes[1];
435
+ expect(namesPageHeading.tagName).toEqual('DIV');
436
+ expect(namesPageHeading.textContent).toContain('John');
437
+ expect(namesPageHeading.classList).toContain("group-of-rows");
438
+ taskHeading2 = container.childNodes[0].childNodes[2];
439
+ expect(taskHeading2.tagName).toEqual('H3');
440
+ expect(taskHeading2.textContent).toEqual('Task 2');
441
+ expect(taskHeading2.classList).toContain("govuk-!-margin-top-8");
442
+ expect(taskHeading2.classList).toContain("govuk-!-margin-bottom-0");
443
+ gradePageHeading = container.childNodes[0].childNodes[3];
444
+ expect(gradePageHeading.tagName).toEqual('H4');
445
+ expect(gradePageHeading.textContent).toEqual("What's your grade?");
446
+ expect(gradePageHeading.classList).toContain("govuk-!-margin-top-6");
447
+ expect(gradePageHeading.classList).toContain("govuk-!-margin-bottom-5");
448
+
449
+ case 22:
450
+ case "end":
451
+ return _context14.stop();
452
+ }
453
+ }
454
+ }, _callee14);
455
+ })));
456
+ it('Show answers from multiple address fields into in one DL', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16() {
457
+ var DATA, GROUP_PAGES, cya, groupedComponent, keyGroup, valueGroup, changeButtonDiv, changeButton;
458
+ return regeneratorRuntime.wrap(function _callee16$(_context16) {
459
+ while (1) {
460
+ switch (_context16.prev = _context16.next) {
461
+ case 0:
462
+ DATA = _utils.default.Data.setupForm(_group.default.pages, _group.default.components, _groupData.default);
463
+ GROUP_PAGES = _utils.default.FormPage.getAll(_group.default.pages, _group.default.components, _objectSpread({}, DATA));
464
+ _context16.next = 4;
465
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15() {
466
+ return regeneratorRuntime.wrap(function _callee15$(_context15) {
467
+ while (1) {
468
+ switch (_context15.prev = _context15.next) {
469
+ case 0:
470
+ (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
471
+ pages: GROUP_PAGES,
472
+ onRowAction: ON_ROW_ACTION,
473
+ onAction: ON_ACTION,
474
+ hide_title: true
475
+ }), container);
476
+
477
+ case 1:
478
+ case "end":
479
+ return _context15.stop();
480
+ }
481
+ }
482
+ }, _callee15);
483
+ })));
484
+
416
485
  case 4:
417
486
  cya = checkCYA(container);
418
487
  groupedComponent = cya.childNodes[10];
@@ -434,23 +503,23 @@ describe('components', function () {
434
503
 
435
504
  case 21:
436
505
  case "end":
437
- return _context14.stop();
506
+ return _context16.stop();
438
507
  }
439
508
  }
440
- }, _callee14);
509
+ }, _callee16);
441
510
  })));
442
- it('should render a group with one action button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee16() {
511
+ it('should render a group with one action button', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
443
512
  var GROUP_PAGES, cya, namesGroup, firstNameRow, surname, changeButtonDiv, changeButton;
444
- return regeneratorRuntime.wrap(function _callee16$(_context16) {
513
+ return regeneratorRuntime.wrap(function _callee18$(_context18) {
445
514
  while (1) {
446
- switch (_context16.prev = _context16.next) {
515
+ switch (_context18.prev = _context18.next) {
447
516
  case 0:
448
517
  GROUP_PAGES = _utils.default.FormPage.getAll(_groupOfRow.default.pages, _groupOfRow.default.components, _objectSpread({}, DATA));
449
- _context16.next = 3;
450
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15() {
451
- return regeneratorRuntime.wrap(function _callee15$(_context15) {
518
+ _context18.next = 3;
519
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17() {
520
+ return regeneratorRuntime.wrap(function _callee17$(_context17) {
452
521
  while (1) {
453
- switch (_context15.prev = _context15.next) {
522
+ switch (_context17.prev = _context17.next) {
454
523
  case 0:
455
524
  (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
456
525
  pages: GROUP_PAGES,
@@ -461,10 +530,10 @@ describe('components', function () {
461
530
 
462
531
  case 1:
463
532
  case "end":
464
- return _context15.stop();
533
+ return _context17.stop();
465
534
  }
466
535
  }
467
- }, _callee15);
536
+ }, _callee17);
468
537
  })));
469
538
 
470
539
  case 3:
@@ -490,17 +559,17 @@ describe('components', function () {
490
559
 
491
560
  case 22:
492
561
  case "end":
493
- return _context16.stop();
562
+ return _context18.stop();
494
563
  }
495
564
  }
496
- }, _callee16);
565
+ }, _callee18);
497
566
  })));
498
- it('should show page components corrently with interpolated title and cya_label, if label is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee18() {
567
+ it('should show page components corrently with interpolated title and cya_label, if label is missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
499
568
  var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes5, cyaTitle, cyaChildNode, names, _names$childNodes3, firstName, surname, _firstName$childNodes, label;
500
569
 
501
- return regeneratorRuntime.wrap(function _callee18$(_context18) {
570
+ return regeneratorRuntime.wrap(function _callee20$(_context20) {
502
571
  while (1) {
503
- switch (_context18.prev = _context18.next) {
572
+ switch (_context20.prev = _context20.next) {
504
573
  case 0:
505
574
  _PAGES = [].concat(_userProfile.default.pages); // eslint-disable-next-line no-template-curly-in-string
506
575
 
@@ -515,11 +584,11 @@ describe('components', function () {
515
584
  cya_label: "Text ${currentUser.familyName}"
516
585
  });
517
586
  T_PAGES = _utils.default.FormPage.getAll(_PAGES, _COMPONENTS, DATA);
518
- _context18.next = 7;
519
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee17() {
520
- return regeneratorRuntime.wrap(function _callee17$(_context17) {
587
+ _context20.next = 7;
588
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
589
+ return regeneratorRuntime.wrap(function _callee19$(_context19) {
521
590
  while (1) {
522
- switch (_context17.prev = _context17.next) {
591
+ switch (_context19.prev = _context19.next) {
523
592
  case 0:
524
593
  (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
525
594
  pages: T_PAGES,
@@ -529,10 +598,10 @@ describe('components', function () {
529
598
 
530
599
  case 1:
531
600
  case "end":
532
- return _context17.stop();
601
+ return _context19.stop();
533
602
  }
534
603
  }
535
- }, _callee17);
604
+ }, _callee19);
536
605
  })));
537
606
 
538
607
  case 7:
@@ -549,17 +618,17 @@ describe('components', function () {
549
618
 
550
619
  case 17:
551
620
  case "end":
552
- return _context18.stop();
621
+ return _context20.stop();
553
622
  }
554
623
  }
555
- }, _callee18);
624
+ }, _callee20);
556
625
  })));
557
- it('should show page components corrently with no label, if label and cya_label are missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee20() {
626
+ it('should show page components corrently with no label, if label and cya_label are missing', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22() {
558
627
  var _PAGES, _COMPONENTS, T_PAGES, cya, _cya$childNodes6, cyaChildNode, names, _names$childNodes4, firstName, surname, _firstName$childNodes2, label;
559
628
 
560
- return regeneratorRuntime.wrap(function _callee20$(_context20) {
629
+ return regeneratorRuntime.wrap(function _callee22$(_context22) {
561
630
  while (1) {
562
- switch (_context20.prev = _context20.next) {
631
+ switch (_context22.prev = _context22.next) {
563
632
  case 0:
564
633
  _PAGES = [].concat(_userProfile.default.pages);
565
634
  _COMPONENTS = [].concat(_userProfile.default.components);
@@ -569,11 +638,11 @@ describe('components', function () {
569
638
  cya_label: undefined
570
639
  });
571
640
  T_PAGES = _utils.default.FormPage.getAll(_PAGES, _COMPONENTS, _objectSpread({}, DATA));
572
- _context20.next = 6;
573
- return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee19() {
574
- return regeneratorRuntime.wrap(function _callee19$(_context19) {
641
+ _context22.next = 6;
642
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21() {
643
+ return regeneratorRuntime.wrap(function _callee21$(_context21) {
575
644
  while (1) {
576
- switch (_context19.prev = _context19.next) {
645
+ switch (_context21.prev = _context21.next) {
577
646
  case 0:
578
647
  (0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
579
648
  pages: T_PAGES,
@@ -583,10 +652,10 @@ describe('components', function () {
583
652
 
584
653
  case 1:
585
654
  case "end":
586
- return _context19.stop();
655
+ return _context21.stop();
587
656
  }
588
657
  }
589
- }, _callee19);
658
+ }, _callee21);
590
659
  })));
591
660
 
592
661
  case 6:
@@ -602,10 +671,10 @@ describe('components', function () {
602
671
 
603
672
  case 15:
604
673
  case "end":
605
- return _context20.stop();
674
+ return _context22.stop();
606
675
  }
607
676
  }
608
- }, _callee20);
677
+ }, _callee22);
609
678
  })));
610
679
  });
611
680
  });
@@ -68,7 +68,7 @@ var FormComponent = function FormComponent(_ref) {
68
68
 
69
69
  var validation = (0, _hooks.useValidation)();
70
70
 
71
- var _useRefData = (0, _hooks.useRefData)(component),
71
+ var _useRefData = (0, _hooks.useRefData)(component, formData),
72
72
  data = _useRefData.data,
73
73
  status = _useRefData.status;
74
74
 
@@ -4,6 +4,7 @@ import { Details, Heading, Link } from '@ukhomeoffice/cop-react-components';
4
4
  import withMock from 'storybook-addon-mock';
5
5
 
6
6
  <!-- Local imports -->
7
+ import { HooksContextProvider, ValidationContextProvider } from '../../context';
7
8
  import FormComponent from './FormComponent';
8
9
 
9
10
  <!-- JSON documents -->
@@ -54,7 +55,11 @@ on the basis of a <Link href="/?path=/docs/f-json-component">JSON</Link> configu
54
55
  // Do something with the target here.
55
56
  };
56
57
  return (
57
- <FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
58
+ <HooksContextProvider>
59
+ <ValidationContextProvider>
60
+ <FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
61
+ </ValidationContextProvider>
62
+ </HooksContextProvider>
58
63
  );
59
64
  }}
60
65
  </Story>
@@ -101,7 +106,11 @@ on the basis of a <Link href="/?path=/docs/f-json-component">JSON</Link> configu
101
106
  // Do something with the target here.
102
107
  };
103
108
  return (
104
- <FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
109
+ <HooksContextProvider>
110
+ <ValidationContextProvider>
111
+ <FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
112
+ </ValidationContextProvider>
113
+ </HooksContextProvider>
105
114
  );
106
115
  }}
107
116
  </Story>
@@ -117,7 +126,11 @@ on the basis of a <Link href="/?path=/docs/f-json-component">JSON</Link> configu
117
126
  // Do something with the target here.
118
127
  };
119
128
  return (
120
- <FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
129
+ <HooksContextProvider>
130
+ <ValidationContextProvider>
131
+ <FormComponent component={COMPONENT} value={''} onChange={ON_CHANGE} />
132
+ </ValidationContextProvider>
133
+ </HooksContextProvider>
121
134
  );
122
135
  }}
123
136
  </Story>
@@ -160,7 +173,11 @@ on the basis of a <Link href="/?path=/docs/f-json-component">JSON</Link> configu
160
173
  // Do something with the target here.
161
174
  };
162
175
  return (
163
- <FormComponent component={COMPONENT} value={''} wrap={false} onChange={ON_CHANGE} />
176
+ <HooksContextProvider>
177
+ <ValidationContextProvider>
178
+ <FormComponent component={COMPONENT} value={''} wrap={false} onChange={ON_CHANGE} />
179
+ </ValidationContextProvider>
180
+ </HooksContextProvider>
164
181
  );
165
182
  }}
166
183
  </Story>
@@ -4,6 +4,7 @@ import { Details, Heading, Link } from '@ukhomeoffice/cop-react-components';
4
4
  import withMock from 'storybook-addon-mock';
5
5
 
6
6
  <!-- Local imports -->
7
+ import { HooksContextProvider, ValidationContextProvider } from '../../context';
7
8
  import Utils from '../../utils';
8
9
  import FormPage from './FormPage';
9
10
 
@@ -51,7 +52,11 @@ on the basis of a <Link href="/?path=/docs/f-json-page">JSON</Link> configuratio
51
52
  console.log('action invoked', action, patch);
52
53
  };
53
54
  return (
54
- <FormPage page={PAGE} onAction={ON_ACTION} />
55
+ <HooksContextProvider>
56
+ <ValidationContextProvider>
57
+ <FormPage page={PAGE} onAction={ON_ACTION} />
58
+ </ValidationContextProvider>
59
+ </HooksContextProvider>
55
60
  );
56
61
  }}
57
62
  </Story>
@@ -94,7 +99,11 @@ on the basis of a <Link href="/?path=/docs/f-json-page">JSON</Link> configuratio
94
99
  console.log('action invoked', action, patch);
95
100
  };
96
101
  return (
97
- <FormPage page={PAGE} onAction={ON_ACTION} />
102
+ <HooksContextProvider>
103
+ <ValidationContextProvider>
104
+ <FormPage page={PAGE} onAction={ON_ACTION} />
105
+ </ValidationContextProvider>
106
+ </HooksContextProvider>
98
107
  );
99
108
  }}
100
109
  </Story>
@@ -111,7 +120,11 @@ on the basis of a <Link href="/?path=/docs/f-json-page">JSON</Link> configuratio
111
120
  console.log('action invoked', action, patch);
112
121
  };
113
122
  return (
114
- <FormPage page={PAGE} onAction={ON_ACTION} />
123
+ <HooksContextProvider>
124
+ <ValidationContextProvider>
125
+ <FormPage page={PAGE} onAction={ON_ACTION} />
126
+ </ValidationContextProvider>
127
+ </HooksContextProvider>
115
128
  );
116
129
  }}
117
130
  </Story>
@@ -73,7 +73,8 @@ 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;
76
+ noChangeAction = _ref.noChangeAction,
77
+ newPageId = _ref.newPageId;
77
78
  return /*#__PURE__*/_react.default.createElement(_context.HooksContextProvider, {
78
79
  overrides: hooks
79
80
  }, /*#__PURE__*/_react.default.createElement(_context.ValidationContextProvider, null, /*#__PURE__*/_react.default.createElement(InternalFormRenderer, {
@@ -89,7 +90,8 @@ var FormRenderer = function FormRenderer(_ref) {
89
90
  className: className,
90
91
  hide_title: hide_title,
91
92
  summaryListClassModifiers: summaryListClassModifiers,
92
- noChangeAction: noChangeAction
93
+ noChangeAction: noChangeAction,
94
+ newPageId: newPageId
93
95
  })));
94
96
  };
95
97
 
@@ -109,7 +111,8 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
109
111
  className = _ref2.className,
110
112
  hide_title = _ref2.hide_title,
111
113
  summaryListClassModifiers = _ref2.summaryListClassModifiers,
112
- noChangeAction = _ref2.noChangeAction;
114
+ noChangeAction = _ref2.noChangeAction,
115
+ newPageId = _ref2.newPageId;
113
116
 
114
117
  // Set up the initial states.
115
118
  var _useState = (0, _react.useState)({}),
@@ -240,13 +243,21 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
240
243
  clearErrors();
241
244
  setPageId(newPageId);
242
245
  hooks.onPageChange(newPageId);
243
- }; // Handle actions from pages.
246
+ };
244
247
 
248
+ (0, _react.useEffect)(function () {
249
+ if (newPageId !== undefined) setPageId(newPageId);
250
+ }, [newPageId]); // Handle actions from pages.
245
251
 
246
252
  var onPageAction = function onPageAction(action, patch) {
247
- // Re-apply the patch to the page's formData.
253
+ if (action.type === _models.PageAction.TYPES.CANCEL) {
254
+ hooks.onCancel();
255
+ return;
256
+ } // Re-apply the patch to the page's formData.
248
257
  // This should normally have no effect but will prevent issues
249
258
  // with validation if formData happens to have been wiped.
259
+
260
+
250
261
  formState.page.formData = _objectSpread(_objectSpread({}, formState.page.formData), patch); // Check to see whether the action is able to proceed, which in
251
262
  // in the case of a submission will validate the fields in the page.
252
263
 
@@ -312,10 +323,15 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
312
323
  setCurrentTask(currentTask);
313
324
 
314
325
  if (currentTask.state === _models.TaskStates.TYPES.COMPLETE) {
315
- onPageChange(_models.FormPages.CYA);
326
+ if (hubDetails !== null && hubDetails !== void 0 && hubDetails.noTaskCYAs) {
327
+ var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
328
+ onPageChange(currentPage || currentTask.pages[0]);
329
+ } else {
330
+ onPageChange(_models.FormPages.CYA);
331
+ }
316
332
  } else if (currentTask.state === _models.TaskStates.TYPES.IN_PROGRESS) {
317
- var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
318
- onPageChange(currentPage || currentTask.pages[0]);
333
+ var _currentPage = data.formStatus.tasks[currentTask.name].currentPage;
334
+ onPageChange(_currentPage || currentTask.pages[0]);
319
335
  } else {
320
336
  onPageChange(currentTask.pages[0]);
321
337
  }
@@ -382,6 +398,10 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
382
398
  });
383
399
  }
384
400
  }
401
+
402
+ if (action.type === _models.PageAction.TYPES.CANCEL) {
403
+ hooks.onCancel();
404
+ }
385
405
  };
386
406
 
387
407
  var classes = _utils.default.classBuilder(classBlock, classModifiers, className);
@@ -399,7 +419,9 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
399
419
  onRowAction: onCYARowAction,
400
420
  summaryListClassModifiers: summaryListClassModifiers,
401
421
  hide_title: hide_title,
402
- noChangeAction: noChangeAction
422
+ noChangeAction: noChangeAction,
423
+ sections: typeof hubDetails !== 'undefined' ? hubDetails.sections : [],
424
+ type: type
403
425
  })), hub === _models.HubFormats.TASK && formState.pageId === _models.FormPages.HUB && /*#__PURE__*/_react.default.createElement(_TaskList.default, {
404
426
  sections: hubDetails.sections,
405
427
  refNumber: data['businessKey'],
@@ -415,7 +437,7 @@ FormRenderer.propTypes = InternalFormRenderer.propTypes = {
415
437
  title: _propTypes.default.string,
416
438
 
417
439
  /** See <a href="/?path=/docs/f-json--page#formtypes">FormTypes</a>. */
418
- type: _propTypes.default.oneOf([_models.FormTypes.CYA, _models.FormTypes.FORM, _models.FormTypes.HUB, _models.FormTypes.TASK, _models.FormTypes.WIZARD]).isRequired,
440
+ type: _propTypes.default.oneOf([_models.FormTypes.CYA, _models.FormTypes.FORM, _models.FormTypes.HUB, _models.FormTypes.TASK, _models.FormTypes.WIZARD, _models.FormTypes.TASKCYA]).isRequired,
419
441
  components: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
420
442
  pages: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
421
443
  hub: _propTypes.default.object,
@@ -99,6 +99,10 @@ describe('components', function () {
99
99
  return page.childNodes[page.childNodes.length - 1].childNodes[0].childNodes[0];
100
100
  };
101
101
 
102
+ var getCancelButton = function getCancelButton(page) {
103
+ return page.childNodes[page.childNodes.length - 1].childNodes[1].childNodes[0];
104
+ };
105
+
102
106
  it('should start on the hub page correctly and display the title', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
103
107
  var form, title, hub;
104
108
  return regeneratorRuntime.wrap(function _callee2$(_context2) {
@@ -743,5 +747,154 @@ describe('components', function () {
743
747
  }
744
748
  }, _callee20);
745
749
  })));
750
+ it('should go to the last page of a complete task if noTaskCYAs specified', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22() {
751
+ var ON_SUBMIT, HOOKS, TASK_LIST_WITH_NO_TASK_CYAS, taskList, newPage;
752
+ return regeneratorRuntime.wrap(function _callee22$(_context22) {
753
+ while (1) {
754
+ switch (_context22.prev = _context22.next) {
755
+ case 0:
756
+ ON_SUBMIT = function ON_SUBMIT(type, payload, onSuccess, onError) {
757
+ onSuccess();
758
+ };
759
+
760
+ HOOKS = {
761
+ onSubmit: ON_SUBMIT
762
+ };
763
+ TASK_LIST_WITH_NO_TASK_CYAS = JSON.parse(JSON.stringify(_taskList.default));
764
+ TASK_LIST_WITH_NO_TASK_CYAS.hub.noTaskCYAs = true;
765
+ TASK_LIST_WITH_NO_TASK_CYAS.pages[1].actions[0] = {
766
+ type: 'save',
767
+ complete: true
768
+ };
769
+ _context22.next = 7;
770
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee21() {
771
+ return regeneratorRuntime.wrap(function _callee21$(_context21) {
772
+ while (1) {
773
+ switch (_context21.prev = _context21.next) {
774
+ case 0:
775
+ (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, TASK_LIST_WITH_NO_TASK_CYAS, {
776
+ hooks: HOOKS
777
+ })), container);
778
+
779
+ case 1:
780
+ case "end":
781
+ return _context21.stop();
782
+ }
783
+ }
784
+ }, _callee21);
785
+ })));
786
+
787
+ case 7:
788
+ taskList = container.childNodes[0].childNodes[1]; // Launch first task
789
+
790
+ _react.fireEvent.click(taskList.childNodes[3].childNodes[0].childNodes[0].childNodes[0], {}); // Fill first page and navigate
791
+
792
+
793
+ newPage = container.childNodes[0].childNodes[0];
794
+
795
+ _react.fireEvent.change(newPage.childNodes[1].childNodes[2].childNodes[0].childNodes[1], {
796
+ target: {
797
+ name: 'date-day',
798
+ value: '7'
799
+ }
800
+ });
801
+
802
+ _react.fireEvent.change(newPage.childNodes[1].childNodes[2].childNodes[1].childNodes[1], {
803
+ target: {
804
+ name: 'date-month',
805
+ value: '7'
806
+ }
807
+ });
808
+
809
+ _react.fireEvent.change(newPage.childNodes[1].childNodes[2].childNodes[2].childNodes[1], {
810
+ target: {
811
+ name: 'date-year',
812
+ value: '2022'
813
+ }
814
+ });
815
+
816
+ _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {}); // Fill second page
817
+
818
+
819
+ newPage = container.childNodes[0].childNodes[0];
820
+
821
+ _react.fireEvent.click(newPage.childNodes[1].childNodes[2].childNodes[0].childNodes[0], {});
822
+
823
+ _react.fireEvent.click(newPage.childNodes[2].childNodes[0], {}); // Launch same task again
824
+
825
+
826
+ _react.fireEvent.click(container.childNodes[0].childNodes[1].childNodes[3].childNodes[0].childNodes[0].childNodes[0], {}); // Should be on the second page
827
+
828
+
829
+ expect(container.childNodes[0].childNodes[0].childNodes[0].textContent).toEqual('Event Mode');
830
+
831
+ case 19:
832
+ case "end":
833
+ return _context22.stop();
834
+ }
835
+ }
836
+ }, _callee22);
837
+ })));
838
+ it('should handle cancellation from a page', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee24() {
839
+ var ON_CANCEL_CALLS, ON_CANCEL, HOOKS, form, hub, _hub$childNodes5, civilServantList, link, page, cancel;
840
+
841
+ return regeneratorRuntime.wrap(function _callee24$(_context24) {
842
+ while (1) {
843
+ switch (_context24.prev = _context24.next) {
844
+ case 0:
845
+ ON_CANCEL_CALLS = [];
846
+
847
+ ON_CANCEL = function ON_CANCEL() {
848
+ ON_CANCEL_CALLS.push(undefined);
849
+ };
850
+
851
+ HOOKS = {
852
+ onCancel: ON_CANCEL
853
+ };
854
+ _context24.next = 5;
855
+ return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee23() {
856
+ return regeneratorRuntime.wrap(function _callee23$(_context23) {
857
+ while (1) {
858
+ switch (_context23.prev = _context23.next) {
859
+ case 0:
860
+ (0, _reactDom.render)( /*#__PURE__*/_react2.default.createElement(_FormRenderer.default, _extends({}, _userProfile.default, {
861
+ data: _userProfileData.default,
862
+ hooks: HOOKS
863
+ })), container);
864
+
865
+ case 1:
866
+ case "end":
867
+ return _context23.stop();
868
+ }
869
+ }
870
+ }, _callee23);
871
+ })));
872
+
873
+ case 5:
874
+ form = checkForm(container); // Navigate to the "Are you a civil servant?" page.
875
+
876
+ hub = form.childNodes[1]; // Hub = CYA
877
+
878
+ _hub$childNodes5 = _slicedToArray(hub.childNodes, 3), civilServantList = _hub$childNodes5[2];
879
+ link = getChangeLink(civilServantList);
880
+
881
+ _react.fireEvent.click(link, {}); // Should already be answered "Yes", so simply click "Continue".
882
+
883
+
884
+ page = form.childNodes[0];
885
+ cancel = getCancelButton(page);
886
+ expect(ON_CANCEL_CALLS.length).toEqual(0);
887
+
888
+ _react.fireEvent.click(cancel, {});
889
+
890
+ expect(ON_CANCEL_CALLS.length).toEqual(1);
891
+
892
+ case 15:
893
+ case "end":
894
+ return _context24.stop();
895
+ }
896
+ }
897
+ }, _callee24);
898
+ })));
746
899
  });
747
900
  });
@@ -13,22 +13,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
13
13
 
14
14
  var getSubmissionStatus = function getSubmissionStatus(formType, pages, currentPageId, action, formData, currentTask, isCompleted) {
15
15
  if (formType === _models.FormTypes.TASK) {
16
- var formStatus = formData.formStatus ? formData.formStatus : {};
17
- formStatus.tasks = formStatus.tasks ? formStatus.tasks : {};
18
- formStatus.tasks[currentTask.name] = formStatus.tasks[currentTask.name] ? formStatus.tasks[currentTask.name] : {};
16
+ var formStatus = formData.formStatus || {};
17
+ formStatus.tasks = formStatus.tasks || {};
18
+ formStatus.tasks[currentTask.name] = formStatus.tasks[currentTask.name] || {};
19
19
 
20
20
  if (currentPageId === (_models.FormPages.CYA || 'submitForm') && isCompleted) {
21
21
  formStatus.tasks[currentTask.name].complete = true;
22
22
  } else if ((action === null || action === void 0 ? void 0 : action.type) === _models.PageAction.TYPES.SAVE_AND_NAVIGATE) {
23
- console.log('pg action sc');
24
23
  formStatus.tasks[currentTask.name] = {
25
24
  complete: false,
26
25
  currentPage: (0, _getNextPageId.default)(formType, pages, currentPageId, action, formData)
27
26
  };
28
27
  } else {
29
- console.log('got to else stmt');
30
28
  formStatus.tasks[currentTask.name] = {
31
- complete: false,
29
+ complete: !!(action !== null && action !== void 0 && action.complete),
32
30
  currentPage: currentPageId
33
31
  };
34
32
  }
@@ -240,6 +240,21 @@ describe('components', function () {
240
240
  })
241
241
  });
242
242
  });
243
+ it("should mark the current task as complete if the action indicates as much", function () {
244
+ var CURRENT_PAGE_ID = PAGES[0].id;
245
+ var TASK_NAME = 'taskName';
246
+ var CURRENT_TASK = {
247
+ name: TASK_NAME
248
+ };
249
+ var ACTION = {
250
+ complete: true
251
+ };
252
+ expect((0, _getSubmissionStatus.default)(FORM_TYPE, PAGES, CURRENT_PAGE_ID, ACTION, {}, CURRENT_TASK, true)).toMatchObject({
253
+ tasks: _defineProperty({}, TASK_NAME, {
254
+ complete: true
255
+ })
256
+ });
257
+ });
243
258
  });
244
259
  });
245
260
  });
@@ -45,7 +45,9 @@ var DEFAULT_HOOKS = {
45
45
  },
46
46
  onSubmit: function onSubmit(type, payload, onSuccess, onError) {
47
47
  if (typeof onSuccess === 'function') onSuccess();
48
- }
48
+ },
49
+ onCancel: function onCancel() {} // Consuming application must provide function to action, else this does nothing.
50
+
49
51
  };
50
52
  var ALLOWED_HOOKS = Object.keys(DEFAULT_HOOKS);
51
53
  exports.ALLOWED_HOOKS = ALLOWED_HOOKS;
@@ -62,7 +64,8 @@ var HooksContextProvider = function HooksContextProvider(_ref) {
62
64
  onGetComponent: (overrides === null || overrides === void 0 ? void 0 : overrides.onGetComponent) || DEFAULT_HOOKS.onGetComponent,
63
65
  onPageChange: (overrides === null || overrides === void 0 ? void 0 : overrides.onPageChange) || DEFAULT_HOOKS.onPageChange,
64
66
  onRequest: (overrides === null || overrides === void 0 ? void 0 : overrides.onRequest) || DEFAULT_HOOKS.onRequest,
65
- onSubmit: (overrides === null || overrides === void 0 ? void 0 : overrides.onSubmit) || DEFAULT_HOOKS.onSubmit
67
+ onSubmit: (overrides === null || overrides === void 0 ? void 0 : overrides.onSubmit) || DEFAULT_HOOKS.onSubmit,
68
+ onCancel: (overrides === null || overrides === void 0 ? void 0 : overrides.onCancel) || DEFAULT_HOOKS.onCancel
66
69
  }),
67
70
  _useState2 = _slicedToArray(_useState, 2),
68
71
  hooks = _useState2[0],
@@ -33,6 +33,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
33
33
 
34
34
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
35
35
 
36
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
37
+
38
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
39
+
40
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
41
+
36
42
  var STATUS_LOADING = 'loading';
37
43
  exports.STATUS_LOADING = STATUS_LOADING;
38
44
  var STATUS_COMPLETE = 'complete';
@@ -48,8 +54,10 @@ var getRefDataUrl = function getRefDataUrl(component) {
48
54
  return undefined;
49
55
  };
50
56
 
51
- var useRefData = function useRefData(component) {
52
- var url = getRefDataUrl(component);
57
+ var useRefData = function useRefData(component, formData) {
58
+ var url = getRefDataUrl(_objectSpread(_objectSpread({}, component), {}, {
59
+ formData: formData
60
+ }));
53
61
 
54
62
  var _useGetRequest = (0, _useGetRequest2.default)(url),
55
63
  _status = _useGetRequest.status,
@@ -11,7 +11,7 @@
11
11
  "label": "First name",
12
12
  "type": "input",
13
13
  "readonly": true,
14
- "groupId": "addressDetails",
14
+ "groupid": "addressDetails",
15
15
  "source": {
16
16
  "field": "currentUser.givenName"
17
17
  }
@@ -22,7 +22,7 @@
22
22
  "label": "Last name",
23
23
  "type": "text",
24
24
  "readonly": true,
25
- "groupId": "addressDetails",
25
+ "groupid": "addressDetails",
26
26
  "source": {
27
27
  "field": "currentUser.familyName"
28
28
  }
@@ -33,7 +33,7 @@
33
33
  "label": "Are you a civil servant?",
34
34
  "type": "radios",
35
35
  "required": true,
36
- "groupId": "addressDetails",
36
+ "groupid": "addressDetails",
37
37
  "data": {
38
38
  "url": "${urls.refData}/areYouACivilServant"
39
39
  }
@@ -130,7 +130,7 @@
130
130
  "label": "Address",
131
131
  "type": "text",
132
132
  "required": true,
133
- "groupId": "addressDetails",
133
+ "groupid": "addressDetails",
134
134
  "custom_errors": [
135
135
  {
136
136
  "type": "required",
@@ -147,7 +147,7 @@
147
147
  "label": "City",
148
148
  "type": "text",
149
149
  "required": true,
150
- "groupId": "addressDetails",
150
+ "groupid": "addressDetails",
151
151
  "custom_errors": [
152
152
  {
153
153
  "type": "required",
@@ -181,7 +181,7 @@
181
181
  "label": "Postcode",
182
182
  "type": "text",
183
183
  "required": true,
184
- "groupId": "addressDetails",
184
+ "groupid": "addressDetails",
185
185
  "custom_errors": [
186
186
  {
187
187
  "type": "required",
@@ -138,7 +138,7 @@
138
138
  "label": ""
139
139
  }
140
140
  ],
141
- "actions": ["submit"],
141
+ "actions": ["submit", "cancel"],
142
142
  "cya_link": {
143
143
  "page": "civil-servant-status",
144
144
  "aria_suffix": "civil servant status"
@@ -9,12 +9,14 @@ var TYPE_CHECK_YOUR_ANSWERS = 'cya';
9
9
  var TYPE_HUB_AND_SPOKE = 'hub-and-spoke';
10
10
  var TYPE_TASK_LIST = 'task-list';
11
11
  var TYPE_WIZARD = 'wizard';
12
+ var TYPE_TASK_LIST_CYA = 'task-list-cya';
12
13
  var FormTypes = {
13
14
  FORM: TYPE_FORM,
14
15
  CYA: TYPE_CHECK_YOUR_ANSWERS,
15
16
  HUB: TYPE_HUB_AND_SPOKE,
16
17
  TASK: TYPE_TASK_LIST,
17
- WIZARD: TYPE_WIZARD
18
+ WIZARD: TYPE_WIZARD,
19
+ TASKCYA: TYPE_TASK_LIST_CYA
18
20
  };
19
21
  var _default = FormTypes;
20
22
  exports.default = _default;
@@ -9,12 +9,14 @@ var _DefaultPageActions;
9
9
 
10
10
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
11
 
12
+ var TYPE_CANCEL = 'cancel';
12
13
  var TYPE_NAVIGATE = 'navigate';
13
14
  var TYPE_SAVE_AND_CONTINUE = 'saveAndContinue';
14
15
  var TYPE_SAVE_AND_NAVIGATE = 'saveAndNavigate';
15
16
  var TYPE_SAVE_AND_RETURN = 'saveAndReturn';
16
17
  var TYPE_SUBMIT = 'submit';
17
18
  var PageActionTypes = {
19
+ CANCEL: TYPE_CANCEL,
18
20
  NAVIGATE: TYPE_NAVIGATE,
19
21
  SAVE_AND_CONTINUE: TYPE_SAVE_AND_CONTINUE,
20
22
  SAVE_AND_NAVIGATE: TYPE_SAVE_AND_NAVIGATE,
@@ -22,7 +24,12 @@ var PageActionTypes = {
22
24
  SUBMIT: TYPE_SUBMIT
23
25
  };
24
26
  exports.PageActionTypes = PageActionTypes;
25
- var DefaultPageActions = (_DefaultPageActions = {}, _defineProperty(_DefaultPageActions, TYPE_NAVIGATE, undefined), _defineProperty(_DefaultPageActions, TYPE_SAVE_AND_CONTINUE, {
27
+ var DefaultPageActions = (_DefaultPageActions = {}, _defineProperty(_DefaultPageActions, TYPE_CANCEL, {
28
+ type: TYPE_CANCEL,
29
+ validate: false,
30
+ label: 'Cancel',
31
+ classModifiers: 'secondary'
32
+ }), _defineProperty(_DefaultPageActions, TYPE_NAVIGATE, undefined), _defineProperty(_DefaultPageActions, TYPE_SAVE_AND_CONTINUE, {
26
33
  type: TYPE_SAVE_AND_CONTINUE,
27
34
  validate: true,
28
35
  label: 'Save and continue'
@@ -15,7 +15,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
15
15
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
16
 
17
17
  describe('utils.CheckYourAnswers.getCYARowsForCollection', function () {
18
- it('should get a single placeholder row when there are no items', function () {
18
+ it('should get a single entry point row when there are no items', function () {
19
19
  var FORM_DATA = undefined;
20
20
  var PAGE = {
21
21
  id: 'page',
@@ -43,6 +43,10 @@ var setupRefDataUrlForComponent = function setupRefDataUrlForComponent(component
43
43
  return setupRefDataForCollection(component, data);
44
44
  }
45
45
 
46
+ if (component.type === _models.ComponentTypes.SELECT) {
47
+ return component;
48
+ }
49
+
46
50
  if (component.data && component.data.url) {
47
51
  return _objectSpread(_objectSpread({}, component), {}, {
48
52
  data: _objectSpread(_objectSpread({}, component.data), {}, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "3.11.1-alpha",
3
+ "version": "3.15.0",
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.10.0",
19
+ "@ukhomeoffice/cop-react-components": "1.12.0",
20
20
  "axios": "^0.23.0",
21
21
  "dayjs": "^1.11.0",
22
22
  "govuk-frontend": "^3.13.0",