@reltio/components 1.4.2159 → 1.4.2161
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.
- package/AddressAutocompleteEditor/AddressAutocompleteEditor.d.ts +10 -0
- package/AddressAutocompleteEditor/AddressAutocompleteEditor.js +223 -0
- package/AddressAutocompleteEditor/AddressAutocompleteEditor.module.css.js +9 -0
- package/AddressAutocompleteEditor/AddressAutocompleteEditor.test.d.ts +1 -0
- package/AddressAutocompleteEditor/AddressAutocompleteEditor.test.js +522 -0
- package/AddressAutocompleteEditor/helpers.d.ts +10 -0
- package/AddressAutocompleteEditor/helpers.js +18 -0
- package/AddressAutocompleteEditor/index.d.ts +1 -0
- package/AddressAutocompleteEditor/index.js +1 -0
- package/BasicTable/index.d.ts +1 -0
- package/EditModeAttributesPager/components/AttributeRenderer/AttributeRenderer.js +1 -1
- package/EditorsFactory/EditorsFactory.js +4 -0
- package/ReferenceAttributeEditor/ReferenceAttributeEditor.js +5 -3
- package/RelationEditor/RelationEditor.js +6 -4
- package/SimpleAttributeEditor/SimpleAttributeEditor.d.ts +1 -0
- package/SimpleAttributeEditor/SimpleAttributeEditor.js +15 -4
- package/cjs/AddressAutocompleteEditor/AddressAutocompleteEditor.d.ts +10 -0
- package/cjs/AddressAutocompleteEditor/AddressAutocompleteEditor.js +253 -0
- package/cjs/AddressAutocompleteEditor/AddressAutocompleteEditor.module.css.js +9 -0
- package/cjs/AddressAutocompleteEditor/AddressAutocompleteEditor.test.d.ts +1 -0
- package/cjs/AddressAutocompleteEditor/AddressAutocompleteEditor.test.js +527 -0
- package/cjs/AddressAutocompleteEditor/helpers.d.ts +10 -0
- package/cjs/AddressAutocompleteEditor/helpers.js +24 -0
- package/cjs/AddressAutocompleteEditor/index.d.ts +1 -0
- package/cjs/AddressAutocompleteEditor/index.js +5 -0
- package/cjs/BasicTable/index.d.ts +1 -0
- package/cjs/EditModeAttributesPager/components/AttributeRenderer/AttributeRenderer.js +1 -1
- package/cjs/EditorsFactory/EditorsFactory.js +4 -0
- package/cjs/ReferenceAttributeEditor/ReferenceAttributeEditor.js +5 -3
- package/cjs/RelationEditor/RelationEditor.js +6 -4
- package/cjs/SimpleAttributeEditor/SimpleAttributeEditor.d.ts +1 -0
- package/cjs/SimpleAttributeEditor/SimpleAttributeEditor.js +14 -3
- package/cjs/contexts/AttributeValueContext/index.d.ts +3 -0
- package/cjs/contexts/AttributeValueContext/index.js +9 -0
- package/cjs/contexts/AutoCompleteContext/helpers.d.ts +24 -0
- package/cjs/contexts/AutoCompleteContext/helpers.js +165 -0
- package/cjs/contexts/AutoCompleteContext/index.d.ts +12 -0
- package/cjs/contexts/AutoCompleteContext/index.js +83 -0
- package/cjs/contexts/ProfileTablesContext/index.js +1 -0
- package/contexts/AttributeValueContext/index.d.ts +3 -0
- package/contexts/AttributeValueContext/index.js +3 -0
- package/contexts/AutoCompleteContext/helpers.d.ts +24 -0
- package/contexts/AutoCompleteContext/helpers.js +159 -0
- package/contexts/AutoCompleteContext/index.d.ts +12 -0
- package/contexts/AutoCompleteContext/index.js +56 -0
- package/contexts/ProfileTablesContext/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TextFieldProps } from '@mui/material/TextField';
|
|
3
|
+
export declare const INPUT_DEBOUNCE_INTERVAL = 400;
|
|
4
|
+
type Props = Omit<TextFieldProps, 'onChange' | 'value'> & {
|
|
5
|
+
value?: string;
|
|
6
|
+
onChange?: (value: string) => void;
|
|
7
|
+
fullWidth?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const AddressAutocompleteEditor: ({ value, onChange, InputProps, fullWidth, ...otherProps }: Props) => React.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
|
+
var t = {};
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
+
t[p] = s[p];
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
+
t[p[i]] = s[p[i]];
|
|
56
|
+
}
|
|
57
|
+
return t;
|
|
58
|
+
};
|
|
59
|
+
import React, { useState, useCallback, useMemo, useContext, useEffect } from 'react';
|
|
60
|
+
import classnames from 'classnames';
|
|
61
|
+
import { identity } from 'ramda';
|
|
62
|
+
import { useContextSelector } from '@fluentui/react-context-selector';
|
|
63
|
+
import Autocomplete from '@mui/material/Autocomplete';
|
|
64
|
+
import ListItem from '@mui/material/ListItem';
|
|
65
|
+
import ListItemText from '@mui/material/ListItemText';
|
|
66
|
+
import LinearProgress from '@mui/material/LinearProgress';
|
|
67
|
+
import Typography from '@mui/material/Typography';
|
|
68
|
+
import TextField from '@mui/material/TextField';
|
|
69
|
+
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
|
|
70
|
+
import i18n from 'ui-i18n';
|
|
71
|
+
import { searchAddresses, fetchAddressDetails, debounce, AddressType } from '@reltio/mdm-sdk';
|
|
72
|
+
import { AddressAutoCompleteContext } from '../contexts/AutoCompleteContext';
|
|
73
|
+
import { AttributeValueContext } from '../contexts/AttributeValueContext';
|
|
74
|
+
import { convertSearchResultToOption, getOptionLabel, isOptionEqualToValue } from './helpers';
|
|
75
|
+
import { useSafePromise } from '../hooks/useSafePromise';
|
|
76
|
+
import styles from './AddressAutocompleteEditor.module.css';
|
|
77
|
+
export var INPUT_DEBOUNCE_INTERVAL = 400;
|
|
78
|
+
export var AddressAutocompleteEditor = function (_a) {
|
|
79
|
+
var _b = _a.value, value = _b === void 0 ? '' : _b, onChange = _a.onChange, InputProps = _a.InputProps, _c = _a.fullWidth, fullWidth = _c === void 0 ? true : _c, otherProps = __rest(_a, ["value", "onChange", "InputProps", "fullWidth"]);
|
|
80
|
+
var _d = useState(value), inputValue = _d[0], setInputValue = _d[1];
|
|
81
|
+
var _e = useState([]), options = _e[0], setOptions = _e[1];
|
|
82
|
+
var _f = useState(false), loading = _f[0], setLoading = _f[1];
|
|
83
|
+
var _g = useState(false), detailsLoading = _g[0], setDetailsLoading = _g[1];
|
|
84
|
+
var _h = useState(false), open = _h[0], setOpen = _h[1];
|
|
85
|
+
var searchSafePromise = useSafePromise();
|
|
86
|
+
var detailsSafePromise = useSafePromise();
|
|
87
|
+
var onPopulateAttributes = useContextSelector(AddressAutoCompleteContext, function (c) { return c === null || c === void 0 ? void 0 : c.onPopulateAttributes; });
|
|
88
|
+
var getAutocompleteSettings = useContextSelector(AddressAutoCompleteContext, function (c) { return c === null || c === void 0 ? void 0 : c.getAutocompleteSettings; });
|
|
89
|
+
var _j = useContext(AttributeValueContext) || {}, valueUri = _j.uri, attributeTypeUri = _j.type;
|
|
90
|
+
var autocompleteSettings = useMemo(function () { return getAutocompleteSettings === null || getAutocompleteSettings === void 0 ? void 0 : getAutocompleteSettings(attributeTypeUri, valueUri); }, [getAutocompleteSettings, valueUri, attributeTypeUri]);
|
|
91
|
+
var countries = autocompleteSettings.countries, countryNames = autocompleteSettings.countryNames, limit = autocompleteSettings.limit, minSearchTextLen = autocompleteSettings.minSearchTextLen;
|
|
92
|
+
var countriesHash = countries.toString();
|
|
93
|
+
useEffect(function () {
|
|
94
|
+
setOptions([]);
|
|
95
|
+
}, [countriesHash]);
|
|
96
|
+
var fetchAddressSuggestions = useCallback(function (searchTerm) { return __awaiter(void 0, void 0, void 0, function () {
|
|
97
|
+
var results, convertedOptions, error_1;
|
|
98
|
+
return __generator(this, function (_a) {
|
|
99
|
+
switch (_a.label) {
|
|
100
|
+
case 0:
|
|
101
|
+
setLoading(true);
|
|
102
|
+
_a.label = 1;
|
|
103
|
+
case 1:
|
|
104
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
105
|
+
return [4 /*yield*/, searchSafePromise(searchAddresses({
|
|
106
|
+
text: searchTerm,
|
|
107
|
+
limit: limit,
|
|
108
|
+
countries: countries
|
|
109
|
+
}))];
|
|
110
|
+
case 2:
|
|
111
|
+
results = _a.sent();
|
|
112
|
+
convertedOptions = results.map(convertSearchResultToOption);
|
|
113
|
+
setOptions(convertedOptions);
|
|
114
|
+
return [3 /*break*/, 5];
|
|
115
|
+
case 3:
|
|
116
|
+
error_1 = _a.sent();
|
|
117
|
+
console.warn('Error fetching address suggestions:', error_1);
|
|
118
|
+
setOptions([]);
|
|
119
|
+
return [3 /*break*/, 5];
|
|
120
|
+
case 4:
|
|
121
|
+
setLoading(false);
|
|
122
|
+
return [7 /*endfinally*/];
|
|
123
|
+
case 5: return [2 /*return*/];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}); }, [countries, limit, searchSafePromise]);
|
|
127
|
+
var fetchAddressDetailsById = useCallback(function (addressId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
128
|
+
var error_2;
|
|
129
|
+
return __generator(this, function (_a) {
|
|
130
|
+
switch (_a.label) {
|
|
131
|
+
case 0:
|
|
132
|
+
setDetailsLoading(true);
|
|
133
|
+
_a.label = 1;
|
|
134
|
+
case 1:
|
|
135
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
136
|
+
return [4 /*yield*/, detailsSafePromise(fetchAddressDetails(addressId))];
|
|
137
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
138
|
+
case 3:
|
|
139
|
+
error_2 = _a.sent();
|
|
140
|
+
console.warn('Error fetching address details:', error_2);
|
|
141
|
+
return [2 /*return*/, null];
|
|
142
|
+
case 4:
|
|
143
|
+
setDetailsLoading(false);
|
|
144
|
+
return [7 /*endfinally*/];
|
|
145
|
+
case 5: return [2 /*return*/];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}); }, [detailsSafePromise]);
|
|
149
|
+
var debouncedFetchAddressSuggestions = useCallback(debounce(fetchAddressSuggestions, INPUT_DEBOUNCE_INTERVAL), [
|
|
150
|
+
fetchAddressSuggestions
|
|
151
|
+
]);
|
|
152
|
+
var handleInputChange = useCallback(function (event, newInputValue) {
|
|
153
|
+
setInputValue(newInputValue);
|
|
154
|
+
if (newInputValue.trim().length >= minSearchTextLen) {
|
|
155
|
+
debouncedFetchAddressSuggestions(newInputValue);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
setOptions([]);
|
|
159
|
+
}
|
|
160
|
+
}, [debouncedFetchAddressSuggestions, minSearchTextLen]);
|
|
161
|
+
var handleOptionSelect = useCallback(function (event, selectedOption) { return __awaiter(void 0, void 0, void 0, function () {
|
|
162
|
+
var addressDetail;
|
|
163
|
+
return __generator(this, function (_a) {
|
|
164
|
+
switch (_a.label) {
|
|
165
|
+
case 0:
|
|
166
|
+
if (!selectedOption) return [3 /*break*/, 3];
|
|
167
|
+
if (selectedOption.type === AddressType.Container) {
|
|
168
|
+
return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
setInputValue(selectedOption.fullAddress);
|
|
171
|
+
if (onChange) {
|
|
172
|
+
onChange(selectedOption.fullAddress);
|
|
173
|
+
}
|
|
174
|
+
if (!onPopulateAttributes) return [3 /*break*/, 2];
|
|
175
|
+
return [4 /*yield*/, fetchAddressDetailsById(selectedOption.id)];
|
|
176
|
+
case 1:
|
|
177
|
+
addressDetail = _a.sent();
|
|
178
|
+
onPopulateAttributes(attributeTypeUri, valueUri, addressDetail === null || addressDetail === void 0 ? void 0 : addressDetail[0]);
|
|
179
|
+
_a.label = 2;
|
|
180
|
+
case 2:
|
|
181
|
+
setOpen(false);
|
|
182
|
+
return [3 /*break*/, 4];
|
|
183
|
+
case 3:
|
|
184
|
+
setInputValue('');
|
|
185
|
+
if (onChange) {
|
|
186
|
+
onChange('');
|
|
187
|
+
}
|
|
188
|
+
_a.label = 4;
|
|
189
|
+
case 4: return [2 /*return*/];
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}); }, [fetchAddressDetailsById, onChange, onPopulateAttributes, attributeTypeUri, valueUri]);
|
|
193
|
+
var handleBlur = useCallback(function () {
|
|
194
|
+
setOpen(false);
|
|
195
|
+
}, []);
|
|
196
|
+
var renderOption = useCallback(function (props, option) {
|
|
197
|
+
var _a;
|
|
198
|
+
var isContainer = option.type === AddressType.Container;
|
|
199
|
+
return (React.createElement(ListItem, __assign({}, props, { className: classnames(styles.option, (_a = {}, _a[styles.containerOption] = isContainer, _a)) }),
|
|
200
|
+
React.createElement(ListItemText, { primary: option.fullAddress, primaryTypographyProps: { variant: 'body1' }, secondaryTypographyProps: { variant: 'body2', color: 'textSecondary' } }),
|
|
201
|
+
isContainer && (React.createElement("div", null,
|
|
202
|
+
React.createElement(ArrowForwardIosIcon, null)))));
|
|
203
|
+
}, []);
|
|
204
|
+
var renderInput = useCallback(function (props) { return (React.createElement(TextField, __assign({}, otherProps, props, { placeholder: i18n.text('Start typing to autocomplete'), fullWidth: fullWidth, onBlur: handleBlur, InputProps: __assign(__assign(__assign({}, InputProps), props.InputProps), { endAdornment: React.createElement(React.Fragment, null, props.InputProps.endAdornment) }) }))); }, [fullWidth, handleBlur, InputProps, otherProps]);
|
|
205
|
+
var renderListbox = useCallback(React.forwardRef(function ListboxComponent(props, ref) {
|
|
206
|
+
return (React.createElement(React.Fragment, null,
|
|
207
|
+
detailsLoading && React.createElement(LinearProgress, { color: "primary" }),
|
|
208
|
+
React.createElement("ul", __assign({ ref: ref }, props),
|
|
209
|
+
React.createElement("li", { className: styles.countryHeader },
|
|
210
|
+
React.createElement(Typography, { variant: "body2", fontWeight: 500 },
|
|
211
|
+
i18n.text('Searching in'),
|
|
212
|
+
": ",
|
|
213
|
+
countryNames.join(', ')),
|
|
214
|
+
React.createElement(Typography, { variant: "caption", color: "textSecondary" }, i18n.text('To search in a different country, update the Country field'))),
|
|
215
|
+
props.children)));
|
|
216
|
+
}), [detailsLoading, countryNames]);
|
|
217
|
+
var openOptionsList = useCallback(function (_event) {
|
|
218
|
+
setOpen(true);
|
|
219
|
+
}, []);
|
|
220
|
+
return (React.createElement(Autocomplete, { className: styles.root, open: open, onOpen: openOptionsList, value: inputValue, onChange: handleOptionSelect, inputValue: inputValue, onInputChange: handleInputChange, options: options, getOptionLabel: getOptionLabel, loading: loading, renderInput: renderInput, renderOption: renderOption, renderGroup: function (params) { return params.children; }, ListboxComponent: renderListbox, noOptionsText: inputValue.trim().length < minSearchTextLen
|
|
221
|
+
? i18n.text('Please enter at least {{minSearchTextLen}} characters', { minSearchTextLen: minSearchTextLen })
|
|
222
|
+
: i18n.text('No addresses found'), loadingText: i18n.text('Searching addresses...'), filterOptions: identity, isOptionEqualToValue: isOptionEqualToValue, popupIcon: null, clearIcon: null, freeSolo: true, "data-reltio-id": "address-autocomplete-editor" }));
|
|
223
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const styles = {"root":"AddressAutocompleteEditor-root--1FDrD","countryHeader":"AddressAutocompleteEditor-countryHeader--k5tRp","loadingContainer":"AddressAutocompleteEditor-loadingContainer--j-U45","option":"AddressAutocompleteEditor-option--3hah-","containerOption":"AddressAutocompleteEditor-containerOption--aLgUn","listbox":"AddressAutocompleteEditor-listbox--cZCpg"};
|
|
2
|
+
if (typeof document !== 'undefined') {
|
|
3
|
+
const head = document.head || document.getElementsByTagName('head')[0]
|
|
4
|
+
const style = document.createElement('style');
|
|
5
|
+
style.type = 'text/css'
|
|
6
|
+
style.innerHTML = `.AddressAutocompleteEditor-root--1FDrD{width:100%}.AddressAutocompleteEditor-countryHeader--k5tRp{background-color:rgba(0,0,0,.04);border-bottom:1px solid rgba(0,0,0,.12);font-weight:500;padding:8px 16px}.AddressAutocompleteEditor-loadingContainer--j-U45{align-items:center;display:flex;justify-content:center;padding:16px}.AddressAutocompleteEditor-option--3hah-{padding:8px 16px}.AddressAutocompleteEditor-containerOption--aLgUn:hover{background-color:rgba(0,0,0,.04)!important}.AddressAutocompleteEditor-listbox--cZCpg{padding:0}`;
|
|
7
|
+
head.appendChild(style);
|
|
8
|
+
}
|
|
9
|
+
export default styles;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|