@ukhomeoffice/cop-react-form-renderer 2.5.0 → 2.6.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/FormComponent/Container.test.js +250 -0
- package/dist/components/FormComponent/FormComponent.js +101 -22
- package/dist/components/FormPage/FormPage.js +2 -1
- package/dist/hooks/index.js +19 -1
- package/dist/models/ComponentTypes.js +2 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.js +40 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForContainer.test.js +257 -0
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.js +9 -1
- package/dist/utils/CheckYourAnswers/getCYARowsForPage.test.js +44 -0
- package/dist/utils/CheckYourAnswers/showComponentCYA.js +6 -0
- package/dist/utils/Component/cleanAttributes.js +1 -1
- package/dist/utils/Component/showComponent.js +2 -20
- package/dist/utils/Condition/index.js +19 -0
- package/dist/utils/Condition/meetsAllConditions.js +40 -0
- package/dist/utils/Condition/meetsAllConditions.test.js +62 -0
- package/dist/utils/{meetsCondition.js → Condition/meetsCondition.js} +0 -0
- package/dist/utils/Condition/meetsCondition.test.js +302 -0
- package/dist/utils/Condition/setupConditions.js +47 -0
- package/dist/utils/Condition/setupConditions.test.js +35 -0
- package/dist/utils/Container/getEditableComponents.js +38 -0
- package/dist/utils/Container/getEditableComponents.test.js +157 -0
- package/dist/utils/Container/index.js +22 -0
- package/dist/utils/Container/setupNesting.js +45 -0
- package/dist/utils/Container/setupNesting.test.js +92 -0
- package/dist/utils/Container/showContainer.js +61 -0
- package/dist/utils/Container/showContainer.test.js +128 -0
- package/dist/utils/Data/getDataPath.js +90 -0
- package/dist/utils/Data/getDataPath.test.js +52 -0
- package/dist/utils/Data/index.js +3 -0
- package/dist/utils/FormPage/getFormPage.js +4 -2
- package/dist/utils/FormPage/getFormPage.test.js +18 -7
- package/dist/utils/FormPage/getFormPages.test.js +5 -2
- package/dist/utils/FormPage/index.js +0 -3
- package/dist/utils/FormPage/showFormPage.js +7 -27
- package/dist/utils/Hub/getFormHub.test.js +5 -2
- package/dist/utils/Validate/index.js +7 -1
- package/dist/utils/Validate/validateComponent.js +26 -6
- package/dist/utils/Validate/validateComponent.test.js +44 -0
- package/dist/utils/Validate/validateDate.js +11 -0
- package/dist/utils/Validate/validateDate.test.js +6 -0
- package/dist/utils/Validate/validatePage.js +6 -8
- package/dist/utils/Validate/validateTime.js +19 -0
- package/dist/utils/Validate/validateTime.test.js +6 -0
- package/dist/utils/index.js +6 -3
- package/package.json +1 -1
- package/dist/utils/FormPage/getEditableComponents.js +0 -28
- package/dist/utils/FormPage/getEditableComponents.test.js +0 -75
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
var _react = require("@testing-library/react");
|
|
6
|
+
|
|
7
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
8
|
+
|
|
9
|
+
var _models = require("../../models");
|
|
10
|
+
|
|
11
|
+
var _FormComponent = _interopRequireWildcard(require("./FormComponent"));
|
|
12
|
+
|
|
13
|
+
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); }
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
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); } }
|
|
20
|
+
|
|
21
|
+
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); }); }; }
|
|
22
|
+
|
|
23
|
+
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; }
|
|
24
|
+
|
|
25
|
+
describe('components.FormComponent.Container', function () {
|
|
26
|
+
var _ID;
|
|
27
|
+
|
|
28
|
+
var ID = 'container';
|
|
29
|
+
var NESTED_ID = 'nested';
|
|
30
|
+
var TEXT_ID = 'text';
|
|
31
|
+
var TEXT_VALUE = 'alpha';
|
|
32
|
+
var NESTED_TEXT_VALUE = 'charlie';
|
|
33
|
+
|
|
34
|
+
var FORM_DATA = _defineProperty({}, ID, (_ID = {}, _defineProperty(_ID, TEXT_ID, TEXT_VALUE), _defineProperty(_ID, NESTED_ID, _defineProperty({}, TEXT_ID, NESTED_TEXT_VALUE)), _ID));
|
|
35
|
+
|
|
36
|
+
var TEXT_COMPONENT = {
|
|
37
|
+
id: TEXT_ID,
|
|
38
|
+
fieldId: TEXT_ID,
|
|
39
|
+
type: _models.ComponentTypes.TEXT,
|
|
40
|
+
label: 'Text component',
|
|
41
|
+
hint: 'Text hint'
|
|
42
|
+
};
|
|
43
|
+
it('should render a container component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
44
|
+
var CONTAINER, _render, container, c, formGroup, label, hint, input;
|
|
45
|
+
|
|
46
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
47
|
+
while (1) {
|
|
48
|
+
switch (_context.prev = _context.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
CONTAINER = {
|
|
51
|
+
id: ID,
|
|
52
|
+
fieldId: ID,
|
|
53
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
54
|
+
components: [TEXT_COMPONENT]
|
|
55
|
+
};
|
|
56
|
+
_render = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
57
|
+
component: CONTAINER,
|
|
58
|
+
value: FORM_DATA[ID],
|
|
59
|
+
formData: FORM_DATA
|
|
60
|
+
})), container = _render.container; // Check the container itself.
|
|
61
|
+
|
|
62
|
+
c = container.childNodes[0];
|
|
63
|
+
expect(c.tagName).toEqual('DIV');
|
|
64
|
+
expect(c.classList).toContain(_FormComponent.DEFAULT_CONTAINER_CLASS); // And now check the single text component within it.
|
|
65
|
+
|
|
66
|
+
formGroup = c.childNodes[0];
|
|
67
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
68
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
69
|
+
label = formGroup.childNodes[0];
|
|
70
|
+
expect(label.tagName).toEqual('LABEL');
|
|
71
|
+
expect(label.classList).toContain('govuk-label');
|
|
72
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
73
|
+
expect(label.getAttribute('for')).toEqual(TEXT_ID);
|
|
74
|
+
hint = formGroup.childNodes[1];
|
|
75
|
+
expect(hint.tagName).toEqual('SPAN');
|
|
76
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
77
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
78
|
+
input = formGroup.childNodes[2];
|
|
79
|
+
expect(input.tagName).toEqual('INPUT');
|
|
80
|
+
expect(input.classList).toContain('govuk-input');
|
|
81
|
+
expect(input.id).toEqual(TEXT_ID);
|
|
82
|
+
expect(input.value).toEqual(TEXT_VALUE);
|
|
83
|
+
|
|
84
|
+
case 22:
|
|
85
|
+
case "end":
|
|
86
|
+
return _context.stop();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, _callee);
|
|
90
|
+
})));
|
|
91
|
+
it('should render a nested container component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
92
|
+
var CONTAINER, _render2, container, c, nested, formGroup, label, hint, input;
|
|
93
|
+
|
|
94
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
95
|
+
while (1) {
|
|
96
|
+
switch (_context2.prev = _context2.next) {
|
|
97
|
+
case 0:
|
|
98
|
+
CONTAINER = {
|
|
99
|
+
id: ID,
|
|
100
|
+
fieldId: ID,
|
|
101
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
102
|
+
components: [{
|
|
103
|
+
id: NESTED_ID,
|
|
104
|
+
fieldId: NESTED_ID,
|
|
105
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
106
|
+
components: [TEXT_COMPONENT]
|
|
107
|
+
}]
|
|
108
|
+
};
|
|
109
|
+
_render2 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
110
|
+
component: CONTAINER,
|
|
111
|
+
value: FORM_DATA[ID],
|
|
112
|
+
formData: FORM_DATA
|
|
113
|
+
})), container = _render2.container; // Check the container itself.
|
|
114
|
+
|
|
115
|
+
c = container.childNodes[0];
|
|
116
|
+
expect(c.tagName).toEqual('DIV');
|
|
117
|
+
expect(c.classList).toContain(_FormComponent.DEFAULT_CONTAINER_CLASS); // Check the nested container.
|
|
118
|
+
|
|
119
|
+
nested = c.childNodes[0];
|
|
120
|
+
expect(nested.tagName).toEqual('DIV');
|
|
121
|
+
expect(nested.classList).toContain(_FormComponent.DEFAULT_CONTAINER_CLASS); // And now check the single text component within the nested container.
|
|
122
|
+
|
|
123
|
+
formGroup = nested.childNodes[0];
|
|
124
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
125
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
126
|
+
label = formGroup.childNodes[0];
|
|
127
|
+
expect(label.tagName).toEqual('LABEL');
|
|
128
|
+
expect(label.classList).toContain('govuk-label');
|
|
129
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
130
|
+
expect(label.getAttribute('for')).toEqual(TEXT_ID);
|
|
131
|
+
hint = formGroup.childNodes[1];
|
|
132
|
+
expect(hint.tagName).toEqual('SPAN');
|
|
133
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
134
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
135
|
+
input = formGroup.childNodes[2];
|
|
136
|
+
expect(input.tagName).toEqual('INPUT');
|
|
137
|
+
expect(input.classList).toContain('govuk-input');
|
|
138
|
+
expect(input.id).toEqual(TEXT_ID);
|
|
139
|
+
expect(input.value).toEqual(NESTED_TEXT_VALUE);
|
|
140
|
+
|
|
141
|
+
case 25:
|
|
142
|
+
case "end":
|
|
143
|
+
return _context2.stop();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}, _callee2);
|
|
147
|
+
})));
|
|
148
|
+
it('should handle a change to a component appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
149
|
+
var ON_CHANGE_EVENTS, ON_CHANGE, CONTAINER, _render3, container, c, formGroup, input, NEW_TEXT_VALUE, EVENT;
|
|
150
|
+
|
|
151
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
152
|
+
while (1) {
|
|
153
|
+
switch (_context3.prev = _context3.next) {
|
|
154
|
+
case 0:
|
|
155
|
+
ON_CHANGE_EVENTS = [];
|
|
156
|
+
|
|
157
|
+
ON_CHANGE = function ON_CHANGE(e) {
|
|
158
|
+
ON_CHANGE_EVENTS.push(e);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
CONTAINER = {
|
|
162
|
+
id: ID,
|
|
163
|
+
fieldId: ID,
|
|
164
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
165
|
+
components: [{
|
|
166
|
+
id: TEXT_ID,
|
|
167
|
+
fieldId: TEXT_ID,
|
|
168
|
+
type: _models.ComponentTypes.TEXT,
|
|
169
|
+
label: 'Text component'
|
|
170
|
+
}]
|
|
171
|
+
};
|
|
172
|
+
_render3 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
173
|
+
component: CONTAINER,
|
|
174
|
+
value: FORM_DATA[ID],
|
|
175
|
+
formData: FORM_DATA,
|
|
176
|
+
onChange: ON_CHANGE
|
|
177
|
+
})), container = _render3.container; // Get hold of the text input.
|
|
178
|
+
|
|
179
|
+
c = container.childNodes[0];
|
|
180
|
+
formGroup = c.childNodes[0];
|
|
181
|
+
input = formGroup.childNodes[2];
|
|
182
|
+
NEW_TEXT_VALUE = 'bravo';
|
|
183
|
+
EVENT = {
|
|
184
|
+
target: {
|
|
185
|
+
name: TEXT_ID,
|
|
186
|
+
value: NEW_TEXT_VALUE
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
_react.fireEvent.change(input, EVENT); // And confirm the formData has been changed.
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
expect(ON_CHANGE_EVENTS.length).toEqual(1);
|
|
194
|
+
expect(ON_CHANGE_EVENTS[0].target.name).toEqual(ID);
|
|
195
|
+
expect(ON_CHANGE_EVENTS[0].target.value[TEXT_ID]).toEqual(NEW_TEXT_VALUE);
|
|
196
|
+
|
|
197
|
+
case 13:
|
|
198
|
+
case "end":
|
|
199
|
+
return _context3.stop();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}, _callee3);
|
|
203
|
+
})));
|
|
204
|
+
it('should handle a null value appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
205
|
+
var CONTAINER, _render4, container, c, formGroup, label, hint, input;
|
|
206
|
+
|
|
207
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
208
|
+
while (1) {
|
|
209
|
+
switch (_context4.prev = _context4.next) {
|
|
210
|
+
case 0:
|
|
211
|
+
CONTAINER = {
|
|
212
|
+
id: ID,
|
|
213
|
+
fieldId: ID,
|
|
214
|
+
type: _models.ComponentTypes.CONTAINER,
|
|
215
|
+
components: [TEXT_COMPONENT]
|
|
216
|
+
};
|
|
217
|
+
_render4 = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
218
|
+
component: CONTAINER
|
|
219
|
+
})), container = _render4.container; // Check the container itself.
|
|
220
|
+
|
|
221
|
+
c = container.childNodes[0];
|
|
222
|
+
expect(c.tagName).toEqual('DIV');
|
|
223
|
+
expect(c.classList).toContain(_FormComponent.DEFAULT_CONTAINER_CLASS); // And now check the single text component within it.
|
|
224
|
+
|
|
225
|
+
formGroup = c.childNodes[0];
|
|
226
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
227
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
228
|
+
label = formGroup.childNodes[0];
|
|
229
|
+
expect(label.tagName).toEqual('LABEL');
|
|
230
|
+
expect(label.classList).toContain('govuk-label');
|
|
231
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
232
|
+
expect(label.getAttribute('for')).toEqual(TEXT_ID);
|
|
233
|
+
hint = formGroup.childNodes[1];
|
|
234
|
+
expect(hint.tagName).toEqual('SPAN');
|
|
235
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
236
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
237
|
+
input = formGroup.childNodes[2];
|
|
238
|
+
expect(input.tagName).toEqual('INPUT');
|
|
239
|
+
expect(input.classList).toContain('govuk-input');
|
|
240
|
+
expect(input.id).toEqual(TEXT_ID);
|
|
241
|
+
expect(input.value).toEqual('');
|
|
242
|
+
|
|
243
|
+
case 22:
|
|
244
|
+
case "end":
|
|
245
|
+
return _context4.stop();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}, _callee4);
|
|
249
|
+
})));
|
|
250
|
+
});
|
|
@@ -1,36 +1,25 @@
|
|
|
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
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.DEFAULT_CONTAINER_CLASS = void 0;
|
|
9
7
|
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
9
|
|
|
12
10
|
var _react = require("react");
|
|
13
11
|
|
|
14
|
-
var
|
|
12
|
+
var _hooks = require("../../hooks");
|
|
15
13
|
|
|
16
|
-
var
|
|
14
|
+
var _models = require("../../models");
|
|
17
15
|
|
|
18
16
|
var _utils = _interopRequireDefault(require("../../utils"));
|
|
19
17
|
|
|
20
|
-
var _excluded = ["
|
|
21
|
-
|
|
22
|
-
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); }
|
|
23
|
-
|
|
24
|
-
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; }
|
|
18
|
+
var _excluded = ["container", "value", "formData", "onChange", "wrap"],
|
|
19
|
+
_excluded2 = ["component", "value", "formData", "wrap", "onChange"];
|
|
25
20
|
|
|
26
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
22
|
|
|
28
|
-
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; }
|
|
29
|
-
|
|
30
|
-
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; }
|
|
31
|
-
|
|
32
|
-
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; }
|
|
33
|
-
|
|
34
23
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
35
24
|
|
|
36
25
|
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."); }
|
|
@@ -43,21 +32,98 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
43
32
|
|
|
44
33
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
45
34
|
|
|
35
|
+
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); }
|
|
36
|
+
|
|
37
|
+
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; }
|
|
38
|
+
|
|
39
|
+
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; }
|
|
40
|
+
|
|
41
|
+
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; }
|
|
42
|
+
|
|
46
43
|
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; }
|
|
47
44
|
|
|
48
45
|
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; }
|
|
49
46
|
|
|
50
|
-
var
|
|
51
|
-
|
|
47
|
+
var DEFAULT_CONTAINER_CLASS = 'hods-form-container';
|
|
48
|
+
exports.DEFAULT_CONTAINER_CLASS = DEFAULT_CONTAINER_CLASS;
|
|
49
|
+
|
|
50
|
+
var Container = function Container(_ref) {
|
|
51
|
+
var container = _ref.container,
|
|
52
52
|
value = _ref.value,
|
|
53
|
-
|
|
53
|
+
formData = _ref.formData,
|
|
54
54
|
onChange = _ref.onChange,
|
|
55
|
+
wrap = _ref.wrap,
|
|
55
56
|
attrs = _objectWithoutProperties(_ref, _excluded);
|
|
56
57
|
|
|
57
|
-
var
|
|
58
|
+
var onComponentChange = function onComponentChange(_ref2) {
|
|
59
|
+
var target = _ref2.target;
|
|
60
|
+
|
|
61
|
+
var val = _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, target.name, target.value));
|
|
62
|
+
|
|
63
|
+
if (typeof onChange === 'function') {
|
|
64
|
+
onChange({
|
|
65
|
+
target: {
|
|
66
|
+
name: container.fieldId,
|
|
67
|
+
value: val
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var shouldShow = function shouldShow(options) {
|
|
74
|
+
if (options.type === _models.ComponentTypes.CONTAINER) {
|
|
75
|
+
return _utils.default.Container.show(options, formData);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return _utils.default.Component.show(options, formData);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, attrs, {
|
|
82
|
+
className: DEFAULT_CONTAINER_CLASS,
|
|
83
|
+
id: container.id
|
|
84
|
+
}), container.components && container.components.filter(shouldShow).map(function (component, index) {
|
|
85
|
+
var val = value ? value[component.fieldId] : '';
|
|
86
|
+
return /*#__PURE__*/React.createElement(FormComponent, {
|
|
87
|
+
key: index,
|
|
88
|
+
component: component,
|
|
89
|
+
formData: formData,
|
|
90
|
+
value: val || '',
|
|
91
|
+
wrap: wrap,
|
|
92
|
+
onChange: onComponentChange
|
|
93
|
+
});
|
|
94
|
+
}));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
Container.propTypes = {
|
|
98
|
+
container: _propTypes.default.shape({
|
|
99
|
+
id: _propTypes.default.string.isRequired,
|
|
100
|
+
fieldId: _propTypes.default.string.isRequired,
|
|
101
|
+
components: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
102
|
+
fieldId: _propTypes.default.string,
|
|
103
|
+
type: _propTypes.default.string
|
|
104
|
+
}))
|
|
105
|
+
}).isRequired,
|
|
106
|
+
value: _propTypes.default.any,
|
|
107
|
+
formData: _propTypes.default.any,
|
|
108
|
+
wrap: _propTypes.default.bool,
|
|
109
|
+
onChange: _propTypes.default.func
|
|
110
|
+
};
|
|
111
|
+
Container.defaultProps = {
|
|
112
|
+
wrap: true
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
var FormComponent = function FormComponent(_ref3) {
|
|
116
|
+
var component = _ref3.component,
|
|
117
|
+
value = _ref3.value,
|
|
118
|
+
formData = _ref3.formData,
|
|
119
|
+
wrap = _ref3.wrap,
|
|
120
|
+
onChange = _ref3.onChange,
|
|
121
|
+
attrs = _objectWithoutProperties(_ref3, _excluded2);
|
|
122
|
+
|
|
123
|
+
var _useHooks = (0, _hooks.useHooks)(),
|
|
58
124
|
hooks = _useHooks.hooks;
|
|
59
125
|
|
|
60
|
-
var _useRefData = (0,
|
|
126
|
+
var _useRefData = (0, _hooks.useRefData)(component),
|
|
61
127
|
data = _useRefData.data,
|
|
62
128
|
status = _useRefData.status;
|
|
63
129
|
|
|
@@ -67,10 +133,21 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
67
133
|
setOptions = _useState2[1];
|
|
68
134
|
|
|
69
135
|
(0, _react.useEffect)(function () {
|
|
70
|
-
if (status ===
|
|
136
|
+
if (status === _hooks.STATUS_COMPLETE) {
|
|
71
137
|
setOptions(data);
|
|
72
138
|
}
|
|
73
139
|
}, [component, data, status]);
|
|
140
|
+
|
|
141
|
+
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
142
|
+
return /*#__PURE__*/React.createElement(Container, {
|
|
143
|
+
container: component,
|
|
144
|
+
wrap: wrap,
|
|
145
|
+
onChange: onChange,
|
|
146
|
+
value: value,
|
|
147
|
+
formData: formData
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
74
151
|
return _utils.default.Component.get(_objectSpread(_objectSpread(_objectSpread({}, attrs), component), {}, {
|
|
75
152
|
label: component.label || '',
|
|
76
153
|
hint: component.hint || '',
|
|
@@ -82,6 +159,7 @@ var FormComponent = function FormComponent(_ref) {
|
|
|
82
159
|
|
|
83
160
|
FormComponent.propTypes = {
|
|
84
161
|
component: _propTypes.default.shape({
|
|
162
|
+
fieldId: _propTypes.default.string,
|
|
85
163
|
label: _propTypes.default.string,
|
|
86
164
|
hint: _propTypes.default.string,
|
|
87
165
|
data: _propTypes.default.shape({
|
|
@@ -90,6 +168,7 @@ FormComponent.propTypes = {
|
|
|
90
168
|
})
|
|
91
169
|
}).isRequired,
|
|
92
170
|
value: _propTypes.default.any,
|
|
171
|
+
formData: _propTypes.default.any,
|
|
93
172
|
wrap: _propTypes.default.bool,
|
|
94
173
|
onChange: _propTypes.default.func
|
|
95
174
|
};
|
|
@@ -97,7 +97,8 @@ var FormPage = function FormPage(_ref) {
|
|
|
97
97
|
key: index,
|
|
98
98
|
component: component,
|
|
99
99
|
onChange: onPageChange,
|
|
100
|
-
value: page.formData[component.fieldId] || ''
|
|
100
|
+
value: page.formData[component.fieldId] || '',
|
|
101
|
+
formData: page.formData
|
|
101
102
|
});
|
|
102
103
|
}), /*#__PURE__*/_react.default.createElement(_PageActions.default, {
|
|
103
104
|
actions: page.actions,
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
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
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
8
|
+
Object.defineProperty(exports, "STATUS_COMPLETE", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _useRefData.STATUS_COMPLETE;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "STATUS_LOADING", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _useRefData.STATUS_LOADING;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
6
20
|
Object.defineProperty(exports, "useAxios", {
|
|
7
21
|
enumerable: true,
|
|
8
22
|
get: function get() {
|
|
@@ -34,6 +48,10 @@ var _useHooks = _interopRequireDefault(require("./useHooks"));
|
|
|
34
48
|
|
|
35
49
|
var _useGetRequest = _interopRequireDefault(require("./useGetRequest"));
|
|
36
50
|
|
|
37
|
-
var _useRefData =
|
|
51
|
+
var _useRefData = _interopRequireWildcard(require("./useRefData"));
|
|
52
|
+
|
|
53
|
+
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); }
|
|
54
|
+
|
|
55
|
+
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; }
|
|
38
56
|
|
|
39
57
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var TYPE_AUTOCOMPLETE = 'autocomplete';
|
|
8
8
|
var TYPE_CHECKBOXES = 'checkboxes';
|
|
9
|
+
var TYPE_CONTAINER = 'container';
|
|
9
10
|
var TYPE_DATE = 'date';
|
|
10
11
|
var TYPE_EMAIL = 'email';
|
|
11
12
|
var TYPE_HEADING = 'heading';
|
|
@@ -19,6 +20,7 @@ var TYPE_TIME = 'time';
|
|
|
19
20
|
var ComponentTypes = {
|
|
20
21
|
AUTOCOMPLETE: TYPE_AUTOCOMPLETE,
|
|
21
22
|
CHECKBOXES: TYPE_CHECKBOXES,
|
|
23
|
+
CONTAINER: TYPE_CONTAINER,
|
|
22
24
|
DATE: TYPE_DATE,
|
|
23
25
|
EMAIL: TYPE_EMAIL,
|
|
24
26
|
HEADING: TYPE_HEADING,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _models = require("../../models");
|
|
9
|
+
|
|
10
|
+
var _getCYARow = _interopRequireDefault(require("./getCYARow"));
|
|
11
|
+
|
|
12
|
+
var _showComponentCYA = _interopRequireDefault(require("./showComponentCYA"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
var getCYARowsForContainer = function getCYARowsForContainer(page, container, formData, onAction) {
|
|
23
|
+
if ((0, _showComponentCYA.default)(container, page.formData)) {
|
|
24
|
+
return container.components.filter(function (c) {
|
|
25
|
+
return (0, _showComponentCYA.default)(c, page.formData);
|
|
26
|
+
}).flatMap(function (component) {
|
|
27
|
+
if (component.type === _models.ComponentTypes.CONTAINER) {
|
|
28
|
+
var fd = formData ? formData[component.fieldId] : undefined;
|
|
29
|
+
return getCYARowsForContainer(page, component, fd, onAction);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (0, _getCYARow.default)(_objectSpread(_objectSpread({}, page), {}, {
|
|
33
|
+
formData: formData
|
|
34
|
+
}), component, onAction);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var _default = getCYARowsForContainer;
|
|
40
|
+
exports.default = _default;
|