@salesforcedevs/dx-components 1.31.0 → 1.32.0-alpha.10

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,6 +13,7 @@ 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). */
16
17
  .sidebar-content {
17
18
  overflow-y: auto;
18
19
  padding: var(--dx-g-spacing-sm) 0 var(--dx-g-spacing-2xl);
@@ -48,10 +48,6 @@
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}
55
51
  ></dx-sidebar-search>
56
52
  </div>
57
53
  <slot name="version-picker"></slot>
@@ -69,7 +65,7 @@
69
65
  <img
70
66
  lwc:if={isSearchLoading}
71
67
  class="loading-skeleton padding-horizontal"
72
- src="https://developer.salesforce.com/ns-assets/sidebar-loading.svg"
68
+ src="https://a.sfdcstatic.com/developer-website/prod/images/sidebar-loading.svg"
73
69
  alt="loading"
74
70
  />
75
71
  <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";
5
4
  import { toJson } from "dxUtils/normalizers";
6
5
  import SidebarSearch from "dx/sidebarSearch";
7
6
  import { SidebarBase } from "dxBaseElements/sidebarBase";
8
7
 
9
8
  const MOBILE_SIZE_MATCH = "768px";
10
9
 
10
+ const getSearchQueryParam = (): string | null =>
11
+ typeof window !== "undefined"
12
+ ? new URLSearchParams(window.location.search).get("q")
13
+ : null;
14
+
11
15
  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,7 +51,6 @@ 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;
55
54
  private requestedFetchMoreResults: boolean = false;
56
55
 
57
56
  private get areResultsEmpty(): boolean {
@@ -130,7 +129,7 @@ export default class Sidebar extends SidebarBase {
130
129
  constructor() {
131
130
  super();
132
131
 
133
- if (getSidebarSearchParams()) {
132
+ if (getSearchQueryParam()) {
134
133
  this.isSearchLoading = true;
135
134
  this.scrollToSelectedSearchResult = true;
136
135
  }
@@ -162,20 +161,22 @@ export default class Sidebar extends SidebarBase {
162
161
 
163
162
  private onSearchChange(e: CustomEvent) {
164
163
  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
+ }
165
171
  this.searchResults = e.detail.results;
166
172
  this.searchValue = e.detail.value;
167
173
  }
168
174
 
169
175
  private onSearchLoading(e: CustomEvent) {
170
- if (!e.detail.loading && this.scrollToSelectedSearchResult) {
171
- this.selectedSearchResultIndex = this.searchResults.findIndex(
172
- (r) => r.selected
173
- );
174
- }
175
176
  this.isSearchLoading = e.detail;
176
177
  }
177
178
 
178
- private onSidebarSearchContentScroll(scrollEvent) {
179
+ private onSidebarSearchContentScroll(scrollEvent: Event) {
179
180
  if (this.isSearchLoading) {
180
181
  return;
181
182
  }
@@ -196,23 +197,37 @@ export default class Sidebar extends SidebarBase {
196
197
  }
197
198
 
198
199
  private initializeSearchScrollPosition() {
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;
214
- this.scrollToSelectedSearchResult = false;
200
+ if (!this.scrollToSelectedSearchResult || this.isSearchLoading) {
201
+ return;
215
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
+ });
229
+ this.scrollToSelectedSearchResult = false;
230
+ });
216
231
  }
217
232
 
218
233
  private assignValueToLabel(node: TreeNode): void {