@k-int/address-plugins 1.0.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.
Files changed (82) hide show
  1. package/README.md +249 -0
  2. package/es/address-plugin-british-isles/index.js +13 -0
  3. package/es/address-plugin-british-isles/src/AddressFieldsGBR.js +110 -0
  4. package/es/address-plugin-british-isles/src/backendToFields.js +45 -0
  5. package/es/address-plugin-british-isles/src/fieldOrder.js +16 -0
  6. package/es/address-plugin-british-isles/src/fieldsToBackend.js +101 -0
  7. package/es/address-plugin-british-isles/src/index.js +21 -0
  8. package/es/address-plugin-british-isles/src/listOfSupportedCountries.js +8 -0
  9. package/es/address-plugin-generic/index.js +13 -0
  10. package/es/address-plugin-generic/src/AddressFieldsGeneric.js +140 -0
  11. package/es/address-plugin-generic/src/backendToFields.js +53 -0
  12. package/es/address-plugin-generic/src/fieldOrder.js +19 -0
  13. package/es/address-plugin-generic/src/fieldsToBackend.js +140 -0
  14. package/es/address-plugin-generic/src/index.js +21 -0
  15. package/es/address-plugin-generic/src/listOfSupportedCountries.js +8 -0
  16. package/es/address-plugin-north-america/index.js +13 -0
  17. package/es/address-plugin-north-america/src/AddressFieldsUSA.js +106 -0
  18. package/es/address-plugin-north-america/src/backendToFields.js +41 -0
  19. package/es/address-plugin-north-america/src/fieldOrder.js +15 -0
  20. package/es/address-plugin-north-america/src/fieldsToBackend.js +98 -0
  21. package/es/address-plugin-north-america/src/index.js +21 -0
  22. package/es/address-plugin-north-america/src/listOfSupportedCountries.js +8 -0
  23. package/es/address-utils/index.js +16 -0
  24. package/es/address-utils/src/deleteFieldIfExists.js +17 -0
  25. package/es/address-utils/src/getExistingLineField.js +14 -0
  26. package/es/address-utils/src/index.js +27 -0
  27. package/es/address-utils/src/requiredValidator.js +20 -0
  28. package/es/index.js +31 -0
  29. package/package.json +65 -0
  30. package/src/address-plugin-british-isles/README.md +31 -0
  31. package/src/address-plugin-british-isles/index.js +1 -0
  32. package/src/address-plugin-british-isles/src/AddressFieldsGBR.js +88 -0
  33. package/src/address-plugin-british-isles/src/backendToFields.js +43 -0
  34. package/src/address-plugin-british-isles/src/fieldOrder.js +11 -0
  35. package/src/address-plugin-british-isles/src/fieldsToBackend.js +51 -0
  36. package/src/address-plugin-british-isles/src/index.js +9 -0
  37. package/src/address-plugin-british-isles/src/listOfSupportedCountries.js +3 -0
  38. package/src/address-plugin-generic/README.md +6 -0
  39. package/src/address-plugin-generic/index.js +1 -0
  40. package/src/address-plugin-generic/src/AddressFieldsGeneric.js +112 -0
  41. package/src/address-plugin-generic/src/backendToFields.js +51 -0
  42. package/src/address-plugin-generic/src/fieldOrder.js +14 -0
  43. package/src/address-plugin-generic/src/fieldsToBackend.js +68 -0
  44. package/src/address-plugin-generic/src/index.js +9 -0
  45. package/src/address-plugin-generic/src/listOfSupportedCountries.js +3 -0
  46. package/src/address-plugin-north-america/README.md +33 -0
  47. package/src/address-plugin-north-america/index.js +1 -0
  48. package/src/address-plugin-north-america/src/AddressFieldsUSA.js +85 -0
  49. package/src/address-plugin-north-america/src/backendToFields.js +40 -0
  50. package/src/address-plugin-north-america/src/fieldOrder.js +10 -0
  51. package/src/address-plugin-north-america/src/fieldsToBackend.js +50 -0
  52. package/src/address-plugin-north-america/src/index.js +8 -0
  53. package/src/address-plugin-north-america/src/listOfSupportedCountries.js +2 -0
  54. package/src/address-utils/README.md +40 -0
  55. package/src/address-utils/index.js +1 -0
  56. package/src/address-utils/src/deleteFieldIfExists.js +8 -0
  57. package/src/address-utils/src/getExistingLineField.js +8 -0
  58. package/src/address-utils/src/index.js +5 -0
  59. package/src/address-utils/src/requiredValidator.js +12 -0
  60. package/src/index.js +4 -0
  61. package/translations/ui-address-plugins/ar.json +38 -0
  62. package/translations/ui-address-plugins/ca.json +1 -0
  63. package/translations/ui-address-plugins/cs_CZ.json +38 -0
  64. package/translations/ui-address-plugins/da.json +38 -0
  65. package/translations/ui-address-plugins/de.json +38 -0
  66. package/translations/ui-address-plugins/en.json +44 -0
  67. package/translations/ui-address-plugins/en_US.json +1 -0
  68. package/translations/ui-address-plugins/es.json +38 -0
  69. package/translations/ui-address-plugins/fr.json +38 -0
  70. package/translations/ui-address-plugins/hi_IN.json +38 -0
  71. package/translations/ui-address-plugins/hu.json +38 -0
  72. package/translations/ui-address-plugins/it_IT.json +38 -0
  73. package/translations/ui-address-plugins/ja.json +38 -0
  74. package/translations/ui-address-plugins/ko.json +1 -0
  75. package/translations/ui-address-plugins/nb.json +1 -0
  76. package/translations/ui-address-plugins/nn.json +1 -0
  77. package/translations/ui-address-plugins/pl.json +38 -0
  78. package/translations/ui-address-plugins/pt_PT.json +38 -0
  79. package/translations/ui-address-plugins/ru.json +38 -0
  80. package/translations/ui-address-plugins/sv.json +38 -0
  81. package/translations/ui-address-plugins/ur.json +1 -0
  82. package/translations/ui-address-plugins/zh_CN.json +38 -0
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _AddressFieldsUSA = _interopRequireDefault(require("./AddressFieldsUSA"));
8
+ var _fieldsToBackend = _interopRequireDefault(require("./fieldsToBackend"));
9
+ var _backendToFields = _interopRequireDefault(require("./backendToFields"));
10
+ var _listOfSupportedCountries = _interopRequireDefault(require("./listOfSupportedCountries"));
11
+ var _fieldOrder = _interopRequireDefault(require("./fieldOrder"));
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ const pluginName = 'address-plugin-north-america';
14
+ var _default = exports.default = {
15
+ addressFields: _AddressFieldsUSA.default,
16
+ fieldsToBackend: _fieldsToBackend.default,
17
+ backendToFields: _backendToFields.default,
18
+ listOfSupportedCountries: _listOfSupportedCountries.default,
19
+ fieldOrder: _fieldOrder.default,
20
+ pluginName
21
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const listOfSupportedCountries = ['US', 'CA'];
8
+ var _default = exports.default = listOfSupportedCountries;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _src = require("./src");
7
+ Object.keys(_src).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _src[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _src[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _getExistingLineField2 = _interopRequireDefault(require("./getExistingLineField"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ const deleteFieldIfExists = (incomingLines, field) => {
10
+ var _getExistingLineField;
11
+ const id = (_getExistingLineField = (0, _getExistingLineField2.default)(incomingLines, field)) === null || _getExistingLineField === void 0 ? void 0 : _getExistingLineField.id;
12
+ return id ? {
13
+ id,
14
+ _delete: true
15
+ } : null;
16
+ };
17
+ var _default = exports.default = deleteFieldIfExists;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const getExistingLineField = (lineArray, field) => {
8
+ const filteredArray = lineArray === null || lineArray === void 0 ? void 0 : lineArray.filter(line => {
9
+ var _line$type;
10
+ return ((_line$type = line.type) === null || _line$type === void 0 ? void 0 : _line$type.value) === field;
11
+ });
12
+ return filteredArray === null || filteredArray === void 0 ? void 0 : filteredArray[0];
13
+ };
14
+ var _default = exports.default = getExistingLineField;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "deleteFieldIfExists", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _deleteFieldIfExists.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "getExistingLineField", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _getExistingLineField.default;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "requiredValidator", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _requiredValidator.requiredValidator;
22
+ }
23
+ });
24
+ var _getExistingLineField = _interopRequireDefault(require("./getExistingLineField"));
25
+ var _deleteFieldIfExists = _interopRequireDefault(require("./deleteFieldIfExists"));
26
+ var _requiredValidator = require("./requiredValidator");
27
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.requiredValidator = void 0;
7
+ var _reactIntl = require("react-intl");
8
+ var _jsxRuntime = require("react/jsx-runtime");
9
+ // This is essentially a clone of the validator found in https://github.com/folio-org/stripes-erm-components/blob/master/lib/validators.js
10
+
11
+ const required = value => {
12
+ const blankString = /^\s+$/;
13
+ if (value && !blankString.test(value) || value === false || value === 0) {
14
+ return undefined;
15
+ }
16
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactIntl.FormattedMessage, {
17
+ id: "stripes-core.label.missingRequiredField"
18
+ });
19
+ };
20
+ exports.requiredValidator = required;
package/es/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AddressUtils = void 0;
7
+ Object.defineProperty(exports, "pluginGBR", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _addressPluginBritishIsles.default;
11
+ }
12
+ });
13
+ Object.defineProperty(exports, "pluginGeneric", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _addressPluginGeneric.default;
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "pluginNA", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _addressPluginNorthAmerica.default;
23
+ }
24
+ });
25
+ var _addressPluginBritishIsles = _interopRequireDefault(require("./address-plugin-british-isles"));
26
+ var _addressPluginGeneric = _interopRequireDefault(require("./address-plugin-generic"));
27
+ var _addressPluginNorthAmerica = _interopRequireDefault(require("./address-plugin-north-america"));
28
+ var _AddressUtils = _interopRequireWildcard(require("./address-utils"));
29
+ exports.AddressUtils = _AddressUtils;
30
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
31
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@k-int/address-plugins",
3
+ "description": "Collection of React address forms designed for different countries",
4
+ "version": "1.0.0",
5
+ "scripts": {
6
+ "lint": "eslint src",
7
+ "clean": "rm -rf ./node_modules ./*/node_modules ./yarn.lock && yarn install",
8
+ "clean-build": "yarn clean && yarn build",
9
+ "build:es": "rm -rf ./es && babel --extensions .js --ignore ./src/**/tests/**/* ./src --out-dir es",
10
+ "build": "yarn build:es",
11
+ "prepare": "yarn build"
12
+ },
13
+ "sideEffects": [
14
+ "*.css"
15
+ ],
16
+ "license": "Apache-2.0",
17
+ "engines": {
18
+ "node": ">=10.0.0"
19
+ },
20
+ "dependencies": {
21
+ "@k-int/address-utils": "^1.1.0",
22
+ "classnames": "^2.2.6",
23
+ "react-flexbox-grid": "^2.1.2",
24
+ "react-intl": "^7.1.5",
25
+ "prop-types": "^15.6.0"
26
+ },
27
+ "devDependencies": {
28
+ "@babel/cli": "^7.18.10",
29
+ "@babel/core": "^7.18.6",
30
+ "@babel/eslint-parser": "^7.15.0",
31
+ "@babel/plugin-proposal-class-properties": "^7.12.1",
32
+ "@babel/plugin-proposal-decorators": "^7.12.1",
33
+ "@babel/plugin-proposal-function-sent": "^7.18.6",
34
+ "@babel/plugin-proposal-throw-expressions": "^7.18.6",
35
+ "@babel/plugin-transform-runtime": "^7.12.1",
36
+ "@babel/preset-env": "^7.18.9",
37
+ "@babel/preset-react": "^7.18.6",
38
+ "@folio/stripes-cli": "^4.0.0",
39
+ "@semantic-release/changelog": "^6.0.3",
40
+ "@semantic-release/git": "^10.0.1",
41
+ "@semantic-release/gitlab": "^13.2.9",
42
+ "babel-jest": "^26.6.3",
43
+ "babel-plugin-const-enum": "^1.0.1",
44
+ "babel-plugin-module-resolver": "^5.0.0",
45
+ "babel-plugin-require-context-hook": "^1.0.0",
46
+ "babel-plugin-transform-async-to-promises": "^0.8.15",
47
+ "babel-polyfill": "^6.26.0",
48
+ "eslint": "^7.0.0",
49
+ "react": "^18.2.0",
50
+ "react-dom": "^18.2.0",
51
+ "semantic-release": "^25.0.1"
52
+ },
53
+ "peerDependencies": {
54
+ "react": "*",
55
+ "react-dom": "*",
56
+ "react-intl": "*"
57
+ },
58
+ "main": "src/index.js",
59
+ "module": "es/index.js",
60
+ "repository": {
61
+ "type": "git",
62
+ "url": "git@gitlab.com:knowledge-integration/folio/addressplugins.git"
63
+ },
64
+ "author": "knowledgeintegration"
65
+ }
@@ -0,0 +1,31 @@
1
+
2
+
3
+
4
+
5
+
6
+ # address-plugin-british-isles
7
+
8
+ This is a plugin designed for use with `address-plugin-utils` as part of a general set of plugins. This plugin in particular refers to the Great Britain specific address form.
9
+ ## Generic information
10
+ For the generic information about how these plugins operate, please see [here](https://gitlab.com/knowledge-integration/folio/addressplugins/-/blob/main/README.md). (I'd HIGHLY recommend starting there rather than trying to jump in blind here).
11
+
12
+ ## plugin-specific details
13
+ There aren't any magic properties to these fields, but there is a set way to fill them in.
14
+
15
+ The user is expected to fill out an address such as
16
+ ```
17
+ Paradise House,
18
+ 35 Paradise St,
19
+ Sheffield City Centre,
20
+ Sheffield
21
+ S3 8PZ
22
+ ```
23
+ as:
24
+ `Paradise House -> Building name`.
25
+ `35 Paradise St -> Street Address` (Street address number would **not** be expected to be separated into building name).
26
+ `Sheffield City Centre -(?)> Town`. This is an optional field, and I'd expect the address to work fine without this proviso, but this would be the place for a location within a city but larger than a street.
27
+ `Sheffield -> City`.
28
+ `S3 8PZ -> Post Code`.
29
+
30
+ ## Supported countries
31
+ This plugin currently supports address forms for England, Scotland, Wales and Northern Ireland
@@ -0,0 +1 @@
1
+ export { default } from './src';
@@ -0,0 +1,88 @@
1
+ import PropTypes from 'prop-types';
2
+ import { FormattedMessage } from 'react-intl';
3
+ import { Row, Col } from 'react-flexbox-grid';
4
+ import { requiredValidator } from '../../address-utils';
5
+
6
+ const AddressFieldsGBR = ({ AddressTextField, name }) => {
7
+ return (
8
+ <>
9
+ <Row>
10
+ <Col xs={4}>
11
+ <AddressTextField
12
+ name={name ? `${name}.premise` : 'premise'}
13
+ label={<FormattedMessage id="ui-address-plugins.GBR.premise" />}
14
+ />
15
+ </Col>
16
+ <Col xs={4}>
17
+ <AddressTextField
18
+ name={name ? `${name}.thoroughfare` : 'thoroughfare'}
19
+ label={<FormattedMessage id="ui-address-plugins.GBR.thoroughfare" />}
20
+ required
21
+ validator={requiredValidator}
22
+ />
23
+ </Col>
24
+ <Col xs={4}>
25
+ <AddressTextField
26
+ name={name ? `${name}.postalCodeOrTown` : 'postalCodeOrTown'}
27
+ label={<FormattedMessage id="ui-address-plugins.GBR.postalCodeOrTown" />}
28
+ />
29
+ </Col>
30
+ </Row>
31
+ <Row>
32
+ <Col xs={4}>
33
+ <AddressTextField
34
+ name={name ? `${name}.locality` : 'locality'}
35
+ label={<FormattedMessage id="ui-address-plugins.GBR.locality" />}
36
+ required
37
+ validator={requiredValidator}
38
+ />
39
+ </Col>
40
+ <Col xs={4}>
41
+ <AddressTextField
42
+ name={name ? `${name}.administrativeArea` : 'administrativeArea'}
43
+ label={<FormattedMessage id="ui-address-plugins.GBR.administrativeArea" />}
44
+ required
45
+ validator={requiredValidator}
46
+ />
47
+ </Col>
48
+ <Col xs={4}>
49
+ <AddressTextField
50
+ name={name ? `${name}.postalCode` : 'postalCode'}
51
+ label={<FormattedMessage id="ui-address-plugins.GBR.postalCode" />}
52
+ required
53
+ validator={requiredValidator}
54
+ />
55
+ </Col>
56
+ </Row>
57
+ <Row>
58
+ <Col xs={12}>
59
+ <AddressTextField
60
+ name={name ? `${name}.country` : 'country'}
61
+ label={<FormattedMessage id="ui-address-plugins.GBR.country" />}
62
+ required
63
+ validator={requiredValidator}
64
+ />
65
+ </Col>
66
+ </Row>
67
+ </>
68
+ );
69
+ };
70
+
71
+ AddressFieldsGBR.propTypes = {
72
+ AddressTextField: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
73
+ name: PropTypes.string,
74
+ savedAddress: PropTypes.shape({
75
+ addressLabel: PropTypes.string,
76
+ countryCode: PropTypes.string,
77
+ id: PropTypes.string,
78
+ lines: PropTypes.arrayOf(PropTypes.shape({
79
+ id: PropTypes.string.isRequired,
80
+ type: PropTypes.shape({
81
+ value: PropTypes.string.isRequired
82
+ }).isRequired,
83
+ value: PropTypes.string.isRequired
84
+ })),
85
+ }),
86
+ };
87
+
88
+ export default AddressFieldsGBR;
@@ -0,0 +1,43 @@
1
+ import { getExistingLineField } from '../../address-utils';
2
+
3
+ const backendToFields = (address) => {
4
+ const addressFields = {};
5
+
6
+ const premise = getExistingLineField(address.lines, 'premise')?.value;
7
+ const thoroughfare = getExistingLineField(address.lines, 'thoroughfare')?.value;
8
+ const postalCodeOrTown = getExistingLineField(address.lines, 'postalcodeortown')?.value;
9
+ const locality = getExistingLineField(address.lines, 'locality')?.value;
10
+ const postalCode = getExistingLineField(address.lines, 'postalcode')?.value;
11
+ const administrativeArea = getExistingLineField(address.lines, 'administrativearea')?.value;
12
+ const country = getExistingLineField(address.lines, 'country')?.value;
13
+ const countryCode = address?.countryCode;
14
+
15
+ if (premise) {
16
+ addressFields.premise = premise;
17
+ }
18
+ if (thoroughfare) {
19
+ addressFields.thoroughfare = thoroughfare;
20
+ }
21
+ if (postalCodeOrTown) {
22
+ addressFields.postalCodeOrTown = postalCodeOrTown;
23
+ }
24
+ if (locality) {
25
+ addressFields.locality = locality;
26
+ }
27
+ if (postalCode) {
28
+ addressFields.postalCode = postalCode;
29
+ }
30
+ if (administrativeArea) {
31
+ addressFields.administrativeArea = administrativeArea;
32
+ }
33
+ if (country) {
34
+ addressFields.country = country;
35
+ }
36
+ if (countryCode) {
37
+ addressFields.countryCode = countryCode;
38
+ }
39
+
40
+ return addressFields;
41
+ };
42
+
43
+ export default backendToFields;
@@ -0,0 +1,11 @@
1
+ const fieldOrder = {
2
+ 'Premise': 0,
3
+ 'Thoroughfare': 1,
4
+ 'PostalCodeOrTown': 2,
5
+ 'Locality': 3,
6
+ 'AdministrativeArea': 4,
7
+ 'PostalCode': 5,
8
+ 'Country': 6
9
+ };
10
+
11
+ export default fieldOrder;
@@ -0,0 +1,51 @@
1
+ import { deleteFieldIfExists, getExistingLineField } from '../../address-utils';
2
+
3
+ const fieldsToBackend = (address) => {
4
+ const addressId = address.id || null;
5
+ const countryCode = address.countryCode || null;
6
+ const newAddress = {};
7
+ let lines = [];
8
+
9
+ if (address.premise) {
10
+ const id = getExistingLineField(address.lines, 'premise')?.id;
11
+ lines.push({ type: { value: 'Premise' }, value: address.premise, id });
12
+ } else {
13
+ lines.push(deleteFieldIfExists(address.lines, 'premise'));
14
+ }
15
+ if (address.thoroughfare) {
16
+ const id = getExistingLineField(address.lines, 'thoroughfare')?.id;
17
+ lines.push({ type: { value: 'Thoroughfare' }, value: address.thoroughfare, id });
18
+ }
19
+ if (address.postalCodeOrTown) {
20
+ const id = getExistingLineField(address.lines, 'postalcodeortown')?.id;
21
+ lines.push({ type: { value: 'PostalCodeOrTown' }, value: address.postalCodeOrTown, id });
22
+ } else {
23
+ lines.push(deleteFieldIfExists(address.lines, 'postalcodeortown'));
24
+ }
25
+ if (address.locality) {
26
+ const id = getExistingLineField(address.lines, 'locality')?.id;
27
+ lines.push({ type: { value: 'Locality' }, value: address.locality, id });
28
+ }
29
+ if (address.administrativeArea) {
30
+ const id = getExistingLineField(address.lines, 'administrativearea')?.id;
31
+ lines.push({ type: { value: 'AdministrativeArea' }, value: address.administrativeArea, id });
32
+ }
33
+ if (address.postalCode) {
34
+ const id = getExistingLineField(address.lines, 'postalcode')?.id;
35
+ lines.push({ type: { value: 'PostalCode' }, value: address.postalCode, id });
36
+ }
37
+ if (address.country) {
38
+ const id = getExistingLineField(address.lines, 'country')?.id;
39
+ lines.push({ type: { value: 'Country' }, value: address.country, id });
40
+ }
41
+
42
+ lines = lines.filter(line => (line !== null));
43
+ newAddress.addressLabel = address.addressLabel;
44
+ newAddress.lines = lines;
45
+ newAddress.id = addressId;
46
+ newAddress.countryCode = countryCode;
47
+
48
+ return newAddress;
49
+ };
50
+
51
+ export default fieldsToBackend;
@@ -0,0 +1,9 @@
1
+ import addressFields from './AddressFieldsGBR';
2
+ import fieldsToBackend from './fieldsToBackend';
3
+ import backendToFields from './backendToFields';
4
+ import listOfSupportedCountries from './listOfSupportedCountries';
5
+ import fieldOrder from './fieldOrder';
6
+
7
+ const pluginName = 'address-plugin-british-isles';
8
+
9
+ export default { addressFields, fieldsToBackend, backendToFields, listOfSupportedCountries, fieldOrder, pluginName };
@@ -0,0 +1,3 @@
1
+ const listOfSupportedCountries = ['GB-ENG', 'GB-SCT', 'GB-WLS', 'GB-NIR'];
2
+
3
+ export default listOfSupportedCountries;
@@ -0,0 +1,6 @@
1
+
2
+ # address-plugin-generic
3
+
4
+ This is a plugin designed for use with `address-plugin-utils` as part of a general set of plugins. This plugin in particular acts as a fallback, with fields available for all address fields in the model.
5
+ ## Generic information
6
+ For the generic information about how these plugins operate, please see [here](https://gitlab.com/knowledge-integration/folio/addressplugins/-/blob/main/README.md). (I'd HIGHLY recommend starting there rather than trying to jump in blind here).
@@ -0,0 +1 @@
1
+ export { default } from './src';
@@ -0,0 +1,112 @@
1
+ import PropTypes from 'prop-types';
2
+ import { FormattedMessage } from 'react-intl';
3
+ import { Row, Col } from 'react-flexbox-grid';
4
+ import { requiredValidator } from '../../address-utils';
5
+
6
+ const AddressFieldsGeneric = ({ AddressTextField, name }) => {
7
+ return (
8
+ <>
9
+ <Row>
10
+ <Col xs={6}>
11
+ <AddressTextField
12
+ name={name ? `${name}.department` : 'department'}
13
+ label={<FormattedMessage id="ui-address-plugins.generic.department" />}
14
+ />
15
+ </Col>
16
+ <Col xs={6}>
17
+ <AddressTextField
18
+ name={name ? `${name}.premise` : 'premise'}
19
+ label={<FormattedMessage id="ui-address-plugins.generic.premise" />}
20
+ />
21
+ </Col>
22
+ </Row>
23
+ <Row>
24
+ <Col xs={6}>
25
+ <AddressTextField
26
+ name={name ? `${name}.thoroughfare` : 'thoroughfare'}
27
+ label={<FormattedMessage id="ui-address-plugins.generic.thoroughfare" />}
28
+ required
29
+ validator={requiredValidator}
30
+ />
31
+ </Col>
32
+ <Col xs={6}>
33
+ <AddressTextField
34
+ name={name ? `${name}.postalCodeOrTown` : 'postalCodeOrTown'}
35
+ label={<FormattedMessage id="ui-address-plugins.generic.postalCodeOrTown" />}
36
+ />
37
+ </Col>
38
+ </Row>
39
+ <Row>
40
+ <Col xs={6}>
41
+ <AddressTextField
42
+ name={name ? `${name}.locality` : 'locality'}
43
+ label={<FormattedMessage id="ui-address-plugins.generic.locality" />}
44
+ required
45
+ validator={requiredValidator}
46
+ />
47
+ </Col>
48
+ <Col xs={6}>
49
+ <AddressTextField
50
+ name={name ? `${name}.administrativeArea` : 'administrativeArea'}
51
+ label={<FormattedMessage id="ui-address-plugins.generic.administrativeArea" />}
52
+ required
53
+ validator={requiredValidator}
54
+ />
55
+ </Col>
56
+ </Row>
57
+ <Row>
58
+ <Col xs={4}>
59
+ <AddressTextField
60
+ name={name ? `${name}.postalCode` : 'postalCode'}
61
+ label={<FormattedMessage id="ui-address-plugins.generic.postalCode" />}
62
+ required
63
+ validator={requiredValidator}
64
+ />
65
+ </Col>
66
+ <Col xs={4}>
67
+ <AddressTextField
68
+ name={name ? `${name}.postBox` : 'postBox'}
69
+ label={<FormattedMessage id="ui-address-plugins.generic.postBox" />}
70
+ required={false}
71
+ />
72
+ </Col>
73
+ <Col xs={4}>
74
+ <AddressTextField
75
+ name={name ? `${name}.postOffice` : 'postOffice'}
76
+ label={<FormattedMessage id="ui-address-plugins.generic.postOffice" />}
77
+ required={false}
78
+ />
79
+ </Col>
80
+ </Row>
81
+ <Row>
82
+ <Col xs={12}>
83
+ <AddressTextField
84
+ name={name ? `${name}.country` : 'country'}
85
+ label={<FormattedMessage id="ui-address-plugins.generic.country" />}
86
+ required
87
+ validator={requiredValidator}
88
+ />
89
+ </Col>
90
+ </Row>
91
+ </>
92
+ );
93
+ };
94
+
95
+ AddressFieldsGeneric.propTypes = {
96
+ AddressTextField: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
97
+ name: PropTypes.string,
98
+ savedAddress: PropTypes.shape({
99
+ addressLabel: PropTypes.string,
100
+ countryCode: PropTypes.string,
101
+ id: PropTypes.string,
102
+ lines: PropTypes.arrayOf(PropTypes.shape({
103
+ id: PropTypes.string.isRequired,
104
+ type: PropTypes.shape({
105
+ value: PropTypes.string.isRequired
106
+ }).isRequired,
107
+ value: PropTypes.string.isRequired
108
+ })),
109
+ }),
110
+ };
111
+
112
+ export default AddressFieldsGeneric;
@@ -0,0 +1,51 @@
1
+ import { getExistingLineField } from '../../address-utils';
2
+
3
+ const backendToFields = (address) => {
4
+ const addressFields = {};
5
+
6
+ const department = getExistingLineField(address.lines, 'department')?.value;
7
+ const premise = getExistingLineField(address.lines, 'premise')?.value;
8
+ const thoroughfare = getExistingLineField(address.lines, 'thoroughfare')?.value;
9
+ const postalCodeOrTown = getExistingLineField(address.lines, 'postalcodeortown')?.value;
10
+ const locality = getExistingLineField(address.lines, 'locality')?.value;
11
+ const administrativeArea = getExistingLineField(address.lines, 'administrativearea')?.value;
12
+ const postalCode = getExistingLineField(address.lines, 'postalcode')?.value;
13
+ const postBox = getExistingLineField(address.lines, 'postbox')?.value;
14
+ const postOffice = getExistingLineField(address.lines, 'postoffice')?.value;
15
+ const country = getExistingLineField(address.lines, 'country')?.value;
16
+
17
+ if (department) {
18
+ addressFields.department = department;
19
+ }
20
+ if (premise) {
21
+ addressFields.premise = premise;
22
+ }
23
+ if (thoroughfare) {
24
+ addressFields.thoroughfare = thoroughfare;
25
+ }
26
+ if (postalCodeOrTown) {
27
+ addressFields.postalCodeOrTown = postalCodeOrTown;
28
+ }
29
+ if (locality) {
30
+ addressFields.locality = locality;
31
+ }
32
+ if (administrativeArea) {
33
+ addressFields.administrativeArea = administrativeArea;
34
+ }
35
+ if (postalCode) {
36
+ addressFields.postalCode = postalCode;
37
+ }
38
+ if (postBox) {
39
+ addressFields.postBox = postBox;
40
+ }
41
+ if (postOffice) {
42
+ addressFields.postOffice = postOffice;
43
+ }
44
+ if (country) {
45
+ addressFields.country = country;
46
+ }
47
+
48
+ return addressFields;
49
+ };
50
+
51
+ export default backendToFields;
@@ -0,0 +1,14 @@
1
+ const fieldOrder = {
2
+ 'Department': 0,
3
+ 'Premise': 1,
4
+ 'Thoroughfare': 2,
5
+ 'PostalCodeOrTown': 3,
6
+ 'Locality': 4,
7
+ 'AdministrativeArea': 5,
8
+ 'PostalCode': 6,
9
+ 'PostBox': 7,
10
+ 'PostOffice': 8,
11
+ 'Country': 9
12
+ };
13
+
14
+ export default fieldOrder;