@blaze-cms/plugin-search-ui 0.133.0 → 0.134.0-project-admin-customisations.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 +27 -0
- package/lib/components/SearchAdmin/SearchAdmin.js +71 -21
- package/lib/components/SearchAdmin/SearchAdmin.js.map +1 -1
- package/lib/components/SearchAdmin/SearchAdminSideBar/SearchAdminSideBar.js +112 -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 +81 -29
- 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 +11 -9
- package/lib/components/useSearchResults/useSearchResults.js.map +1 -1
- package/lib-es/components/SearchAdmin/SearchAdmin.js +44 -12
- 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 +54 -14
- 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 +5 -3
- package/lib-es/components/useSearchResults/useSearchResults.js.map +1 -1
- package/package.json +6 -6
- package/src/components/SearchAdmin/SearchAdmin.js +64 -42
- 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 +122 -44
- package/src/components/useSearch/useSearch.js +6 -1
- package/src/components/useSearchResults/useSearchResults.js +13 -4
|
@@ -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';
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
|
|
14
14
|
const SearchResults = ({
|
|
15
15
|
currentValue,
|
|
16
|
+
entities,
|
|
16
17
|
loading,
|
|
17
18
|
results,
|
|
18
19
|
total,
|
|
@@ -22,12 +23,45 @@ const SearchResults = ({
|
|
|
22
23
|
}) => {
|
|
23
24
|
const [verifiedRanges, setVerifiedRanges] = useState([]);
|
|
24
25
|
const [currentIndex, setCurrentIndex] = useState(0);
|
|
26
|
+
const [currentResults, setCurrentResults] = useState('');
|
|
27
|
+
const [allResults, setAllResults] = useState([]);
|
|
28
|
+
const [currentParams, setCurrentParams] = useState('');
|
|
29
|
+
|
|
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);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
[
|
|
48
|
+
allResults,
|
|
49
|
+
currentParams,
|
|
50
|
+
currentResults,
|
|
51
|
+
currentValue,
|
|
52
|
+
entities,
|
|
53
|
+
loading,
|
|
54
|
+
results,
|
|
55
|
+
total,
|
|
56
|
+
verifiedRanges.length
|
|
57
|
+
]
|
|
58
|
+
);
|
|
25
59
|
|
|
26
60
|
const handleRenderedItems = async ({ startIndex }) => {
|
|
27
|
-
const rowsLength =
|
|
61
|
+
const rowsLength = allResults.length;
|
|
28
62
|
const loadIndex = Math.floor(rowsLength / 2) - SEARCH_RESULTS_OVER_SCAN_BUFFER;
|
|
29
63
|
if (loadIndex > 0 && loadIndex < startIndex && !verifiedRanges.includes(loadIndex)) {
|
|
30
|
-
setQueryParams({ value: currentValue, offset:
|
|
64
|
+
setQueryParams({ value: currentValue, offset: allResults.length });
|
|
31
65
|
setVerifiedRanges([...verifiedRanges, loadIndex]);
|
|
32
66
|
setCurrentIndex(startIndex + SEARCH_RESULTS_OVER_SCAN_BUFFER);
|
|
33
67
|
}
|
|
@@ -49,53 +83,96 @@ const SearchResults = ({
|
|
|
49
83
|
return `${day}.${month}.${year}`;
|
|
50
84
|
};
|
|
51
85
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
<div className="modal__content modal__content--search">
|
|
86
|
+
if (!allResults.length)
|
|
87
|
+
return (
|
|
88
|
+
<div className="list list--search">
|
|
56
89
|
<div className="header header--list">
|
|
57
|
-
<h2>
|
|
90
|
+
<h2>No Results</h2>
|
|
58
91
|
</div>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<div className="modal__content modal__content--search">
|
|
97
|
+
<div className="header header--list">
|
|
98
|
+
<h2 className="header--list--results">
|
|
99
|
+
About <b>{total}</b> search keywords results
|
|
100
|
+
</h2>
|
|
101
|
+
</div>
|
|
102
|
+
<VirtualList
|
|
103
|
+
width="100%"
|
|
104
|
+
height={window.innerHeight - SEARCH_RESULTS_ELEMETS_HEIGHT_ABOVE_LIST}
|
|
105
|
+
itemCount={allResults.length}
|
|
106
|
+
itemSize={SEARCH_RESULTS_ITEM_SIZE}
|
|
107
|
+
overscanCount={SEARCH_RESULTS_OVER_SCAN_BUFFER}
|
|
108
|
+
scrollToIndex={currentIndex}
|
|
109
|
+
onItemsRendered={handleRenderedItems}
|
|
110
|
+
renderItem={({ index, style }) => {
|
|
111
|
+
const {
|
|
112
|
+
id,
|
|
113
|
+
docType,
|
|
114
|
+
updated,
|
|
115
|
+
name,
|
|
116
|
+
entityIdentifier,
|
|
117
|
+
published,
|
|
118
|
+
created,
|
|
119
|
+
status
|
|
120
|
+
} = allResults[index];
|
|
121
|
+
const updatedDate = updated ? getDateFormat(updated) : null;
|
|
122
|
+
const createdDate = created ? getDateFormat(created) : null;
|
|
123
|
+
const publishedDate = published ? getDateFormat(published) : null;
|
|
124
|
+
return (
|
|
125
|
+
<div key={index} style={style} className="list__item--resultWrapper">
|
|
126
|
+
<div className="list__item list__item--result">
|
|
127
|
+
<div className="list__item-row list__item-row--result">
|
|
128
|
+
<span className="list__item-identifier">{entityIdentifier}</span>
|
|
129
|
+
<a
|
|
130
|
+
href={getNavigationRoute({
|
|
131
|
+
id,
|
|
132
|
+
docType
|
|
133
|
+
})}
|
|
134
|
+
onClick={() =>
|
|
135
|
+
navigate({
|
|
79
136
|
id,
|
|
80
137
|
docType
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
className="list__item-link">
|
|
141
|
+
{name}
|
|
142
|
+
</a>
|
|
143
|
+
|
|
144
|
+
<div className="list__item-dates">
|
|
145
|
+
{publishedDate && (
|
|
146
|
+
<span>
|
|
147
|
+
<b>Published: </b>
|
|
148
|
+
{publishedDate}
|
|
149
|
+
</span>
|
|
150
|
+
)}
|
|
151
|
+
<span>
|
|
152
|
+
<b>Created: </b>
|
|
153
|
+
{createdDate}
|
|
154
|
+
</span>
|
|
155
|
+
<span>
|
|
156
|
+
<b>Updated: </b>
|
|
157
|
+
{updatedDate}
|
|
158
|
+
</span>
|
|
159
|
+
</div>
|
|
160
|
+
<div className="list__item-status">
|
|
161
|
+
{status && (
|
|
162
|
+
<span>
|
|
163
|
+
<b>Status: </b>
|
|
164
|
+
{status}
|
|
165
|
+
</span>
|
|
166
|
+
)}
|
|
91
167
|
</div>
|
|
92
168
|
</div>
|
|
93
169
|
</div>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}}
|
|
173
|
+
/>
|
|
174
|
+
{loading && <span>Loading...</span>}
|
|
175
|
+
</div>
|
|
99
176
|
);
|
|
100
177
|
};
|
|
101
178
|
|
|
@@ -106,7 +183,8 @@ SearchResults.propTypes = {
|
|
|
106
183
|
setQueryParams: PropTypes.func.isRequired,
|
|
107
184
|
closeModal: PropTypes.func.isRequired,
|
|
108
185
|
history: PropTypes.object.isRequired,
|
|
109
|
-
currentValue: PropTypes.string.isRequired
|
|
186
|
+
currentValue: PropTypes.string.isRequired,
|
|
187
|
+
entities: PropTypes.array.isRequired
|
|
110
188
|
};
|
|
111
189
|
|
|
112
190
|
export default withRouter(SearchResults);
|
|
@@ -5,6 +5,7 @@ import searchQueries from '../../application/query';
|
|
|
5
5
|
function useSearch({ queryKey, resultKeys, entities = [], fields, extraFilters }) {
|
|
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];
|
|
10
11
|
|
|
@@ -35,13 +36,14 @@ function useSearch({ queryKey, resultKeys, entities = [], fields, extraFilters }
|
|
|
35
36
|
const { limit, offset, value } = queryParams;
|
|
36
37
|
const isNewValueSet = value && value !== searchedValue;
|
|
37
38
|
const isNewOffsetSet = previousOffset !== null && offset !== previousOffset;
|
|
39
|
+
const notSameLength = previousEntities.length !== entities.length;
|
|
38
40
|
const parsedEntities = entities.length
|
|
39
41
|
? entities.map(entity => ({
|
|
40
42
|
match: { docType: entity }
|
|
41
43
|
}))
|
|
42
44
|
: [];
|
|
43
45
|
|
|
44
|
-
if (isNewValueSet || isNewOffsetSet) {
|
|
46
|
+
if (isNewValueSet || isNewOffsetSet || notSameLength) {
|
|
45
47
|
getSearchResults({
|
|
46
48
|
variables: {
|
|
47
49
|
limit,
|
|
@@ -72,6 +74,7 @@ function useSearch({ queryKey, resultKeys, entities = [], fields, extraFilters }
|
|
|
72
74
|
});
|
|
73
75
|
setSearchedValue(value);
|
|
74
76
|
setPreviousOffset(offset);
|
|
77
|
+
setPreviousEntities(entities);
|
|
75
78
|
}
|
|
76
79
|
},
|
|
77
80
|
[
|
|
@@ -84,6 +87,8 @@ function useSearch({ queryKey, resultKeys, entities = [], fields, extraFilters }
|
|
|
84
87
|
getSearchResults,
|
|
85
88
|
entities,
|
|
86
89
|
fields,
|
|
90
|
+
entities.length,
|
|
91
|
+
previousEntities.length,
|
|
87
92
|
extraFilters
|
|
88
93
|
]
|
|
89
94
|
);
|
|
@@ -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 => {
|
|
@@ -32,7 +32,16 @@ function useSearchResults({ queryKey, resultKeys, entities, fields }) {
|
|
|
32
32
|
params.value !== searchedValue ? clearList(params) : setParams(params);
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
return [
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
loading,
|
|
38
|
+
results: allResults,
|
|
39
|
+
currentResults,
|
|
40
|
+
newResults: results,
|
|
41
|
+
total
|
|
42
|
+
},
|
|
43
|
+
setQueryParams
|
|
44
|
+
];
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
export default useSearchResults;
|