@salesforcedevs/dw-components 1.20.16 → 1.26.1

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/dw-components",
3
- "version": "1.20.16",
3
+ "version": "1.26.1",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -30,5 +30,5 @@
30
30
  "node": "20.19.0",
31
31
  "yarn": "1.22.19"
32
32
  },
33
- "gitHead": "07815cdf681065e2c2f967ab36c2482ed4819662"
33
+ "gitHead": "49ed0007e33bd44997bb9e1cb5a23051434c3df6"
34
34
  }
@@ -1,5 +1,5 @@
1
1
  import { api, LightningElement } from "lwc";
2
- import { toJson } from "dxUtils/normalizers";
2
+ import { normalizeBoolean, toJson } from "dxUtils/normalizers";
3
3
  import { DocsTile, DropdownItem, Language } from "typings/custom";
4
4
  import qs from "query-string";
5
5
  import uniqBy from "lodash.uniqby";
@@ -57,10 +57,17 @@ export default class DocsGrid extends LightningElement {
57
57
  private _couchDbDocTileExclusions?: Set<any>;
58
58
  private _allLanguages: Array<Language> = [];
59
59
  private filteredItemsSelected: boolean = false;
60
+ private _isFetchingOtherDocs: boolean = false;
61
+ private _ssgEnabled: boolean = false;
60
62
 
61
63
  connectedCallback(): void {
62
64
  this.retrieveDscApis(true);
63
65
 
66
+ // If SSG_ENABLED is true, fetch from /sitemetadata
67
+ if (this.ssgEnabled) {
68
+ this.fetchOtherDocsFromSitemetadata();
69
+ }
70
+
64
71
  this.matchDesktop = window.matchMedia("(min-width: 1024px)");
65
72
  this.matchDesktop.addEventListener("change", this.handleDesktopView);
66
73
 
@@ -98,6 +105,17 @@ export default class DocsGrid extends LightningElement {
98
105
 
99
106
  @api apiDomain = "https://developer.salesforce.com";
100
107
 
108
+ @api
109
+ get ssgEnabled(): boolean {
110
+ return this._ssgEnabled;
111
+ }
112
+
113
+ set ssgEnabled(value) {
114
+ if (value) {
115
+ this._ssgEnabled = normalizeBoolean(value);
116
+ }
117
+ }
118
+
101
119
  @api
102
120
  get externalMicrosites() {
103
121
  return this._externalMicrosites || [];
@@ -122,14 +140,18 @@ export default class DocsGrid extends LightningElement {
122
140
  }
123
141
 
124
142
  set otherDocs(value: any) {
143
+ this._otherDocs = this.transformOtherDocs(value);
144
+ }
145
+
146
+ private transformOtherDocs(value: any): any[] {
125
147
  const allDocs = toJson(value);
126
- this._otherDocs = [];
148
+ const transformed: any[] = [];
127
149
 
128
150
  for (const docs of allDocs) {
129
151
  for (const project of docs.projects) {
130
152
  const firstLink = project.contentTypes[0].href;
131
153
 
132
- this._otherDocs.push({
154
+ transformed.push({
133
155
  id: project.id,
134
156
  title: project.title,
135
157
  description: project.description,
@@ -140,6 +162,34 @@ export default class DocsGrid extends LightningElement {
140
162
  });
141
163
  }
142
164
  }
165
+
166
+ return transformed;
167
+ }
168
+
169
+ async fetchOtherDocsFromSitemetadata(): Promise<void> {
170
+ if (this._isFetchingOtherDocs) {
171
+ return;
172
+ }
173
+
174
+ this._isFetchingOtherDocs = true;
175
+ try {
176
+ const response = await fetch("/sitemetadata");
177
+
178
+ if (response.ok) {
179
+ const data = await response.json();
180
+ this._otherDocs = this.transformOtherDocs(data);
181
+ } else {
182
+ console.error(
183
+ `Failed to fetch sitemetadata: ${response.status}`
184
+ );
185
+ this._otherDocs = [];
186
+ }
187
+ } catch (error) {
188
+ console.error("Error fetching sitemetadata:", error);
189
+ this._otherDocs = [];
190
+ } finally {
191
+ this._isFetchingOtherDocs = false;
192
+ }
143
193
  }
144
194
 
145
195
  @api
@@ -211,17 +261,35 @@ export default class DocsGrid extends LightningElement {
211
261
  this.normalizeProductFilter(name)
212
262
  ) as Filter[];
213
263
 
214
- const filters = [
264
+ this._productFiltersList = this.getSortedFilters([
215
265
  ...externalMicrositesFilters,
216
266
  ...otherDocsFilters,
217
267
  ...apiDocsFilters
218
- ].filter((filter) => filter.value);
268
+ ]);
269
+ }
219
270
 
220
- this._productFiltersList = orderBy(
221
- uniqBy(filters as any, "value"),
271
+ private getSortedFilters(filters: Filter[]): Filter[] {
272
+ const specificFilters = [] as Filter[];
273
+ let allServicesFilter: Filter | undefined;
274
+
275
+ filters.forEach((filter) => {
276
+ if (filter.value === PRODUCT_FILTER_ALL_SERVICES) {
277
+ allServicesFilter = filter;
278
+ } else if (filter.value) {
279
+ // skip empty filters
280
+ specificFilters.push(filter);
281
+ }
282
+ });
283
+
284
+ const orderedSpecificFilters = orderBy(
285
+ uniqBy(specificFilters, "value"),
222
286
  ["value"],
223
287
  ["asc"]
224
288
  );
289
+
290
+ return allServicesFilter
291
+ ? [allServicesFilter, ...orderedSpecificFilters]
292
+ : orderedSpecificFilters;
225
293
  }
226
294
 
227
295
  @api
@@ -382,7 +450,7 @@ export default class DocsGrid extends LightningElement {
382
450
 
383
451
  normalizeProductFilter(val: string): Filter {
384
452
  return {
385
- label: val,
453
+ label: val === "ai" ? "AI" : val,
386
454
  value: val && val.toLowerCase()
387
455
  };
388
456
  }