@ukhomeoffice/cop-react-form-renderer 5.65.1 → 5.67.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.
@@ -27,7 +27,7 @@ var DEFAULT_DELETE_BUTTON_LABEL = exports.DEFAULT_DELETE_BUTTON_LABEL = 'Delete'
27
27
  var DEFAULT_CHANGE_BUTTON_CLASS = exports.DEFAULT_CHANGE_BUTTON_CLASS = 'secondary';
28
28
  var DEFAULT_DELETE_BUTTON_CLASS = exports.DEFAULT_DELETE_BUTTON_CLASS = 'warning';
29
29
  var RenderListView = function RenderListView(_ref) {
30
- var _masterPage$childPage;
30
+ var _config$changeAction, _config$deleteAction, _masterPage$childPage;
31
31
  var id = _ref.id,
32
32
  entryData = _ref.entryData,
33
33
  config = _ref.config,
@@ -50,22 +50,15 @@ var RenderListView = function RenderListView(_ref) {
50
50
  className: classes('actions')
51
51
  }, /*#__PURE__*/_react.default.createElement("li", {
52
52
  className: classes('action')
53
- }, config.changeAction && typeof onFullEdit === 'function' && /*#__PURE__*/_react.default.createElement("div", {
54
- className: "govuk-link",
53
+ }, config.changeAction && typeof onFullEdit === 'function' && /*#__PURE__*/_react.default.createElement("button", {
54
+ type: "button",
55
+ className: "govuk-link govuk-link-button",
55
56
  onClick: function onClick() {
56
57
  return onFullEdit(config.changeAction.page, entryData.id);
57
58
  },
58
- onKeyDown: function onKeyDown(e) {
59
- if (e.key === 'Enter' || e.key === ' ') {
60
- onFullEdit(config.changeAction.page, entryData.id);
61
- }
62
- },
63
- role: "button",
64
- tabIndex: 0,
65
- style: {
66
- cursor: 'pointer'
67
- },
68
- "aria-label": config.changeAction.label
59
+ "aria-label": _copReactComponents.Utils.interpolateString("".concat(((_config$changeAction = config.changeAction) === null || _config$changeAction === void 0 ? void 0 : _config$changeAction.label) || DEFAULT_CHANGE_BUTTON_LABEL, " ").concat(config.title || DEFAULT_TITLE), _objectSpread(_objectSpread({}, entryData), {}, {
60
+ index: entryData.index + 1
61
+ }))
69
62
  }, config.changeAction.label || DEFAULT_CHANGE_BUTTON_LABEL)), /*#__PURE__*/_react.default.createElement("li", {
70
63
  className: classes('action')
71
64
  }, config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
@@ -74,7 +67,9 @@ var RenderListView = function RenderListView(_ref) {
74
67
  return onDelete(entryData);
75
68
  },
76
69
  classModifiers: config.deleteAction.classModifiers || DEFAULT_DELETE_BUTTON_CLASS,
77
- "aria-label": config.deleteAction.label
70
+ "aria-label": _copReactComponents.Utils.interpolateString("".concat(((_config$deleteAction = config.deleteAction) === null || _config$deleteAction === void 0 ? void 0 : _config$deleteAction.label) || DEFAULT_DELETE_BUTTON_LABEL, " ").concat(config.title || DEFAULT_TITLE), _objectSpread(_objectSpread({}, entryData), {}, {
71
+ index: entryData.index + 1
72
+ }))
78
73
  }, config.deleteAction.label || DEFAULT_DELETE_BUTTON_LABEL)))), /*#__PURE__*/_react.default.createElement("div", {
79
74
  className: classes('content')
80
75
  }, /*#__PURE__*/_react.default.createElement("dl", {
@@ -275,3 +275,8 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
275
275
  border-bottom: none;
276
276
  }
277
277
  }
278
+
279
+ .govuk-link-button {
280
+ background: none;
281
+ border: none;
282
+ }
@@ -189,18 +189,14 @@ describe('components.CollectionSummary.RenderListView', function () {
189
189
  masterPage: MASTER_PAGE,
190
190
  getComponentRow: getComponentRow
191
191
  })),
