From e694278159be742e2bc55cecede59a8df53cb4ff Mon Sep 17 00:00:00 2001 From: Artem Alexeyenko Date: Tue, 20 Aug 2024 20:21:00 -0400 Subject: [PATCH 1/6] [sitecore-jss] Introduce extra types from Edge schema into models (cherry picked from commit f09a6cdb997c1844960c8d300d9157a5c0880fae) --- packages/sitecore-jss/src/layout/content-styles.ts | 6 +++++- packages/sitecore-jss/src/layout/index.ts | 1 + packages/sitecore-jss/src/layout/models.ts | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/sitecore-jss/src/layout/content-styles.ts b/packages/sitecore-jss/src/layout/content-styles.ts index 1dc84bb450..ece9a518a5 100644 --- a/packages/sitecore-jss/src/layout/content-styles.ts +++ b/packages/sitecore-jss/src/layout/content-styles.ts @@ -1,6 +1,7 @@ import { SITECORE_EDGE_URL_DEFAULT } from '../constants'; import { ComponentRendering, + DatasourceField, Field, HtmlElementRendering, Item, @@ -59,7 +60,10 @@ export const traversePlaceholder = ( }); }; -export const traverseField = (field: Field | Item | Item[] | undefined, config: Config) => { +export const traverseField = ( + field: Field | Item | Item[] | DatasourceField | undefined, + config: Config +) => { if (!field || config.loadStyles) return; if ('editable' in field && field.editable) { diff --git a/packages/sitecore-jss/src/layout/index.ts b/packages/sitecore-jss/src/layout/index.ts index 9b4eb5cdad..dbcf3376e0 100644 --- a/packages/sitecore-jss/src/layout/index.ts +++ b/packages/sitecore-jss/src/layout/index.ts @@ -16,6 +16,7 @@ export { ComponentParams, EditMode, FieldMetadata, + DatasourceField, } from './models'; export { diff --git a/packages/sitecore-jss/src/layout/models.ts b/packages/sitecore-jss/src/layout/models.ts index 3f60e02081..0871ff4407 100644 --- a/packages/sitecore-jss/src/layout/models.ts +++ b/packages/sitecore-jss/src/layout/models.ts @@ -76,11 +76,15 @@ export type PlaceholdersData = { [P in TYPEDNAME]: Array; }; +export interface DatasourceField { + datasource: Item; +} + /** * Content field data passed to a component */ export interface ComponentFields { - [name: string]: Field | Item | Item[]; + [name: string]: Field | Item | Item[] | DatasourceField; } /** @@ -137,7 +141,7 @@ export interface FieldMetadata { } /** - * Content data returned from Content Service + * Content data returned from Layout Service */ export interface Item { name: string; @@ -147,6 +151,12 @@ export interface Item { fields: { [name: string]: Field | Item | Item[] | undefined; }; + field?: { + [name: string]: Field; + }; + children?: { + results: Item[]; + }; } /** From 16ce8d41b19c118538eb00b5a3e207184d02568b Mon Sep 17 00:00:00 2001 From: Artem Alexeyenko Date: Tue, 20 Aug 2024 20:21:28 -0400 Subject: [PATCH 2/6] mid-way implementation --- .../link-list/link-list.component.html | 17 ++++++++ .../link-list/link-list.component.ts | 39 +++++++++++++++++++ .../sitecore-jss-angular/src/public_api.ts | 1 + 3 files changed, 57 insertions(+) create mode 100644 packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html create mode 100644 packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.ts diff --git a/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html b/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html new file mode 100644 index 0000000000..2c24269286 --- /dev/null +++ b/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html @@ -0,0 +1,17 @@ +
+
+ +

+
+
    +
  • + +
  • +
+
+ + Link list + +
\ No newline at end of file diff --git a/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.ts b/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.ts new file mode 100644 index 0000000000..26df670ff3 --- /dev/null +++ b/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.ts @@ -0,0 +1,39 @@ +import { Component, OnInit } from '@angular/core'; +import { SxaComponent } from '../sxa.component'; +import { Field, LinkField, DatasourceField } from '@sitecore-jss/sitecore-jss-angular'; + +@Component({ + selector: 'app-link-list', + templateUrl: './link-list.component.html', +}) +export class LinkListComponent extends SxaComponent implements OnInit { + source: DatasourceField; + title?: Field; + fieldLinks: LinkField[]; + field: Field; + + getFieldLinkClass(index: number): string { + let className = `item${index}`; + className += (index + 1) % 2 == 0 ? ' even' : ' odd'; + if (index === 0) { + className += ' first'; + } + if (index + 1 === this.fieldLinks.length) { + className += ' last'; + } + return className; + } + + ngOnInit() { + super.ngOnInit(); + const source = this.rendering.fields?.data as unknown; + const datasource = (source as DatasourceField).datasource; + this.title = datasource.field?.title as Field; + this.fieldLinks = []; + datasource.children.results.forEach(item => { + if (item.field?.link) + this.fieldLinks.push(item.field.link as LinkField); + }); + console.log(this.fieldLinks); + } +} diff --git a/packages/sitecore-jss-angular/src/public_api.ts b/packages/sitecore-jss-angular/src/public_api.ts index da7ec5f344..1602c37e0b 100644 --- a/packages/sitecore-jss-angular/src/public_api.ts +++ b/packages/sitecore-jss-angular/src/public_api.ts @@ -57,6 +57,7 @@ export { ComponentParams, getContentStylesheetLink, EditMode, + DatasourceField, } from '@sitecore-jss/sitecore-jss/layout'; export { RetryStrategy, From e3bfb6b18506cffbe0af377bc4b00fb1cda875e8 Mon Sep 17 00:00:00 2001 From: Artem Alexeyenko Date: Wed, 21 Aug 2024 15:15:40 -0400 Subject: [PATCH 3/6] rework implementation --- .../link-list/link-list.component.html | 2 +- .../link-list/link-list.component.ts | 26 +++++++++---------- .../src/components/rendering-field.ts | 19 ++++++++++++++ .../sitecore-jss-angular/src/public_api.ts | 2 +- .../sitecore-jss/src/layout/content-styles.ts | 6 +---- packages/sitecore-jss/src/layout/index.ts | 1 - packages/sitecore-jss/src/layout/models.ts | 16 +++--------- 7 files changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html b/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html index 2c24269286..73345c8ddb 100644 --- a/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html +++ b/packages/create-sitecore-jss/src/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html @@ -1,4 +1,4 @@ -
+