@ukhomeoffice/cop-react-form-renderer 5.13.2 → 5.13.3-bravo
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.
- package/dist/components/CheckYourAnswers/Answer.js +2 -2
- package/dist/components/CheckYourAnswers/Answer.test.js +2 -3
- package/dist/components/CollectionPage/CollectionPage.js +0 -6
- package/dist/components/CollectionPage/CollectionPage.test.js +1 -1
- package/dist/components/FormComponent/Collection.test.js +10 -10
- package/dist/components/FormComponent/Container.test.js +3 -3
- package/dist/components/FormComponent/FormComponent.test.js +3 -3
- package/dist/components/FormPage/FormPage.test.js +1 -1
- package/dist/components/FormRenderer/FormRenderer.js +0 -1
- package/dist/components/FormRenderer/FormRenderer.test.js +1 -5
- package/dist/components/FormRenderer/onCYAAction.js +1 -5
- package/dist/components/FormRenderer/onCYAAction.test.js +5 -8
- package/dist/components/FormRenderer/onPageAction.js +5 -8
- package/dist/components/FormRenderer/onPageAction.test.js +5 -6
- package/dist/components/TaskList/TaskList.js +1 -2
- package/dist/context/HooksContext/HooksContext.js +1 -1
- package/dist/hooks/useRefData.js +2 -1
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/models/EventTypes.js +1 -3
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +0 -1
- package/dist/utils/Component/getComponent.js +13 -0
- package/dist/utils/Component/getComponentTests/getComponent.calculation.test.js +2 -2
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +6 -6
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var
|
|
9
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
10
10
|
var _FormComponent = _interopRequireDefault(require("../FormComponent"));
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
12
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
@@ -20,7 +20,7 @@ var Answer = function Answer(_ref) {
|
|
|
20
20
|
component = _ref.component,
|
|
21
21
|
formData = _ref.formData;
|
|
22
22
|
if (!value) {
|
|
23
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
23
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.VisuallyHidden, null, "No answer");
|
|
24
24
|
}
|
|
25
25
|
if (!component) {
|
|
26
26
|
return Object.prototype.hasOwnProperty.call(value, 'label') ? value.label : value;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
var _Readonly = require("@ukhomeoffice/cop-react-components/dist/Readonly");
|
|
5
4
|
var _react = _interopRequireDefault(require("react"));
|
|
6
5
|
var _setupTests = require("../../setupTests");
|
|
7
6
|
var _Answer = _interopRequireDefault(require("./Answer"));
|
|
@@ -66,7 +65,7 @@ describe('components', function () {
|
|
|
66
65
|
})), container = _renderWithValidation3.container;
|
|
67
66
|
answer = container.childNodes[0];
|
|
68
67
|
expect(answer.tagName).toEqual('DIV');
|
|
69
|
-
expect(answer.classList).toContain(
|
|
68
|
+
expect(answer.classList).toContain(DEFAULT_READONLY_CLASS);
|
|
70
69
|
expect(answer.textContent).toEqual(VALUE);
|
|
71
70
|
case 7:
|
|
72
71
|
case "end":
|
|
@@ -125,7 +124,7 @@ describe('components', function () {
|
|
|
125
124
|
})), container = _renderWithValidation5.container;
|
|
126
125
|
answer = container.childNodes[0];
|
|
127
126
|
expect(answer.tagName).toEqual('DIV');
|
|
128
|
-
expect(answer.classList).toContain(
|
|
127
|
+
expect(answer.classList).toContain(DEFAULT_READONLY_CLASS);
|
|
129
128
|
expect(answer.textContent).toEqual('hardcoded delta');
|
|
130
129
|
case 8:
|
|
131
130
|
case "end":
|
|
@@ -29,7 +29,6 @@ var DEFAULT_CLASS = _FormPage2.DEFAULT_CLASS;
|
|
|
29
29
|
exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
30
30
|
var CollectionPage = function CollectionPage(_ref) {
|
|
31
31
|
var page = _ref.page,
|
|
32
|
-
onCollectionChange = _ref.onCollectionChange,
|
|
33
32
|
onAction = _ref.onAction,
|
|
34
33
|
hashLink = _ref.hashLink,
|
|
35
34
|
classBlock = _ref.classBlock,
|
|
@@ -63,9 +62,6 @@ var CollectionPage = function CollectionPage(_ref) {
|
|
|
63
62
|
value: newValue
|
|
64
63
|
}
|
|
65
64
|
});
|
|
66
|
-
if (typeof onCollectionChange === 'function') {
|
|
67
|
-
onCollectionChange(page.formData);
|
|
68
|
-
}
|
|
69
65
|
};
|
|
70
66
|
var reportActiveIdChange = function reportActiveIdChange(newActiveId) {
|
|
71
67
|
onPageChange({
|
|
@@ -123,7 +119,6 @@ CollectionPage.propTypes = {
|
|
|
123
119
|
actions: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.shape({}), _propTypes.default.string])),
|
|
124
120
|
formData: _propTypes.default.shape({}).isRequired
|
|
125
121
|
}).isRequired,
|
|
126
|
-
onCollectionChange: _propTypes.default.func,
|
|
127
122
|
onAction: _propTypes.default.func.isRequired,
|
|
128
123
|
hashLink: _propTypes.default.bool,
|
|
129
124
|
classBlock: _propTypes.default.string,
|
|
@@ -131,7 +126,6 @@ CollectionPage.propTypes = {
|
|
|
131
126
|
className: _propTypes.default.string
|
|
132
127
|
};
|
|
133
128
|
CollectionPage.defaultProps = {
|
|
134
|
-
onCollectionChange: undefined,
|
|
135
129
|
hashLink: false,
|
|
136
130
|
classBlock: DEFAULT_CLASS,
|
|
137
131
|
classModifiers: [],
|
|
@@ -150,7 +150,7 @@ describe('components.CollectionPage', function () {
|
|
|
150
150
|
expect(input.tagName).toEqual('INPUT');
|
|
151
151
|
expect(input.classList).toContain('govuk-input');
|
|
152
152
|
expect(input.id).toEqual(fieldId);
|
|
153
|
-
expect(input.value).toEqual(val);
|
|
153
|
+
expect(input.dataset.value).toEqual(val);
|
|
154
154
|
return input;
|
|
155
155
|
};
|
|
156
156
|
var checkAutoCompleteField = function checkAutoCompleteField(formGroup, fieldId, lbl, hnt, val) {
|
|
@@ -84,7 +84,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
84
84
|
expect(input.tagName).toEqual('INPUT');
|
|
85
85
|
expect(input.classList).toContain('govuk-input');
|
|
86
86
|
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
87
|
-
expect(input.value).toEqual(TEXT_VALUE);
|
|
87
|
+
expect(input.dataset.value).toEqual(TEXT_VALUE);
|
|
88
88
|
case 30:
|
|
89
89
|
case "end":
|
|
90
90
|
return _context.stop();
|
|
@@ -392,7 +392,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
392
392
|
input = formGroup.childNodes[2];
|
|
393
393
|
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
394
394
|
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
395
|
-
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
395
|
+
expect(input.dataset.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
396
396
|
expect(input.textContent).toEqual(TEXT_VALUE);
|
|
397
397
|
case 30:
|
|
398
398
|
case "end":
|
|
@@ -518,7 +518,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
518
518
|
expect(input.tagName).toEqual('INPUT');
|
|
519
519
|
expect(input.classList).toContain('govuk-input');
|
|
520
520
|
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
521
|
-
expect(input.value).toEqual(TEXT_VALUE);
|
|
521
|
+
expect(input.dataset.value).toEqual(TEXT_VALUE);
|
|
522
522
|
|
|
523
523
|
// First item component 2
|
|
524
524
|
formGroup = itemContainer.childNodes[1];
|
|
@@ -537,7 +537,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
537
537
|
expect(input.tagName).toEqual('INPUT');
|
|
538
538
|
expect(input.classList).toContain('govuk-input');
|
|
539
539
|
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
540
|
-
expect(input.value).toEqual('charlie');
|
|
540
|
+
expect(input.dataset.value).toEqual('charlie');
|
|
541
541
|
|
|
542
542
|
// Check the second item and confirm there is no hint
|
|
543
543
|
itemTwo = c.childNodes[1];
|
|
@@ -564,7 +564,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
564
564
|
expect(inputTwo.tagName).toEqual('INPUT');
|
|
565
565
|
expect(inputTwo.classList).toContain('govuk-input');
|
|
566
566
|
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
567
|
-
expect(inputTwo.value).toEqual('beta');
|
|
567
|
+
expect(inputTwo.dataset.value).toEqual('beta');
|
|
568
568
|
|
|
569
569
|
// Second item second component
|
|
570
570
|
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
@@ -581,7 +581,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
581
581
|
expect(inputTwo.tagName).toEqual('INPUT');
|
|
582
582
|
expect(inputTwo.classList).toContain('govuk-input');
|
|
583
583
|
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
584
|
-
expect(inputTwo.value).toEqual('delta');
|
|
584
|
+
expect(inputTwo.dataset.value).toEqual('delta');
|
|
585
585
|
case 87:
|
|
586
586
|
case "end":
|
|
587
587
|
return _context11.stop();
|
|
@@ -658,7 +658,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
658
658
|
expect(input.tagName).toEqual('INPUT');
|
|
659
659
|
expect(input.classList).toContain('govuk-input');
|
|
660
660
|
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
661
|
-
expect(input.value).toEqual(TEXT_VALUE);
|
|
661
|
+
expect(input.dataset.value).toEqual(TEXT_VALUE);
|
|
662
662
|
|
|
663
663
|
// First item component 2
|
|
664
664
|
formGroup = itemContainer.childNodes[1];
|
|
@@ -677,7 +677,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
677
677
|
expect(input.tagName).toEqual('INPUT');
|
|
678
678
|
expect(input.classList).toContain('govuk-input');
|
|
679
679
|
expect(input.id).toEqual("".concat(ID, "[0].textTwo"));
|
|
680
|
-
expect(input.value).toEqual('charlie');
|
|
680
|
+
expect(input.dataset.value).toEqual('charlie');
|
|
681
681
|
|
|
682
682
|
// Check the second item and confirm there is no hint
|
|
683
683
|
itemTwo = c.childNodes[1];
|
|
@@ -704,7 +704,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
704
704
|
expect(inputTwo.tagName).toEqual('INPUT');
|
|
705
705
|
expect(inputTwo.classList).toContain('govuk-input');
|
|
706
706
|
expect(inputTwo.id).toEqual("".concat(ID, "[1].").concat(TEXT_ID));
|
|
707
|
-
expect(inputTwo.value).toEqual('beta');
|
|
707
|
+
expect(inputTwo.dataset.value).toEqual('beta');
|
|
708
708
|
|
|
709
709
|
// Second item second component
|
|
710
710
|
formGroupTwo = itemContainerTwo.childNodes[1];
|
|
@@ -721,7 +721,7 @@ describe('components.FormComponent.Collection', function () {
|
|
|
721
721
|
expect(inputTwo.tagName).toEqual('INPUT');
|
|
722
722
|
expect(inputTwo.classList).toContain('govuk-input');
|
|
723
723
|
expect(inputTwo.id).toEqual("".concat(ID, "[1].textTwo"));
|
|
724
|
-
expect(inputTwo.value).toEqual('delta');
|
|
724
|
+
expect(inputTwo.dataset.value).toEqual('delta');
|
|
725
725
|
case 89:
|
|
726
726
|
case "end":
|
|
727
727
|
return _context12.stop();
|
|
@@ -76,7 +76,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
76
76
|
expect(input.tagName).toEqual('INPUT');
|
|
77
77
|
expect(input.classList).toContain('govuk-input');
|
|
78
78
|
expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
79
|
-
expect(input.value).toEqual(TEXT_VALUE);
|
|
79
|
+
expect(input.dataset.value).toEqual(TEXT_VALUE);
|
|
80
80
|
case 22:
|
|
81
81
|
case "end":
|
|
82
82
|
return _context.stop();
|
|
@@ -130,7 +130,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
130
130
|
expect(input.tagName).toEqual('INPUT');
|
|
131
131
|
expect(input.classList).toContain('govuk-input');
|
|
132
132
|
expect(input.id).toEqual("".concat(ID, ".").concat(NESTED_ID, ".").concat(TEXT_ID));
|
|
133
|
-
expect(input.value).toEqual(NESTED_TEXT_VALUE);
|
|
133
|
+
expect(input.dataset.value).toEqual(NESTED_TEXT_VALUE);
|
|
134
134
|
case 25:
|
|
135
135
|
case "end":
|
|
136
136
|
return _context2.stop();
|
|
@@ -359,7 +359,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
359
359
|
input = formGroup.childNodes[2];
|
|
360
360
|
expect(input.tagName).toEqual('DIV'); // Now readonly, so a DIV.
|
|
361
361
|
expect(input.classList).toContain('hods-readonly'); // Now readonly, so hods-readonly
|
|
362
|
-
expect(input.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
362
|
+
expect(input.dataset.id).toEqual("".concat(ID, ".").concat(TEXT_ID));
|
|
363
363
|
expect(input.textContent).toEqual(TEXT_VALUE);
|
|
364
364
|
case 22:
|
|
365
365
|
case "end":
|
|
@@ -47,7 +47,7 @@ describe('components', function () {
|
|
|
47
47
|
expect(input.tagName).toEqual('INPUT');
|
|
48
48
|
expect(input.classList).toContain('govuk-input');
|
|
49
49
|
expect(input.id).toEqual(ID);
|
|
50
|
-
expect(input.value).toEqual(VALUE);
|
|
50
|
+
expect(input.dataset.value).toEqual(VALUE);
|
|
51
51
|
case 22:
|
|
52
52
|
case "end":
|
|
53
53
|
return _context.stop();
|
|
@@ -80,7 +80,7 @@ describe('components', function () {
|
|
|
80
80
|
expect(input.tagName).toEqual('INPUT');
|
|
81
81
|
expect(input.classList).toContain('govuk-input');
|
|
82
82
|
expect(input.id).toEqual(ID);
|
|
83
|
-
expect(input.value).toEqual(VALUE);
|
|
83
|
+
expect(input.dataset.value).toEqual(VALUE);
|
|
84
84
|
case 10:
|
|
85
85
|
case "end":
|
|
86
86
|
return _context2.stop();
|
|
@@ -215,7 +215,7 @@ describe('components', function () {
|
|
|
215
215
|
expect(input.tagName).toEqual('INPUT');
|
|
216
216
|
expect(input.classList).toContain('govuk-input');
|
|
217
217
|
expect(input.id).toEqual(ID);
|
|
218
|
-
expect(input.value).toEqual(VALUE);
|
|
218
|
+
expect(input.dataset.value).toEqual(VALUE);
|
|
219
219
|
case 23:
|
|
220
220
|
case "end":
|
|
221
221
|
return _context6.stop();
|
|
@@ -138,7 +138,7 @@ describe('components.FormPage', function () {
|
|
|
138
138
|
expect(input.tagName).toEqual('INPUT');
|
|
139
139
|
expect(input.classList).toContain('govuk-input');
|
|
140
140
|
expect(input.id).toEqual(fieldId);
|
|
141
|
-
expect(input.value).toEqual(val);
|
|
141
|
+
expect(input.dataset.value).toEqual(val);
|
|
142
142
|
return input;
|
|
143
143
|
};
|
|
144
144
|
var checkAutoCompleteField = function checkAutoCompleteField(formGroup, fieldId, lbl, hnt, val) {
|
|
@@ -354,7 +354,6 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
|
|
|
354
354
|
className: formState.page.className
|
|
355
355
|
}), formState.page && !formState.cya && formState.page.collection && /*#__PURE__*/_react.default.createElement(_CollectionPage.default, {
|
|
356
356
|
page: formState.page,
|
|
357
|
-
onCollectionChange: onChange,
|
|
358
357
|
onAction: function onAction(action, patch, patchLabel) {
|
|
359
358
|
(0, _onPageAction.default)(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors);
|
|
360
359
|
},
|
|
@@ -552,13 +552,9 @@ describe('components', function () {
|
|
|
552
552
|
})));
|
|
553
553
|
case 7:
|
|
554
554
|
taskList = container.childNodes[0].childNodes[1];
|
|
555
|
-
taskList.childNodes.forEach(function (child) {
|
|
556
|
-
// eslint-disable-next-line no-console
|
|
557
|
-
console.log("taskList, child = ".concat(JSON.stringify(child.textContent)));
|
|
558
|
-
});
|
|
559
555
|
expect(taskList.childNodes[5].textContent).not.toEqual("test text");
|
|
560
556
|
expect(taskList.childNodes[5].classList).not.toContain('govuk-textarea');
|
|
561
|
-
case
|
|
557
|
+
case 10:
|
|
562
558
|
case "end":
|
|
563
559
|
return _context22.stop();
|
|
564
560
|
}
|
|
@@ -101,11 +101,7 @@ var onCYAAction = function onCYAAction(setPagePoint, action, pages, validate, co
|
|
|
101
101
|
onPageChange(_helpers.default.getNextPageId(type, pages, pageId, action, (_formState$page = formState.page) === null || _formState$page === void 0 ? void 0 : _formState$page.formData));
|
|
102
102
|
}
|
|
103
103
|
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
104
|
-
|
|
105
|
-
pages: pages,
|
|
106
|
-
components: components
|
|
107
|
-
}, _objectSpread({}, data), _models.EventTypes.CANCEL);
|
|
108
|
-
hooks.onCancel(formData);
|
|
104
|
+
hooks.onCancel();
|
|
109
105
|
}
|
|
110
106
|
};
|
|
111
107
|
var _default = onCYAAction;
|
|
@@ -102,15 +102,15 @@ describe('components.FormRenderer.onCYAAction', function () {
|
|
|
102
102
|
onFormComplete: function onFormComplete() {
|
|
103
103
|
this.onFormCompleteCalls += 1;
|
|
104
104
|
},
|
|
105
|
-
|
|
106
|
-
onCancel: function onCancel(
|
|
107
|
-
this.
|
|
105
|
+
onCancelCalls: 0,
|
|
106
|
+
onCancel: function onCancel() {
|
|
107
|
+
this.onCancelCalls += 1;
|
|
108
108
|
},
|
|
109
109
|
reset: function reset() {
|
|
110
110
|
this.onSubmitCalls = 0;
|
|
111
111
|
this.onSubmitArgs = [];
|
|
112
112
|
this.onFormCompleteCalls = 0;
|
|
113
|
-
this.
|
|
113
|
+
this.onCancelCalls = 0;
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
var setPagePointCalls = 0;
|
|
@@ -578,9 +578,6 @@ describe('components.FormRenderer.onCYAAction', function () {
|
|
|
578
578
|
}
|
|
579
579
|
});
|
|
580
580
|
_onCYAAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
581
|
-
expect(MOCK_HOOKS.
|
|
582
|
-
expect(MOCK_HOOKS.onCancelArgs[0]).toMatchObject({
|
|
583
|
-
id: 'formId'
|
|
584
|
-
});
|
|
581
|
+
expect(MOCK_HOOKS.onCancelCalls).toEqual(1);
|
|
585
582
|
});
|
|
586
583
|
});
|
|
@@ -20,6 +20,11 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
20
20
|
// patchLabel captures non-ID values
|
|
21
21
|
// for display purposes after submission.)
|
|
22
22
|
var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors) {
|
|
23
|
+
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
24
|
+
hooks.onCancel();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
;
|
|
23
28
|
// Save a copy of data in case submit errors and we need to revert
|
|
24
29
|
var preSubmitData = _objectSpread({}, data);
|
|
25
30
|
var form = formState;
|
|
@@ -31,14 +36,6 @@ var onPageAction = function onPageAction(action, patch, patchLabel, hooks, data,
|
|
|
31
36
|
// This should normally have no effect but will prevent issues
|
|
32
37
|
// with validation if formData happens to have been wiped.
|
|
33
38
|
form.page.formData = _objectSpread(_objectSpread({}, form.page.formData), _patch);
|
|
34
|
-
|
|
35
|
-
// Exposes form data to consuming application.
|
|
36
|
-
if (action.type === _models.PageAction.TYPES.CANCEL) {
|
|
37
|
-
hooks.onCancel(form.page.formData);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
;
|
|
41
|
-
|
|
42
39
|
// Check to see whether the action is able to proceed, which in
|
|
43
40
|
// in the case of a submission will validate the fields in the page.
|
|
44
41
|
if (_helpers.default.canActionProceed(action, form.page, validate.page)) {
|
|
@@ -121,15 +121,15 @@ describe('components.FormRenderer.onPageAction', function () {
|
|
|
121
121
|
onFormComplete: function onFormComplete() {
|
|
122
122
|
this.onFormCompleteCalls += 1;
|
|
123
123
|
},
|
|
124
|
-
|
|
125
|
-
onCancel: function onCancel(
|
|
126
|
-
this.
|
|
124
|
+
onCancelCalls: 0,
|
|
125
|
+
onCancel: function onCancel() {
|
|
126
|
+
this.onCancelCalls += 1;
|
|
127
127
|
},
|
|
128
128
|
reset: function reset() {
|
|
129
129
|
this.onSubmitCalls = 0;
|
|
130
130
|
this.onSubmitArgs = [];
|
|
131
131
|
this.onFormCompleteCalls = 0;
|
|
132
|
-
this.
|
|
132
|
+
this.onCancelCalls = 0;
|
|
133
133
|
this.onActionCalls = 0;
|
|
134
134
|
},
|
|
135
135
|
onActionCalls: 0,
|
|
@@ -290,8 +290,7 @@ describe('components.FormRenderer.onPageAction', function () {
|
|
|
290
290
|
action: ACTION
|
|
291
291
|
});
|
|
292
292
|
_onPageAction.default.apply(void 0, Object.values(CUSTOM_ARGS));
|
|
293
|
-
expect(MOCK_HOOKS.
|
|
294
|
-
expect(MOCK_HOOKS.onCancelArgs[0]).toMatchObject({});
|
|
293
|
+
expect(MOCK_HOOKS.onCancelCalls).toEqual(1);
|
|
295
294
|
// Shouldn't get to the point of validation if
|
|
296
295
|
// action is a cancel action.
|
|
297
296
|
expect(_helpers.default.canActionProceedCalls).toEqual(0);
|
|
@@ -8,7 +8,6 @@ exports.default = exports.DEFAULT_INCOMPLETE_TITLE = exports.DEFAULT_CLASS = voi
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
11
|
-
var _dist = require("@ukhomeoffice/cop-react-components/dist");
|
|
12
11
|
var _models = require("../../models");
|
|
13
12
|
var _Task = _interopRequireDefault(require("./Task"));
|
|
14
13
|
var _showComponent = _interopRequireDefault(require("../../utils/Component/showComponent"));
|
|
@@ -103,7 +102,7 @@ var TaskList = function TaskList(_ref) {
|
|
|
103
102
|
className: classes('section')
|
|
104
103
|
}, sections.length > 1 ? "".concat(index + 1, ". ") : '', section.name), /*#__PURE__*/_react.default.createElement("ol", {
|
|
105
104
|
className: classes('items')
|
|
106
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
105
|
+
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.Hint, null, section.label ? section.label : ''), section.tasks.filter(function (task) {
|
|
107
106
|
return task.state !== _models.TaskStates.TYPES.SKIPPED;
|
|
108
107
|
}).map(function (task) {
|
|
109
108
|
return /*#__PURE__*/_react.default.createElement(_Task.default, {
|
|
@@ -56,7 +56,7 @@ var DEFAULT_HOOKS = {
|
|
|
56
56
|
return errors;
|
|
57
57
|
},
|
|
58
58
|
// Returns the list of errors already found in FR by default.
|
|
59
|
-
onCancel: function onCancel(
|
|
59
|
+
onCancel: function onCancel() {} // Consuming application must provide function to action, else this does nothing.
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
var ALLOWED_HOOKS = Object.keys(DEFAULT_HOOKS);
|
package/dist/hooks/useRefData.js
CHANGED
|
@@ -52,7 +52,8 @@ var useRefData = function useRefData(component, formData) {
|
|
|
52
52
|
setStatus = _useState4[1];
|
|
53
53
|
(0, _react.useEffect)(function () {
|
|
54
54
|
if (!url) {
|
|
55
|
-
|
|
55
|
+
var _component$data;
|
|
56
|
+
if ((_component$data = component.data) !== null && _component$data !== void 0 && _component$data.options) {
|
|
56
57
|
setData(_Data.default.refData.toOptions(component.data.options, component.item));
|
|
57
58
|
}
|
|
58
59
|
setStatus(STATUS_COMPLETE);
|
|
@@ -10,6 +10,7 @@ var TYPE_CALCULATION = 'calculation';
|
|
|
10
10
|
var TYPE_CHECKBOXES = 'checkboxes';
|
|
11
11
|
var TYPE_COLLECTION = 'collection';
|
|
12
12
|
var TYPE_CONTAINER = 'container';
|
|
13
|
+
var TYPE_DATA = 'data';
|
|
13
14
|
var TYPE_DATE = 'date';
|
|
14
15
|
var TYPE_DETAILS = 'details';
|
|
15
16
|
var TYPE_EMAIL = 'email';
|
|
@@ -34,6 +35,7 @@ var ComponentTypes = {
|
|
|
34
35
|
CHECKBOXES: TYPE_CHECKBOXES,
|
|
35
36
|
COLLECTION: TYPE_COLLECTION,
|
|
36
37
|
CONTAINER: TYPE_CONTAINER,
|
|
38
|
+
DATA: TYPE_DATA,
|
|
37
39
|
DATE: TYPE_DATE,
|
|
38
40
|
DETAILS: TYPE_DETAILS,
|
|
39
41
|
EMAIL: TYPE_EMAIL,
|
|
@@ -6,11 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var TYPE_BLUR = 'blur';
|
|
8
8
|
var TYPE_SUBMIT = 'submit';
|
|
9
|
-
var TYPE_CANCEL = 'cancel';
|
|
10
9
|
var EventTypes = {
|
|
11
10
|
BLUR: TYPE_BLUR,
|
|
12
|
-
SUBMIT: TYPE_SUBMIT
|
|
13
|
-
CANCEL: TYPE_CANCEL
|
|
11
|
+
SUBMIT: TYPE_SUBMIT
|
|
14
12
|
};
|
|
15
13
|
var _default = EventTypes;
|
|
16
14
|
exports.default = _default;
|
|
@@ -9,7 +9,6 @@ var _Component = _interopRequireDefault(require("../Component"));
|
|
|
9
9
|
var _Container = _interopRequireDefault(require("../Container"));
|
|
10
10
|
var _getSourceData = _interopRequireDefault(require("../Data/getSourceData"));
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
/* eslint-disable no-console */
|
|
13
12
|
// Local imports
|
|
14
13
|
|
|
15
14
|
var EXCLUDE_FROM_CYA = [_models.ComponentTypes.ALERT, _models.ComponentTypes.HEADING, _models.ComponentTypes.HTML, _models.ComponentTypes.INSET_TEXT];
|
|
@@ -80,6 +80,17 @@ var getCalculation = function getCalculation(config) {
|
|
|
80
80
|
readonly: true
|
|
81
81
|
}));
|
|
82
82
|
};
|
|
83
|
+
var getData = function getData(config) {
|
|
84
|
+
var options = [];
|
|
85
|
+
_Data.default.getOptions(config, function (val) {
|
|
86
|
+
options = val;
|
|
87
|
+
});
|
|
88
|
+
var attrs = (0, _cleanAttributes.default)(config);
|
|
89
|
+
var text = JSON.stringify(options, null, 2);
|
|
90
|
+
return /*#__PURE__*/_react.default.createElement(_copReactComponents.TextArea, _extends({}, attrs, {
|
|
91
|
+
value: text
|
|
92
|
+
}));
|
|
93
|
+
};
|
|
83
94
|
var getDate = function getDate(config) {
|
|
84
95
|
var attrs = (0, _cleanAttributes.default)(config);
|
|
85
96
|
return /*#__PURE__*/_react.default.createElement(_copReactComponents.DateInput, attrs);
|
|
@@ -220,6 +231,8 @@ var getComponentByType = function getComponentByType(config) {
|
|
|
220
231
|
return getParagraph(config);
|
|
221
232
|
case _models.ComponentTypes.LIST:
|
|
222
233
|
return getList(config);
|
|
234
|
+
case _models.ComponentTypes.DATA:
|
|
235
|
+
return getData(config);
|
|
223
236
|
default:
|
|
224
237
|
{
|
|
225
238
|
return null;
|
|
@@ -148,7 +148,7 @@ describe('utils.Component.get', function () {
|
|
|
148
148
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
149
149
|
expect(input.tagName).toEqual('DIV');
|
|
150
150
|
expect(input.classList).toContain('hods-readonly');
|
|
151
|
-
expect(input.id).toEqual(ID);
|
|
151
|
+
expect(input.dataset.id).toEqual(ID);
|
|
152
152
|
expect("".concat(COMPONENT.formData[FIELD_ID])).toEqual(test.result);
|
|
153
153
|
case 13:
|
|
154
154
|
case "end":
|
|
@@ -258,7 +258,7 @@ describe('utils.Component.get', function () {
|
|
|
258
258
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
259
259
|
expect(input.tagName).toEqual('DIV');
|
|
260
260
|
expect(input.classList).toContain('hods-readonly');
|
|
261
|
-
expect(input.id).toEqual(ID);
|
|
261
|
+
expect(input.dataset.id).toEqual(ID);
|
|
262
262
|
expect(error).toBeCalledTimes(1);
|
|
263
263
|
expect(error).toBeCalledWith(test.error);
|
|
264
264
|
});
|
|
@@ -51,7 +51,7 @@ describe('utils.Component.get', function () {
|
|
|
51
51
|
expect(input.tagName).toEqual('INPUT');
|
|
52
52
|
expect(input.classList).toContain('govuk-input');
|
|
53
53
|
expect(input.id).toEqual(ID);
|
|
54
|
-
expect(input.value).toEqual(VALUE);
|
|
54
|
+
expect(input.dataset.value).toEqual(VALUE);
|
|
55
55
|
child2 = container.childNodes[1];
|
|
56
56
|
expect(child2.childNodes[0].childNodes.length).toEqual(3);
|
|
57
57
|
expect(child2.classList).toContain('govuk-form-group');
|
|
@@ -62,9 +62,9 @@ describe('utils.Component.get', function () {
|
|
|
62
62
|
expect(input2.tagName).toEqual('DIV');
|
|
63
63
|
expect(input2.classList).toContain('govuk-date-input');
|
|
64
64
|
expect(input2.id).toEqual(ID2);
|
|
65
|
-
expect(input2.childNodes[0].childNodes[1].value).toEqual('1');
|
|
66
|
-
expect(input2.childNodes[1].childNodes[1].value).toEqual('2');
|
|
67
|
-
expect(input2.childNodes[2].childNodes[1].value).toEqual('2022');
|
|
65
|
+
expect(input2.childNodes[0].childNodes[1].dataset.value).toEqual('1');
|
|
66
|
+
expect(input2.childNodes[1].childNodes[1].dataset.value).toEqual('2');
|
|
67
|
+
expect(input2.childNodes[2].childNodes[1].dataset.value).toEqual('2022');
|
|
68
68
|
case 35:
|
|
69
69
|
case "end":
|
|
70
70
|
return _context.stop();
|
|
@@ -133,7 +133,7 @@ describe('utils.Component.get', function () {
|
|
|
133
133
|
expect(input.tagName).toEqual('INPUT');
|
|
134
134
|
expect(input.classList).toContain('govuk-input');
|
|
135
135
|
expect(input.id).toEqual("".concat(CONTAINER_ID, ".").concat(FIELD_ID));
|
|
136
|
-
expect(input.value).toEqual(VALUE);
|
|
136
|
+
expect(input.dataset.value).toEqual(VALUE);
|
|
137
137
|
case 19:
|
|
138
138
|
case "end":
|
|
139
139
|
return _context3.stop();
|
|
@@ -172,7 +172,7 @@ describe('utils.Component.get', function () {
|
|
|
172
172
|
expect(input.tagName).toEqual('INPUT');
|
|
173
173
|
expect(input.classList).toContain('govuk-input');
|
|
174
174
|
expect(input.id).toEqual("".concat(COLLECTION_ID, "[0].").concat(FIELD_ID));
|
|
175
|
-
expect(input.value).toEqual(VALUE);
|
|
175
|
+
expect(input.dataset.value).toEqual(VALUE);
|
|
176
176
|
case 19:
|
|
177
177
|
case "end":
|
|
178
178
|
return _context4.stop();
|