@rh-support/components 2.1.61-beta.2 → 2.1.62
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/TopContentSearch/TopContentSearch.d.ts.map +1 -1
- package/lib/esm/TopContentSearch/TopContentSearch.js +1 -0
- 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/package.json +5 -5
|
@@ -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,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,qBAyHR"}
|
|
@@ -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('');
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.62",
|
|
4
4
|
"description": "Contains all reusabel components for support app",
|
|
5
5
|
"author": "Vikas Rathee <vrathee@redhat.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -67,9 +67,9 @@
|
|
|
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.45",
|
|
72
|
+
"@rh-support/utils": "2.1.34",
|
|
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": "ecb9820a2fe40793e79c0f9f4786ec657070fe64"
|
|
113
113
|
}
|