@blaze-cms/plugin-search-ui 0.146.0-translations.6 → 0.147.0-rc-eagle.2

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 (91) hide show
  1. package/lib/application/query/index.js +31 -15
  2. package/lib/application/query/index.js.map +1 -1
  3. package/lib/components/SearchAdmin/RecentSearches/RecentSearches.js +33 -42
  4. package/lib/components/SearchAdmin/RecentSearches/RecentSearches.js.map +1 -1
  5. package/lib/components/SearchAdmin/RecentSearches/index.js +2 -3
  6. package/lib/components/SearchAdmin/RecentSearches/index.js.map +1 -1
  7. package/lib/components/SearchAdmin/SearchAdmin.js +63 -105
  8. package/lib/components/SearchAdmin/SearchAdmin.js.map +1 -1
  9. package/lib/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js +50 -78
  10. package/lib/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js.map +1 -1
  11. package/lib/components/SearchAdmin/SearchAdminSideBar/index.js +2 -3
  12. package/lib/components/SearchAdmin/SearchAdminSideBar/index.js.map +1 -1
  13. package/lib/components/SearchAdmin/SearchBar/SearchBar.js +41 -45
  14. package/lib/components/SearchAdmin/SearchBar/SearchBar.js.map +1 -1
  15. package/lib/components/SearchAdmin/SearchBar/index.js +2 -3
  16. package/lib/components/SearchAdmin/SearchBar/index.js.map +1 -1
  17. package/lib/components/SearchAdmin/SearchResults/SearchResults.js +100 -149
  18. package/lib/components/SearchAdmin/SearchResults/SearchResults.js.map +1 -1
  19. package/lib/components/SearchAdmin/SearchResults/index.js +2 -3
  20. package/lib/components/SearchAdmin/SearchResults/index.js.map +1 -1
  21. package/lib/components/SearchAdmin/TriggerModal/TriggerModal.js +10 -12
  22. package/lib/components/SearchAdmin/TriggerModal/TriggerModal.js.map +1 -1
  23. package/lib/components/SearchAdmin/TriggerModal/index.js +2 -3
  24. package/lib/components/SearchAdmin/TriggerModal/index.js.map +1 -1
  25. package/lib/components/SearchAdmin/index.js +2 -3
  26. package/lib/components/SearchAdmin/index.js.map +1 -1
  27. package/lib/components/SearchPublishedContent/SearchPublishedContent.js +74 -100
  28. package/lib/components/SearchPublishedContent/SearchPublishedContent.js.map +1 -1
  29. package/lib/components/SearchPublishedContent/index.js +2 -3
  30. package/lib/components/SearchPublishedContent/index.js.map +1 -1
  31. package/lib/components/useLocalStorage/index.js +2 -3
  32. package/lib/components/useLocalStorage/index.js.map +1 -1
  33. package/lib/components/useLocalStorage/useLocalStorage.js +8 -15
  34. package/lib/components/useLocalStorage/useLocalStorage.js.map +1 -1
  35. package/lib/components/useSearch/index.js +2 -3
  36. package/lib/components/useSearch/index.js.map +1 -1
  37. package/lib/components/useSearch/useSearch.js +64 -88
  38. package/lib/components/useSearch/useSearch.js.map +1 -1
  39. package/lib/components/useSearchResults/index.js +2 -3
  40. package/lib/components/useSearchResults/index.js.map +1 -1
  41. package/lib/components/useSearchResults/useSearchResults.js +34 -51
  42. package/lib/components/useSearchResults/useSearchResults.js.map +1 -1
  43. package/lib/constants.js +10 -10
  44. package/lib/constants.js.map +1 -1
  45. package/lib/hooks/index.js +2 -3
  46. package/lib/hooks/index.js.map +1 -1
  47. package/lib/hooks/useDebounceSearch.js +31 -38
  48. package/lib/hooks/useDebounceSearch.js.map +1 -1
  49. package/lib/index.js +8 -9
  50. package/lib/index.js.map +1 -1
  51. package/lib-es/application/query/index.js.map +1 -1
  52. package/lib-es/components/SearchAdmin/RecentSearches/RecentSearches.js.map +1 -1
  53. package/lib-es/components/SearchAdmin/RecentSearches/index.js.map +1 -1
  54. package/lib-es/components/SearchAdmin/SearchAdmin.js.map +1 -1
  55. package/lib-es/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js.map +1 -1
  56. package/lib-es/components/SearchAdmin/SearchAdminSideBar/index.js.map +1 -1
  57. package/lib-es/components/SearchAdmin/SearchBar/SearchBar.js.map +1 -1
  58. package/lib-es/components/SearchAdmin/SearchBar/index.js.map +1 -1
  59. package/lib-es/components/SearchAdmin/SearchResults/SearchResults.js +2 -2
  60. package/lib-es/components/SearchAdmin/SearchResults/SearchResults.js.map +1 -1
  61. package/lib-es/components/SearchAdmin/SearchResults/index.js.map +1 -1
  62. package/lib-es/components/SearchAdmin/TriggerModal/TriggerModal.js.map +1 -1
  63. package/lib-es/components/SearchAdmin/TriggerModal/index.js.map +1 -1
  64. package/lib-es/components/SearchAdmin/index.js.map +1 -1
  65. package/lib-es/components/SearchPublishedContent/SearchPublishedContent.js.map +1 -1
  66. package/lib-es/components/SearchPublishedContent/index.js.map +1 -1
  67. package/lib-es/components/useLocalStorage/index.js.map +1 -1
  68. package/lib-es/components/useLocalStorage/useLocalStorage.js.map +1 -1
  69. package/lib-es/components/useSearch/index.js.map +1 -1
  70. package/lib-es/components/useSearch/useSearch.js +8 -5
  71. package/lib-es/components/useSearch/useSearch.js.map +1 -1
  72. package/lib-es/components/useSearchResults/index.js.map +1 -1
  73. package/lib-es/components/useSearchResults/useSearchResults.js +4 -2
  74. package/lib-es/components/useSearchResults/useSearchResults.js.map +1 -1
  75. package/lib-es/constants.js +3 -2
  76. package/lib-es/constants.js.map +1 -1
  77. package/lib-es/hooks/index.js.map +1 -1
  78. package/lib-es/hooks/useDebounceSearch.js +4 -2
  79. package/lib-es/hooks/useDebounceSearch.js.map +1 -1
  80. package/lib-es/index.js.map +1 -1
  81. package/package.json +21 -16
  82. package/src/components/SearchAdmin/SearchAdmin.js +5 -8
  83. package/src/components/SearchAdmin/SearchResults/SearchResults.js +33 -39
  84. package/src/components/SearchPublishedContent/SearchPublishedContent.js +6 -9
  85. package/src/components/useSearch/useSearch.js +57 -57
  86. package/src/components/useSearchResults/useSearchResults.js +8 -11
  87. package/src/constants.js +4 -2
  88. package/src/hooks/useDebounceSearch.js +9 -11
  89. package/CHANGELOG.md +0 -904
  90. package/babel.config.js +0 -3
  91. package/jest.config.js +0 -5
