@ukhomeoffice/cop-react-form-renderer 2.9.1 → 2.10.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.
- package/dist/components/CheckYourAnswers/CheckYourAnswers.js +8 -12
- package/dist/components/CheckYourAnswers/CheckYourAnswers.test.js +10 -8
- package/dist/components/FormComponent/Collection.js +244 -0
- package/dist/components/FormComponent/Collection.scss +23 -0
- package/dist/components/FormComponent/Container.js +110 -0
- package/dist/components/FormComponent/Container.test.js +26 -26
- package/dist/components/FormComponent/FormComponent.js +64 -128
- package/dist/components/FormComponent/FormComponent.test.js +19 -19
- package/dist/components/FormComponent/helpers/getComponentError.js +31 -0
- package/dist/components/FormComponent/helpers/getComponentError.test.js +52 -0
- package/dist/components/FormComponent/helpers/index.js +15 -0
- package/dist/components/FormPage/FormPage.js +7 -11
- package/dist/components/FormPage/FormPage.test.js +12 -76
- package/dist/components/FormRenderer/FormRenderer.js +103 -44
- package/dist/components/FormRenderer/helpers/canActionProceed.js +3 -12
- package/dist/components/FormRenderer/helpers/canActionProceed.test.js +41 -65
- package/dist/components/FormRenderer/helpers/canCYASubmit.js +3 -24
- package/dist/components/FormRenderer/helpers/canCYASubmit.test.js +72 -145
- package/dist/components/SummaryList/GroupAction.js +1 -1
- package/dist/components/SummaryList/SummaryList.js +33 -18
- package/dist/components/SummaryList/SummaryList.scss +12 -8
- package/dist/components/SummaryList/SummaryList.test.js +94 -27
- package/dist/components/SummaryList/SummaryListRow.js +51 -0
- package/dist/components/SummaryList/SummaryListTitleRow.js +30 -0
- package/dist/context/ValidationContext/ValidationContext.js +122 -0
- package/dist/context/ValidationContext/ValidationContext.test.js +98 -0
- package/dist/context/ValidationContext/index.js +23 -0
- package/dist/context/index.js +15 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useValidation.js +19 -0
- package/dist/index.js +11 -5
- package/dist/models/CollectionLabels.js +14 -0
- package/dist/models/index.js +8 -0
- package/dist/setupTests.js +32 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +2 -0
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +6 -10
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.js +89 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForCollection.test.js +194 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +9 -13
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +11 -4
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +58 -14
- package/dist/utils/Component/getDefaultValue.js +25 -0
- package/dist/utils/Component/getDefaultValue.test.js +53 -0
- package/dist/utils/Component/index.js +4 -1
- package/package.json +1 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
var _react = require("@testing-library/react");
|
|
6
4
|
|
|
7
5
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
@@ -10,11 +8,13 @@ var _react2 = _interopRequireDefault(require("react"));
|
|
|
10
8
|
|
|
11
9
|
var _models = require("../../models");
|
|
12
10
|
|
|
13
|
-
var
|
|
11
|
+
var _setupTests = require("../../setupTests");
|
|
12
|
+
|
|
13
|
+
var _constants = require("../../utils/Meta/constants");
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
var _Container = require("./Container");
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
18
18
|
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
20
|
|
|
@@ -36,7 +36,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
36
36
|
var TEXT_ID = 'text';
|
|
37
37
|
var TEXT_VALUE = 'alpha';
|
|
38
38
|
var NESTED_TEXT_VALUE = 'charlie';
|
|
39
|
-
var FORM_DATA = (_FORM_DATA = {}, _defineProperty(_FORM_DATA, ID, (_ID = {}, _defineProperty(_ID, TEXT_ID, TEXT_VALUE), _defineProperty(_ID, NESTED_ID, _defineProperty({}, TEXT_ID, NESTED_TEXT_VALUE)), _ID)), _defineProperty(_FORM_DATA,
|
|
39
|
+
var FORM_DATA = (_FORM_DATA = {}, _defineProperty(_FORM_DATA, ID, (_ID = {}, _defineProperty(_ID, TEXT_ID, TEXT_VALUE), _defineProperty(_ID, NESTED_ID, _defineProperty({}, TEXT_ID, NESTED_TEXT_VALUE)), _ID)), _defineProperty(_FORM_DATA, _constants.META_PROPERTY, _defineProperty({}, _constants.META_DOCUMENTS_PROPERTY, [{
|
|
40
40
|
field: 'epsilon.zeta',
|
|
41
41
|
name: 'ez.jpg',
|
|
42
42
|
type: 'image/jpg',
|
|
@@ -51,7 +51,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
51
51
|
hint: 'Text hint'
|
|
52
52
|
};
|
|
53
53
|
it('should render a container component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
54
|
-
var CONTAINER,
|
|
54
|
+
var CONTAINER, _renderWithValidation, container, c, formGroup, label, hint, input;
|
|
55
55
|
|
|
56
56
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
57
57
|
while (1) {
|
|
@@ -63,15 +63,15 @@ describe('components.FormComponent.Container', function () {
|
|
|
63
63
|
type: _models.ComponentTypes.CONTAINER,
|
|
64
64
|
components: [TEXT_COMPONENT]
|
|
65
65
|
};
|
|
66
|
-
|
|
66
|
+
_renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
67
67
|
component: CONTAINER,
|
|
68
68
|
value: FORM_DATA[ID],
|
|
69
69
|
formData: FORM_DATA
|
|
70
|
-
})), container =
|
|
70
|
+
})), container = _renderWithValidation.container; // Check the container itself.
|
|
71
71
|
|
|
72
72
|
c = container.childNodes[0];
|
|
73
73
|
expect(c.tagName).toEqual('DIV');
|
|
74
|
-
expect(c.classList).toContain(
|
|
74
|
+
expect(c.classList).toContain(_Container.DEFAULT_CLASS); // And now check the single text component within it.
|
|
75
75
|
|
|
76
76
|
formGroup = c.childNodes[0];
|
|
77
77
|
expect(formGroup.tagName).toEqual('DIV');
|
|
@@ -99,7 +99,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
99
99
|
}, _callee);
|
|
100
100
|
})));
|
|
101
101
|
it('should render a nested container component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
102
|
-
var CONTAINER,
|
|
102
|
+
var CONTAINER, _renderWithValidation2, container, c, nested, formGroup, label, hint, input;
|
|
103
103
|
|
|
104
104
|
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
105
105
|
while (1) {
|
|
@@ -116,19 +116,19 @@ describe('components.FormComponent.Container', function () {
|
|
|
116
116
|
components: [TEXT_COMPONENT]
|
|
117
117
|
}]
|
|
118
118
|
};
|
|
119
|
-
|
|
119
|
+
_renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
120
120
|
component: CONTAINER,
|
|
121
121
|
value: FORM_DATA[ID],
|
|
122
122
|
formData: FORM_DATA
|
|
123
|
-
})), container =
|
|
123
|
+
})), container = _renderWithValidation2.container; // Check the container itself.
|
|
124
124
|
|
|
125
125
|
c = container.childNodes[0];
|
|
126
126
|
expect(c.tagName).toEqual('DIV');
|
|
127
|
-
expect(c.classList).toContain(
|
|
127
|
+
expect(c.classList).toContain(_Container.DEFAULT_CLASS); // Check the nested container.
|
|
128
128
|
|
|
129
129
|
nested = c.childNodes[0];
|
|
130
130
|
expect(nested.tagName).toEqual('DIV');
|
|
131
|
-
expect(nested.classList).toContain(
|
|
131
|
+
expect(nested.classList).toContain(_Container.DEFAULT_CLASS); // And now check the single text component within the nested container.
|
|
132
132
|
|
|
133
133
|
formGroup = nested.childNodes[0];
|
|
134
134
|
expect(formGroup.tagName).toEqual('DIV');
|
|
@@ -156,7 +156,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
156
156
|
}, _callee2);
|
|
157
157
|
})));
|
|
158
158
|
it('should handle a change to a component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
159
|
-
var ON_CHANGE_EVENTS, ON_CHANGE, CONTAINER,
|
|
159
|
+
var ON_CHANGE_EVENTS, ON_CHANGE, CONTAINER, _renderWithValidation3, container, c, formGroup, input, NEW_TEXT_VALUE, EVENT;
|
|
160
160
|
|
|
161
161
|
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
162
162
|
while (1) {
|
|
@@ -179,12 +179,12 @@ describe('components.FormComponent.Container', function () {
|
|
|
179
179
|
label: 'Text component'
|
|
180
180
|
}]
|
|
181
181
|
};
|
|
182
|
-
|
|
182
|
+
_renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
183
183
|
component: CONTAINER,
|
|
184
184
|
value: FORM_DATA[ID],
|
|
185
185
|
formData: FORM_DATA,
|
|
186
186
|
onChange: ON_CHANGE
|
|
187
|
-
})), container =
|
|
187
|
+
})), container = _renderWithValidation3.container; // Get hold of the text input.
|
|
188
188
|
|
|
189
189
|
c = container.childNodes[0];
|
|
190
190
|
formGroup = c.childNodes[0];
|
|
@@ -212,7 +212,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
212
212
|
}, _callee3);
|
|
213
213
|
})));
|
|
214
214
|
it('should handle a change to a file type component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
215
|
-
var FILE_ID, ON_CHANGE_EVENTS, ON_CHANGE, CONTAINER,
|
|
215
|
+
var FILE_ID, ON_CHANGE_EVENTS, ON_CHANGE, CONTAINER, _renderWithValidation4, container, c, formGroup, input, FILE_EXTENSION, FILE_NAME, FILE_TYPE, str, blob, FILE, containerChangeValue, metaChangeValue;
|
|
216
216
|
|
|
217
217
|
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
218
218
|
while (1) {
|
|
@@ -237,12 +237,12 @@ describe('components.FormComponent.Container', function () {
|
|
|
237
237
|
label: 'File component'
|
|
238
238
|
}]
|
|
239
239
|
};
|
|
240
|
-
|
|
240
|
+
_renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
241
241
|
component: CONTAINER,
|
|
242
242
|
value: FORM_DATA[ID],
|
|
243
243
|
formData: FORM_DATA,
|
|
244
244
|
onChange: ON_CHANGE
|
|
245
|
-
})), container =
|
|
245
|
+
})), container = _renderWithValidation4.container; // Get hold of the text input.
|
|
246
246
|
|
|
247
247
|
c = container.childNodes[0];
|
|
248
248
|
formGroup = c.childNodes[0];
|
|
@@ -264,7 +264,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
264
264
|
expect(ON_CHANGE_EVENTS.length).toEqual(2); // One for the file, another for the meta.
|
|
265
265
|
|
|
266
266
|
expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
|
|
267
|
-
expect(ON_CHANGE_EVENTS[1].target.name).toEqual(
|
|
267
|
+
expect(ON_CHANGE_EVENTS[1].target.name).toEqual(_constants.META_PROPERTY);
|
|
268
268
|
containerChangeValue = JSON.parse(JSON.stringify(ON_CHANGE_EVENTS[0].target.value));
|
|
269
269
|
metaChangeValue = JSON.parse(JSON.stringify(ON_CHANGE_EVENTS[1].target.value));
|
|
270
270
|
expect(metaChangeValue.documents.length).toEqual(2); // Existing one, plus this new one.
|
|
@@ -281,7 +281,7 @@ describe('components.FormComponent.Container', function () {
|
|
|
281
281
|
}, _callee4);
|
|
282
282
|
})));
|
|
283
283
|
it('should handle a null value appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
284
|
-
var CONTAINER,
|
|
284
|
+
var CONTAINER, _renderWithValidation5, container, c, formGroup, label, hint, input;
|
|
285
285
|
|
|
286
286
|
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
287
287
|
while (1) {
|
|
@@ -293,13 +293,13 @@ describe('components.FormComponent.Container', function () {
|
|
|
293
293
|
type: _models.ComponentTypes.CONTAINER,
|
|
294
294
|
components: [TEXT_COMPONENT]
|
|
295
295
|
};
|
|
296
|
-
|
|
296
|
+
_renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
297
297
|
component: CONTAINER
|
|
298
|
-
})), container =
|
|
298
|
+
})), container = _renderWithValidation5.container; // Check the container itself.
|
|
299
299
|
|
|
300
300
|
c = container.childNodes[0];
|
|
301
301
|
expect(c.tagName).toEqual('DIV');
|
|
302
|
-
expect(c.classList).toContain(
|
|
302
|
+
expect(c.classList).toContain(_Container.DEFAULT_CLASS); // And now check the single text component within it.
|
|
303
303
|
|
|
304
304
|
formGroup = c.childNodes[0];
|
|
305
305
|
expect(formGroup.tagName).toEqual('DIV');
|
|
@@ -5,7 +5,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.default =
|
|
8
|
+
exports.default = void 0;
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -17,8 +17,13 @@ var _models = require("../../models");
|
|
|
17
17
|
|
|
18
18
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
19
19
|
|
|
20
|
-
var
|
|
21
|
-
|
|
20
|
+
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
21
|
+
|
|
22
|
+
var _Container = _interopRequireDefault(require("./Container"));
|
|
23
|
+
|
|
24
|
+
var _helpers = require("./helpers");
|
|
25
|
+
|
|
26
|
+
var _excluded = ["component", "value", "formData", "wrap", "onChange"];
|
|
22
27
|
|
|
23
28
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
24
29
|
|
|
@@ -26,6 +31,14 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
26
31
|
|
|
27
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
33
|
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
41
|
+
|
|
29
42
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
30
43
|
|
|
31
44
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -38,108 +51,23 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
38
51
|
|
|
39
52
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
40
53
|
|
|
41
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
42
|
-
|
|
43
|
-
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; }
|
|
44
|
-
|
|
45
|
-
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; }
|
|
46
|
-
|
|
47
|
-
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; }
|
|
48
|
-
|
|
49
54
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
50
55
|
|
|
51
56
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
52
57
|
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
var META_DOCUMENTS_PROPERTY = 'documents';
|
|
56
|
-
exports.META_DOCUMENTS_PROPERTY = META_DOCUMENTS_PROPERTY;
|
|
57
|
-
var DEFAULT_CONTAINER_CLASS = 'hods-form-container';
|
|
58
|
-
exports.DEFAULT_CONTAINER_CLASS = DEFAULT_CONTAINER_CLASS;
|
|
59
|
-
|
|
60
|
-
var Container = function Container(_ref) {
|
|
61
|
-
var container = _ref.container,
|
|
58
|
+
var FormComponent = function FormComponent(_ref) {
|
|
59
|
+
var component = _ref.component,
|
|
62
60
|
value = _ref.value,
|
|
63
61
|
formData = _ref.formData,
|
|
64
|
-
onChange = _ref.onChange,
|
|
65
62
|
wrap = _ref.wrap,
|
|
63
|
+
onChange = _ref.onChange,
|
|
66
64
|
attrs = _objectWithoutProperties(_ref, _excluded);
|
|
67
65
|
|
|
68
|
-
var onComponentChange = function onComponentChange(_ref2) {
|
|
69
|
-
var target = _ref2.target;
|
|
70
|
-
|
|
71
|
-
if (typeof onChange === 'function') {
|
|
72
|
-
if (target.name === META_PROPERTY) {
|
|
73
|
-
onChange({
|
|
74
|
-
target: target
|
|
75
|
-
});
|
|
76
|
-
} else {
|
|
77
|
-
var val = _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, target.name, target.value));
|
|
78
|
-
|
|
79
|
-
onChange({
|
|
80
|
-
target: {
|
|
81
|
-
name: container.fieldId,
|
|
82
|
-
value: val
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
var shouldShow = function shouldShow(options) {
|
|
90
|
-
if (options.type === _models.ComponentTypes.CONTAINER) {
|
|
91
|
-
return _utils.default.Container.show(options, formData);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return _utils.default.Component.show(options, formData);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return /*#__PURE__*/_react.default.createElement("div", _extends({}, attrs, {
|
|
98
|
-
className: DEFAULT_CONTAINER_CLASS,
|
|
99
|
-
id: container.id
|
|
100
|
-
}), container.components && container.components.filter(shouldShow).map(function (component, index) {
|
|
101
|
-
var defaultValue = component.type === _models.ComponentTypes.FILE ? {} : '';
|
|
102
|
-
var val = value ? value[component.fieldId] : defaultValue;
|
|
103
|
-
return /*#__PURE__*/_react.default.createElement(FormComponent, {
|
|
104
|
-
key: index,
|
|
105
|
-
component: component,
|
|
106
|
-
formData: formData,
|
|
107
|
-
value: val || defaultValue,
|
|
108
|
-
wrap: wrap,
|
|
109
|
-
onChange: onComponentChange
|
|
110
|
-
});
|
|
111
|
-
}));
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
Container.propTypes = {
|
|
115
|
-
container: _propTypes.default.shape({
|
|
116
|
-
id: _propTypes.default.string.isRequired,
|
|
117
|
-
fieldId: _propTypes.default.string.isRequired,
|
|
118
|
-
components: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
119
|
-
fieldId: _propTypes.default.string,
|
|
120
|
-
type: _propTypes.default.string
|
|
121
|
-
}))
|
|
122
|
-
}).isRequired,
|
|
123
|
-
value: _propTypes.default.any,
|
|
124
|
-
formData: _propTypes.default.any,
|
|
125
|
-
wrap: _propTypes.default.bool,
|
|
126
|
-
onChange: _propTypes.default.func
|
|
127
|
-
};
|
|
128
|
-
Container.defaultProps = {
|
|
129
|
-
wrap: true
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
var FormComponent = function FormComponent(_ref3) {
|
|
133
|
-
var component = _ref3.component,
|
|
134
|
-
value = _ref3.value,
|
|
135
|
-
formData = _ref3.formData,
|
|
136
|
-
wrap = _ref3.wrap,
|
|
137
|
-
onChange = _ref3.onChange,
|
|
138
|
-
attrs = _objectWithoutProperties(_ref3, _excluded2);
|
|
139
|
-
|
|
140
66
|
var _useHooks = (0, _hooks.useHooks)(),
|
|
141
67
|
hooks = _useHooks.hooks;
|
|
142
68
|
|
|
69
|
+
var validation = (0, _hooks.useValidation)();
|
|
70
|
+
|
|
143
71
|
var _useRefData = (0, _hooks.useRefData)(component),
|
|
144
72
|
data = _useRefData.data,
|
|
145
73
|
status = _useRefData.status;
|
|
@@ -155,60 +83,68 @@ var FormComponent = function FormComponent(_ref3) {
|
|
|
155
83
|
}
|
|
156
84
|
}, [component, data, status]);
|
|
157
85
|
|
|
158
|
-
var
|
|
159
|
-
var
|
|
160
|
-
|
|
161
|
-
var documents = (((_formData$META_PROPER = formData[META_PROPERTY]) === null || _formData$META_PROPER === void 0 ? void 0 : _formData$META_PROPER.documents) || []).filter(function (d) {
|
|
162
|
-
return d.field !== component.full_path;
|
|
163
|
-
});
|
|
86
|
+
var onComponentChange = function onComponentChange(_ref2) {
|
|
87
|
+
var target = _ref2.target;
|
|
164
88
|
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
})
|
|
89
|
+
if (typeof onChange === 'function') {
|
|
90
|
+
onChange({
|
|
91
|
+
target: target
|
|
92
|
+
});
|
|
93
|
+
return true;
|
|
169
94
|
}
|
|
170
95
|
|
|
96
|
+
return false;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
100
|
+
return /*#__PURE__*/_react.default.createElement(_Container.default, _extends({}, attrs, {
|
|
101
|
+
container: component,
|
|
102
|
+
wrap: wrap,
|
|
103
|
+
onChange: onComponentChange,
|
|
104
|
+
value: value || _utils.default.Component.defaultValue(component),
|
|
105
|
+
formData: formData
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (component.type === _models.ComponentTypes.COLLECTION) {
|
|
110
|
+
return /*#__PURE__*/_react.default.createElement(_Collection.default, _extends({}, attrs, {
|
|
111
|
+
config: component,
|
|
112
|
+
wrap: wrap,
|
|
113
|
+
onChange: onComponentChange,
|
|
114
|
+
value: value || _utils.default.Component.defaultValue(component),
|
|
115
|
+
formData: formData
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
var changeMetaDocuments = function changeMetaDocuments(document) {
|
|
171
120
|
onChange({
|
|
172
121
|
target: {
|
|
173
|
-
name:
|
|
174
|
-
value:
|
|
175
|
-
documents: documents
|
|
176
|
-
})
|
|
122
|
+
name: _utils.default.Meta.name,
|
|
123
|
+
value: _utils.default.Meta.documents.setForField(document, formData, component.full_path)
|
|
177
124
|
}
|
|
178
125
|
});
|
|
179
126
|
};
|
|
180
127
|
|
|
181
|
-
var
|
|
182
|
-
var target =
|
|
183
|
-
|
|
184
|
-
if (typeof onChange === 'function') {
|
|
185
|
-
onChange({
|
|
186
|
-
target: target
|
|
187
|
-
});
|
|
128
|
+
var onComponentChangeExtended = function onComponentChangeExtended(_ref3) {
|
|
129
|
+
var target = _ref3.target;
|
|
188
130
|
|
|
131
|
+
if (onComponentChange({
|
|
132
|
+
target: target
|
|
133
|
+
})) {
|
|
189
134
|
if (component.type === _models.ComponentTypes.FILE) {
|
|
190
135
|
changeMetaDocuments(target.value);
|
|
191
136
|
}
|
|
192
137
|
}
|
|
193
138
|
};
|
|
194
139
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
wrap: wrap,
|
|
199
|
-
onChange: onComponentChange,
|
|
200
|
-
value: value,
|
|
201
|
-
formData: formData
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
var defaultValue = component.type === _models.ComponentTypes.FILE ? {} : '';
|
|
206
|
-
return _utils.default.Component.get(_objectSpread(_objectSpread(_objectSpread({}, attrs), component), {}, {
|
|
140
|
+
return _utils.default.Component.get(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, attrs), component), {}, {
|
|
141
|
+
id: component.full_path || component.id
|
|
142
|
+
}, (0, _helpers.getComponentError)(component, validation === null || validation === void 0 ? void 0 : validation.errors)), {}, {
|
|
207
143
|
label: component.label || '',
|
|
208
144
|
hint: component.hint || '',
|
|
209
145
|
options: options,
|
|
210
|
-
value: value || defaultValue,
|
|
211
|
-
onChange:
|
|
146
|
+
value: value || _utils.default.Component.defaultValue(component),
|
|
147
|
+
onChange: onComponentChangeExtended,
|
|
212
148
|
formData: formData
|
|
213
149
|
}), wrap, hooks.onGetComponent);
|
|
214
150
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _react = require("
|
|
4
|
-
|
|
5
|
-
var _react2 = _interopRequireDefault(require("react"));
|
|
3
|
+
var _react = _interopRequireDefault(require("react"));
|
|
6
4
|
|
|
7
5
|
var _useHooks = require("../../hooks/useHooks");
|
|
8
6
|
|
|
7
|
+
var _setupTests = require("../../setupTests");
|
|
8
|
+
|
|
9
9
|
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
10
10
|
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -20,7 +20,7 @@ describe('components', function () {
|
|
|
20
20
|
(0, _useHooks.resetHooks)();
|
|
21
21
|
});
|
|
22
22
|
it('should render a text component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
23
|
-
var ID, VALUE, COMPONENT, ON_CHANGE,
|
|
23
|
+
var ID, VALUE, COMPONENT, ON_CHANGE, _renderWithValidation, container, formGroup, label, hint, input;
|
|
24
24
|
|
|
25
25
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
26
26
|
while (1) {
|
|
@@ -38,12 +38,12 @@ describe('components', function () {
|
|
|
38
38
|
|
|
39
39
|
ON_CHANGE = function ON_CHANGE() {};
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
_renderWithValidation = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
42
42
|
"data-testid": ID,
|
|
43
43
|
component: COMPONENT,
|
|
44
44
|
value: VALUE,
|
|
45
45
|
onChange: ON_CHANGE
|
|
46
|
-
})), container =
|
|
46
|
+
})), container = _renderWithValidation.container; // text components are wrapper in a FormGroup by default.
|
|
47
47
|
|
|
48
48
|
formGroup = container.childNodes[0];
|
|
49
49
|
expect(formGroup.tagName).toEqual('DIV');
|
|
@@ -71,7 +71,7 @@ describe('components', function () {
|
|
|
71
71
|
}, _callee);
|
|
72
72
|
})));
|
|
73
73
|
it('should render a text component appropriately with wrap turned off', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
74
|
-
var ID, VALUE, COMPONENT, ON_CHANGE,
|
|
74
|
+
var ID, VALUE, COMPONENT, ON_CHANGE, _renderWithValidation2, container, input;
|
|
75
75
|
|
|
76
76
|
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
77
77
|
while (1) {
|
|
@@ -89,13 +89,13 @@ describe('components', function () {
|
|
|
89
89
|
|
|
90
90
|
ON_CHANGE = function ON_CHANGE() {};
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
_renderWithValidation2 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
93
93
|
"data-testid": ID,
|
|
94
94
|
component: COMPONENT,
|
|
95
95
|
wrap: false,
|
|
96
96
|
value: VALUE,
|
|
97
97
|
onChange: ON_CHANGE
|
|
98
|
-
})), container =
|
|
98
|
+
})), container = _renderWithValidation2.container; // With wrap = false, there should be no form group.
|
|
99
99
|
|
|
100
100
|
input = container.childNodes[0];
|
|
101
101
|
expect(input.tagName).toEqual('INPUT');
|
|
@@ -111,7 +111,7 @@ describe('components', function () {
|
|
|
111
111
|
}, _callee2);
|
|
112
112
|
})));
|
|
113
113
|
it('should render an html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
114
|
-
var ID, COMPONENT,
|
|
114
|
+
var ID, COMPONENT, _renderWithValidation3, container, p;
|
|
115
115
|
|
|
116
116
|
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
117
117
|
while (1) {
|
|
@@ -123,10 +123,10 @@ describe('components', function () {
|
|
|
123
123
|
tagName: 'p',
|
|
124
124
|
content: 'HTML content'
|
|
125
125
|
};
|
|
126
|
-
|
|
126
|
+
_renderWithValidation3 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
127
127
|
"data-testid": ID,
|
|
128
128
|
component: COMPONENT
|
|
129
|
-
})), container =
|
|
129
|
+
})), container = _renderWithValidation3.container;
|
|
130
130
|
p = container.childNodes[0];
|
|
131
131
|
expect(p.tagName).toEqual('P');
|
|
132
132
|
expect(p.textContent).toEqual(COMPONENT.content);
|
|
@@ -139,14 +139,14 @@ describe('components', function () {
|
|
|
139
139
|
}, _callee3);
|
|
140
140
|
})));
|
|
141
141
|
it('should render an overridden html component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
142
|
-
var ID, COMPONENT,
|
|
142
|
+
var ID, COMPONENT, _renderWithValidation4, container, div;
|
|
143
143
|
|
|
144
144
|
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
145
145
|
while (1) {
|
|
146
146
|
switch (_context4.prev = _context4.next) {
|
|
147
147
|
case 0:
|
|
148
148
|
(0, _useHooks.addHook)('onGetComponent', function (config, wrap) {
|
|
149
|
-
return /*#__PURE__*/
|
|
149
|
+
return /*#__PURE__*/_react.default.createElement("div", null, "".concat(config.type, " | ").concat(config.tagName, " | ").concat(config.content, " | ").concat(wrap));
|
|
150
150
|
});
|
|
151
151
|
ID = 'component';
|
|
152
152
|
COMPONENT = {
|
|
@@ -154,10 +154,10 @@ describe('components', function () {
|
|
|
154
154
|
tagName: 'p',
|
|
155
155
|
content: 'HTML content'
|
|
156
156
|
};
|
|
157
|
-
|
|
157
|
+
_renderWithValidation4 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
158
158
|
"data-testid": ID,
|
|
159
159
|
component: COMPONENT
|
|
160
|
-
})), container =
|
|
160
|
+
})), container = _renderWithValidation4.container;
|
|
161
161
|
div = container.childNodes[0];
|
|
162
162
|
expect(div.tagName).toEqual('DIV');
|
|
163
163
|
expect(div.textContent).toEqual("".concat(COMPONENT.type, " | ").concat(COMPONENT.tagName, " | ").concat(COMPONENT.content, " | true"));
|
|
@@ -170,7 +170,7 @@ describe('components', function () {
|
|
|
170
170
|
}, _callee4);
|
|
171
171
|
})));
|
|
172
172
|
it('should render the correct html component when the override returns null', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
173
|
-
var ID, COMPONENT,
|
|
173
|
+
var ID, COMPONENT, _renderWithValidation5, container, p;
|
|
174
174
|
|
|
175
175
|
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
176
176
|
while (1) {
|
|
@@ -185,10 +185,10 @@ describe('components', function () {
|
|
|
185
185
|
tagName: 'p',
|
|
186
186
|
content: 'HTML content'
|
|
187
187
|
};
|
|
188
|
-
|
|
188
|
+
_renderWithValidation5 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react.default.createElement(_FormComponent.default, {
|
|
189
189
|
"data-testid": ID,
|
|
190
190
|
component: COMPONENT
|
|
191
|
-
})), container =
|
|
191
|
+
})), container = _renderWithValidation5.container;
|
|
192
192
|
p = container.childNodes[0];
|
|
193
193
|
expect(p.tagName).toEqual('P');
|
|
194
194
|
expect(p.textContent).toEqual(COMPONENT.content);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var getComponentError = function getComponentError(component, errors) {
|
|
9
|
+
if (Array.isArray(errors)) {
|
|
10
|
+
var error = errors.find(function (err) {
|
|
11
|
+
return err.id === (component.full_path || component.id);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
if (error) {
|
|
15
|
+
var props = {
|
|
16
|
+
error: error.error
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
if (error.properties) {
|
|
20
|
+
props.propsInError = error.properties;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return props;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var _default = getComponentError;
|
|
31
|
+
exports.default = _default;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getComponentError = _interopRequireDefault(require("./getComponentError"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('components.FormComponent.helpers.getComponentError', function () {
|
|
8
|
+
var ALPHA = {
|
|
9
|
+
id: 'alpha'
|
|
10
|
+
};
|
|
11
|
+
var BETA = {
|
|
12
|
+
id: 'beta',
|
|
13
|
+
full_path: 'beta'
|
|
14
|
+
};
|
|
15
|
+
var ALPHA_ERROR = {
|
|
16
|
+
id: ALPHA.id,
|
|
17
|
+
error: 'Alpha is required'
|
|
18
|
+
};
|
|
19
|
+
var BETA_ERROR = {
|
|
20
|
+
id: BETA.id,
|
|
21
|
+
error: 'Year is required',
|
|
22
|
+
properties: {
|
|
23
|
+
year: true
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
it('should return undefined if the errors array is undefined', function () {
|
|
27
|
+
expect((0, _getComponentError.default)(ALPHA, undefined)).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
it('should return undefined if the errors array is null', function () {
|
|
30
|
+
expect((0, _getComponentError.default)(ALPHA, null)).toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
it('should return undefined if the errors array is empty', function () {
|
|
33
|
+
expect((0, _getComponentError.default)(ALPHA, [])).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
it('should return undefined if the errors array does not contain an error for the component', function () {
|
|
36
|
+
var ERRORS = [BETA_ERROR];
|
|
37
|
+
expect((0, _getComponentError.default)(ALPHA, ERRORS)).toBeUndefined();
|
|
38
|
+
});
|
|
39
|
+
it('should return an appropriate response if the errors array contains an error for the component', function () {
|
|
40
|
+
var ERRORS = [ALPHA_ERROR];
|
|
41
|
+
expect((0, _getComponentError.default)(ALPHA, ERRORS)).toEqual({
|
|
42
|
+
error: ALPHA_ERROR.error
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('should return an appropriate response if the errors array contains an error with properties for the component', function () {
|
|
46
|
+
var ERRORS = [BETA_ERROR];
|
|
47
|
+
expect((0, _getComponentError.default)(BETA, ERRORS)).toEqual({
|
|
48
|
+
error: BETA_ERROR.error,
|
|
49
|
+
propsInError: BETA_ERROR.properties
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|