@ukhomeoffice/cop-react-form-renderer 2.8.4 → 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 +11 -9
- 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 +65 -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 +6 -2
- 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/json/group.json +1 -17
- package/dist/json/port.json +346 -0
- package/dist/json/sublocation.json +859 -0
- package/dist/json/terminal.json +81 -0
- package/dist/models/CollectionLabels.js +14 -0
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/models/index.js +8 -0
- package/dist/setupTests.js +32 -0
- package/dist/utils/CheckYourAnswers/getCYARow.js +14 -0
- package/dist/utils/CheckYourAnswers/getCYARow.test.js +34 -11
- package/dist/utils/CheckYourAnswers/getCYARowForGroup.js +1 -0
- 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/cleanAttributes.js +1 -1
- package/dist/utils/Component/getComponent.js +36 -3
- package/dist/utils/Component/getComponentTests/getComponent.nested.test.js +92 -0
- 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/dist/utils/Meta/constants.js +10 -0
- package/dist/utils/Meta/documents/getDocuments.js +18 -0
- package/dist/utils/Meta/documents/getDocuments.test.js +43 -0
- package/dist/utils/Meta/documents/index.js +23 -0
- package/dist/utils/Meta/documents/setDocumentForField.js +36 -0
- package/dist/utils/Meta/documents/setDocumentForField.test.js +49 -0
- package/dist/utils/Meta/index.js +21 -0
- package/dist/utils/Validate/validateCollection.js +42 -0
- package/dist/utils/Validate/validateCollection.test.js +74 -0
- package/dist/utils/Validate/validateComponent.js +67 -48
- package/dist/utils/Validate/validateComponent.test.js +247 -188
- package/dist/utils/Validate/validateContainer.js +29 -0
- package/dist/utils/Validate/validateContainer.test.js +68 -0
- package/dist/utils/index.js +4 -1
- package/package.json +2 -2
|
@@ -13,6 +13,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
13
13
|
|
|
14
14
|
var _react = _interopRequireWildcard(require("react"));
|
|
15
15
|
|
|
16
|
+
var _hooks = require("../../hooks");
|
|
17
|
+
|
|
16
18
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
17
19
|
|
|
18
20
|
var _PageActions = _interopRequireDefault(require("../PageActions"));
|
|
@@ -74,13 +76,11 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
74
76
|
|
|
75
77
|
var _useState3 = (0, _react.useState)([]),
|
|
76
78
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
listOfGroups = _useState4[0],
|
|
80
|
+
setListOfGroups = _useState4[1];
|
|
79
81
|
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
listOfGroups = _useState6[0],
|
|
83
|
-
setListOfGroups = _useState6[1];
|
|
82
|
+
var _useValidation = (0, _hooks.useValidation)(),
|
|
83
|
+
errors = _useValidation.errors;
|
|
84
84
|
|
|
85
85
|
(0, _react.useEffect)(function () {
|
|
86
86
|
var getRows = function getRows(page, pageIndex) {
|
|
@@ -112,10 +112,6 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
112
112
|
return index === pages.length - 1;
|
|
113
113
|
};
|
|
114
114
|
|
|
115
|
-
var onError = function onError(errors) {
|
|
116
|
-
setErrors(errors);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
115
|
(0, _react.useEffect)(function () {
|
|
120
116
|
var groupsList = function groupsList() {
|
|
121
117
|
var groupIds = [];
|
|
@@ -160,7 +156,7 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
160
156
|
key: pageIndex
|
|
161
157
|
}, !hide_page_titles && page.title && !isGroup(page.id) && /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, page.title), isGroup(page.id) && /*#__PURE__*/_react.default.createElement("div", {
|
|
162
158
|
className: "group-title"
|
|
163
|
-
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, currentGroup.title
|
|
159
|
+
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.MediumHeading, null, currentGroup.title || page.title)), /*#__PURE__*/_react.default.createElement(_SummaryList.default, {
|
|
164
160
|
className: className,
|
|
165
161
|
rows: page.rows,
|
|
166
162
|
classModifiers: summaryListClassModifiers,
|
|
@@ -170,7 +166,7 @@ var CheckYourAnswers = function CheckYourAnswers(_ref) {
|
|
|
170
166
|
}), !hide_actions && /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
171
167
|
actions: actions,
|
|
172
168
|
onAction: function onAction(action) {
|
|
173
|
-
return _onAction(action
|
|
169
|
+
return _onAction(action);
|
|
174
170
|
}
|
|
175
171
|
}));
|
|
176
172
|
};
|
|
@@ -28,6 +28,8 @@ var _group = _interopRequireDefault(require("../../json/group.json"));
|
|
|
28
28
|
|
|
29
29
|
var _groupOfRow = _interopRequireDefault(require("../../json/groupOfRow.json"));
|
|
30
30
|
|
|
31
|
+
var _setupTests = require("../../setupTests");
|
|
32
|
+
|
|
31
33
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
32
34
|
|
|
33
35
|
var _CheckYourAnswers = _interopRequireWildcard(require("./CheckYourAnswers"));
|
|
@@ -135,7 +137,7 @@ describe('components', function () {
|
|
|
135
137
|
while (1) {
|
|
136
138
|
switch (_context.prev = _context.next) {
|
|
137
139
|
case 0:
|
|
138
|
-
(0,
|
|
140
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
139
141
|
pages: PAGES,
|
|
140
142
|
onRowAction: ON_ROW_ACTION,
|
|
141
143
|
onAction: ON_ACTION
|
|
@@ -175,7 +177,7 @@ describe('components', function () {
|
|
|
175
177
|
while (1) {
|
|
176
178
|
switch (_context3.prev = _context3.next) {
|
|
177
179
|
case 0:
|
|
178
|
-
(0,
|
|
180
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
179
181
|
title: TITLE,
|
|
180
182
|
pages: PAGES,
|
|
181
183
|
onRowAction: ON_ROW_ACTION,
|
|
@@ -216,7 +218,7 @@ describe('components', function () {
|
|
|
216
218
|
while (1) {
|
|
217
219
|
switch (_context5.prev = _context5.next) {
|
|
218
220
|
case 0:
|
|
219
|
-
(0,
|
|
221
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
220
222
|
pages: PAGES,
|
|
221
223
|
onRowAction: ON_ROW_ACTION,
|
|
222
224
|
onAction: ON_ACTION
|
|
@@ -260,7 +262,7 @@ describe('components', function () {
|
|
|
260
262
|
while (1) {
|
|
261
263
|
switch (_context7.prev = _context7.next) {
|
|
262
264
|
case 0:
|
|
263
|
-
(0,
|
|
265
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
264
266
|
pages: PAGES,
|
|
265
267
|
onRowAction: ON_ROW_ACTION,
|
|
266
268
|
onAction: ON_ACTION
|
|
@@ -304,7 +306,7 @@ describe('components', function () {
|
|
|
304
306
|
while (1) {
|
|
305
307
|
switch (_context9.prev = _context9.next) {
|
|
306
308
|
case 0:
|
|
307
|
-
(0,
|
|
309
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
308
310
|
pages: PAGES,
|
|
309
311
|
onRowAction: ON_ROW_ACTION,
|
|
310
312
|
onAction: ON_ACTION,
|
|
@@ -350,7 +352,7 @@ describe('components', function () {
|
|
|
350
352
|
while (1) {
|
|
351
353
|
switch (_context11.prev = _context11.next) {
|
|
352
354
|
case 0:
|
|
353
|
-
(0,
|
|
355
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
354
356
|
pages: PAGES,
|
|
355
357
|
onRowAction: ON_ROW_ACTION,
|
|
356
358
|
onAction: ON_ACTION,
|
|
@@ -396,7 +398,7 @@ describe('components', function () {
|
|
|
396
398
|
while (1) {
|
|
397
399
|
switch (_context13.prev = _context13.next) {
|
|
398
400
|
case 0:
|
|
399
|
-
(0,
|
|
401
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
400
402
|
pages: GROUP_PAGES,
|
|
401
403
|
onRowAction: ON_ROW_ACTION,
|
|
402
404
|
onAction: ON_ACTION,
|
|
@@ -416,7 +418,7 @@ describe('components', function () {
|
|
|
416
418
|
groupedComponent = cya.childNodes[10];
|
|
417
419
|
keyGroup = groupedComponent.childNodes[0].childNodes[0].childNodes[0];
|
|
418
420
|
expect(keyGroup.tagName).toEqual('DT');
|
|
419
|
-
expect(keyGroup.textContent).toEqual('Address details
|
|
421
|
+
expect(keyGroup.textContent).toEqual('Address details');
|
|
420
422
|
valueGroup = groupedComponent.childNodes[0].childNodes[0].childNodes[1];
|
|
421
423
|
expect(valueGroup.childNodes.length).toEqual(4);
|
|
422
424
|
expect(valueGroup.tagName).toEqual('DD');
|
|
@@ -450,7 +452,7 @@ describe('components', function () {
|
|
|
450
452
|
while (1) {
|
|
451
453
|
switch (_context15.prev = _context15.next) {
|
|
452
454
|
case 0:
|
|
453
|
-
(0,
|
|
455
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react.default.createElement(_CheckYourAnswers.default, {
|
|
454
456
|
pages: GROUP_PAGES,
|
|
455
457
|
onRowAction: ON_ROW_ACTION,
|
|
456
458
|
onAction: ON_ACTION,
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = exports.DEFAULT_CLASS = void 0;
|
|
9
|
+
|
|
10
|
+
var _copReactComponents = require("@ukhomeoffice/cop-react-components");
|
|
11
|
+
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
15
|
+
|
|
16
|
+
var _models = require("../../models");
|
|
17
|
+
|
|
18
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
19
|
+
|
|
20
|
+
var _Container = _interopRequireDefault(require("./Container"));
|
|
21
|
+
|
|
22
|
+
require("./Collection.scss");
|
|
23
|
+
|
|
24
|
+
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); }
|
|
25
|
+
|
|
26
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
37
|
+
|
|
38
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
39
|
+
|
|
40
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
41
|
+
|
|
42
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
43
|
+
|
|
44
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
45
|
+
|
|
46
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
47
|
+
|
|
48
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
49
|
+
|
|
50
|
+
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."); }
|
|
51
|
+
|
|
52
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
53
|
+
|
|
54
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
55
|
+
|
|
56
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
57
|
+
|
|
58
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
59
|
+
|
|
60
|
+
var DEFAULT_CLASS = 'hods-form-collection';
|
|
61
|
+
exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
62
|
+
|
|
63
|
+
var Collection = function Collection(_ref) {
|
|
64
|
+
var config = _ref.config,
|
|
65
|
+
_value = _ref.value,
|
|
66
|
+
formData = _ref.formData,
|
|
67
|
+
onChange = _ref.onChange,
|
|
68
|
+
wrap = _ref.wrap;
|
|
69
|
+
|
|
70
|
+
var _useState = (0, _react.useState)(),
|
|
71
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
72
|
+
value = _useState2[0],
|
|
73
|
+
setValue = _useState2[1];
|
|
74
|
+
|
|
75
|
+
(0, _react.useEffect)(function () {
|
|
76
|
+
setValue(_value || []);
|
|
77
|
+
}, [_value, setValue]);
|
|
78
|
+
|
|
79
|
+
var reportChange = function reportChange(newValue) {
|
|
80
|
+
setValue(newValue);
|
|
81
|
+
|
|
82
|
+
if (typeof onChange === 'function') {
|
|
83
|
+
onChange({
|
|
84
|
+
target: {
|
|
85
|
+
name: config.fieldId,
|
|
86
|
+
value: newValue
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var onCollectionChange = function onCollectionChange(_ref2) {
|
|
93
|
+
var target = _ref2.target;
|
|
94
|
+
|
|
95
|
+
if (typeof onChange === 'function') {
|
|
96
|
+
if (target.name === _utils.default.Meta.name) {
|
|
97
|
+
onChange({
|
|
98
|
+
target: target
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
var itemIndex = value.findIndex(function (item) {
|
|
102
|
+
return item.id === target.name;
|
|
103
|
+
});
|
|
104
|
+
reportChange([].concat(_toConsumableArray(value.slice(0, itemIndex)), [target.value], _toConsumableArray(value.slice(itemIndex + 1))));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
var onAddAnother = /*#__PURE__*/function () {
|
|
110
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
111
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
112
|
+
while (1) {
|
|
113
|
+
switch (_context.prev = _context.next) {
|
|
114
|
+
case 0:
|
|
115
|
+
reportChange([].concat(_toConsumableArray(value), [{
|
|
116
|
+
id: Date.now().toString()
|
|
117
|
+
}]));
|
|
118
|
+
|
|
119
|
+
case 1:
|
|
120
|
+
case "end":
|
|
121
|
+
return _context.stop();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, _callee);
|
|
125
|
+
}));
|
|
126
|
+
|
|
127
|
+
return function onAddAnother() {
|
|
128
|
+
return _ref3.apply(this, arguments);
|
|
129
|
+
};
|
|
130
|
+
}();
|
|
131
|
+
|
|
132
|
+
var onRemoveItem = /*#__PURE__*/function () {
|
|
133
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(item) {
|
|
134
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
135
|
+
while (1) {
|
|
136
|
+
switch (_context2.prev = _context2.next) {
|
|
137
|
+
case 0:
|
|
138
|
+
reportChange(value.filter(function (i) {
|
|
139
|
+
return i.id !== item.id;
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
case 1:
|
|
143
|
+
case "end":
|
|
144
|
+
return _context2.stop();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}, _callee2);
|
|
148
|
+
}));
|
|
149
|
+
|
|
150
|
+
return function onRemoveItem(_x) {
|
|
151
|
+
return _ref4.apply(this, arguments);
|
|
152
|
+
};
|
|
153
|
+
}();
|
|
154
|
+
|
|
155
|
+
var labels = _objectSpread(_objectSpread({}, _models.CollectionLabels), config.labels);
|
|
156
|
+
|
|
157
|
+
var classes = _utils.default.classBuilder(DEFAULT_CLASS, [], config.className);
|
|
158
|
+
|
|
159
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
160
|
+
className: classes(),
|
|
161
|
+
id: config.id
|
|
162
|
+
}, config.label && /*#__PURE__*/_react.default.createElement(_copReactComponents.Label, {
|
|
163
|
+
id: config.id,
|
|
164
|
+
required: config.required,
|
|
165
|
+
className: classes('title')
|
|
166
|
+
}, config.label), value && value.map(function (item, index) {
|
|
167
|
+
var full_path = "".concat(config.full_path || config.fieldId, "[").concat(index, "]");
|
|
168
|
+
var labelCount = (config.countOffset || 0) + index + 1;
|
|
169
|
+
|
|
170
|
+
var itemTitle = _utils.default.interpolateString(labels.item, _objectSpread(_objectSpread({}, item), {}, {
|
|
171
|
+
index: labelCount
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
var removeLabel = _utils.default.interpolateString(labels.remove, _objectSpread(_objectSpread({}, item), {}, {
|
|
175
|
+
index: labelCount
|
|
176
|
+
}));
|
|
177
|
+
|
|
178
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
179
|
+
className: "".concat(classes('item')),
|
|
180
|
+
key: item.id
|
|
181
|
+
}, /*#__PURE__*/_react.default.createElement(_copReactComponents.Label, {
|
|
182
|
+
id: item.id,
|
|
183
|
+
required: true,
|
|
184
|
+
className: classes('item-title')
|
|
185
|
+
}, itemTitle, !config.disableAddAndRemove && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
186
|
+
onClick: function onClick() {
|
|
187
|
+
return onRemoveItem(item);
|
|
188
|
+
},
|
|
189
|
+
classModifiers: "secondary"
|
|
190
|
+
}, removeLabel)), /*#__PURE__*/_react.default.createElement(_Container.default, {
|
|
191
|
+
container: {
|
|
192
|
+
id: item.id,
|
|
193
|
+
fieldId: item.id,
|
|
194
|
+
type: 'container',
|
|
195
|
+
required: config.required,
|
|
196
|
+
full_path: full_path,
|
|
197
|
+
components: config.item.map(function (component) {
|
|
198
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
199
|
+
label: _utils.default.interpolateString(component.label, _objectSpread(_objectSpread({}, item), {}, {
|
|
200
|
+
index: labelCount
|
|
201
|
+
})),
|
|
202
|
+
full_path: "".concat(full_path, ".").concat(component.fieldId)
|
|
203
|
+
});
|
|
204
|
+
})
|
|
205
|
+
},
|
|
206
|
+
value: item,
|
|
207
|
+
formData: formData,
|
|
208
|
+
onChange: onCollectionChange,
|
|
209
|
+
wrap: wrap
|
|
210
|
+
}));
|
|
211
|
+
}), !config.disableAddAndRemove && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, null, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
212
|
+
onClick: onAddAnother,
|
|
213
|
+
classModifiers: "secondary"
|
|
214
|
+
}, labels.add)));
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
Collection.propTypes = {
|
|
218
|
+
config: _propTypes.default.shape({
|
|
219
|
+
id: _propTypes.default.string.isRequired,
|
|
220
|
+
fieldId: _propTypes.default.string.isRequired,
|
|
221
|
+
label: _propTypes.default.string,
|
|
222
|
+
labels: _propTypes.default.shape({
|
|
223
|
+
item: _propTypes.default.string,
|
|
224
|
+
add: _propTypes.default.string,
|
|
225
|
+
remove: _propTypes.default.string
|
|
226
|
+
}),
|
|
227
|
+
disableAddAndRemove: _propTypes.default.bool,
|
|
228
|
+
countOffset: _propTypes.default.number,
|
|
229
|
+
className: _propTypes.default.string,
|
|
230
|
+
item: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
231
|
+
fieldId: _propTypes.default.string,
|
|
232
|
+
type: _propTypes.default.string
|
|
233
|
+
}))
|
|
234
|
+
}).isRequired,
|
|
235
|
+
value: _propTypes.default.arrayOf(_propTypes.default.shape()),
|
|
236
|
+
formData: _propTypes.default.any,
|
|
237
|
+
wrap: _propTypes.default.bool,
|
|
238
|
+
onChange: _propTypes.default.func
|
|
239
|
+
};
|
|
240
|
+
Collection.defaultProps = {
|
|
241
|
+
value: []
|
|
242
|
+
};
|
|
243
|
+
var _default = Collection;
|
|
244
|
+
exports.default = _default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.hods-form-collection {
|
|
2
|
+
&__title {
|
|
3
|
+
font-size: 1.5rem;
|
|
4
|
+
font-weight: 700;
|
|
5
|
+
margin-bottom: 0.75rem;
|
|
6
|
+
}
|
|
7
|
+
&__item {
|
|
8
|
+
margin-top: 0;
|
|
9
|
+
position: relative;
|
|
10
|
+
}
|
|
11
|
+
&__item-title {
|
|
12
|
+
display: block;
|
|
13
|
+
font-weight: 700;
|
|
14
|
+
font-size: 1.25rem;
|
|
15
|
+
line-height: 1.1111111;
|
|
16
|
+
margin-bottom: 0.75rem;
|
|
17
|
+
.hods-button {
|
|
18
|
+
margin-bottom: 0.25rem;
|
|
19
|
+
margin-top: -0.3125rem;
|
|
20
|
+
float: right;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DEFAULT_CLASS = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
|
|
12
|
+
var _models = require("../../models");
|
|
13
|
+
|
|
14
|
+
var _utils = _interopRequireDefault(require("../../utils"));
|
|
15
|
+
|
|
16
|
+
var _FormComponent = _interopRequireDefault(require("./FormComponent"));
|
|
17
|
+
|
|
18
|
+
var _excluded = ["container", "value", "formData", "onChange", "wrap"];
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
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); }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
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; }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
var DEFAULT_CLASS = 'hods-form-container';
|
|
35
|
+
exports.DEFAULT_CLASS = DEFAULT_CLASS;
|
|
36
|
+
|
|
37
|
+
var Container = function Container(_ref) {
|
|
38
|
+
var container = _ref.container,
|
|
39
|
+
value = _ref.value,
|
|
40
|
+
formData = _ref.formData,
|
|
41
|
+
onChange = _ref.onChange,
|
|
42
|
+
wrap = _ref.wrap,
|
|
43
|
+
attrs = _objectWithoutProperties(_ref, _excluded);
|
|
44
|
+
|
|
45
|
+
var onComponentChange = function onComponentChange(_ref2) {
|
|
46
|
+
var target = _ref2.target;
|
|
47
|
+
|
|
48
|
+
if (typeof onChange === 'function') {
|
|
49
|
+
if (target.name === _utils.default.Meta.name) {
|
|
50
|
+
onChange({
|
|
51
|
+
target: target
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
var val = _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, target.name, target.value));
|
|
55
|
+
|
|
56
|
+
onChange({
|
|
57
|
+
target: {
|
|
58
|
+
name: container.fieldId,
|
|
59
|
+
value: val
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
var shouldShow = function shouldShow(options) {
|
|
67
|
+
if (options.type === _models.ComponentTypes.CONTAINER) {
|
|
68
|
+
return _utils.default.Container.show(options, formData);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return _utils.default.Component.show(options, formData);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return /*#__PURE__*/_react.default.createElement("div", _extends({}, attrs, {
|
|
75
|
+
className: DEFAULT_CLASS,
|
|
76
|
+
id: container.id
|
|
77
|
+
}), container.components && container.components.filter(shouldShow).map(function (component, index) {
|
|
78
|
+
var defaultValue = component.type === _models.ComponentTypes.FILE ? {} : '';
|
|
79
|
+
var val = value ? value[component.fieldId] : defaultValue;
|
|
80
|
+
return /*#__PURE__*/_react.default.createElement(_FormComponent.default, _extends({
|
|
81
|
+
key: index
|
|
82
|
+
}, attrs, {
|
|
83
|
+
component: component,
|
|
84
|
+
formData: formData,
|
|
85
|
+
value: val || defaultValue,
|
|
86
|
+
wrap: wrap,
|
|
87
|
+
onChange: onComponentChange
|
|
88
|
+
}));
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
Container.propTypes = {
|
|
93
|
+
container: _propTypes.default.shape({
|
|
94
|
+
id: _propTypes.default.string.isRequired,
|
|
95
|
+
fieldId: _propTypes.default.string.isRequired,
|
|
96
|
+
components: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
97
|
+
fieldId: _propTypes.default.string,
|
|
98
|
+
type: _propTypes.default.string
|
|
99
|
+
}))
|
|
100
|
+
}).isRequired,
|
|
101
|
+
value: _propTypes.default.any,
|
|
102
|
+
formData: _propTypes.default.any,
|
|
103
|
+
wrap: _propTypes.default.bool,
|
|
104
|
+
onChange: _propTypes.default.func
|
|
105
|
+
};
|
|
106
|
+
Container.defaultProps = {
|
|
107
|
+
wrap: true
|
|
108
|
+
};
|
|
109
|
+
var _default = Container;
|
|
110
|
+
exports.default = _default;
|