@ukhomeoffice/cop-react-form-renderer 5.7.0 → 5.9.0-alpha

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.
@@ -29,6 +29,7 @@ var DEFAULT_CLASS = _FormPage2.DEFAULT_CLASS;
29
29
  exports.DEFAULT_CLASS = DEFAULT_CLASS;
30
30
  var CollectionPage = function CollectionPage(_ref) {
31
31
  var page = _ref.page,
32
+ onCollectionChange = _ref.onCollectionChange,
32
33
  onAction = _ref.onAction,
33
34
  hashLink = _ref.hashLink,
34
35
  classBlock = _ref.classBlock,
@@ -62,6 +63,9 @@ var CollectionPage = function CollectionPage(_ref) {
62
63
  value: newValue
63
64
  }
64
65
  });
66
+ if (typeof onChange === 'function') {
67
+ onCollectionChange(page.formData);
68
+ }
65
69
  };
66
70
  var reportActiveIdChange = function reportActiveIdChange(newActiveId) {
67
71
  onPageChange({
@@ -354,6 +354,7 @@ var InternalFormRenderer = function InternalFormRenderer(_ref2) {
354
354
  className: formState.page.className
355
355
  }), formState.page && !formState.cya && formState.page.collection && /*#__PURE__*/_react.default.createElement(_CollectionPage.default, {
356
356
  page: formState.page,
357
+ onCollectionChange: onChange,
357
358
  onAction: function onAction(action, patch, patchLabel) {
358
359
  (0, _onPageAction.default)(action, patch, patchLabel, hooks, data, formState, validate, onPageChange, type, pages, components, pageId, setPagePoint, currentTask, setData, hubDetails, setSubmitted, addErrors);
359
360
  },
@@ -21,7 +21,12 @@ var getAutocompleteSource = function getAutocompleteSource(config) {
21
21
  var lcQuery = query ? query.toLowerCase() : '';
22
22
  populateResults(options.filter(function (opt) {
23
23
  var label = labelMaker ? labelMaker(opt) : opt.label || '';
24
- return label.toLowerCase().includes(lcQuery);
24
+ if (label.toLowerCase().includes(lcQuery)) {
25
+ return true;
26
+ }
27
+ return opt.synonyms ? opt.synonyms.some(function (synonym) {
28
+ return synonym.toLowerCase().includes(lcQuery);
29
+ }) : false;
25
30
  }));
26
31
  };
27
32
  };
@@ -141,6 +141,29 @@ describe('utils', function () {
141
141
  }]);
142
142
  });
143
143
  });
144
+ it('should match options using a defined synonym', function () {
145
+ var CONFIG = {
146
+ data: {
147
+ options: [{
148
+ value: 'a',
149
+ label: 'Alpha',
150
+ synonyms: ['first']
151
+ }, {
152
+ value: 'b'
153
+ }]
154
+ }
155
+ };
156
+ var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
157
+ expect(typeof SOURCE === 'function').toBeTruthy();
158
+ SOURCE('first', function (results) {
159
+ expect(results.length).toEqual(1);
160
+ expect(results).toEqual([{
161
+ value: 'a',
162
+ label: 'Alpha',
163
+ synonyms: ['first']
164
+ }]);
165
+ });
166
+ });
144
167
  });
145
168
  describe('with custom item labels', function () {
146
169
  it('should get any specified options from the config', function () {
@@ -346,6 +369,42 @@ describe('utils', function () {
346
369
  }]);
347
370
  });
348
371
  });
372
+ it('should match options using a defined synonym', function () {
373
+ var CONFIG = {
374
+ item: {
375
+ value: 'currencyCode',
376
+ label: 'currencyCode',
377
+ // eslint-disable-next-line no-template-curly-in-string
378
+ format: '${currencyName} (${currencyCode})'
379
+ },
380
+ data: {
381
+ options: [{
382
+ currencyName: 'Great British Pounds',
383
+ currencyCode: 'GBP',
384
+ value: 'GBP',
385
+ label: 'GBP'
386
+ }, {
387
+ currencyName: 'United States Dollars',
388
+ currencyCode: 'USD',
389
+ value: 'USD',
390
+ label: 'USD',
391
+ synonyms: ['bucks']
392
+ }]
393
+ }
394
+ };
395
+ var SOURCE = (0, _getAutocompleteSource.default)(CONFIG);
396
+ expect(typeof SOURCE === 'function').toBeTruthy();
397
+ SOURCE('bucks', function (results) {
398
+ expect(results.length).toEqual(1);
399
+ expect(results).toEqual([{
400
+ currencyName: 'United States Dollars',
401
+ currencyCode: 'USD',
402
+ value: 'USD',
403
+ label: 'USD',
404
+ synonyms: ['bucks']
405
+ }]);
406
+ });
407
+ });
349
408
  });
350
409
  });
351
410
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ukhomeoffice/cop-react-form-renderer",
3
- "version": "5.7.0",
3
+ "version": "5.9.0-alpha",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "clean": "rimraf dist",