@salesforcedevs/dx-components 1.32.0-alpha.8 → 1.32.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.
@@ -13,7 +13,6 @@ dx-empty-state {
13
13
  display: none;
14
14
  }
15
15
 
16
- /* Scrollable list: when content overflows, last visible item is cut by container to indicate more items (per spec). */
17
16
  .sidebar-content {
18
17
  overflow-y: auto;
19
18
  padding: var(--dx-g-spacing-sm) 0 var(--dx-g-spacing-2xl);
@@ -48,6 +48,10 @@
48
48
  <dx-sidebar-search
49
49
  onchange={onSearchChange}
50
50
  onloading={onSearchLoading}
51
+ coveo-organization-id={coveoOrganizationId}
52
+ coveo-public-access-token={coveoPublicAccessToken}
53
+ coveo-search-hub={coveoSearchHub}
54
+ coveo-advanced-query-config={coveoAdvancedQueryConfig}
51
55
  ></dx-sidebar-search>
52
56
  </div>
53
57
  <slot name="version-picker"></slot>
@@ -65,7 +69,7 @@
65
69
  <img
66
70
  lwc:if={isSearchLoading}
67
71
  class="loading-skeleton padding-horizontal"
68
- src="https://a.sfdcstatic.com/developer-website/prod/images/sidebar-loading.svg"
72
+ src="https://developer.salesforce.com/ns-assets/sidebar-loading.svg"
69
73
  alt="loading"
70
74
  />
71
75
  <template
@@ -1,18 +1,18 @@
1
1
  import cx from "classnames";
2
2
  import { api, track } from "lwc";
3
3
  import { TreeNode, SidebarSearchResult } from "typings/custom";
4
+ import { getSidebarSearchParams } from "dxUtils/coveo";
4
5
  import { toJson } from "dxUtils/normalizers";
5
6
  import SidebarSearch from "dx/sidebarSearch";
6
7
  import { SidebarBase } from "dxBaseElements/sidebarBase";
7
8
 
8
9
  const MOBILE_SIZE_MATCH = "768px";
9
10
 
10
- const getSearchQueryParam = (): string | null =>
11
- typeof window !== "undefined"
12
- ? new URLSearchParams(window.location.search).get("q")
13
- : null;
14
-
15
11
  export default class Sidebar extends SidebarBase {
12
+ @api coveoOrganizationId!: string;
13
+ @api coveoPublicAccessToken!: string;
14
+ @api coveoSearchHub!: string;
15
+ @api coveoAdvancedQueryConfig!: string;
16
16
  @api header: string = "";
17
17
 
18
18
  @api
@@ -51,6 +51,7 @@ export default class Sidebar extends SidebarBase {
51
51
  private searchValue: string | null = null;
52
52
  private searchResults: SidebarSearchResult[] = [];
53
53
  private scrollToSelectedSearchResult: boolean = false;
54
+ private selectedSearchResultIndex: number = -1;
54
55
  private requestedFetchMoreResults: boolean = false;
55
56
 
56
57
  private get areResultsEmpty(): boolean {
@@ -129,7 +130,7 @@ export default class Sidebar extends SidebarBase {
129
130
  constructor() {
130
131
  super();
131
132
 
132
- if (getSearchQueryParam()) {
133
+ if (getSidebarSearchParams()) {
133
134
  this.isSearchLoading = true;
134
135
  this.scrollToSelectedSearchResult = true;
135
136
  }
@@ -161,22 +162,20 @@ export default class Sidebar extends SidebarBase {
161
162
 
162
163
  private onSearchChange(e: CustomEvent) {
163
164
  this.requestedFetchMoreResults = false;
164
- const isFirstSearchHydration = this.searchValue === null;
165
- const hasSelectedResult = (e.detail.results || []).some(
166
- (result: SidebarSearchResult) => !!result.selected
167
- );
168
- if (isFirstSearchHydration && hasSelectedResult) {
169
- this.scrollToSelectedSearchResult = true;
170
- }
171
165
  this.searchResults = e.detail.results;
172
166
  this.searchValue = e.detail.value;
173
167
  }
174
168
 
175
169
  private onSearchLoading(e: CustomEvent) {
170
+ if (!e.detail.loading && this.scrollToSelectedSearchResult) {
171
+ this.selectedSearchResultIndex = this.searchResults.findIndex(
172
+ (r) => r.selected
173
+ );
174
+ }
176
175
  this.isSearchLoading = e.detail;
177
176
  }
178
177
 
179
- private onSidebarSearchContentScroll(scrollEvent: Event) {
178
+ private onSidebarSearchContentScroll(scrollEvent) {
180
179
  if (this.isSearchLoading) {
181
180
  return;
182
181
  }
@@ -197,37 +196,23 @@ export default class Sidebar extends SidebarBase {
197
196
  }
198
197
 
199
198
  private initializeSearchScrollPosition() {
200
- if (!this.scrollToSelectedSearchResult || this.isSearchLoading) {
201
- return;
202
- }
203
-
204
- const selectedSearchResultIndex = this.searchResults.findIndex(
205
- (r) => r.selected
206
- );
207
- if (selectedSearchResultIndex < 0) {
208
- return;
209
- }
210
-
211
- const searchContent = this.template.querySelector(
212
- ".sidebar-content-search"
213
- ) as HTMLElement | null;
214
- const allResultItems = searchContent?.querySelectorAll(
215
- "dx-sidebar-search-result"
216
- );
217
- const selectedResult =
218
- (allResultItems?.[selectedSearchResultIndex] as HTMLElement) ||
219
- null;
220
- if (!searchContent || !selectedResult) {
221
- return;
222
- }
223
-
224
- window.requestAnimationFrame(() => {
225
- selectedResult.scrollIntoView({
226
- block: "start",
227
- inline: "nearest"
228
- });
199
+ if (
200
+ this.scrollToSelectedSearchResult &&
201
+ this.selectedSearchResultIndex >= 0
202
+ ) {
203
+ const selectedResult = this.template.querySelector(
204
+ `dx-sidebar-search-result:nth-child(${
205
+ this.selectedSearchResultIndex + 1
206
+ })`
207
+ );
208
+ if (!selectedResult || !selectedResult.parentNode) {
209
+ return;
210
+ }
211
+ (selectedResult.parentNode as HTMLElement).scrollTop =
212
+ selectedResult.offsetTop -
213
+ (selectedResult.parentNode as HTMLElement).offsetTop;
229
214
  this.scrollToSelectedSearchResult = false;
230
- });
215
+ }
231
216
  }
232
217
 
233
218
  private assignValueToLabel(node: TreeNode): void {