@salesforcedevs/dx-components 0.10.1-alpha.102 → 0.10.1-alpha.106

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.10.1-alpha.102",
3
+ "version": "0.10.1-alpha.106",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -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
  }
@@ -157,21 +142,30 @@ 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 });
154
+ if (this.preloadedState) {
155
+ this.searchBox.updateText(this.value || "");
156
+ }
170
157
 
171
158
  if (!this.isValueEmpty) {
172
159
  this.dispatchHighlightedTermChange();
173
160
  }
174
- this.dispatchOnLoading(false); // might not be needed
161
+
162
+ if (!this.preloadedState && !this.isValueEmpty) {
163
+ this.submitSearch();
164
+ }
165
+
166
+ if (!this.preloadedState && this.isValueEmpty) {
167
+ this.dispatchOnLoading(false);
168
+ }
175
169
  };
176
170
 
177
171
  private onResultListChange = () => {
@@ -200,11 +194,16 @@ export default class SidebarSearch extends LightningElement {
200
194
  }
201
195
 
202
196
  if (!isLoading) {
203
- console.log("CHANGING RESULTS");
204
197
  this.dispatchOnChangeEvent(results);
205
198
  }
206
199
 
207
- this.dispatchOnLoading(isLoading);
200
+ if (!this.fetchingMoreResults) {
201
+ this.dispatchOnLoading(isLoading);
202
+ }
203
+
204
+ if (!isLoading && this.fetchingMoreResults) {
205
+ this.fetchingMoreResults = false;
206
+ }
208
207
  };
209
208
 
210
209
  private setAdvancedFilters(engine: SearchEngine) {
@@ -312,7 +311,7 @@ export default class SidebarSearch extends LightningElement {
312
311
  this.updateRecentSearches();
313
312
  this.searchBox.submit();
314
313
  }
315
- }, 360).bind(this);
314
+ }, SEARCH_DEBOUNCE_DELAY);
316
315
 
317
316
  private onClickRecentSearch(e: CustomEvent) {
318
317
  this.value = e.detail;
@@ -333,6 +332,10 @@ export default class SidebarSearch extends LightningElement {
333
332
  private onInputChange(e: CustomEvent) {
334
333
  this.value = e.detail;
335
334
 
335
+ if (!this.isValueEmpty) {
336
+ this.dispatchOnLoading(true);
337
+ }
338
+
336
339
  if (this.searchBox && !this.isValueEmpty) {
337
340
  this.submitSearch();
338
341
  }