@salesforcedevs/dx-components 0.10.1-alpha.101 → 0.10.1-alpha.105
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/package.json
CHANGED
|
@@ -10,34 +10,23 @@ import {
|
|
|
10
10
|
buildSearchBox,
|
|
11
11
|
loadAdvancedSearchQueryActions,
|
|
12
12
|
SearchEngine,
|
|
13
|
-
buildSearchStatus,
|
|
14
13
|
SearchAppState
|
|
15
14
|
} from "@coveo/headless";
|
|
16
15
|
import { buildSearchEngine, getSidebarSearchParams } from "utils/coveo";
|
|
17
16
|
import { RecentSearches } from "utils/recentSearches";
|
|
18
17
|
import { toJson } from "utils/normalizers";
|
|
19
18
|
import { Option, PopoverRequestCloseType } from "typings/custom";
|
|
20
|
-
import preloadedState from './__tests__/preloadedState';
|
|
21
19
|
|
|
22
20
|
const SESSION_KEY = "dx-sidebar-search-state";
|
|
23
21
|
|
|
24
22
|
const DEFAULT_RESULT_COUNT = 20;
|
|
23
|
+
const SEARCH_DEBOUNCE_DELAY = 780;
|
|
25
24
|
|
|
26
25
|
const UserRecentSearches = new RecentSearches();
|
|
27
26
|
|
|
28
27
|
const normalizeCoveoAdvancedQueryValue = (version: string): string =>
|
|
29
28
|
version.split(".").join("\\.");
|
|
30
29
|
|
|
31
|
-
function executeFirstSearch(engine: SearchEngine) {
|
|
32
|
-
return new Promise((resolve) => {
|
|
33
|
-
const searchStatus = buildSearchStatus(engine);
|
|
34
|
-
searchStatus.subscribe(
|
|
35
|
-
() => searchStatus.state.firstSearchExecuted && resolve(true)
|
|
36
|
-
);
|
|
37
|
-
engine.executeFirstSearch();
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
30
|
export default class SidebarSearch extends LightningElement {
|
|
42
31
|
@api coveoOrganizationId!: string;
|
|
43
32
|
@api coveoPublicAccessToken!: string;
|
|
@@ -53,6 +42,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
53
42
|
@api
|
|
54
43
|
public fetchMoreResults() {
|
|
55
44
|
if (this.resultList) {
|
|
45
|
+
this.fetchingMoreResults = true;
|
|
56
46
|
this.resultList.fetchMoreResults();
|
|
57
47
|
}
|
|
58
48
|
}
|
|
@@ -66,6 +56,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
66
56
|
private searchBox: SearchBox | null = null;
|
|
67
57
|
private value?: string = "";
|
|
68
58
|
private engine: SearchEngine | null = null;
|
|
59
|
+
private fetchingMoreResults: boolean = false;
|
|
69
60
|
|
|
70
61
|
private get hasCorrectCoveoConfig(): boolean {
|
|
71
62
|
const coveoConfigurations = [
|
|
@@ -124,14 +115,8 @@ export default class SidebarSearch extends LightningElement {
|
|
|
124
115
|
return;
|
|
125
116
|
}
|
|
126
117
|
const state = JSON.parse(stringified);
|
|
127
|
-
console.log(
|
|
128
|
-
{ state },
|
|
129
|
-
state?.query?.q,
|
|
130
|
-
this.value,
|
|
131
|
-
state?.query?.q === this.value
|
|
132
|
-
);
|
|
118
|
+
console.log({ state }, state?.query?.q === this.value, this.value);
|
|
133
119
|
if (state?.query?.q === this.value) {
|
|
134
|
-
console.log("assigning state");
|
|
135
120
|
this.preloadedState = state;
|
|
136
121
|
}
|
|
137
122
|
}
|
|
@@ -141,7 +126,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
141
126
|
organizationId: this.coveoOrganizationId,
|
|
142
127
|
publicAccessToken: this.coveoPublicAccessToken,
|
|
143
128
|
searchHub: this.coveoSearchHub,
|
|
144
|
-
preloadedState: preloadedState
|
|
129
|
+
preloadedState: this.preloadedState
|
|
145
130
|
});
|
|
146
131
|
|
|
147
132
|
if (!this.engine) {
|
|
@@ -157,21 +142,26 @@ export default class SidebarSearch extends LightningElement {
|
|
|
157
142
|
numberOfResults: DEFAULT_RESULT_COUNT
|
|
158
143
|
}
|
|
159
144
|
});
|
|
145
|
+
|
|
160
146
|
this.searchBox = buildSearchBox(this.engine, {
|
|
161
147
|
options: { numberOfSuggestions: 3 }
|
|
162
148
|
});
|
|
149
|
+
|
|
163
150
|
this.setAdvancedFilters(this.engine);
|
|
164
151
|
|
|
165
152
|
this.resultList?.subscribe(this.onResultListChange);
|
|
166
153
|
|
|
167
|
-
// await executeFirstSearch(this.engine);
|
|
168
|
-
|
|
169
|
-
console.log({ resultList: this.resultList, engine: this.engine });
|
|
170
|
-
|
|
171
154
|
if (!this.isValueEmpty) {
|
|
172
155
|
this.dispatchHighlightedTermChange();
|
|
173
156
|
}
|
|
174
|
-
|
|
157
|
+
|
|
158
|
+
if (!this.preloadedState && !this.isValueEmpty) {
|
|
159
|
+
this.submitSearch();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!this.preloadedState && this.isValueEmpty) {
|
|
163
|
+
this.dispatchOnLoading(false);
|
|
164
|
+
}
|
|
175
165
|
};
|
|
176
166
|
|
|
177
167
|
private onResultListChange = () => {
|
|
@@ -200,11 +190,16 @@ export default class SidebarSearch extends LightningElement {
|
|
|
200
190
|
}
|
|
201
191
|
|
|
202
192
|
if (!isLoading) {
|
|
203
|
-
console.log('CHANGING RESULTS');
|
|
204
193
|
this.dispatchOnChangeEvent(results);
|
|
205
194
|
}
|
|
206
195
|
|
|
207
|
-
this.
|
|
196
|
+
if (!this.fetchingMoreResults) {
|
|
197
|
+
this.dispatchOnLoading(isLoading);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (!isLoading && this.fetchingMoreResults) {
|
|
201
|
+
this.fetchingMoreResults = false;
|
|
202
|
+
}
|
|
208
203
|
};
|
|
209
204
|
|
|
210
205
|
private setAdvancedFilters(engine: SearchEngine) {
|
|
@@ -312,7 +307,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
312
307
|
this.updateRecentSearches();
|
|
313
308
|
this.searchBox.submit();
|
|
314
309
|
}
|
|
315
|
-
},
|
|
310
|
+
}, SEARCH_DEBOUNCE_DELAY);
|
|
316
311
|
|
|
317
312
|
private onClickRecentSearch(e: CustomEvent) {
|
|
318
313
|
this.value = e.detail;
|
|
@@ -333,6 +328,10 @@ export default class SidebarSearch extends LightningElement {
|
|
|
333
328
|
private onInputChange(e: CustomEvent) {
|
|
334
329
|
this.value = e.detail;
|
|
335
330
|
|
|
331
|
+
if (!this.isValueEmpty) {
|
|
332
|
+
this.dispatchOnLoading(true);
|
|
333
|
+
}
|
|
334
|
+
|
|
336
335
|
if (this.searchBox && !this.isValueEmpty) {
|
|
337
336
|
this.submitSearch();
|
|
338
337
|
}
|