@ukhomeoffice/cop-react-form-renderer 4.41.0 → 4.43.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.
@@ -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, !config.disableAddAndRemove && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
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 appropriately make child components of items readonly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
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 _callee7$(_context7) {
396
+ return regeneratorRuntime.wrap(function _callee9$(_context9) {
326
397
  while (1) {
327
- switch (_context7.prev = _context7.next) {
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 _context7.stop();
447
+ return _context9.stop();
377
448
  }
378
449
  }
379
- }, _callee7);
450
+ }, _callee9);
380
451
  })));
381
452
  });
@@ -470,6 +470,8 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
470
470
  if (hubDetails !== null && hubDetails !== void 0 && hubDetails.noTaskCYAs) {
471
471
  var currentPage = data.formStatus.tasks[currentTask.name].currentPage;
472
472
  onPageChange(currentPage || currentTask.pages[0]);
473
+ } else if (currentTask.customCYA) {
474
+ onPageChange(currentTask.customCYA);
473
475
  } else {
474
476
  onPageChange(_models.FormPages.CYA);
475
477
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "4.41.0",
3
+ "version": "4.43.0",
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.9.0",
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",