@rh-support/components 2.1.61 → 2.1.63
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/lib/esm/PhoneInput/PhoneInput.d.ts +1 -0
- package/lib/esm/PhoneInput/PhoneInput.d.ts.map +1 -1
- package/lib/esm/PhoneInput/PhoneInput.js +48 -16
- package/lib/esm/TagsSelector/TagsSelector.d.ts +13 -0
- package/lib/esm/TagsSelector/TagsSelector.d.ts.map +1 -0
- package/lib/esm/TagsSelector/TagsSelector.js +69 -0
- package/lib/esm/TagsSelector/index.d.ts +2 -0
- package/lib/esm/TagsSelector/index.d.ts.map +1 -0
- package/lib/esm/TagsSelector/index.js +1 -0
- package/lib/esm/TagsSelector/tagSelector.css +3 -0
- package/lib/esm/TopContentSearch/TopContentSearch.d.ts +2 -1
- package/lib/esm/TopContentSearch/TopContentSearch.d.ts.map +1 -1
- package/lib/esm/TopContentSearch/TopContentSearch.js +4 -3
- package/lib/esm/helperFunctions/errorMessage.d.ts +0 -1
- package/lib/esm/helperFunctions/errorMessage.d.ts.map +1 -1
- package/lib/esm/hooks/index.d.ts +1 -0
- package/lib/esm/hooks/index.d.ts.map +1 -1
- package/lib/esm/hooks/index.js +1 -0
- package/lib/esm/hooks/useSearchDocument.d.ts +7 -0
- package/lib/esm/hooks/useSearchDocument.d.ts.map +1 -0
- package/lib/esm/hooks/useSearchDocument.js +42 -0
- package/lib/esm/hooks/useSelectKeyboardNavigator.d.ts +1 -1
- package/lib/esm/hooks/useSelectKeyboardNavigator.d.ts.map +1 -1
- package/lib/esm/index.d.ts +1 -0
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +1 -0
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAM3B,OAAO,KAA8B,MAAM,OAAO,CAAC;AAKnD,UAAU,MAAM;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IACtE,mBAAmB,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,OAAO,KAAA,KAAK,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAM3B,OAAO,KAA8B,MAAM,OAAO,CAAC;AAKnD,UAAU,MAAM;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IACtE,mBAAmB,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,OAAO,KAAA,KAAK,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC;AA4ED,eAAO,MAAM,WAAW,gBAAiB,MAAM;;;CAqB9C,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,qBAoRvC"}
|
|
@@ -32,11 +32,24 @@ const initializedCountries = COUNTRY_DATA.map((country) => {
|
|
|
32
32
|
};
|
|
33
33
|
return countryItem;
|
|
34
34
|
});
|
|
35
|
+
const trimAndReplacePlusFromPhone = (value) => {
|
|
36
|
+
var _a;
|
|
37
|
+
if (!value)
|
|
38
|
+
return '';
|
|
39
|
+
return (_a = value === null || value === void 0 ? void 0 : value.trim()) === null || _a === void 0 ? void 0 : _a.replace('+', '');
|
|
40
|
+
};
|
|
41
|
+
const removeAllSpaces = (value) => {
|
|
42
|
+
// to remove all trailing and in between spaces
|
|
43
|
+
if (!value)
|
|
44
|
+
return '';
|
|
45
|
+
return value === null || value === void 0 ? void 0 : value.replace(/\s+/g, '');
|
|
46
|
+
};
|
|
35
47
|
// Formatting phone numbers according to country
|
|
36
48
|
const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
37
49
|
if (isEmpty(fullPhoneNumber))
|
|
38
50
|
return '';
|
|
39
51
|
let localPhone = fullPhoneNumber === null || fullPhoneNumber === void 0 ? void 0 : fullPhoneNumber.replace(PREFIX, '');
|
|
52
|
+
localPhone = removeAllSpaces(localPhone);
|
|
40
53
|
if (isEmpty(localPhone))
|
|
41
54
|
return '';
|
|
42
55
|
// Formatting inputted number
|
|
@@ -57,6 +70,8 @@ const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
|
57
70
|
pattern += localFormat[j];
|
|
58
71
|
}
|
|
59
72
|
}
|
|
73
|
+
const isPatternWithPrefix = pattern.replace(/\s+/g, '').startsWith(PREFIX);
|
|
74
|
+
pattern = isPatternWithPrefix ? pattern : !isEmpty(isPatternWithPrefix) ? PREFIX + pattern : '';
|
|
60
75
|
return pattern;
|
|
61
76
|
};
|
|
62
77
|
// return phoneline and countrycode for any given phone
|
|
@@ -78,12 +93,13 @@ export const getPhoneObj = (phoneNumber) => {
|
|
|
78
93
|
};
|
|
79
94
|
};
|
|
80
95
|
export function PhoneInput(props) {
|
|
81
|
-
const { phoneValue, countryCode, onCountryCodeChange, onPhoneValueChange, validations, setInvalid } = props;
|
|
96
|
+
const { phoneValue, countryCode, onCountryCodeChange, onPhoneValueChange, validations, setInvalid, shouldNotSetCountryCode, } = props;
|
|
82
97
|
const { t } = useTranslation();
|
|
83
98
|
const [isOpen, setIsOpen] = useState(false);
|
|
84
99
|
const [iso2, setIso2] = useState('');
|
|
85
100
|
const [formattedNumber, setFormattedNumber] = useState('');
|
|
86
101
|
const [format, setFormat] = useState('');
|
|
102
|
+
const [phoneWithoutCountryCode, setPhoneWithoutCountryCode] = useState('');
|
|
87
103
|
const [countryObj, setCountryObj] = useState({
|
|
88
104
|
name: '', // Country name
|
|
89
105
|
regions: [''], // Surronding regions
|
|
@@ -98,8 +114,11 @@ export function PhoneInput(props) {
|
|
|
98
114
|
let localPhone = phoneNumber === null || phoneNumber === void 0 ? void 0 : phoneNumber.replace(PREFIX, '').trim();
|
|
99
115
|
localPhone = localPhone === null || localPhone === void 0 ? void 0 : localPhone.replace('(', '').trim();
|
|
100
116
|
localPhone = localPhone === null || localPhone === void 0 ? void 0 : localPhone.replace(/ +/g, '');
|
|
101
|
-
|
|
117
|
+
if (shouldNotSetCountryCode) {
|
|
118
|
+
return PREFIX + DEFAULT_MASK; // default format for portal phone without country code
|
|
119
|
+
}
|
|
102
120
|
if (!isEmpty(countryObj) && isEqual(localPhone, countryObj.dialCode)) {
|
|
121
|
+
// if the user selects a value from the dropdown and the country code is the same as prev, iso2 values shouldn't override
|
|
103
122
|
onCountryCodeChange && onCountryCodeChange(PREFIX + countryObj.countryCode);
|
|
104
123
|
return countryObj.format;
|
|
105
124
|
}
|
|
@@ -198,24 +217,15 @@ export function PhoneInput(props) {
|
|
|
198
217
|
React.createElement("div", { className: "pf-v5-u-display-inline-flex" },
|
|
199
218
|
React.createElement("div", { className: `flag ${iso2}`, style: { marginRight: '5px' } }),
|
|
200
219
|
iso2.toUpperCase())));
|
|
201
|
-
useEffect(() => {
|
|
202
|
-
if (isEmpty(phoneValue)) {
|
|
203
|
-
setInvalid && setInvalid(false);
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
if (isEmpty(iso2)) {
|
|
207
|
-
const localFormat = setLocalFormat(phoneValue);
|
|
208
|
-
const _formattedNumber = formatNumber(phoneValue, localFormat);
|
|
209
|
-
setFormattedNumber(_formattedNumber);
|
|
210
|
-
}
|
|
211
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
|
-
}, []);
|
|
213
220
|
useEffect(() => {
|
|
214
221
|
if (!isEmpty(countryObj.iso2) && `${PREFIX}${countryObj.dialCode}` !== countryCode) {
|
|
222
|
+
if (shouldNotSetCountryCode) {
|
|
223
|
+
onCountryCodeChange && onCountryCodeChange(PREFIX + countryObj.dialCode);
|
|
224
|
+
}
|
|
215
225
|
setIso2(countryObj.iso2);
|
|
216
226
|
setFormat(countryObj.format);
|
|
217
|
-
onPhoneValueChange(`${PREFIX}${countryObj.dialCode}`);
|
|
218
|
-
setFormattedNumber(`${PREFIX}${countryObj.dialCode}`);
|
|
227
|
+
onPhoneValueChange(`${PREFIX}${countryObj.dialCode} ${trimAndReplacePlusFromPhone(phoneWithoutCountryCode)}`);
|
|
228
|
+
setFormattedNumber(`${PREFIX}${countryObj.dialCode} ${trimAndReplacePlusFromPhone(phoneWithoutCountryCode)}`);
|
|
219
229
|
}
|
|
220
230
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
221
231
|
}, [countryObj]);
|
|
@@ -243,15 +253,37 @@ export function PhoneInput(props) {
|
|
|
243
253
|
setInvalid && setInvalid(false);
|
|
244
254
|
setFormattedNumber('');
|
|
245
255
|
onPhoneValueChange('');
|
|
256
|
+
setPhoneWithoutCountryCode('');
|
|
246
257
|
}
|
|
247
258
|
else {
|
|
248
259
|
onPhoneValueChange(phoneValue);
|
|
249
260
|
const localFormat = setLocalFormat(phoneValue);
|
|
250
261
|
const _formattedNumber = formatNumber(phoneValue, localFormat);
|
|
251
262
|
setFormattedNumber(_formattedNumber);
|
|
263
|
+
// to have phone without country code so it can populated with the newly selected country code
|
|
264
|
+
// instead of keeping it just country code
|
|
265
|
+
setPhoneWithoutCountryCode(removeAllSpaces(phoneValue).replace(countryCode, ''));
|
|
252
266
|
}
|
|
253
267
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
254
268
|
}, [phoneValue]);
|
|
269
|
+
// For first time user whose phone is fetched from portal without country code
|
|
270
|
+
// For phone length less or equal to 10 country code shouldn't be fetched to avoid faulty phone population
|
|
271
|
+
// shouldNotSetCountryCode flag from ContactPhoneNumber
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (shouldNotSetCountryCode) {
|
|
274
|
+
setIso2('');
|
|
275
|
+
onCountryCodeChange && onCountryCodeChange('');
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
setIso2(countryObj.iso2);
|
|
279
|
+
onCountryCodeChange && onCountryCodeChange(PREFIX + countryCode);
|
|
280
|
+
}
|
|
281
|
+
onPhoneValueChange && onPhoneValueChange(removeAllSpaces(phoneValue)); // removing trailing and in between spaces
|
|
282
|
+
const localFormat = setLocalFormat(phoneValue);
|
|
283
|
+
const _formattedNumber = formatNumber(phoneValue, localFormat);
|
|
284
|
+
setFormattedNumber(_formattedNumber);
|
|
285
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
286
|
+
}, [shouldNotSetCountryCode]);
|
|
255
287
|
return (React.createElement(InputGroup, { className: "phone-number-input" },
|
|
256
288
|
React.createElement(InputGroupItem, null,
|
|
257
289
|
React.createElement("div", null,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import './tagSelector.css';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
interface IProps {
|
|
4
|
+
tagOptions: any[];
|
|
5
|
+
selectedTags?: any[];
|
|
6
|
+
onChange: (tags: any[]) => void;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
id?: string;
|
|
9
|
+
typeahead?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function TagsSelector({ tagOptions, onChange, placeholder, id, typeahead, selectedTags }: IProps): React.JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=TagsSelector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TagsSelector.d.ts","sourceRoot":"","sources":["../../../src/TagsSelector/TagsSelector.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAkB3B,OAAO,KAAuC,MAAM,OAAO,CAAC;AAK5D,UAAU,MAAM;IACZ,UAAU,EAAE,GAAG,EAAE,CAAC;IAClB,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC;IACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,YAAY,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,SAAS,EAAE,YAAiB,EAAE,EAAE,MAAM,qBAyI3G"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import './tagSelector.css';
|
|
2
|
+
import { Button, Chip, ChipGroup, Flex, MenuToggle, Select, SelectList, SelectOption, TextInputGroup, TextInputGroupMain, TextInputGroupUtilities, } from '@patternfly/react-core';
|
|
3
|
+
import TimesIcon from '@patternfly/react-icons/dist/js/icons/times-icon';
|
|
4
|
+
import { isEmpty } from 'lodash';
|
|
5
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
6
|
+
import { Trans, useTranslation } from 'react-i18next';
|
|
7
|
+
import { useSelectKeyboardNavigator } from '../hooks/useSelectKeyboardNavigator';
|
|
8
|
+
export function TagsSelector({ tagOptions, onChange, placeholder, id, typeahead, selectedTags = [] }) {
|
|
9
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
10
|
+
const [selected, setSelected] = useState(selectedTags);
|
|
11
|
+
const [query, setQuery] = useState('');
|
|
12
|
+
const textInputRef = React.useRef();
|
|
13
|
+
const selectOptions = useMemo(() => {
|
|
14
|
+
let newSelectOptions = tagOptions;
|
|
15
|
+
if (!isEmpty(query)) {
|
|
16
|
+
newSelectOptions = tagOptions.filter((t) => t.tagName.toLowerCase().includes(query.toLowerCase()));
|
|
17
|
+
if (!isOpen) {
|
|
18
|
+
setIsOpen(true);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return newSelectOptions;
|
|
22
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
23
|
+
}, [query, tagOptions]);
|
|
24
|
+
const { t } = useTranslation();
|
|
25
|
+
const onToggleClick = () => {
|
|
26
|
+
setIsOpen(!isOpen);
|
|
27
|
+
};
|
|
28
|
+
const onSelect = (selection) => {
|
|
29
|
+
var _a;
|
|
30
|
+
let newSelected = [];
|
|
31
|
+
if (selected.some((tag) => tag.id === selection.id)) {
|
|
32
|
+
newSelected = selected.filter((s) => s.id !== selection.id);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
newSelected = [...selected, selection];
|
|
36
|
+
}
|
|
37
|
+
setSelected(newSelected);
|
|
38
|
+
(_a = textInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
39
|
+
};
|
|
40
|
+
const { onInputKeyDown, focusedItemIndex } = useSelectKeyboardNavigator({
|
|
41
|
+
list: tagOptions,
|
|
42
|
+
isOpen,
|
|
43
|
+
setIsOpen,
|
|
44
|
+
onSelect,
|
|
45
|
+
});
|
|
46
|
+
const handleClear = () => {
|
|
47
|
+
var _a;
|
|
48
|
+
setSelected([]);
|
|
49
|
+
setQuery('');
|
|
50
|
+
(_a = textInputRef === null || textInputRef === void 0 ? void 0 : textInputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
51
|
+
};
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
onChange && onChange(selected);
|
|
54
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
|
+
}, [selected]);
|
|
56
|
+
const selectedChipGroup = (React.createElement(ChipGroup, { numChips: 2 }, selected.map((label) => (React.createElement(Chip, { key: label.id, onClick: (e) => {
|
|
57
|
+
e.stopPropagation();
|
|
58
|
+
onSelect(label);
|
|
59
|
+
} }, label.tagName)))));
|
|
60
|
+
const toggle = (toggleRef) => (React.createElement(MenuToggle, Object.assign({ ref: toggleRef, onClick: onToggleClick, className: "pf-v5-u-flex-grow-1", isExpanded: isOpen, onKeyDown: onInputKeyDown, disabled: isEmpty(tagOptions) }, (typeahead && { variant: 'typeahead' })), typeahead ? (React.createElement(TextInputGroup, { isPlain: true },
|
|
61
|
+
React.createElement(TextInputGroupMain, { id: "tags-selector-search-input", value: query, onClick: onToggleClick, onChange: (e, v) => setQuery(v), onKeyDown: onInputKeyDown, innerRef: textInputRef, isExpanded: isOpen, placeholder: placeholder || t('Search for a tag') }, selectedChipGroup),
|
|
62
|
+
React.createElement(TextInputGroupUtilities, null, selected.length > 0 && (React.createElement(Button, { variant: "plain", onClick: handleClear, "aria-label": "clear-all-tags" },
|
|
63
|
+
React.createElement(TimesIcon, { "aria-hidden": true })))))) : (React.createElement(Flex, null,
|
|
64
|
+
selectedChipGroup,
|
|
65
|
+
React.createElement("span", { className: `${!isEmpty(selected) && 'pf-v5-u-ml-xs'}` },
|
|
66
|
+
React.createElement(Trans, null, "Select a tag"))))));
|
|
67
|
+
return (React.createElement(Select, { isOpen: isOpen, selected: selected, toggle: toggle, onSelect: (_, selection) => onSelect(selection), isScrollable: true, onOpenChange: () => setIsOpen(false), popperProps: { direction: 'down', enableFlip: false }, id: id || 'tag-selector' },
|
|
68
|
+
React.createElement(SelectList, { isAriaMultiselectable: true }, selectOptions.map((tag, index) => (React.createElement(SelectOption, { key: tag.id, value: tag, isFocused: index === focusedItemIndex, isSelected: selected.some((t) => t.id === tag.id) }, tag.tagName))))));
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/TagsSelector/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TagsSelector';
|
|
@@ -7,10 +7,11 @@ interface IProps {
|
|
|
7
7
|
topContentData: ITopContentList[];
|
|
8
8
|
enableEventTracking?: boolean;
|
|
9
9
|
onSearch: (searchVal: string, searchResults: ITopContentList[]) => void;
|
|
10
|
+
className?: string;
|
|
10
11
|
searchQuery?: string;
|
|
11
12
|
setSearchQuery?: Function;
|
|
12
13
|
}
|
|
13
14
|
export declare const getTopContentUrl: (contentUrl: string) => string;
|
|
14
|
-
export declare function TopContentSearch({ topContentData, topContentResultsWrapperRef, onSearch, dataTrackingId, enableEventTracking, searchQuery, setSearchQuery, }: IProps): React.JSX.Element;
|
|
15
|
+
export declare function TopContentSearch({ topContentData, topContentResultsWrapperRef, onSearch, dataTrackingId, enableEventTracking, className, searchQuery, setSearchQuery, }: IProps): React.JSX.Element;
|
|
15
16
|
export {};
|
|
16
17
|
//# sourceMappingURL=TopContentSearch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TopContentSearch.d.ts","sourceRoot":"","sources":["../../../src/TopContentSearch/TopContentSearch.tsx"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,2DAA2D,CAAC;AAQ5F,OAAO,KAA4D,MAAM,OAAO,CAAC;AAGjF,UAAU,MAAM;IACZ,cAAc,EAAE,MAAM,CAAC;IACvB,2BAA2B,EAAE,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACzD,cAAc,EAAE,eAAe,EAAE,CAAC;IAClC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,QAAQ,CAAC;CAC7B;AAED,eAAO,MAAM,gBAAgB,eAAgB,MAAM,WASlD,CAAC;AAOF,wBAAgB,gBAAgB,CAAC,EAC7B,cAAmB,EACnB,2BAA6C,EAC7C,QAAQ,EACR,cAAc,EACd,mBAA2B,EAC3B,WAAgB,EAChB,cAAc,GACjB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"TopContentSearch.d.ts","sourceRoot":"","sources":["../../../src/TopContentSearch/TopContentSearch.tsx"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,2DAA2D,CAAC;AAQ5F,OAAO,KAA4D,MAAM,OAAO,CAAC;AAGjF,UAAU,MAAM;IACZ,cAAc,EAAE,MAAM,CAAC;IACvB,2BAA2B,EAAE,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACzD,cAAc,EAAE,eAAe,EAAE,CAAC;IAClC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,QAAQ,CAAC;CAC7B;AAED,eAAO,MAAM,gBAAgB,eAAgB,MAAM,WASlD,CAAC;AAOF,wBAAgB,gBAAgB,CAAC,EAC7B,cAAmB,EACnB,2BAA6C,EAC7C,QAAQ,EACR,cAAc,EACd,mBAA2B,EAC3B,SAAS,EACT,WAAgB,EAChB,cAAc,GACjB,EAAE,MAAM,qBAyHR"}
|
|
@@ -31,7 +31,7 @@ var CustomEvents;
|
|
|
31
31
|
CustomEvents["inputChange"] = "top-content-filter-input-change";
|
|
32
32
|
CustomEvents["inputClear"] = "top-content-filter-input-clear";
|
|
33
33
|
})(CustomEvents || (CustomEvents = {}));
|
|
34
|
-
export function TopContentSearch({ topContentData = [], topContentResultsWrapperRef = { current: {} }, onSearch, dataTrackingId, enableEventTracking = false, searchQuery = '', setSearchQuery, }) {
|
|
34
|
+
export function TopContentSearch({ topContentData = [], topContentResultsWrapperRef = { current: {} }, onSearch, dataTrackingId, enableEventTracking = false, className, searchQuery = '', setSearchQuery, }) {
|
|
35
35
|
const [searchText, setSearchText] = useState(searchQuery);
|
|
36
36
|
const { t } = useTranslation();
|
|
37
37
|
const searchWorkerRef = useRef(new SearchApi({
|
|
@@ -70,6 +70,7 @@ export function TopContentSearch({ topContentData = [], topContentResultsWrapper
|
|
|
70
70
|
}, [topContentResultsWrapperRef]);
|
|
71
71
|
const onSearchInputClear = useCallback((event) => {
|
|
72
72
|
setSearchText('');
|
|
73
|
+
setSearchQuery && setSearchQuery('');
|
|
73
74
|
onSearch('', topContentData);
|
|
74
75
|
logCustomEvent(CustomEvents.inputClear, event);
|
|
75
76
|
highlightSearchResults('');
|
|
@@ -113,8 +114,8 @@ export function TopContentSearch({ topContentData = [], topContentResultsWrapper
|
|
|
113
114
|
},
|
|
114
115
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
115
116
|
[]);
|
|
116
|
-
return (React.createElement("div", { className:
|
|
117
|
-
React.createElement("label", { htmlFor: "top-content-search-input"
|
|
117
|
+
return (React.createElement("div", { className: className, ref: searchWrapperRef },
|
|
118
|
+
React.createElement("label", { htmlFor: "top-content-search-input" },
|
|
118
119
|
React.createElement(Trans, null, "Filter results:")),
|
|
119
120
|
React.createElement(SearchInput, { id: "top-content-search-input", className: "top-content-search-input pf-v5-u-flex-grow-1", "aria-label": t('search top content'), placeholder: t('Enter relevant keywords'), value: searchText, "data-tracking-id": dataTrackingId, onChange: (e, val) => onSearchInputChange(val), onClear: onSearchInputClear })));
|
|
120
121
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorMessage.d.ts","sourceRoot":"","sources":["../../../src/helperFunctions/errorMessage.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errorMessage.d.ts","sourceRoot":"","sources":["../../../src/helperFunctions/errorMessage.tsx"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAS7B,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;CACjC;AAED,MAAM,WAAW,SAAS;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACxC;AAoDD,iBAAS,wBAAwB,CAAC,KAAK,KAAA,EAAE,aAAa,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,GAAG,CAAC,OAAO,CAwCxF;AAED,iBAAS,iBAAiB,CAAC,KAAK,KAAA,EAAE,WAAW,CAAC,EAAE,SAAS,GAAG,MAAM,CAIjE;AAED,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/esm/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC"}
|
package/lib/esm/hooks/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface IIndexStrategy<T> {
|
|
2
|
+
indexKey: keyof T;
|
|
3
|
+
strategy: (doc: T) => string;
|
|
4
|
+
}
|
|
5
|
+
export declare function useSearchDocument<T>(documents: T[], searchQuery: string, indexStrategy: IIndexStrategy<T>): T[];
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=useSearchDocument.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSearchDocument.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSearchDocument.ts"],"names":[],"mappings":"AAMA,UAAU,cAAc,CAAC,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,MAAM,CAAC;CAChC;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC,OAwCzG"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import SearchApi, { INDEX_MODES } from 'js-worker-search';
|
|
11
|
+
import isEmpty from 'lodash/isEmpty';
|
|
12
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
13
|
+
import { useDeepCompareDebounce } from './useDebounce';
|
|
14
|
+
export function useSearchDocument(documents, searchQuery, indexStrategy) {
|
|
15
|
+
const [filteredDocs, setFilteredDocs] = useState(documents);
|
|
16
|
+
const searchWorkerRef = useRef(new SearchApi({
|
|
17
|
+
indexMode: INDEX_MODES.ALL_SUBSTRINGS,
|
|
18
|
+
caseSensitive: false,
|
|
19
|
+
matchAnyToken: true,
|
|
20
|
+
}));
|
|
21
|
+
const handleSearch = useCallback((query) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (isEmpty(query)) {
|
|
23
|
+
setFilteredDocs(documents);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const indexedVals = yield searchWorkerRef.current.search(query);
|
|
27
|
+
setFilteredDocs(documents.filter((d) => indexedVals.includes(d[indexStrategy.indexKey])));
|
|
28
|
+
}),
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
[documents]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
documents.forEach((doc) => {
|
|
33
|
+
const indexedString = indexStrategy.strategy(doc);
|
|
34
|
+
searchWorkerRef.current.indexDocument(doc[indexStrategy.indexKey], indexedString);
|
|
35
|
+
});
|
|
36
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
|
+
}, [documents]);
|
|
38
|
+
useDeepCompareDebounce(() => {
|
|
39
|
+
handleSearch(searchQuery);
|
|
40
|
+
}, [searchQuery, documents], 500);
|
|
41
|
+
return filteredDocs;
|
|
42
|
+
}
|
|
@@ -6,7 +6,7 @@ interface IProps {
|
|
|
6
6
|
onSelect: (value: any) => void;
|
|
7
7
|
}
|
|
8
8
|
export declare function useSelectKeyboardNavigator({ list, isOpen, setIsOpen, onSelect }: IProps): {
|
|
9
|
-
onInputKeyDown: (event:
|
|
9
|
+
onInputKeyDown: (event: any) => void;
|
|
10
10
|
focusedItemIndex: number;
|
|
11
11
|
};
|
|
12
12
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectKeyboardNavigator.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSelectKeyboardNavigator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,UAAU,MAAM;IACZ,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAC1D,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAClC;AAED,wBAAgB,0BAA0B,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"useSelectKeyboardNavigator.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSelectKeyboardNavigator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,UAAU,MAAM;IACZ,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;IAC1D,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAClC;AAED,wBAAgB,0BAA0B,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,MAAM;;;EAwDvF"}
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
|
package/lib/esm/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.63",
|
|
4
4
|
"description": "Contains all reusabel components for support app",
|
|
5
5
|
"author": "Vikas Rathee <vrathee@redhat.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"prepublishOnly": "npm run build"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@cee-eng/hydrajs": "4.17.
|
|
47
|
+
"@cee-eng/hydrajs": "4.17.21",
|
|
48
48
|
"@cee-eng/ui-toolkit": "1.1.8",
|
|
49
49
|
"@patternfly/patternfly": "5.1.0",
|
|
50
50
|
"@patternfly/react-core": "5.1.1",
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"use-deep-compare-effect": "^1.6.1"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@cee-eng/hydrajs": "4.17.
|
|
65
|
+
"@cee-eng/hydrajs": "4.17.21",
|
|
66
66
|
"@cee-eng/ui-toolkit": "1.1.8",
|
|
67
67
|
"@patternfly/patternfly": "5.1.0",
|
|
68
68
|
"@patternfly/react-core": "5.1.1",
|
|
69
69
|
"@patternfly/react-table": "5.1.1",
|
|
70
|
-
"@rh-support/types": "2.0.
|
|
71
|
-
"@rh-support/user-permissions": "2.1.
|
|
72
|
-
"@rh-support/utils": "2.1.
|
|
70
|
+
"@rh-support/types": "2.0.4",
|
|
71
|
+
"@rh-support/user-permissions": "2.1.46",
|
|
72
|
+
"@rh-support/utils": "2.1.35",
|
|
73
73
|
"dompurify": "^2.2.6",
|
|
74
74
|
"downshift": "^6.0.5",
|
|
75
75
|
"js-worker-search": "^1.4.1",
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"defaults and supports es6-module",
|
|
110
110
|
"maintained node versions"
|
|
111
111
|
],
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "85dc8cf2f736478dc995cb52e1a5be8e608e2fb8"
|
|
113
113
|
}
|