@salesforcedevs/dx-components 1.3.233 → 1.3.235

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/lwc.config.json CHANGED
@@ -33,6 +33,7 @@
33
33
  "dx/checkboxGroup",
34
34
  "dx/checkboxNative",
35
35
  "dx/codeBlock",
36
+ "dx/coveoRecommendations",
36
37
  "dx/dropdown",
37
38
  "dx/emptyState",
38
39
  "dx/faq",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.3.233",
3
+ "version": "1.3.235",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -44,5 +44,5 @@
44
44
  "volta": {
45
45
  "node": "16.19.1"
46
46
  },
47
- "gitHead": "785bc6c465ffebb8863a7656806f10aab70d3cb5"
47
+ "gitHead": "20dfffe17d70ea773baaf0c9fd71b3c3e1b0162b"
48
48
  }
@@ -13,6 +13,7 @@ export default class CardBlogPost extends LightningElement {
13
13
  @api target?: string | null = null;
14
14
  @api title!: string;
15
15
  @api authors?: Array<any> | null = null;
16
+ @api origin?: string = "wordpress";
16
17
 
17
18
  // LWC is being compiled so that datetime is being interpreted as date-time
18
19
  // ONLY from from the implementation in dx-card-blog-post-provider
@@ -26,7 +27,8 @@ export default class CardBlogPost extends LightningElement {
26
27
  click_url: `${window.location.origin}${this.href}`,
27
28
  element_title: this.title,
28
29
  element_type: "card",
29
- content_category: "link"
30
+ content_category: "link",
31
+ recommendation_type: this.origin
30
32
  };
31
33
  track(event.target!, "custEv_blogCardClick", {
32
34
  ...payload,
@@ -0,0 +1,8 @@
1
+ .spinner-container {
2
+ position: relative;
3
+ margin-top: 85px;
4
+ }
5
+
6
+ dx-section.section-reduced-padding {
7
+ --dx-c-section-padding-vertical: unset;
8
+ }
@@ -0,0 +1,24 @@
1
+ <template>
2
+ <dx-section lwc:if={showRecommendations} class="section-reduced-padding">
3
+ <dx-spinner lwc:if={recommendationsLoading}>
4
+ <div class="spinner-container">
5
+ <dx-spinner size="large" variant="brand"></dx-spinner>
6
+ </div>
7
+ </dx-spinner>
8
+ <dx-grid columns="three" class="recent-posts">
9
+ <template for:each={recommendations} for:item="recommendation">
10
+ <dx-card-blog-post
11
+ authors={recommendation.authors}
12
+ body={recommendation.yoast_head_json.description}
13
+ datetime={recommendation.yoast_head_json.article_published_time}
14
+ href={recommendation.yoast_head_json.canonical}
15
+ img-alt={recommendation.yoast_head_json.title}
16
+ img-src={recommendation.featured_image}
17
+ key={recommendation.id}
18
+ title={recommendation.yoast_head_json.title}
19
+ origin="coveo"
20
+ ></dx-card-blog-post>
21
+ </template>
22
+ </dx-grid>
23
+ </dx-section>
24
+ </template>
@@ -0,0 +1,57 @@
1
+ import { LightningElement, api } from "lwc";
2
+
3
+ export default class CoveoRecommendations extends LightningElement {
4
+ @api coveoAuthToken!: string;
5
+
6
+ _recommendations = [] as any[];
7
+
8
+ private get recommendations(): any[] {
9
+ return this._recommendations || [];
10
+ }
11
+
12
+ showRecommendations = true;
13
+ recommendationsLoading = true;
14
+
15
+ connectedCallback() {
16
+ const actionsHistory = localStorage.getItem(
17
+ "__coveo.analytics.history"
18
+ );
19
+ const url = "https://platform.cloud.coveo.com/rest/search/v2";
20
+ fetch(url, {
21
+ headers: {
22
+ Authorization: `Bearer ${this.coveoAuthToken}`,
23
+ "Content-Type": "application/json"
24
+ },
25
+ method: "POST",
26
+ body: JSON.stringify({
27
+ pipeline: "Recommendations_Developer_Blogs",
28
+ searchHub: "developerWebsiteBlogs",
29
+ numberOfResults: 3,
30
+ actionsHistory: JSON.parse(actionsHistory!)
31
+ })
32
+ }).then(
33
+ async (response) => {
34
+ try {
35
+ const results = (await response.json()).results;
36
+ const blogDataLoadTasks = results
37
+ .slice(0, 3)
38
+ .map(async (rec: any) => {
39
+ const slug = rec.uri.split("/").pop();
40
+ const blogDataUrl = `https://developer.salesforce.com/blogs/wp-json/wp/v2/posts?slug=${slug}&state=publish&_embed=wp:featuredmedia`;
41
+ return (await (await fetch(blogDataUrl)).json())[0];
42
+ });
43
+ this._recommendations = await Promise.all(
44
+ blogDataLoadTasks
45
+ );
46
+ } catch (ex) {
47
+ this.showRecommendations = false;
48
+ } finally {
49
+ this.recommendationsLoading = false;
50
+ }
51
+ },
52
+ () => {
53
+ this.showRecommendations = false;
54
+ }
55
+ );
56
+ }
57
+ }