@@ -1 +1 @@
1
- {"version":3,"file":"useDebounceSearch.js","names":["useEffect","useState","useDebounce","useSearchResults","SEARCH_PUBLISHED","useDebounceSearch","entities","resultKeys","fields","initialSearchTerm","searchTerm","setSearchTerm","previousSearchTerm","setPreviousSearchTerm","debouncedSearchTerm","loading","results","setQueryParams","queryKey","value"],"sources":["../../src/hooks/useDebounceSearch.js"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { useDebounce } from '@blaze-react/utils/lib/customHooks';\nimport useSearchResults from '../components/useSearchResults';\nimport { SEARCH_PUBLISHED } from '../constants';\n\nconst useDebounceSearch = ({ entities, resultKeys, fields, initialSearchTerm }) => {\n const [searchTerm, setSearchTerm] = useState(initialSearchTerm ?? '');\n const [previousSearchTerm, setPreviousSearchTerm] = useState(null);\n const debouncedSearchTerm = useDebounce(searchTerm, 500);\n\n const [{ loading, results }, setQueryParams] = useSearchResults({\n queryKey: SEARCH_PUBLISHED,\n resultKeys,\n entities,\n fields\n });\n\n useEffect(\n () => {\n if (debouncedSearchTerm && debouncedSearchTerm !== previousSearchTerm) {\n setQueryParams({ value: debouncedSearchTerm });\n setPreviousSearchTerm(debouncedSearchTerm);\n }\n },\n [debouncedSearchTerm, previousSearchTerm, setQueryParams]\n );\n\n return {\n loading,\n results,\n searchTerm,\n setSearchTerm,\n setPreviousSearchTerm,\n debouncedSearchTerm,\n previousSearchTerm\n };\n};\n\nexport default useDebounceSearch;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,WAAW,QAAQ,oCAAoC;AAChE,OAAOC,gBAAgB,MAAM,gCAAgC;AAC7D,SAASC,gBAAgB,QAAQ,cAAc;AAE/C,MAAMC,iBAAiB,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,UAAU;EAAEC,MAAM;EAAEC;AAAkB,CAAC,KAAK;EACjF,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGV,QAAQ,CAACQ,iBAAiB,aAAjBA,iBAAiB,cAAjBA,iBAAiB,GAAI,EAAE,CAAC;EACrE,MAAM,CAACG,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGZ,QAAQ,CAAC,IAAI,CAAC;EAClE,MAAMa,mBAAmB,GAAGZ,WAAW,CAACQ,UAAU,EAAE,GAAG,CAAC;EAExD,MAAM,CAAC;IAAEK,OAAO;IAAEC;EAAQ,CAAC,EAAEC,cAAc,CAAC,GAAGd,gBAAgB,CAAC;IAC9De,QAAQ,EAAEd,gBAAgB;IAC1BG,UAAU;IACVD,QAAQ;IACRE;EACF,CAAC,CAAC;EAEFR,SAAS,CACP,MAAM;IACJ,IAAIc,mBAAmB,IAAIA,mBAAmB,KAAKF,kBAAkB,EAAE;MACrEK,cAAc,CAAC;QAAEE,KAAK,EAAEL;MAAoB,CAAC,CAAC;MAC9CD,qBAAqB,CAACC,mBAAmB,CAAC;IAC5C;EACF,CAAC,EACD,CAACA,mBAAmB,EAAEF,kBAAkB,EAAEK,cAAc,CAC1D,CAAC;EAED,OAAO;IACLF,OAAO;IACPC,OAAO;IACPN,UAAU;IACVC,aAAa;IACbE,qBAAqB;IACrBC,mBAAmB;IACnBF;EACF,CAAC;AACH,CAAC;AAED,eAAeP,iBAAiB"}
1
+ {"version":3,"file":"useDebounceSearch.js","names":["useEffect","useState","useDebounce","useSearchResults","SEARCH_PUBLISHED","useDebounceSearch","entities","resultKeys","fields","initialSearchTerm","queryHook","searchTerm","setSearchTerm","previousSearchTerm","setPreviousSearchTerm","debouncedSearchTerm","loading","results","setQueryParams","queryKey","value"],"sources":["../../src/hooks/useDebounceSearch.js"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { useDebounce } from '@blaze-react/utils/lib/customHooks';\nimport useSearchResults from '../components/useSearchResults';\nimport { SEARCH_PUBLISHED } from '../constants';\n\nconst useDebounceSearch = ({ entities, resultKeys, fields, initialSearchTerm, queryHook }) => {\n const [searchTerm, setSearchTerm] = useState(initialSearchTerm ?? '');\n const [previousSearchTerm, setPreviousSearchTerm] = useState(null);\n const debouncedSearchTerm = useDebounce(searchTerm, 500);\n\n const [{ loading, results }, setQueryParams] = useSearchResults({\n queryKey: SEARCH_PUBLISHED,\n resultKeys,\n entities,\n fields,\n queryHook\n });\n\n useEffect(() => {\n if (debouncedSearchTerm && debouncedSearchTerm !== previousSearchTerm) {\n setQueryParams({ value: debouncedSearchTerm });\n setPreviousSearchTerm(debouncedSearchTerm);\n }\n }, [debouncedSearchTerm, previousSearchTerm, setQueryParams]);\n\n return {\n loading,\n results,\n searchTerm,\n setSearchTerm,\n setPreviousSearchTerm,\n debouncedSearchTerm,\n previousSearchTerm\n };\n};\n\nexport default useDebounceSearch;\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,WAAW,QAAQ,oCAAoC;AAChE,OAAOC,gBAAgB,MAAM,gCAAgC;AAC7D,SAASC,gBAAgB,QAAQ,cAAc;AAE/C,MAAMC,iBAAiB,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,UAAU;EAAEC,MAAM;EAAEC,iBAAiB;EAAEC;AAAU,CAAC,KAAK;EAC5F,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAGX,QAAQ,CAACQ,iBAAiB,aAAjBA,iBAAiB,cAAjBA,iBAAiB,GAAI,EAAE,CAAC;EACrE,MAAM,CAACI,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGb,QAAQ,CAAC,IAAI,CAAC;EAClE,MAAMc,mBAAmB,GAAGb,WAAW,CAACS,UAAU,EAAE,GAAG,CAAC;EAExD,MAAM,CAAC;IAAEK,OAAO;IAAEC;EAAQ,CAAC,EAAEC,cAAc,CAAC,GAAGf,gBAAgB,CAAC;IAC9DgB,QAAQ,EAAEf,gBAAgB;IAC1BG,UAAU;IACVD,QAAQ;IACRE,MAAM;IACNE;EACF,CAAC,CAAC;EAEFV,SAAS,CAAC,MAAM;IACd,IAAIe,mBAAmB,IAAIA,mBAAmB,KAAKF,kBAAkB,EAAE;MACrEK,cAAc,CAAC;QAAEE,KAAK,EAAEL;MAAoB,CAAC,CAAC;MAC9CD,qBAAqB,CAACC,mBAAmB,CAAC;IAC5C;EACF,CAAC,EAAE,CAACA,mBAAmB,EAAEF,kBAAkB,EAAEK,cAAc,CAAC,CAAC;EAE7D,OAAO;IACLF,OAAO;IACPC,OAAO;IACPN,UAAU;IACVC,aAAa;IACbE,qBAAqB;IACrBC,mBAAmB;IACnBF;EACF,CAAC;AACH,CAAC;AAED,eAAeR,iBAAiB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["SearchAdmin","SearchPublishedContent","SearchBar","useDebounceSearch"],"sources":["../src/index.js"],"sourcesContent":["import SearchAdmin from './components/SearchAdmin';\nimport SearchPublishedContent from './components/SearchPublishedContent';\nimport SearchBar from './components/SearchAdmin/SearchBar';\nimport useDebounceSearch from './hooks/useDebounceSearch';\n\nexport { SearchAdmin, SearchPublishedContent, SearchBar, useDebounceSearch };\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,0BAA0B;AAClD,OAAOC,sBAAsB,MAAM,qCAAqC;AACxE,OAAOC,SAAS,MAAM,oCAAoC;AAC1D,OAAOC,iBAAiB,MAAM,2BAA2B;AAEzD,SAASH,WAAW,EAAEC,sBAAsB,EAAEC,SAAS,EAAEC,iBAAiB"}
1
+ {"version":3,"file":"index.js","names":["SearchAdmin","SearchPublishedContent","SearchBar","useDebounceSearch"],"sources":["../src/index.js"],"sourcesContent":["import SearchAdmin from './components/SearchAdmin';\nimport SearchPublishedContent from './components/SearchPublishedContent';\nimport SearchBar from './components/SearchAdmin/SearchBar';\nimport useDebounceSearch from './hooks/useDebounceSearch';\n\nexport { SearchAdmin, SearchPublishedContent, SearchBar, useDebounceSearch };\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,0BAA0B;AAClD,OAAOC,sBAAsB,MAAM,qCAAqC;AACxE,OAAOC,SAAS,MAAM,oCAAoC;AAC1D,OAAOC,iBAAiB,MAAM,2BAA2B;AAEzD,SAASH,WAAW,EAAEC,sBAAsB,EAAEC,SAAS,EAAEC,iBAAiB","ignoreList":[]}
package/package.json CHANGED
@@ -1,24 +1,29 @@
1
1
  {
2
2
  "name": "@blaze-cms/plugin-search-ui",
3
- "version": "0.146.0-translations.6",
3
+ "version": "0.147.0-rc-eagle.2",
4
4
  "description": "Blaze plugin search ui",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-es/index.js",
7
- "sideEffects": false,
7
+ "files": [
8
+ "lib",
9
+ "lib-es",
10
+ "src"
11
+ ],
12
+ "source": "src/index.js",
8
13
  "directories": {
9
14
  "src": "src/"
10
15
  },
11
16
  "scripts": {
12
17
  "test": "jest",
13
- "lint": "yarn run lint:js",
18
+ "lint": "npm run lint:js",
14
19
  "lint:js": "eslint .",
15
20
  "clean": "rm -Rf ./lib/ && rm -Rf ./lib-es/",
16
21
  "build:cjs": "BABEL_ENV=cjs ../../node_modules/.bin/babel ./src --out-dir ./lib --source-maps --root-mode upward",
17
22
  "build:esm": "BABEL_ENV=esm ../../node_modules/.bin/babel ./src --out-dir ./lib-es --source-maps --root-mode upward",
18
- "build": "yarn run build:cjs && yarn run build:esm",
19
- "build:clean": "yarn run clean && yarn run build",
20
- "prepublishOnly": "yarn run build:clean",
21
- "postpublish": "yarn run clean"
23
+ "build": "npm run build:cjs && npm run build:esm",
24
+ "build:clean": "npm run clean && npm run build",
25
+ "prepublishOnly": "npm run build:clean",
26
+ "postpublish": "npm run clean"
22
27
  },
23
28
  "author": {
24
29
  "email": "hello@thebyte9.com",
@@ -27,30 +32,30 @@
27
32
  },
28
33
  "license": "GPL-3.0",
29
34
  "dependencies": {
30
- "@blaze-cms/admin-ui-utils": "0.146.0-translations.6",
31
- "@blaze-cms/core-errors": "0.146.0-translations.0",
32
- "@blaze-cms/setup-ui": "^0.140.3",
35
+ "@blaze-cms/admin-ui-utils": "0.147.0-rc-eagle.2",
36
+ "@blaze-cms/core-errors": "0.147.0-rc-eagle.2",
37
+ "@blaze-cms/setup-ui": "0.147.0-rc-eagle.2",
33
38
  "@blaze-react/button": "0.5.19",
34
- "@blaze-react/input": "0.8.0-alpha.78",
39
+ "@blaze-react/checkboxes": "^0.7.0",
40
+ "@blaze-react/input": "0.8.0-alpha.100",
35
41
  "@blaze-react/utils": "0.5.15",
36
42
  "classnames": "^2.2.6",
37
- "core-js": "^3.2.1",
38
43
  "react-icons": "^4.11.0",
39
44
  "react-router-dom": "^5.0.1",
40
45
  "react-tiny-virtual-list": "2.2.0"
41
46
  },
42
47
  "devDependencies": {
43
- "@blaze-cms/core-ui": "0.146.0-translations.0"
48
+ "@blaze-cms/core-ui": "0.147.0-rc-eagle.2"
44
49
  },
45
50
  "peerDependencies": {
46
51
  "@apollo/client": "3.x",
47
- "@blaze-cms/admin": "^0.97.2",
52
+ "@blaze-cms/admin": "^0.145.0",
48
53
  "prop-types": "^15.7.2",
49
- "react": "^17.0.2"
54
+ "react": ">= 18"
50
55
  },
51
56
  "eslintIgnore": [
52
57
  "lib/*",
53
58
  "lib-es/*"
54
59
  ],
55
- "gitHead": "3cfd3eef1049e8d197602cbcc4a4d6f94c8fa71b"
60
+ "gitHead": "156a1560d7bc2bbd57b5b51fdf11098349bb26f5"
56
61
  }
@@ -25,14 +25,11 @@ const SearchAdmin = () => {
25
25
  entities
26
26
  });
27
27
 
28
- useEffect(
29
- () => {
30
- if (searchInputRef && searchInputRef.current) {
31
- searchInputRef.current.focus();
32
- }
33
- },
34
- [displaySearchModalFrame]
35
- );
28
+ useEffect(() => {
29
+ if (searchInputRef && searchInputRef.current) {
30
+ searchInputRef.current.focus();
31
+ }
32
+ }, [displaySearchModalFrame]);
36
33
 
37
34
  const handleSearchTerm = ({ target: { value } }) => {
38
35
  setSearchTerm(value);
@@ -6,7 +6,8 @@ import VirtualList from 'react-tiny-virtual-list';
6
6
  import { withRouter } from 'react-router-dom';
7
7
  import {
8
8
  SEARCH_RESULTS_OVER_SCAN_BUFFER,
9
- SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST,
9
+ SEARCH_RESULTS_ELEMENTS_HEIGHT_ABOVE_LIST,
10
+ SEARCH_RESULTS_HEIGHT_OFFSET,
10
11
  SEARCH_RESULTS_ITEM_SIZE,
11
12
  FILE
12
13
  } from '../../../constants';
@@ -27,35 +28,32 @@ const SearchResults = ({
27
28
  const [allResults, setAllResults] = useState([]);
28
29
  const [currentParams, setCurrentParams] = useState('');
29
30
 
30
- useEffect(
31
- () => {
32
- if (!loading) {
33
- const newResults = results.map(({ id }) => id).join(',');
34
- if (currentResults !== newResults) {
35
- const newParams = `${currentValue},${entities.join(',')}`;
36
- if (newParams !== currentParams) {
37
- setAllResults(results);
38
- setCurrentParams(newParams);
39
- if (verifiedRanges.length) setVerifiedRanges([]);
40
- } else {
41
- setAllResults(allResults.concat(results));
42
- }
43
- setCurrentResults(newResults);
31
+ useEffect(() => {
32
+ if (!loading) {
33
+ const newResults = results.map(({ id }) => id).join(',');
34
+ if (currentResults !== newResults) {
35
+ const newParams = `${currentValue},${entities.join(',')}`;
36
+ if (newParams !== currentParams) {
37
+ setAllResults(results);
38
+ setCurrentParams(newParams);
39
+ if (verifiedRanges.length) setVerifiedRanges([]);
40
+ } else {
41
+ setAllResults(allResults.concat(results));
44
42
  }
43
+ setCurrentResults(newResults);
45
44
  }
46
- },
47
- [
48
- allResults,
49
- currentParams,
50
- currentResults,
51
- currentValue,
52
- entities,
53
- loading,
54
- results,
55
- total,
56
- verifiedRanges.length
57
- ]
58
- );
45
+ }
46
+ }, [
47
+ allResults,
48
+ currentParams,
49
+ currentResults,
50
+ currentValue,
51
+ entities,
52
+ loading,
53
+ results,
54
+ total,
55
+ verifiedRanges.length
56
+ ]);
59
57
 
60
58
  const handleRenderedItems = async ({ startIndex }) => {
61
59
  const rowsLength = allResults.length;
@@ -101,23 +99,19 @@ const SearchResults = ({
101
99
  </div>
102
100
  <VirtualList
103
101
  width="100%"
104
- height={window.innerHeight - SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST}
102
+ height={
103
+ window.innerHeight -
104
+ SEARCH_RESULTS_ELEMENTS_HEIGHT_ABOVE_LIST -
105
+ SEARCH_RESULTS_HEIGHT_OFFSET
106
+ }
105
107
  itemCount={allResults.length}
106
108
  itemSize={SEARCH_RESULTS_ITEM_SIZE}
107
109
  overscanCount={SEARCH_RESULTS_OVER_SCAN_BUFFER}
108
110
  scrollToIndex={currentIndex}
109
111
  onItemsRendered={handleRenderedItems}
110
112
  renderItem={({ index, style }) => {
111
- const {
112
- id,
113
- docType,
114
- updated,
115
- name,
116
- entityIdentifier,
117
- published,
118
- created,
119
- status
120
- } = allResults[index];
113
+ const { id, docType, updated, name, entityIdentifier, published, created, status } =
114
+ allResults[index];
121
115
  const updatedDate = updated ? getDateFormat(updated) : null;
122
116
  const createdDate = created ? getDateFormat(created) : null;
123
117
  const publishedDate = published ? getDateFormat(published) : null;
@@ -53,15 +53,12 @@ const SearchPublishedContent = ({
53
53
  [displaySearchBar]
54
54
  );
55
55
 
56
- useEffect(
57
- () => {
58
- if (debouncedSearchTerm && debouncedSearchTerm !== previousSearchTerm) {
59
- setQueryParams({ value: `${debouncedSearchTerm}*` });
60
- setPreviousSearchTerm(debouncedSearchTerm);
61
- }
62
- },
63
- [debouncedSearchTerm, previousSearchTerm, setQueryParams]
64
- );
56
+ useEffect(() => {
57
+ if (debouncedSearchTerm && debouncedSearchTerm !== previousSearchTerm) {
58
+ setQueryParams({ value: `${debouncedSearchTerm}*` });
59
+ setPreviousSearchTerm(debouncedSearchTerm);
60
+ }
61
+ }, [debouncedSearchTerm, previousSearchTerm, setQueryParams]);
65
62
 
66
63
  const handleOnChange = ({ target: { value = '' } = {} }) => {
67
64
  onChange(value);
@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
2
2
  import { useLazyQuery } from '@apollo/client';
3
3
  import searchQueries from '../../application/query';
4
4
 
5
- function useSearch({ queryKey, resultKeys, entities = [], fields, extraFilters }) {
5
+ function useSearch({ queryKey, resultKeys, entities = [], fields, extraFilters, queryHook }) {
6
6
  const [queryParams, setParams] = useState({ limit: 20, offset: 0, value: '' });
7
7
  const [searchedValue, setSearchedValue] = useState(null);
8
8
  const [previousEntities, setPreviousEntities] = useState([]);
@@ -31,67 +31,67 @@ function useSearch({ queryKey, resultKeys, entities = [], fields, extraFilters }
31
31
  setParams({ ...queryParams, ...newQueryParams });
32
32
  };
33
33
 
34
- useEffect(
35
- () => {
36
- const { limit, offset, value } = queryParams;
37
- const isNewValueSet = value && value !== searchedValue;
38
- const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;
39
- const notSameLength = previousEntities.length !== entities.length;
40
- const parsedEntities = entities.length
41
- ? entities.map(entity => ({
42
- match: { docType: entity }
43
- }))
44
- : [];
34
+ useEffect(() => {
35
+ const { limit, offset, value } = queryParams;
36
+ const isNewValueSet = value && value !== searchedValue;
37
+ const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;
38
+ const notSameLength = previousEntities.length !== entities.length;
39
+ const parsedEntities = entities.length
40
+ ? entities.map(entity => ({
41
+ match: { docType: entity }
42
+ }))
43
+ : [];
45
44
 
46
- if (isNewValueSet || isNewOffsetSet || notSameLength) {
47
- getSearchResults({
48
- variables: {
49
- limit,
50
- offset,
51
- rawQuery: {
52
- query: {
53
- bool: {
54
- must: [
55
- {
56
- query_string: {
57
- query: value,
58
- fields,
59
- type: 'most_fields',
60
- default_operator: 'AND',
61
- extraFilters
62
- }
63
- },
64
- {
65
- bool: {
66
- should: parsedEntities
67
- }
45
+ if (value && (isNewValueSet || isNewOffsetSet || notSameLength)) {
46
+ const variables = {
47
+ variables: {
48
+ limit,
49
+ offset,
50
+ rawQuery: {
51
+ query: {
52
+ bool: {
53
+ must: [
54
+ {
55
+ query_string: {
56
+ query: value,
57
+ fields,
58
+ type: 'most_fields',
59
+ default_operator: 'AND',
60
+ extraFilters
68
61
  }
69
- ]
70
- }
62
+ },
63
+ {
64
+ bool: {
65
+ should: parsedEntities
66
+ }
67
+ }
68
+ ]
71
69
  }
72
70
  }
73
71
  }
74
- });
75
- setSearchedValue(value);
76
- setPreviousOffset(offset);
77
- setPreviousEntities(entities);
78
- }
79
- },
80
- [
81
- queryParams,
82
- queryParams.limit,
83
- queryParams.value,
84
- queryParams.offset,
85
- searchedValue,
86
- previousOffset,
87
- getSearchResults,
88
- entities,
89
- fields,
90
- entities.length,
91
- previousEntities.length,
92
- extraFilters
93
- ]
94
- );
72
+ }
73
+ };
74
+ const updatedVariables = queryHook ? queryHook(variables) : variables;
75
+ getSearchResults(updatedVariables);
76
+ setSearchedValue(value);
77
+ setPreviousOffset(offset);
78
+ setPreviousEntities(entities);
79
+ }
80
+ }, [
81
+ queryParams,
82
+ queryParams.limit,
83
+ queryParams.value,
84
+ queryParams.offset,
85
+ searchedValue,
86
+ previousOffset,
87
+ getSearchResults,
88
+ entities,
89
+ fields,
90
+ entities.length,
91
+ previousEntities.length,
92
+ extraFilters,
93
+ queryHook
94
+ ]);
95
95
 
96
96
  return [
97
97
  { searchedValue: queryParams.value, loading, data: { results: results || jsonResults, total } },
@@ -1,7 +1,7 @@
1
1
  import { useState, useEffect } from 'react';
2
2
  import useSearch from '../useSearch';
3
3
 
4
- function useSearchResults({ queryKey, resultKeys, entities, fields }) {
4
+ function useSearchResults({ queryKey, resultKeys, entities, fields, queryHook }) {
5
5
  const [currentResults, setCurrentResults] = useState([]);
6
6
  const [allResults, setAllResults] = useState([]);
7
7
  const [
@@ -11,17 +11,14 @@ function useSearchResults({ queryKey, resultKeys, entities, fields }) {
11
11
  data: { results, total }
12
12
  },
13
13
  setParams
14
- ] = useSearch({ queryKey, resultKeys, entities, fields });
14
+ ] = useSearch({ queryKey, resultKeys, entities, fields, queryHook });
15
15
 
16
- useEffect(
17
- () => {
18
- if (currentResults.length !== results.length) {
19
- setAllResults([...allResults, ...results]);
20
- setCurrentResults(results);
21
- }
22
- },
23
- [allResults, currentResults, results]
24
- );
16
+ useEffect(() => {
17
+ if (currentResults.length !== results.length) {
18
+ setAllResults([...allResults, ...results]);
19
+ setCurrentResults(results);
20
+ }
21
+ }, [allResults, currentResults, results]);
25
22
 
26
23
  const clearList = params => {
27
24
  setAllResults([]);
package/src/constants.js CHANGED
@@ -1,7 +1,8 @@
1
1
  const SEARCH_ADMIN = 'SEARCH_ADMIN';
2
2
  const SEARCH_PUBLISHED = 'SEARCH_PUBLISHED';
3
3
  const SEARCH_RESULTS_OVER_SCAN_BUFFER = 0;
4
- const SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST = 186;
4
+ const SEARCH_RESULTS_ELEMENTS_HEIGHT_ABOVE_LIST = 186;
5
+ const SEARCH_RESULTS_HEIGHT_OFFSET = 100;
5
6
  const SEARCH_RESULTS_ITEM_SIZE = 105;
6
7
  const DEFAULT_RESULTS_KEYS = 'name, url';
7
8
  const SEARCH_BUTTON = 'search-button';
@@ -11,7 +12,8 @@ export {
11
12
  SEARCH_ADMIN,
12
13
  SEARCH_PUBLISHED,
13
14
  SEARCH_RESULTS_OVER_SCAN_BUFFER,
14
- SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST,
15
+ SEARCH_RESULTS_ELEMENTS_HEIGHT_ABOVE_LIST,
16
+ SEARCH_RESULTS_HEIGHT_OFFSET,
15
17
  SEARCH_RESULTS_ITEM_SIZE,
16
18
  DEFAULT_RESULTS_KEYS,
17
19
  SEARCH_BUTTON,
@@ -3,7 +3,7 @@ import { useDebounce } from '@blaze-react/utils/lib/customHooks';
3
3
  import useSearchResults from '../components/useSearchResults';
4
4
  import { SEARCH_PUBLISHED } from '../constants';
5
5
 
6
- const useDebounceSearch = ({ entities, resultKeys, fields, initialSearchTerm }) => {
6
+ const useDebounceSearch = ({ entities, resultKeys, fields, initialSearchTerm, queryHook }) => {
7
7
  const [searchTerm, setSearchTerm] = useState(initialSearchTerm ?? '');
8
8
  const [previousSearchTerm, setPreviousSearchTerm] = useState(null);
9
9
  const debouncedSearchTerm = useDebounce(searchTerm, 500);
@@ -12,18 +12,16 @@ const useDebounceSearch = ({ entities, resultKeys, fields, initialSearchTerm })
12
12
  queryKey: SEARCH_PUBLISHED,
13
13
  resultKeys,
14
14
  entities,
15
- fields
15
+ fields,
16
+ queryHook
16
17
  });
17
18
 
18
- useEffect(
19
- () => {
20
- if (debouncedSearchTerm && debouncedSearchTerm !== previousSearchTerm) {
21
- setQueryParams({ value: debouncedSearchTerm });
22
- setPreviousSearchTerm(debouncedSearchTerm);
23
- }
24
- },
25
- [debouncedSearchTerm, previousSearchTerm, setQueryParams]
26
- );
19
+ useEffect(() => {
20
+ if (debouncedSearchTerm && debouncedSearchTerm !== previousSearchTerm) {
21
+ setQueryParams({ value: debouncedSearchTerm });
22
+ setPreviousSearchTerm(debouncedSearchTerm);
23
+ }
24
+ }, [debouncedSearchTerm, previousSearchTerm, setQueryParams]);
27
25
 
28
26
  return {
29
27
  loading,