@ukhomeoffice/cop-react-form-renderer 4.40.0 → 4.42.1
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.
|
@@ -153,6 +153,8 @@ var Collection = function Collection(_ref) {
|
|
|
153
153
|
required: config.required,
|
|
154
154
|
className: classes('title')
|
|
155
155
|
}, config.label), value && value.map(function (item, index) {
|
|
156
|
+
var _config$removeLocatio;
|
|
157
|
+
|
|
156
158
|
var full_path = "".concat(config.full_path || config.fieldId, "[").concat(index, "]");
|
|
157
159
|
var labelCount = (config.countOffset || 0) + index + 1;
|
|
158
160
|
|
|
@@ -164,6 +166,7 @@ var Collection = function Collection(_ref) {
|
|
|
164
166
|
index: labelCount
|
|
165
167
|
}));
|
|
166
168
|
|
|
169
|
+
var removeStyle = config.disableAddAndRemove ? '' : (_config$removeLocatio = config.removeLocation) !== null && _config$removeLocatio !== void 0 ? _config$removeLocatio : 'start';
|
|
167
170
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
168
171
|
className: "".concat(classes('item')),
|
|
169
172
|
key: item.id
|
|
@@ -171,7 +174,7 @@ var Collection = function Collection(_ref) {
|
|
|
171
174
|
id: item.id,
|
|
172
175
|
required: true,
|
|
173
176
|
className: classes('item-title')
|
|
174
|
-
}, itemTitle,
|
|
177
|
+
}, itemTitle, removeStyle === 'start' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
175
178
|
onClick: function onClick() {
|
|
176
179
|
return onRemoveItem(item);
|
|
177
180
|
},
|
|
@@ -198,7 +201,12 @@ var Collection = function Collection(_ref) {
|
|
|
198
201
|
onChange: onCollectionChange,
|
|
199
202
|
onTopLevelChange: onTopLevelChange,
|
|
200
203
|
wrap: wrap
|
|
201
|
-
})
|
|
204
|
+
}), removeStyle === 'end' && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, null, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
205
|
+
onClick: function onClick() {
|
|
206
|
+
return onRemoveItem(item);
|
|
207
|
+
},
|
|
208
|
+
classModifiers: "secondary"
|
|
209
|
+
}, removeLabel)));
|
|
202
210
|
}), !config.disableAddAndRemove && /*#__PURE__*/_react.default.createElement(_copReactComponents.ButtonGroup, null, /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
|
|
203
211
|
onClick: onAddAnother,
|
|
204
212
|
classModifiers: "secondary"
|
|
@@ -215,6 +223,7 @@ Collection.propTypes = {
|
|
|
215
223
|
add: _propTypes.default.string,
|
|
216
224
|
remove: _propTypes.default.string
|
|
217
225
|
}),
|
|
226
|
+
removeLocation: _propTypes.default.string,
|
|
218
227
|
disableAddAndRemove: _propTypes.default.bool,
|
|
219
228
|
countOffset: _propTypes.default.number,
|
|
220
229
|
className: _propTypes.default.string,
|
|
@@ -319,12 +319,83 @@ describe('components.FormComponent.Collection', function () {
|
|
|
319
319
|
}
|
|
320
320
|
}, _callee6);
|
|
321
321
|
})));
|
|
322
|
-
it('should
|
|
322
|
+
it('should handle the alternative styling', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
|
|
323
|
+
var COLLECTION, container, c, addButton, item, label, removeButton;
|
|
324
|
+
return regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
325
|
+
while (1) {
|
|
326
|
+
switch (_context8.prev = _context8.next) {
|
|
327
|
+
case 0:
|
|
328
|
+
COLLECTION = {
|
|
329
|
+
id: ID,
|
|
330
|
+
fieldId: ID,
|
|
331
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
332
|
+
item: [TEXT_COMPONENT],
|
|
333
|
+
removeLocation: 'end'
|
|
334
|
+
};
|
|
335
|
+
container = document.createElement('div');
|
|
336
|
+
document.body.appendChild(container);
|
|
337
|
+
_context8.next = 5;
|
|
338
|
+
return (0, _testUtils.act)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
|
|
339
|
+
return regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
340
|
+
while (1) {
|
|
341
|
+
switch (_context7.prev = _context7.next) {
|
|
342
|
+
case 0:
|
|
343
|
+
(0, _setupTests.renderDomWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
344
|
+
component: COLLECTION
|
|
345
|
+
}), container);
|
|
346
|
+
|
|
347
|
+
case 1:
|
|
348
|
+
case "end":
|
|
349
|
+
return _context7.stop();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}, _callee7);
|
|
353
|
+
})));
|
|
354
|
+
|
|
355
|
+
case 5:
|
|
356
|
+
// Check the container itself.
|
|
357
|
+
c = container.childNodes[0];
|
|
358
|
+
expect(c.tagName).toEqual('DIV');
|
|
359
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS); // And now make sure it has no children OTHER than the button to add an item.
|
|
360
|
+
|
|
361
|
+
expect(c.childNodes.length).toEqual(1); // Get hold of that "Add another" button and click it.
|
|
362
|
+
|
|
363
|
+
addButton = c.childNodes[0].childNodes[0];
|
|
364
|
+
|
|
365
|
+
_react.fireEvent.click(addButton, {}); // Make sure an item has been added.
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
expect(c.childNodes.length).toEqual(2);
|
|
369
|
+
item = c.childNodes[0];
|
|
370
|
+
label = item.childNodes[0];
|
|
371
|
+
expect(label.textContent).toContain(_utils.default.interpolateString(_models.CollectionLabels.item, {
|
|
372
|
+
index: 1
|
|
373
|
+
})); // Get hold of the newly-add item's "Remove" button.
|
|
374
|
+
|
|
375
|
+
removeButton = item.childNodes[2].childNodes[0];
|
|
376
|
+
expect(removeButton.tagName).toEqual('BUTTON');
|
|
377
|
+
expect(removeButton.classList).toContain('hods-button--secondary');
|
|
378
|
+
expect(removeButton.textContent).toContain(_models.CollectionLabels.remove); // Click the "Remove" button
|
|
379
|
+
|
|
380
|
+
_react.fireEvent.click(removeButton, {}); // Make sure the item has been removed.
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
expect(c.childNodes.length).toEqual(1);
|
|
384
|
+
expect(c.childNodes[0].classList).toContain('hods-button-group');
|
|
385
|
+
|
|
386
|
+
case 22:
|
|
387
|
+
case "end":
|
|
388
|
+
return _context8.stop();
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}, _callee8);
|
|
392
|
+
})));
|
|
393
|
+
it('should appropriately make child components of items readonly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
|
|
323
394
|
var COLLECTION, _renderWithValidation5, container, c, item, _item$childNodes2, title, itemContainer, formGroup, label, hint, input;
|
|
324
395
|
|
|
325
|
-
return regeneratorRuntime.wrap(function
|
|
396
|
+
return regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
326
397
|
while (1) {
|
|
327
|
-
switch (
|
|
398
|
+
switch (_context9.prev = _context9.next) {
|
|
328
399
|
case 0:
|
|
329
400
|
COLLECTION = {
|
|
330
401
|
id: ID,
|
|
@@ -373,9 +444,9 @@ describe('components.FormComponent.Collection', function () {
|
|
|
373
444
|
|
|
374
445
|
case 30:
|
|
375
446
|
case "end":
|
|
376
|
-
return
|
|
447
|
+
return _context9.stop();
|
|
377
448
|
}
|
|
378
449
|
}
|
|
379
|
-
},
|
|
450
|
+
}, _callee9);
|
|
380
451
|
})));
|
|
381
452
|
});
|
|
@@ -44,13 +44,16 @@ describe('utils.Component.get', function () {
|
|
|
44
44
|
container = _render.container;
|
|
45
45
|
|
|
46
46
|
var _getAllByTestId = (0, _react.getAllByTestId)(container, ID),
|
|
47
|
-
_getAllByTestId2 = _slicedToArray(_getAllByTestId,
|
|
48
|
-
formGroup = _getAllByTestId2[0]
|
|
49
|
-
wrapper = _getAllByTestId2[1];
|
|
47
|
+
_getAllByTestId2 = _slicedToArray(_getAllByTestId, 1),
|
|
48
|
+
formGroup = _getAllByTestId2[0];
|
|
50
49
|
|
|
51
|
-
var input = wrapper.querySelector('#dropzone').children[0];
|
|
52
50
|
expect(formGroup.tagName).toEqual('DIV');
|
|
53
51
|
expect(formGroup.classList).toContain('govuk-form-group');
|
|
52
|
+
var wrapper = container.querySelector("#".concat(ID));
|
|
53
|
+
expect(wrapper.tagName).toEqual('DIV');
|
|
54
|
+
expect(wrapper.classList).toContain('cop-multi-file-upload');
|
|
55
|
+
expect(wrapper.id).toEqual(ID);
|
|
56
|
+
var input = wrapper.children[1].children[0];
|
|
54
57
|
var label = undefined;
|
|
55
58
|
formGroup.childNodes[0].childNodes.forEach(function (node) {
|
|
56
59
|
// Check if it's an element.
|
|
@@ -61,9 +64,6 @@ describe('utils.Component.get', function () {
|
|
|
61
64
|
expect(label).toBeDefined();
|
|
62
65
|
expect(label.innerHTML).toContain(LABEL);
|
|
63
66
|
expect(label.getAttribute('for')).toEqual(ID);
|
|
64
|
-
expect(wrapper.tagName).toEqual('DIV');
|
|
65
|
-
expect(wrapper.classList).toContain('cop-multi-file-upload');
|
|
66
|
-
expect(wrapper.id).toEqual(ID);
|
|
67
67
|
var str = JSON.stringify({
|
|
68
68
|
alpha: 'bravo'
|
|
69
69
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ukhomeoffice/cop-react-form-renderer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.42.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rimraf dist",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"post-compile": "rimraf dist/*.test.* dist/**/*.test.* dist/**/*.stories.* dist/docs dist/assets"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ukhomeoffice/cop-react-components": "2.
|
|
19
|
+
"@ukhomeoffice/cop-react-components": "2.9.1",
|
|
20
20
|
"axios": "^0.23.0",
|
|
21
21
|
"dayjs": "^1.11.0",
|
|
22
22
|
"govuk-frontend": "^4.3.1",
|