192
- container = _renderWithValidation3.container,
193
- queryByRole = _renderWithValidation3.queryByRole;
192
+ container = _renderWithValidation3.container;
194
193
  var listViewDiv = container.querySelector('.govuk-summary-card');
195
194
  expect(listViewDiv).not.toBeNull();
196
195
 
197
196
  // Check for change button
198
197
  var changeLink = listViewDiv.querySelector('.govuk-link');
199
198
  expect(changeLink.textContent).toEqual(CONFIG.changeAction.label);
200
- var changeButton = queryByRole('button', {
201
- name: CONFIG.changeAction.label
202
- });
203
- expect(changeButton).toBeTruthy();
199
+ expect(changeLink.getAttribute('aria-label')).toEqual("".concat(CONFIG.changeAction.label, " ").concat(CONFIG.title));
204
200
  _react.fireEvent.click(changeLink, {});
205
201
  expect(onChangeCalls).toEqual(1);
206
202
  expect(onChangeArgs[0]).toMatchObject({
@@ -211,10 +207,7 @@ describe('components.CollectionSummary.RenderListView', function () {
211
207
  // Check for delete button
212
208
  var deleteButton = listViewDiv.querySelector('[id$=".deleteButton"]');
213
209
  expect(deleteButton.textContent).toEqual(CONFIG.deleteAction.label);
214
- var deleteButtonElement = queryByRole('button', {
215
- name: CONFIG.deleteAction.label
216
- });
217
- expect(deleteButtonElement).toBeTruthy();
210
+ expect(deleteButton.getAttribute('aria-label')).toEqual("".concat(CONFIG.deleteAction.label, " ").concat(CONFIG.title));
218
211
  _react.fireEvent.click(deleteButton, {});
219
212
  expect(onDeleteCalls).toEqual(1);
220
213
  expect(onDeleteArgs[0]).toEqual(ENTRY);
@@ -21,13 +21,13 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
21
21
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
24
+ 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; }
25
+ 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; }
24
26
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
25
27
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
26
28
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
29
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
28
30
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
29
- 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; }
30
- 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; }
31
31
  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); } }
32
32
  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); }); }; }
33
33
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
@@ -47,7 +47,7 @@ var DEFAULT_DUPLICATE_BUTTON_LABEL = exports.DEFAULT_DUPLICATE_BUTTON_LABEL = 'D
47
47
  var DEFAULT_DETAILS_TITLE = exports.DEFAULT_DETAILS_TITLE = 'Full details';
48
48
  var DEFAULT_CHANGE_BUTTON_CLASS = exports.DEFAULT_CHANGE_BUTTON_CLASS = 'secondary';
