@blaze-cms/plugin-search-ui 0.129.0 → 0.130.0-admin-updates.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.
- package/CHANGELOG.md +25 -0
- package/lib/components/SearchAdmin/SearchAdmin.js +59 -19
- package/lib/components/SearchAdmin/SearchAdmin.js.map +1 -1
- package/lib/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js +113 -0
- package/lib/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js.map +1 -0
- package/lib/components/SearchAdmin/SearchAdminSideBar/index.js +12 -0
- package/lib/components/SearchAdmin/SearchAdminSideBar/index.js.map +1 -0
- package/lib/components/SearchAdmin/SearchResults/SearchResults.js +47 -13
- package/lib/components/SearchAdmin/SearchResults/SearchResults.js.map +1 -1
- package/lib/components/useSearch/useSearch.js +11 -5
- package/lib/components/useSearch/useSearch.js.map +1 -1
- package/lib/components/useSearchResults/useSearchResults.js +9 -9
- package/lib/components/useSearchResults/useSearchResults.js.map +1 -1
- package/lib-es/components/SearchAdmin/SearchAdmin.js +33 -10
- package/lib-es/components/SearchAdmin/SearchAdmin.js.map +1 -1
- package/lib-es/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js +76 -0
- package/lib-es/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js.map +1 -0
- package/lib-es/components/SearchAdmin/SearchAdminSideBar/index.js +3 -0
- package/lib-es/components/SearchAdmin/SearchAdminSideBar/index.js.map +1 -0
- package/lib-es/components/SearchAdmin/SearchResults/SearchResults.js +38 -11
- package/lib-es/components/SearchAdmin/SearchResults/SearchResults.js.map +1 -1
- package/lib-es/components/useSearch/useSearch.js +5 -2
- package/lib-es/components/useSearch/useSearch.js.map +1 -1
- package/lib-es/components/useSearchResults/useSearchResults.js +3 -3
- package/lib-es/components/useSearchResults/useSearchResults.js.map +1 -1
- package/package.json +6 -6
- package/src/components/SearchAdmin/SearchAdmin.js +61 -41
- package/src/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js +88 -0
- package/src/components/SearchAdmin/SearchAdminSideBar/index.js +3 -0
- package/src/components/SearchAdmin/SearchResults/SearchResults.js +98 -41
- package/src/components/useSearch/useSearch.js +8 -2
- package/src/components/useSearchResults/useSearchResults.js +3 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearchResults.js","names":["useState","useEffect","useSearch","useSearchResults","queryKey","resultKeys","entities","fields","
|
|
1
|
+
{"version":3,"file":"useSearchResults.js","names":["useState","useEffect","useSearch","useSearchResults","queryKey","resultKeys","entities","fields","currentResults","setCurrentResults","allResults","setAllResults","searchedValue","loading","data","results","total","setParams","length","clearList","params","_objectSpread","offset","setQueryParams","value"],"sources":["../../../src/components/useSearchResults/useSearchResults.js"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport useSearch from '../useSearch';\n\nfunction useSearchResults({ queryKey, resultKeys, entities, fields }) {\n const [currentResults, setCurrentResults] = useState([]);\n const [allResults, setAllResults] = useState([]);\n const [\n {\n searchedValue,\n loading,\n data: { results, total }\n },\n setParams\n ] = useSearch({ queryKey, resultKeys, entities, fields });\n\n useEffect(\n () => {\n if (currentResults.length !== results.length) {\n setAllResults([...allResults, ...results]);\n setCurrentResults(results);\n }\n },\n [allResults, currentResults, results]\n );\n\n const clearList = params => {\n setAllResults([]);\n setParams({ ...params, offset: 0 });\n };\n\n const setQueryParams = params => {\n params.value !== searchedValue ? clearList(params) : setParams(params);\n };\n return [{ loading, results: allResults, total }, setQueryParams];\n}\n\nexport default useSearchResults;\n"],"mappings":";;;AAAA,SAASA,QAAQ,EAAEC,SAAS,QAAQ,OAAO;AAC3C,OAAOC,SAAS,MAAM,cAAc;AAEpC,SAASC,gBAAgBA,CAAC;EAAEC,QAAQ;EAAEC,UAAU;EAAEC,QAAQ;EAAEC;AAAO,CAAC,EAAE;EACpE,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGT,QAAQ,CAAC,EAAE,CAAC;EACxD,MAAM,CAACU,UAAU,EAAEC,aAAa,CAAC,GAAGX,QAAQ,CAAC,EAAE,CAAC;EAChD,MAAM,CACJ;IACEY,aAAa;IACbC,OAAO;IACPC,IAAI,EAAE;MAAEC,OAAO;MAAEC;IAAM;EACzB,CAAC,EACDC,SAAS,CACV,GAAGf,SAAS,CAAC;IAAEE,QAAQ;IAAEC,UAAU;IAAEC,QAAQ;IAAEC;EAAO,CAAC,CAAC;EAEzDN,SAAS,CACP,MAAM;IACJ,IAAIO,cAAc,CAACU,MAAM,KAAKH,OAAO,CAACG,MAAM,EAAE;MAC5CP,aAAa,CAAC,CAAC,GAAGD,UAAU,EAAE,GAAGK,OAAO,CAAC,CAAC;MAC1CN,iBAAiB,CAACM,OAAO,CAAC;IAC5B;EACF,CAAC,EACD,CAACL,UAAU,EAAEF,cAAc,EAAEO,OAAO,CACtC,CAAC;EAED,MAAMI,SAAS,GAAGC,MAAM,IAAI;IAC1BT,aAAa,CAAC,EAAE,CAAC;IACjBM,SAAS,CAAAI,aAAA,CAAAA,aAAA,KAAMD,MAAM;MAAEE,MAAM,EAAE;IAAC,EAAE,CAAC;EACrC,CAAC;EAED,MAAMC,cAAc,GAAGH,MAAM,IAAI;IAC/BA,MAAM,CAACI,KAAK,KAAKZ,aAAa,GAAGO,SAAS,CAACC,MAAM,CAAC,GAAGH,SAAS,CAACG,MAAM,CAAC;EACxE,CAAC;EACD,OAAO,CAAC;IAAEP,OAAO;IAAEE,OAAO,EAAEL,UAAU;IAAEM;EAAM,CAAC,EAAEO,cAAc,CAAC;AAClE;AAEA,eAAepB,gBAAgB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaze-cms/plugin-search-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.130.0-admin-updates.0",
|
|
4
4
|
"description": "Blaze plugin search ui",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-es/index.js",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "GPL-3.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@blaze-cms/admin-ui-utils": "
|
|
31
|
-
"@blaze-cms/core-errors": "
|
|
32
|
-
"@blaze-cms/setup-ui": "
|
|
30
|
+
"@blaze-cms/admin-ui-utils": "0.130.0-admin-updates.0",
|
|
31
|
+
"@blaze-cms/core-errors": "0.130.0-admin-updates.0",
|
|
32
|
+
"@blaze-cms/setup-ui": "0.130.0-admin-updates.0",
|
|
33
33
|
"@blaze-react/button": "0.5.19",
|
|
34
34
|
"@blaze-react/input": "0.5.30",
|
|
35
35
|
"@blaze-react/utils": "0.5.15",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"react-tiny-virtual-list": "2.2.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@blaze-cms/core-ui": "
|
|
43
|
+
"@blaze-cms/core-ui": "0.130.0-admin-updates.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@apollo/client": "3.x",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"lib/*",
|
|
53
53
|
"lib-es/*"
|
|
54
54
|
],
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "8a7ba4ac0daaa44b8273afc4c23c2ac4f0788ca0"
|
|
56
56
|
}
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import React, { useState, useRef, useEffect } from 'react';
|
|
2
2
|
import classnames from 'classnames';
|
|
3
|
+
import { useDebounce } from '@blaze-react/utils/lib/customHooks';
|
|
3
4
|
import useLocalStorage from '../useLocalStorage';
|
|
4
5
|
import SearchBar from './SearchBar';
|
|
5
6
|
import RecentSearches from './RecentSearches';
|
|
6
7
|
import SearchResults from './SearchResults';
|
|
7
8
|
import TriggerModal from './TriggerModal';
|
|
9
|
+
import SearchAdminSideBar from './SearchAdminSideBar';
|
|
8
10
|
import useSearchResults from '../useSearchResults';
|
|
9
11
|
import { SEARCH_ADMIN } from '../../constants';
|
|
10
12
|
|
|
11
13
|
const SearchAdmin = () => {
|
|
12
14
|
const [searchTerm, setSearchTerm] = useState('');
|
|
15
|
+
const [openSearchSideBar, setOpenSearchSideBar] = useState(true);
|
|
16
|
+
const [entityValues, setEntityValues] = useState([]);
|
|
17
|
+
|
|
13
18
|
const [recentSearches, setRecentSearches] = useLocalStorage('recentSearches', []);
|
|
14
19
|
const [displaySearchModalFrame, setDisplaySearchModalFrame] = useState(false);
|
|
15
20
|
const [enableResults, setEnableResults] = useState(true);
|
|
16
21
|
const searchInputRef = useRef(null);
|
|
22
|
+
const debouncedEntityValues = useDebounce(entityValues, 500);
|
|
17
23
|
const [{ loading, results, total }, setQueryParams] = useSearchResults({
|
|
18
|
-
queryKey: SEARCH_ADMIN
|
|
24
|
+
queryKey: SEARCH_ADMIN,
|
|
25
|
+
entities: debouncedEntityValues.map(e => e.id)
|
|
19
26
|
});
|
|
20
27
|
|
|
21
28
|
useEffect(
|
|
@@ -30,11 +37,13 @@ const SearchAdmin = () => {
|
|
|
30
37
|
const handleSearchTerm = ({ target: { value } }) => {
|
|
31
38
|
setSearchTerm(value);
|
|
32
39
|
};
|
|
40
|
+
|
|
33
41
|
const toggleSearchModal = () => {
|
|
34
42
|
setSearchTerm(null);
|
|
35
43
|
setEnableResults(false);
|
|
36
44
|
setDisplaySearchModalFrame(!displaySearchModalFrame);
|
|
37
45
|
};
|
|
46
|
+
|
|
38
47
|
const search = ({ value }) => {
|
|
39
48
|
if (!value) return;
|
|
40
49
|
!enableResults && setEnableResults(true);
|
|
@@ -68,58 +77,69 @@ const SearchAdmin = () => {
|
|
|
68
77
|
'modal--show': displaySearchModalFrame
|
|
69
78
|
});
|
|
70
79
|
|
|
80
|
+
const searchModalSideBarClassName = classnames('modal__search__sidebar', {
|
|
81
|
+
'modal__search__sidebar--close': !openSearchSideBar
|
|
82
|
+
});
|
|
83
|
+
|
|
71
84
|
const isEmptySearchTermAndData = !searchTerm && !results.length;
|
|
72
85
|
const isEmptySearchTermnAndDisabledResults = !searchTerm && !enableResults;
|
|
73
86
|
const shouldDisplayRecentSearches =
|
|
74
87
|
isEmptySearchTermAndData || isEmptySearchTermnAndDisabledResults;
|
|
75
88
|
|
|
76
|
-
const
|
|
89
|
+
const handleSetEntityValues = newEntity => {
|
|
90
|
+
const entityExists = entityValues.some(entity => entity.id === newEntity.id);
|
|
91
|
+
if (entityExists) {
|
|
92
|
+
setEntityValues(entityValues.filter(entity => entity.id !== newEntity.id));
|
|
93
|
+
} else {
|
|
94
|
+
setEntityValues([...entityValues, newEntity]);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
77
97
|
|
|
78
98
|
return (
|
|
79
99
|
<div className="search search--header">
|
|
80
100
|
<TriggerModal toggleSearchModal={toggleSearchModal} />
|
|
81
101
|
<div className={searchModalResultsClassName}>
|
|
82
102
|
{displaySearchModalFrame && (
|
|
83
|
-
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
<div className="modal__search">
|
|
104
|
+
<SearchAdminSideBar
|
|
105
|
+
searchModalSideBarClassName={searchModalSideBarClassName}
|
|
106
|
+
openSearchSideBar={openSearchSideBar}
|
|
107
|
+
setOpenSearchSideBar={setOpenSearchSideBar}
|
|
108
|
+
handleSetEntityValues={handleSetEntityValues}
|
|
109
|
+
entityValues={entityValues}
|
|
110
|
+
setEntityValues={setEntityValues}
|
|
111
|
+
/>
|
|
112
|
+
<div className="modal__search__content">
|
|
113
|
+
<div className="modal__header modal__header--search">
|
|
114
|
+
<SearchBar
|
|
115
|
+
toggleSearchModal={toggleSearchModal}
|
|
116
|
+
handleKeyDown={handleKeyDown}
|
|
117
|
+
searchInputRef={searchInputRef}
|
|
118
|
+
handleSearchTerm={handleSearchTerm}
|
|
119
|
+
searchTerm={searchTerm}
|
|
120
|
+
search={() => search({ value: searchTerm })}
|
|
121
|
+
/>
|
|
122
|
+
</div>
|
|
123
|
+
{shouldDisplayRecentSearches && (
|
|
124
|
+
<RecentSearches
|
|
125
|
+
recentSearches={recentSearches}
|
|
126
|
+
handleSearchTerm={handleSearchTerm}
|
|
127
|
+
search={search}
|
|
128
|
+
/>
|
|
129
|
+
)}
|
|
130
|
+
{enableResults && (
|
|
131
|
+
<SearchResults
|
|
132
|
+
currentValue={searchTerm}
|
|
133
|
+
searchTerm={searchTerm}
|
|
134
|
+
loading={loading}
|
|
135
|
+
results={results}
|
|
136
|
+
total={total}
|
|
137
|
+
setQueryParams={setQueryParams}
|
|
138
|
+
closeModal={toggleSearchModal}
|
|
139
|
+
/>
|
|
140
|
+
)}
|
|
93
141
|
</div>
|
|
94
|
-
|
|
95
|
-
<RecentSearches
|
|
96
|
-
recentSearches={recentSearches}
|
|
97
|
-
handleSearchTerm={handleSearchTerm}
|
|
98
|
-
search={search}
|
|
99
|
-
/>
|
|
100
|
-
) : (
|
|
101
|
-
<>
|
|
102
|
-
{!showResults && (
|
|
103
|
-
<div className="list list--search">
|
|
104
|
-
<div className="header header--list">
|
|
105
|
-
<h2>No Results</h2>
|
|
106
|
-
</div>
|
|
107
|
-
</div>
|
|
108
|
-
)}
|
|
109
|
-
</>
|
|
110
|
-
)}
|
|
111
|
-
{showResults && (
|
|
112
|
-
<SearchResults
|
|
113
|
-
currentValue={searchTerm}
|
|
114
|
-
searchTerm={searchTerm}
|
|
115
|
-
loading={loading}
|
|
116
|
-
results={results}
|
|
117
|
-
total={total}
|
|
118
|
-
setQueryParams={setQueryParams}
|
|
119
|
-
closeModal={toggleSearchModal}
|
|
120
|
-
/>
|
|
121
|
-
)}
|
|
122
|
-
</>
|
|
142
|
+
</div>
|
|
123
143
|
)}
|
|
124
144
|
</div>
|
|
125
145
|
</div>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { useQuery } from '@apollo/client';
|
|
3
|
+
import { getQuery } from '@blaze-cms/admin-ui-utils';
|
|
4
|
+
import { Checkbox } from '@blaze-react/checkboxes';
|
|
5
|
+
|
|
6
|
+
const MENU_PERMISSIONS = ['update:any', 'update:own', 'create:any', 'create:own'];
|
|
7
|
+
|
|
8
|
+
const SearchAdminSideBar = ({
|
|
9
|
+
searchModalSideBarClassName,
|
|
10
|
+
openSearchSideBar,
|
|
11
|
+
setOpenSearchSideBar,
|
|
12
|
+
handleSetEntityValues,
|
|
13
|
+
entityValues,
|
|
14
|
+
setEntityValues
|
|
15
|
+
}) => {
|
|
16
|
+
const [loadMore, setLoadMore] = useState(false);
|
|
17
|
+
const { data: { getEntitySchemas = [] } = {}, loading } = useQuery(
|
|
18
|
+
getQuery('GET_USER_EDITABLE_ENTITIES'),
|
|
19
|
+
{
|
|
20
|
+
variables: {
|
|
21
|
+
canDoActions: MENU_PERMISSIONS
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (loading) return null;
|
|
27
|
+
|
|
28
|
+
const filteredEntitiesSchemas = getEntitySchemas.filter(entity => {
|
|
29
|
+
if (Object.keys(entity.extras).length) {
|
|
30
|
+
return entity.extras.searchIndexes.includes('admin');
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const entitiesToShow = filteredEntitiesSchemas.slice(
|
|
36
|
+
0,
|
|
37
|
+
loadMore ? filteredEntitiesSchemas.length : 5
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className={searchModalSideBarClassName}>
|
|
42
|
+
<div
|
|
43
|
+
className="modal__search__sidebar__button"
|
|
44
|
+
role="button"
|
|
45
|
+
onClick={() => setOpenSearchSideBar(!openSearchSideBar)}>
|
|
46
|
+
<i className="material-icons">
|
|
47
|
+
{openSearchSideBar ? 'keyboard_arrow_left' : 'keyboard_arrow_right'}
|
|
48
|
+
</i>
|
|
49
|
+
</div>
|
|
50
|
+
<div className="modal__search__sidebar__container">
|
|
51
|
+
<div className="modal__search__sidebar__wrapper">
|
|
52
|
+
<div className="modal__search__sidebar__filters">
|
|
53
|
+
<i className="material-icons modal__search__sidebar__icon">tune</i>
|
|
54
|
+
<span>Filters</span>
|
|
55
|
+
</div>
|
|
56
|
+
<div
|
|
57
|
+
className="modal__search__sidebar__clear"
|
|
58
|
+
role="button"
|
|
59
|
+
onClick={() => setEntityValues([])}>
|
|
60
|
+
<span>Clear all</span>
|
|
61
|
+
<i className="material-icons modal__search__sidebar__icon--clear">replay</i>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
<div className="modal__search__sidebar__entity-list">
|
|
65
|
+
<h1>Entity list</h1>
|
|
66
|
+
{entitiesToShow.map(entity => (
|
|
67
|
+
<Checkbox
|
|
68
|
+
checked={entityValues.some(_entity => _entity.id === entity.id)}
|
|
69
|
+
label={entity.displayName}
|
|
70
|
+
id={entity.id}
|
|
71
|
+
name={entity.id}
|
|
72
|
+
onChange={({ value: { checked } }) => handleSetEntityValues(entity)}
|
|
73
|
+
/>
|
|
74
|
+
))}
|
|
75
|
+
<div
|
|
76
|
+
className="modal__search__sidebar__more"
|
|
77
|
+
role="button"
|
|
78
|
+
onClick={() => setLoadMore(!loadMore)}>
|
|
79
|
+
<i className="material-icons">{!loadMore ? 'navigate_next' : 'expand_less'}</i>
|
|
80
|
+
<span>{loadMore ? 'Less' : 'More'}</span>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default SearchAdminSideBar;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
2
2
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
3
|
-
import React, { useState } from 'react';
|
|
3
|
+
import React, { useState, useEffect } from 'react';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import VirtualList from 'react-tiny-virtual-list';
|
|
6
6
|
import { withRouter } from 'react-router-dom';
|
|
@@ -22,6 +22,20 @@ const SearchResults = ({
|
|
|
22
22
|
}) => {
|
|
23
23
|
const [verifiedRanges, setVerifiedRanges] = useState([]);
|
|
24
24
|
const [currentIndex, setCurrentIndex] = useState(0);
|
|
25
|
+
const [currentResults, setCurrentResults] = useState([]);
|
|
26
|
+
const [currentTotal, setCurrentTotal] = useState(0);
|
|
27
|
+
|
|
28
|
+
useEffect(
|
|
29
|
+
() => {
|
|
30
|
+
if (!loading) {
|
|
31
|
+
const [lowestRange] = verifiedRanges;
|
|
32
|
+
setCurrentTotal(total);
|
|
33
|
+
setCurrentResults(results);
|
|
34
|
+
if (lowestRange > results.length) setVerifiedRanges([]);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
[loading, results, total, verifiedRanges]
|
|
38
|
+
);
|
|
25
39
|
|
|
26
40
|
const handleRenderedItems = async ({ startIndex }) => {
|
|
27
41
|
const rowsLength = results.length;
|
|
@@ -49,53 +63,96 @@ const SearchResults = ({
|
|
|
49
63
|
return `${day}.${month}.${year}`;
|
|
50
64
|
};
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<div className="modal__content modal__content--search">
|
|
66
|
+
if (!currentResults.length)
|
|
67
|
+
return (
|
|
68
|
+
<div className="list list--search">
|
|
56
69
|
<div className="header header--list">
|
|
57
|
-
<h2>
|
|
70
|
+
<h2>No Results</h2>
|
|
58
71
|
</div>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div className="modal__content modal__content--search">
|
|
77
|
+
<div className="header header--list">
|
|
78
|
+
<h2 className="header--list--results">
|
|
79
|
+
About <b>{currentTotal}</b> search keywords results
|
|
80
|
+
</h2>
|
|
81
|
+
</div>
|
|
82
|
+
<VirtualList
|
|
83
|
+
width="100%"
|
|
84
|
+
height={window.innerHeight - SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST}
|
|
85
|
+
itemCount={currentResults.length}
|
|
86
|
+
itemSize={SEARCH_RESULTS_ITEM_SIZE}
|
|
87
|
+
overscanCount={SEARCH_RESULTS_OVER_SCAN_BUFFER}
|
|
88
|
+
scrollToIndex={currentIndex}
|
|
89
|
+
onItemsRendered={handleRenderedItems}
|
|
90
|
+
renderItem={({ index, style }) => {
|
|
91
|
+
const {
|
|
92
|
+
id,
|
|
93
|
+
docType,
|
|
94
|
+
updated,
|
|
95
|
+
name,
|
|
96
|
+
entityIdentifier,
|
|
97
|
+
published,
|
|
98
|
+
created,
|
|
99
|
+
status
|
|
100
|
+
} = currentResults[index];
|
|
101
|
+
const updatedDate = updated ? getDateFormat(updated) : null;
|
|
102
|
+
const createdDate = created ? getDateFormat(created) : null;
|
|
103
|
+
const publishedDate = published ? getDateFormat(published) : null;
|
|
104
|
+
return (
|
|
105
|
+
<div key={index} style={style} className="list__item--resultWrapper">
|
|
106
|
+
<div className="list__item list__item--result">
|
|
107
|
+
<div className="list__item-row list__item-row--result">
|
|
108
|
+
<span className="list__item-identifier">{entityIdentifier}</span>
|
|
109
|
+
<a
|
|
110
|
+
href={getNavigationRoute({
|
|
111
|
+
id,
|
|
112
|
+
docType
|
|
113
|
+
})}
|
|
114
|
+
onClick={() =>
|
|
115
|
+
navigate({
|
|
79
116
|
id,
|
|
80
117
|
docType
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
className="list__item-link">
|
|
121
|
+
{name}
|
|
122
|
+
</a>
|
|
123
|
+
|
|
124
|
+
<div className="list__item-dates">
|
|
125
|
+
{publishedDate && (
|
|
126
|
+
<span>
|
|
127
|
+
<b>Published: </b>
|
|
128
|
+
{publishedDate}
|
|
129
|
+
</span>
|
|
130
|
+
)}
|
|
131
|
+
<span>
|
|
132
|
+
<b>Created: </b>
|
|
133
|
+
{createdDate}
|
|
134
|
+
</span>
|
|
135
|
+
<span>
|
|
136
|
+
<b>Updated: </b>
|
|
137
|
+
{updatedDate}
|
|
138
|
+
</span>
|
|
139
|
+
</div>
|
|
140
|
+
<div className="list__item-status">
|
|
141
|
+
{status && (
|
|
142
|
+
<span>
|
|
143
|
+
<b>Status: </b>
|
|
144
|
+
{status}
|
|
145
|
+
</span>
|
|
146
|
+
)}
|
|
91
147
|
</div>
|
|
92
148
|
</div>
|
|
93
149
|
</div>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
{loading && <span>Loading...</span>}
|
|
155
|
+
</div>
|
|
99
156
|
);
|
|
100
157
|
};
|
|
101
158
|
|
|
@@ -5,8 +5,10 @@ import searchQueries from '../../application/query';
|
|
|
5
5
|
function useSearch({ queryKey, resultKeys, entities = [], fields }) {
|
|
6
6
|
const [queryParams, setParams] = useState({ limit: 20, offset: 0, value: '' });
|
|
7
7
|
const [searchedValue, setSearchedValue] = useState(null);
|
|
8
|
+
const [previousEntities, setPreviousEntities] = useState([]);
|
|
8
9
|
const [previousOffset, setPreviousOffset] = useState(null);
|
|
9
10
|
const buildSearchQuery = searchQueries[queryKey];
|
|
11
|
+
|
|
10
12
|
const [
|
|
11
13
|
getSearchResults,
|
|
12
14
|
{
|
|
@@ -28,13 +30,14 @@ function useSearch({ queryKey, resultKeys, entities = [], fields }) {
|
|
|
28
30
|
const { limit, offset, value } = queryParams;
|
|
29
31
|
const isNewValueSet = value && value !== searchedValue;
|
|
30
32
|
const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;
|
|
33
|
+
const notSameLength = previousEntities.length !== entities.length;
|
|
31
34
|
const parsedEntities = entities.length
|
|
32
35
|
? entities.map(entity => ({
|
|
33
36
|
match: { docType: entity }
|
|
34
37
|
}))
|
|
35
38
|
: [];
|
|
36
39
|
|
|
37
|
-
if (isNewValueSet || isNewOffsetSet) {
|
|
40
|
+
if (isNewValueSet || isNewOffsetSet || notSameLength) {
|
|
38
41
|
getSearchResults({
|
|
39
42
|
variables: {
|
|
40
43
|
limit,
|
|
@@ -64,6 +67,7 @@ function useSearch({ queryKey, resultKeys, entities = [], fields }) {
|
|
|
64
67
|
});
|
|
65
68
|
setSearchedValue(value);
|
|
66
69
|
setPreviousOffset(offset);
|
|
70
|
+
setPreviousEntities(entities);
|
|
67
71
|
}
|
|
68
72
|
},
|
|
69
73
|
[
|
|
@@ -75,7 +79,9 @@ function useSearch({ queryKey, resultKeys, entities = [], fields }) {
|
|
|
75
79
|
previousOffset,
|
|
76
80
|
getSearchResults,
|
|
77
81
|
entities,
|
|
78
|
-
fields
|
|
82
|
+
fields,
|
|
83
|
+
entities.length,
|
|
84
|
+
previousEntities.length
|
|
79
85
|
]
|
|
80
86
|
);
|
|
81
87
|
|
|
@@ -2,6 +2,8 @@ import { useState, useEffect } from 'react';
|
|
|
2
2
|
import useSearch from '../useSearch';
|
|
3
3
|
|
|
4
4
|
function useSearchResults({ queryKey, resultKeys, entities, fields }) {
|
|
5
|
+
const [currentResults, setCurrentResults] = useState([]);
|
|
6
|
+
const [allResults, setAllResults] = useState([]);
|
|
5
7
|
const [
|
|
6
8
|
{
|
|
7
9
|
searchedValue,
|
|
@@ -10,8 +12,6 @@ function useSearchResults({ queryKey, resultKeys, entities, fields }) {
|
|
|
10
12
|
},
|
|
11
13
|
setParams
|
|
12
14
|
] = useSearch({ queryKey, resultKeys, entities, fields });
|
|
13
|
-
const [currentResults, setCurrentResults] = useState([]);
|
|
14
|
-
const [allResults, setAllResults] = useState([]);
|
|
15
15
|
|
|
16
16
|
useEffect(
|
|
17
17
|
() => {
|
|
@@ -20,7 +20,7 @@ function useSearchResults({ queryKey, resultKeys, entities, fields }) {
|
|
|
20
20
|
setCurrentResults(results);
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
|
-
[allResults, currentResults,
|
|
23
|
+
[allResults, currentResults, results]
|
|
24
24
|
);
|
|
25
25
|
|
|
26
26
|
const clearList = params => {
|
|
@@ -31,7 +31,6 @@ function useSearchResults({ queryKey, resultKeys, entities, fields }) {
|
|
|
31
31
|
const setQueryParams = params => {
|
|
32
32
|
params.value !== searchedValue ? clearList(params) : setParams(params);
|
|
33
33
|
};
|
|
34
|
-
|
|
35
34
|
return [{ loading, results: allResults, total }, setQueryParams];
|
|
36
35
|
}
|
|
37
36
|
|