@blaze-cms/plugin-search-ui 0.129.0-admin-updates.2 → 0.129.0-admin-updates.4
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 +19 -0
- package/lib/components/SearchAdmin/RecentSearches/RecentSearches.js.map +1 -1
- package/lib/components/SearchAdmin/SearchAdmin.js +2 -7
- package/lib/components/SearchAdmin/SearchAdmin.js.map +1 -1
- package/lib/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js.map +1 -1
- package/lib/components/SearchAdmin/SearchBar/SearchBar.js.map +1 -1
- package/lib/components/SearchAdmin/SearchResults/SearchResults.js +35 -13
- package/lib/components/SearchAdmin/SearchResults/SearchResults.js.map +1 -1
- package/lib/components/SearchAdmin/TriggerModal/TriggerModal.js.map +1 -1
- package/lib/components/SearchPublishedContent/SearchPublishedContent.js.map +1 -1
- package/lib/components/useSearch/useSearch.js +5 -5
- package/lib/components/useSearch/useSearch.js.map +1 -1
- package/lib/components/useSearchResults/useSearchResults.js +19 -1
- package/lib/components/useSearchResults/useSearchResults.js.map +1 -1
- package/lib/hooks/useDebounceSearch.js.map +1 -1
- package/lib-es/components/SearchAdmin/RecentSearches/RecentSearches.js.map +1 -1
- package/lib-es/components/SearchAdmin/SearchAdmin.js +2 -7
- package/lib-es/components/SearchAdmin/SearchAdmin.js.map +1 -1
- package/lib-es/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js.map +1 -1
- package/lib-es/components/SearchAdmin/SearchBar/SearchBar.js.map +1 -1
- package/lib-es/components/SearchAdmin/SearchResults/SearchResults.js +21 -6
- package/lib-es/components/SearchAdmin/SearchResults/SearchResults.js.map +1 -1
- package/lib-es/components/SearchAdmin/TriggerModal/TriggerModal.js.map +1 -1
- package/lib-es/components/SearchPublishedContent/SearchPublishedContent.js.map +1 -1
- package/lib-es/components/useSearch/useSearch.js +4 -4
- package/lib-es/components/useSearch/useSearch.js.map +1 -1
- package/lib-es/components/useSearchResults/useSearchResults.js +11 -1
- package/lib-es/components/useSearchResults/useSearchResults.js.map +1 -1
- package/lib-es/hooks/useDebounceSearch.js.map +1 -1
- package/package.json +3 -3
- package/src/components/SearchAdmin/SearchAdmin.js +4 -14
- package/src/components/SearchAdmin/SearchResults/SearchResults.js +93 -72
- package/src/components/useSearch/useSearch.js +5 -5
- package/src/components/useSearchResults/useSearchResults.js +15 -2
|
@@ -37,11 +37,13 @@ const SearchAdmin = () => {
|
|
|
37
37
|
const handleSearchTerm = ({ target: { value } }) => {
|
|
38
38
|
setSearchTerm(value);
|
|
39
39
|
};
|
|
40
|
+
|
|
40
41
|
const toggleSearchModal = () => {
|
|
41
42
|
setSearchTerm(null);
|
|
42
43
|
setEnableResults(false);
|
|
43
44
|
setDisplaySearchModalFrame(!displaySearchModalFrame);
|
|
44
45
|
};
|
|
46
|
+
|
|
45
47
|
const search = ({ value }) => {
|
|
46
48
|
if (!value) return;
|
|
47
49
|
!enableResults && setEnableResults(true);
|
|
@@ -84,8 +86,6 @@ const SearchAdmin = () => {
|
|
|
84
86
|
const shouldDisplayRecentSearches =
|
|
85
87
|
isEmptySearchTermAndData || isEmptySearchTermnAndDisabledResults;
|
|
86
88
|
|
|
87
|
-
const showResults = enableResults && results.length;
|
|
88
|
-
|
|
89
89
|
const handleSetEntityValues = newEntity => {
|
|
90
90
|
const entityExists = entityValues.some(entity => entity.id === newEntity.id);
|
|
91
91
|
if (entityExists) {
|
|
@@ -120,24 +120,14 @@ const SearchAdmin = () => {
|
|
|
120
120
|
search={() => search({ value: searchTerm })}
|
|
121
121
|
/>
|
|
122
122
|
</div>
|
|
123
|
-
{shouldDisplayRecentSearches
|
|
123
|
+
{shouldDisplayRecentSearches && (
|
|
124
124
|
<RecentSearches
|
|
125
125
|
recentSearches={recentSearches}
|
|
126
126
|
handleSearchTerm={handleSearchTerm}
|
|
127
127
|
search={search}
|
|
128
128
|
/>
|
|
129
|
-
) : (
|
|
130
|
-
<>
|
|
131
|
-
{!showResults && (
|
|
132
|
-
<div className="list list--search">
|
|
133
|
-
<div className="header header--list">
|
|
134
|
-
<h2>No Results</h2>
|
|
135
|
-
</div>
|
|
136
|
-
</div>
|
|
137
|
-
)}
|
|
138
|
-
</>
|
|
139
129
|
)}
|
|
140
|
-
{
|
|
130
|
+
{enableResults && (
|
|
141
131
|
<SearchResults
|
|
142
132
|
currentValue={searchTerm}
|
|
143
133
|
searchTerm={searchTerm}
|
|
@@ -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,89 +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
|
|
58
|
-
About <b>{total}</b> search keywords results
|
|
59
|
-
</h2>
|
|
70
|
+
<h2>No Results</h2>
|
|
60
71
|
</div>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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({
|
|
90
116
|
id,
|
|
91
117
|
docType
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
className="list__item-link">
|
|
100
|
-
{name}
|
|
101
|
-
</a>
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
className="list__item-link">
|
|
121
|
+
{name}
|
|
122
|
+
</a>
|
|
102
123
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
<span>
|
|
106
|
-
<b>Published: </b>
|
|
107
|
-
{publishedDate}
|
|
108
|
-
</span>
|
|
109
|
-
)}
|
|
124
|
+
<div className="list__item-dates">
|
|
125
|
+
{publishedDate && (
|
|
110
126
|
<span>
|
|
111
|
-
<b>
|
|
112
|
-
{
|
|
127
|
+
<b>Published: </b>
|
|
128
|
+
{publishedDate}
|
|
113
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 && (
|
|
114
142
|
<span>
|
|
115
|
-
<b>
|
|
116
|
-
{
|
|
143
|
+
<b>Status: </b>
|
|
144
|
+
{status}
|
|
117
145
|
</span>
|
|
118
|
-
|
|
119
|
-
<div className="list__item-status">
|
|
120
|
-
{status && (
|
|
121
|
-
<span>
|
|
122
|
-
<b>Status: </b>
|
|
123
|
-
{status}
|
|
124
|
-
</span>
|
|
125
|
-
)}
|
|
126
|
-
</div>
|
|
146
|
+
)}
|
|
127
147
|
</div>
|
|
128
148
|
</div>
|
|
129
149
|
</div>
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
150
|
+
</div>
|
|
151
|
+
);
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
{loading && <span>Loading...</span>}
|
|
155
|
+
</div>
|
|
135
156
|
);
|
|
136
157
|
};
|
|
137
158
|
|
|
@@ -5,10 +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 [
|
|
8
|
+
const [previousEntities, setPreviousEntities] = useState([]);
|
|
9
9
|
const [previousOffset, setPreviousOffset] = useState(null);
|
|
10
|
-
|
|
11
10
|
const buildSearchQuery = searchQueries[queryKey];
|
|
11
|
+
|
|
12
12
|
const [
|
|
13
13
|
getSearchResults,
|
|
14
14
|
{
|
|
@@ -30,7 +30,7 @@ function useSearch({ queryKey, resultKeys, entities = [], fields }) {
|
|
|
30
30
|
const { limit, offset, value } = queryParams;
|
|
31
31
|
const isNewValueSet = value && value !== searchedValue;
|
|
32
32
|
const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;
|
|
33
|
-
const notSameLength =
|
|
33
|
+
const notSameLength = previousEntities.length !== entities.length;
|
|
34
34
|
const parsedEntities = entities.length
|
|
35
35
|
? entities.map(entity => ({
|
|
36
36
|
match: { docType: entity }
|
|
@@ -67,7 +67,7 @@ function useSearch({ queryKey, resultKeys, entities = [], fields }) {
|
|
|
67
67
|
});
|
|
68
68
|
setSearchedValue(value);
|
|
69
69
|
setPreviousOffset(offset);
|
|
70
|
-
|
|
70
|
+
setPreviousEntities(entities);
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
[
|
|
@@ -81,7 +81,7 @@ function useSearch({ queryKey, resultKeys, entities = [], fields }) {
|
|
|
81
81
|
entities,
|
|
82
82
|
fields,
|
|
83
83
|
entities.length,
|
|
84
|
-
|
|
84
|
+
previousEntities.length
|
|
85
85
|
]
|
|
86
86
|
);
|
|
87
87
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
1
2
|
import useSearch from '../useSearch';
|
|
2
3
|
|
|
3
4
|
function useSearchResults({ queryKey, resultKeys, entities, fields }) {
|
|
5
|
+
const [currentResults, setCurrentResults] = useState([]);
|
|
6
|
+
const [allResults, setAllResults] = useState([]);
|
|
4
7
|
const [
|
|
5
8
|
{
|
|
6
9
|
searchedValue,
|
|
@@ -10,15 +13,25 @@ function useSearchResults({ queryKey, resultKeys, entities, fields }) {
|
|
|
10
13
|
setParams
|
|
11
14
|
] = useSearch({ queryKey, resultKeys, entities, fields });
|
|
12
15
|
|
|
16
|
+
useEffect(
|
|
17
|
+
() => {
|
|
18
|
+
if (currentResults.length !== results.length) {
|
|
19
|
+
setAllResults([...allResults, ...results]);
|
|
20
|
+
setCurrentResults(results);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
[allResults, currentResults, results]
|
|
24
|
+
);
|
|
25
|
+
|
|
13
26
|
const clearList = params => {
|
|
27
|
+
setAllResults([]);
|
|
14
28
|
setParams({ ...params, offset: 0 });
|
|
15
29
|
};
|
|
16
30
|
|
|
17
31
|
const setQueryParams = params => {
|
|
18
32
|
params.value !== searchedValue ? clearList(params) : setParams(params);
|
|
19
33
|
};
|
|
20
|
-
|
|
21
|
-
return [{ loading, results, total }, setQueryParams];
|
|
34
|
+
return [{ loading, results: allResults, total }, setQueryParams];
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
export default useSearchResults;
|