49
49
  var SummaryCard = function SummaryCard(_ref) {
50
- var _config$changeAction2, _config$changeAction3, _config$deleteAction, _config$duplicateActi;
50
+ var _config$changeAction2, _config$changeAction3, _config$changeAction4, _config$deleteAction, _config$deleteAction2, _config$duplicateActi, _config$duplicateActi2;
51
51
  var id = _ref.id,
52
52
  entryData = _ref.entryData,
53
53
  config = _ref.config,
@@ -81,7 +81,7 @@ var SummaryCard = function SummaryCard(_ref) {
81
81
  hooks = _useHooks.hooks;
82
82
  var _onAction = /*#__PURE__*/function () {
83
83
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(action, patch) {
84
- var errors, hookErrors, allErrors, allData, _allData$entryData$in, isDuplicate, newEntry;
84
+ var validationData, errors, hookErrors, allErrors, allData, _allData$entryData$in, isDuplicate, newEntry;
85
85
  return _regeneratorRuntime().wrap(function _callee$(_context) {
86
86
  while (1) switch (_context.prev = _context.next) {
87
87
  case 0:
@@ -91,23 +91,25 @@ var SummaryCard = function SummaryCard(_ref) {
91
91
  });
92
92
  resetQuickEditErrors === null || resetQuickEditErrors === void 0 || resetQuickEditErrors();
93
93
  }
94
- if (!(action.type === 'save' && typeof onQuickEdit === 'function' && Object.keys(patch).length)) {
95
- _context.next = 10;
94
+ if (!(action.type === 'save' && typeof onQuickEdit === 'function')) {
95
+ _context.next = 11;
96
96
  break;
97
97
  }
98
- // Local validation
99
- errors = validate.page(quickEditPage);
98
+ validationData = _objectSpread(_objectSpread(_objectSpread({}, quickEditPage.formData), patch), {}, _defineProperty({}, "".concat(parentCollectionName, "ActiveId"), entryData.id)); // Local validation
99
+ errors = validate.page(_objectSpread(_objectSpread({}, quickEditPage), {}, {
100
+ formData: validationData
101
+ }));
100
102
  if (!errors.length) {
101
- _context.next = 5;
103
+ _context.next = 6;
102
104
  break;
103
105
  }
104
106
  return _context.abrupt("return");
105
- case 5:
106
- _context.next = 7;
107
- return hooks.onSubmit('quickEdit', patch, function () {}, function (e) {
107
+ case 6:
108
+ _context.next = 8;
109
+ return hooks.onSubmit('quickEdit', validationData, function () {}, function (e) {
108
110
  hookErrors = e;
109
111
  });
110
- case 7:
112
+ case 8:
111
113
  if (hookErrors) {
112
114
  addErrors(hookErrors);
113
115
  }
@@ -133,7 +135,7 @@ var SummaryCard = function SummaryCard(_ref) {
133
135
  return !prevState;
134
136
  });
135
137
  }
136
- case 10:
138
+ case 11:
137
139
  case "end":
138
140
  return _context.stop();
139
141
  }
@@ -190,20 +192,23 @@ var SummaryCard = function SummaryCard(_ref) {
190
192
  var _config$changeAction;
191
193
  return onFullEdit((_config$changeAction = config.changeAction) === null || _config$changeAction === void 0 ? void 0 : _config$changeAction.page, entryData.id);
192
194
  },
193
- classModifiers: ((_config$changeAction2 = config.changeAction) === null || _config$changeAction2 === void 0 ? void 0 : _config$changeAction2.classModifiers) || DEFAULT_CHANGE_BUTTON_CLASS
194
- }, ((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.label) || DEFAULT_CHANGE_BUTTON_LABEL), config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
195
+ classModifiers: ((_config$changeAction2 = config.changeAction) === null || _config$changeAction2 === void 0 ? void 0 : _config$changeAction2.classModifiers) || DEFAULT_CHANGE_BUTTON_CLASS,
196
+ "aria-label": _utils.default.FormPage.getConditionalText((_config$changeAction3 = config.changeAction) === null || _config$changeAction3 === void 0 ? void 0 : _config$changeAction3.aria_label, entryData)
197
+ }, ((_config$changeAction4 = config.changeAction) === null || _config$changeAction4 === void 0 ? void 0 : _config$changeAction4.label) || DEFAULT_CHANGE_BUTTON_LABEL), config.deleteAction && typeof onDelete === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
195
198
  id: "".concat(id, ".deleteButton"),
196
199
  onClick: function onClick() {
197
200
  return onDelete(entryData);
198
201
  },
199
- classModifiers: "secondary"
200
- }, ((_config$deleteAction = config.deleteAction) === null || _config$deleteAction === void 0 ? void 0 : _config$deleteAction.label) || DEFAULT_DELETE_BUTTON_LABEL), config.duplicateAction && typeof onDuplicate === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
202
+ classModifiers: "secondary",
203
+ "aria-label": _utils.default.FormPage.getConditionalText((_config$deleteAction = config.deleteAction) === null || _config$deleteAction === void 0 ? void 0 : _config$deleteAction.aria_label, entryData)
204
+ }, ((_config$deleteAction2 = config.deleteAction) === null || _config$deleteAction2 === void 0 ? void 0 : _config$deleteAction2.label) || DEFAULT_DELETE_BUTTON_LABEL), config.duplicateAction && typeof onDuplicate === 'function' && /*#__PURE__*/_react.default.createElement(_copReactComponents.Button, {
201
205
  id: "".concat(id, ".duplicateButton"),
202
206
  onClick: function onClick() {
203
207
  onDuplicate(entryData);
204
208
  },
205
- classModifiers: "secondary"
206
- }, ((_config$duplicateActi = config.duplicateAction) === null || _config$duplicateActi === void 0 ? void 0 : _config$duplicateActi.label) || DEFAULT_DUPLICATE_BUTTON_LABEL))), quickEdit && quickEditPage && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
209
+ classModifiers: "secondary",
210
+ "aria-label": _utils.default.FormPage.getConditionalText((_config$duplicateActi = config.duplicateAction) === null || _config$duplicateActi === void 0 ? void 0 : _config$duplicateActi.aria_label, entryData)
211
+ }, ((_config$duplicateActi2 = config.duplicateAction) === null || _config$duplicateActi2 === void 0 ? void 0 : _config$duplicateActi2.label) || DEFAULT_DUPLICATE_BUTTON_LABEL))), quickEdit && quickEditPage && /*#__PURE__*/_react.default.createElement(_FormPage.default, {
207
212
  page: quickEditPage,
208
213
  onAction: function onAction(action, patch) {
209
214
  return _onAction(action, patch);
@@ -235,13 +240,16 @@ SummaryCard.propTypes = {
235
240
  changeAction: _propTypes.default.shape({
236
241
  label: _propTypes.default.string,
237
242
  page: _propTypes.default.string.isRequired,
238
- classModifiers: _propTypes.default.string
243
+ classModifiers: _propTypes.default.string,
244
+ aria_label: _propTypes.default.string
239
245
  }),
240
246
  deleteAction: _propTypes.default.shape({
241
- label: _propTypes.default.string
247
+ label: _propTypes.default.string,
248
+ aria_label: _propTypes.default.string
242
249
  }),
243
250
  duplicateAction: _propTypes.default.shape({
244
- label: _propTypes.default.string
251
+ label: _propTypes.default.string,
252
+ aria_label: _propTypes.default.string
245
253
  }),
246
254
  quickEdit: _propTypes.default.shape({
247
255
  components: _propTypes.default.arrayOf(_propTypes.default.shape({
@@ -51,6 +51,7 @@ $govuk-font-family: 'Roboto', arial, sans-serif;
51
51
 
52
52
  &-actions {
53
53
  width: 35%;
54
+ text-align: center;
54
55
 
55
56
  .hods-button--primary {
56
57
  @extend .hods-button--primary;
@@ -256,7 +256,10 @@ describe('components.CollectionSummary.SummaryCard', function () {
256
256
  var CONFIG = {
257
257
  changeAction: {
258
258
  label: 'Change label',
259
- page: 'testPage'
259
+ page: 'testPage',
260
+ aria_label: [{
261
+ text: 'testText'
262
+ }]
260
263
  }
261
264
  };
262
265
  var _renderWithValidation7 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
@@ -277,6 +280,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
277
280
  var changeButton = headerActionDiv.children[0];
278
281
  expect(changeButton.tagName).toEqual('BUTTON');
279
282
  expect(changeButton.textContent).toEqual(CONFIG.changeAction.label);
283
+ expect(changeButton.getAttribute('aria-label')).toEqual(CONFIG.changeAction.aria_label[0].text);
280
284
  _react.fireEvent.click(changeButton, {});
281
285
  expect(onChangeCalls).toEqual(1);
282
286
  expect(onChangeArgs[0]).toMatchObject({
@@ -363,7 +367,10 @@ describe('components.CollectionSummary.SummaryCard', function () {
363
367
  it('should render correctly', function () {
364
368
  var CONFIG = {
365
369
  deleteAction: {
366
- label: 'Delete label'
370
+ label: 'Delete label',
371
+ aria_label: [{
372
+ text: 'testText'
373
+ }]
367
374
  }
368
375
  };
369
376
  var _renderWithValidation11 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_SummaryCard.default, {
@@ -384,6 +391,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
384
391
  var deleteButton = headerActionDiv.children[0];
385
392
  expect(deleteButton.tagName).toEqual('BUTTON');
386
393
  expect(deleteButton.textContent).toEqual(CONFIG.deleteAction.label);
394
+ expect(deleteButton.getAttribute('aria-label')).toEqual(CONFIG.deleteAction.aria_label[0].text);
387
395
  _react.fireEvent.click(deleteButton, {});
388
396
  expect(onDeleteCalls).toEqual(1);
389
397
  expect(onDeleteArgs[0]).toMatchObject(ENTRY);
@@ -1006,7 +1014,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
1006
1014
  }
1007
1015
  }, _callee6);
1008
1016
  })));
1009
- it('should run hook validation when a value changes and local validation is passed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1017
+ it('should run hook validation when local validation is passed', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1010
1018
  var ON_SUBMIT_CALLS, hooks, ON_QUICK_EDIT_CALLS, ON_QUICK_EDIT, _renderWithValidation27, container, _checkSetup26, headerActionDiv, editButton, quickEdit, component, componentInput, quickEditButtons, saveButton;
1011
1019
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1012
1020
  while (1) switch (_context8.prev = _context8.next) {
@@ -1069,7 +1077,7 @@ describe('components.CollectionSummary.SummaryCard', function () {
1069
1077
  }, _callee7);
1070
1078
  })));
1071
1079
  case 16:
1072
- expect(ON_SUBMIT_CALLS[0]).toEqual({
1080
+ expect(ON_SUBMIT_CALLS[0]).toMatchObject({
1073
1081
  testText: 'new value'
1074
1082
  });
1075
1083
  expect(ON_QUICK_EDIT_CALLS.length).toEqual(0);
@@ -13,13 +13,14 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
13
13
  /**
14
14
  * Combines refdata options with custom options with the use of `from_refdata` in the custom option
15
15
  * Allowing for nesting of components within refdata lists of checkboxes or radios
16
+ * Also allows appending custom options to refdata options list
16
17
  * @param {Array} refdataOptions The list of options coming from refdata
17
18
  * @param {Array} options The list of options being defined in the form
18
19
  * @returns A combined list of refdata options and custom options to be rendered
19
20
  */
20
21
  var nestInRefdataOptions = function nestInRefdataOptions(refdataOptions, options) {
21
22
  var nestedRefdataOptions = refdataOptions;
22
- options.forEach(function (option) {
23
+ options.forEach(function (option, index) {
23
24
  if (option.refdata_match) {
24
25
  var refdataMatch = option.refdata_match;
25
26
  var refdataKey = Object.keys(refdataMatch)[0];
@@ -32,6 +33,16 @@ var nestInRefdataOptions = function nestInRefdataOptions(refdataOptions, options
32
33
  });
33
34
  }
34
35
  }
36
+
37
+ // checks if already exists in `nestedRefdataOptions` else
38
+ // re-renders would cause array to grow with each render
39
+ if (option.combineWithRefdata && !nestedRefdataOptions.includes(option)) {
40
+ // adds previous array entry if string e.g. "or" operator
41
+ if (index > 0 && typeof options[index - 1] === 'string') {
42
+ nestedRefdataOptions.push(options[index - 1]);
43
+ }
44
+ nestedRefdataOptions.push(option);
45
+ }
35
46
  });
36
47
  return nestedRefdataOptions;
37
48
  };
@@ -2,101 +2,235 @@
2
2
 
3
3
  var _nestInRefdataOptions = _interopRequireDefault(require("./nestInRefdataOptions"));
4
4
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
- describe("utils.Data.combineOptions", function () {
6
- it("should combine refdata options with a custom option", function () {
5
+ describe('utils.Data.combineOptions', function () {
6
+ it('should combine refdata options with a custom option', function () {
7
7
  var refdataOptions = [{
8
8
  id: 1,
9
- description: "First refdata item",
10
- value: "firstValue",
11
- label: "First label"
9
+ description: 'First refdata item',
10
+ value: 'firstValue',
11
+ label: 'First label'
12
12
  }, {
13
13
  id: 2,
14
- description: "Second refdata item",
15
- value: "secondValue",
16
- label: "Second label"
14
+ description: 'Second refdata item',
15
+ value: 'secondValue',
16
+ label: 'Second label'
17
17
  }, {
18
18
  id: 3,
19
- description: "Third refdata item",
20
- value: "thirdValue",
21
- label: "Third label"
19
+ description: 'Third refdata item',
20
+ value: 'thirdValue',
21
+ label: 'Third label'
22
22
  }];
23
23
  var customOptions = [{
24
24
  refdata_match: {
25
25
  id: 2
26
26
  },
27
27
  nested: [{
28
- id: "nestedComponent",
29
- fieldId: "nestedComponent",
30
- type: "text",
31
- label: "Nested Component"
28
+ id: 'nestedComponent',
29
+ fieldId: 'nestedComponent',
30
+ type: 'text',
31
+ label: 'Nested Component'
32
32
  }]
33
33
  }];
34
34
  expect((0, _nestInRefdataOptions.default)(refdataOptions, customOptions)).toEqual([{
35
- description: "First refdata item",
35
+ description: 'First refdata item',
36
36
  id: 1,
37
- label: "First label",
38
- value: "firstValue"
37
+ label: 'First label',
38
+ value: 'firstValue'
39
39
  }, {
40
- description: "Second refdata item",
40
+ description: 'Second refdata item',
41
41
  id: 2,
42
- label: "Second label",
42
+ label: 'Second label',
43
43
  nested: [{
44
- id: "nestedComponent",
45
- fieldId: "nestedComponent",
46
- type: "text",
47
- label: "Nested Component"
44
+ id: 'nestedComponent',
45
+ fieldId: 'nestedComponent',
46
+ type: 'text',
47
+ label: 'Nested Component'
48
48
  }],
49
- value: "secondValue"
49
+ value: 'secondValue'
50
50
  }, {
51
- description: "Third refdata item",
51
+ description: 'Third refdata item',
52
52
  id: 3,
53
- label: "Third label",
54
- value: "thirdValue"
53
+ label: 'Third label',
54
+ value: 'thirdValue'
55
55
  }]);
56
56
  });
57
- it("should not combine options if it can't find a matching refdata option", function () {
57
+ it('should not combine options if it can`t find a matching refdata option', function () {
58
58
  var refdataOptions = [{
59
59
  id: 1,
60
- description: "First refdata item",
61
- value: "firstValue",
62
- label: "First label"
60
+ description: 'First refdata item',
61
+ value: 'firstValue',
62
+ label: 'First label'
63
63
  }, {
64
64
  id: 2,
65
- description: "Second refdata item",
66
- value: "secondValue",
67
- label: "Second label"
65
+ description: 'Second refdata item',
66
+ value: 'secondValue',
67
+ label: 'Second label'
68
68
  }, {
69
69
  id: 3,
70
- description: "Third refdata item",
71
- value: "thirdValue",
72
- label: "Third label"
70
+ description: 'Third refdata item',
71
+ value: 'thirdValue',
72
+ label: 'Third label'
73
73
  }];
74
74
  var customOptions = [{
75
75
  refdata_match: {
76
76
  id: 4
77
77
  },
78
78
  nested: [{
79
- id: "nestedComponent",
80
- fieldId: "nestedComponent",
81
- type: "text",
82
- label: "Nested Component"
79
+ id: 'nestedComponent',
80
+ fieldId: 'nestedComponent',
81
+ type: 'text',
82
+ label: 'Nested Component'
83
83
  }]
84
84
  }];
85
85
  expect((0, _nestInRefdataOptions.default)(refdataOptions, customOptions)).toEqual([{
86
- description: "First refdata item",
86
+ description: 'First refdata item',
87
87
  id: 1,
88
- label: "First label",
89
- value: "firstValue"
88
+ label: 'First label',
89
+ value: 'firstValue'
90
90
  }, {
91
- description: "Second refdata item",
91
+ description: 'Second refdata item',
92
92
  id: 2,
93
- label: "Second label",
94
- value: "secondValue"
93
+ label: 'Second label',
94
+ value: 'secondValue'
95
95
  }, {
96
- description: "Third refdata item",
96
+ description: 'Third refdata item',
97
97
  id: 3,
98
- label: "Third label",
99
- value: "thirdValue"
98
+ label: 'Third label',
99
+ value: 'thirdValue'
100
+ }]);
101
+ });
102
+ it('should append refdata options with a custom option when `combineWithRefdata` flag is set', function () {
103
+ var refdataOptions = [{
104
+ id: 1,
105
+ description: 'First refdata item',
106
+ value: 'firstValue',
107
+ label: 'First label'
108
+ }, {
109
+ id: 2,
110
+ description: 'Second refdata item',
111
+ value: 'secondValue',
112
+ label: 'Second label'
113
+ }, {
114
+ id: 3,
115
+ description: 'Third refdata item',
116
+ value: 'thirdValue',
117
+ label: 'Third label'
118
+ }];
119
+ var customOptions = [{
120
+ combineWithRefdata: true,
121
+ id: 'otherComponent',
122
+ fieldId: 'otherComponent',
123
+ type: 'text',
124
+ label: 'Other Component'
125
+ }];
126
+ expect((0, _nestInRefdataOptions.default)(refdataOptions, customOptions)).toEqual([{
127
+ description: 'First refdata item',
128
+ id: 1,
129
+ label: 'First label',
130
+ value: 'firstValue'
131
+ }, {
132
+ description: 'Second refdata item',
133
+ id: 2,
134
+ label: 'Second label',
135
+ value: 'secondValue'
136
+ }, {
137
+ description: 'Third refdata item',
138
+ id: 3,
139
+ label: 'Third label',
140
+ value: 'thirdValue'
141
+ }, {
142
+ combineWithRefdata: true,
143
+ id: 'otherComponent',
144
+ fieldId: 'otherComponent',
145
+ type: 'text',
146
+ label: 'Other Component'
147
+ }]);
148
+ });
149
+ it('should not append refdata options with a custom option when `combineWithRefdata` flag is not set', function () {
150
+ var refdataOptions = [{
151
+ id: 1,
152
+ description: 'First refdata item',
153
+ value: 'firstValue',
154
+ label: 'First label'
155
+ }, {
156
+ id: 2,
157
+ description: 'Second refdata item',
158
+ value: 'secondValue',
159
+ label: 'Second label'
160
+ }, {
161
+ id: 3,
162
+ description: 'Third refdata item',
163
+ value: 'thirdValue',
164
+ label: 'Third label'
165
+ }];
166
+ var customOptions = [{
167
+ id: 'otherComponent',
168
+ fieldId: 'otherComponent',
169
+ type: 'text',
170
+ label: 'Other Component'
171
+ }];
172
+ expect((0, _nestInRefdataOptions.default)(refdataOptions, customOptions)).toEqual([{
173
+ description: 'First refdata item',
174
+ id: 1,
175
+ label: 'First label',
176
+ value: 'firstValue'
177
+ }, {
178
+ description: 'Second refdata item',
179
+ id: 2,
180
+ label: 'Second label',
181
+ value: 'secondValue'
182
+ }, {
183
+ description: 'Third refdata item',
184
+ id: 3,
185
+ label: 'Third label',
186
+ value: 'thirdValue'
187
+ }]);
188
+ });
189
+ it('should append refdata options with a string when `combineWithRefdata` flag is set and custom option comes after string', function () {
190
+ var refdataOptions = [{
191
+ id: 1,
192
+ description: 'First refdata item',
193
+ value: 'firstValue',
194
+ label: 'First label'
195
+ }, {
196
+ id: 2,
197
+ description: 'Second refdata item',
198
+ value: 'secondValue',
199
+ label: 'Second label'
200
+ }, {
201
+ id: 3,
202
+ description: 'Third refdata item',
203
+ value: 'thirdValue',
204
+ label: 'Third label'
205
+ }];
206
+ var customOptions = ["or", {
207
+ combineWithRefdata: true,
208
+ id: 'otherComponent',
209
+ fieldId: 'otherComponent',
210
+ type: 'text',
211
+ label: 'Other Component'
212
+ }];
213
+ expect((0, _nestInRefdataOptions.default)(refdataOptions, customOptions)).toEqual([{
214
+ description: 'First refdata item',
215
+ id: 1,
216
+ label: 'First label',
217
+ value: 'firstValue'
218
+ }, {
219
+ description: 'Second refdata item',
220
+ id: 2,
221
+ label: 'Second label',
222
+ value: 'secondValue'
223
+ }, {
224
+ description: 'Third refdata item',
225
+ id: 3,
226
+ label: 'Third label',
227
+ value: 'thirdValue'
228
+ }, "or", {
229
+ combineWithRefdata: true,
230
+ id: 'otherComponent',
231
+ fieldId: 'otherComponent',
232
+ type: 'text',
233
+ label: 'Other Component'
100
234
  }]);
101
235
  });
102
236
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.65.1",
3
+ "version": "5.67.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",