From 2e41434d2e27c6d9a61907075bbee4bb293f1fc9 Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Thu, 29 Aug 2024 23:46:34 +0300 Subject: [PATCH 01/10] feat: move cms articles from labs --- libs/domain/content/src/index.ts | 1 + .../content/src/models/article.model.ts | 9 ++ .../content/src/models/content.model.ts | 3 + libs/domain/content/src/models/index.ts | 1 + .../article-page-description-meta.resolver.ts | 8 +- .../article-page-title-meta.resolver.ts | 8 +- .../content/src}/resolvers/index.ts | 0 .../content/src/services}/article-context.ts | 2 +- .../content/src/services/content.providers.ts | 39 +++++- .../labs/src/articles/article-page.ts | 115 ------------------ .../labs/src/articles/article-providers.ts | 52 -------- .../labs/src/articles/article-types.ts | 1 - .../labs/src/articles/article.model.ts | 14 --- libs/template/labs/src/articles/index.ts | 5 - ...cle-page-description-meta.resolver.spec.ts | 96 --------------- .../article-page-title-meta.resolver.spec.ts | 96 --------------- libs/template/labs/src/feature.ts | 2 - libs/template/labs/src/index.ts | 1 - .../presets/storefront/experience/footer.ts | 49 ++++++-- .../experience/pages/article-page.ts | 37 ++++++ .../storefront/experience/pages/index.ts | 2 + 21 files changed, 133 insertions(+), 408 deletions(-) create mode 100644 libs/domain/content/src/models/article.model.ts rename libs/{template/labs/src/articles => domain/content/src}/resolvers/article-page-description-meta.resolver.ts (90%) rename libs/{template/labs/src/articles => domain/content/src}/resolvers/article-page-title-meta.resolver.ts (90%) rename libs/{template/labs/src/articles => domain/content/src}/resolvers/index.ts (100%) rename libs/{template/labs/src/articles => domain/content/src/services}/article-context.ts (91%) delete mode 100644 libs/template/labs/src/articles/article-page.ts delete mode 100644 libs/template/labs/src/articles/article-providers.ts delete mode 100644 libs/template/labs/src/articles/article-types.ts delete mode 100644 libs/template/labs/src/articles/article.model.ts delete mode 100644 libs/template/labs/src/articles/index.ts delete mode 100644 libs/template/labs/src/articles/resolvers/article-page-description-meta.resolver.spec.ts delete mode 100644 libs/template/labs/src/articles/resolvers/article-page-title-meta.resolver.spec.ts create mode 100644 libs/template/presets/storefront/experience/pages/article-page.ts diff --git a/libs/domain/content/src/index.ts b/libs/domain/content/src/index.ts index 5cb14365b..0478f3fd3 100644 --- a/libs/domain/content/src/index.ts +++ b/libs/domain/content/src/index.ts @@ -1,3 +1,4 @@ export * from './feature'; export * from './models'; +export * from './resolvers'; export * from './services'; diff --git a/libs/domain/content/src/models/article.model.ts b/libs/domain/content/src/models/article.model.ts new file mode 100644 index 000000000..47ae2c7c2 --- /dev/null +++ b/libs/domain/content/src/models/article.model.ts @@ -0,0 +1,9 @@ +// TODO: create dynamic types and dependable dynamic pages. +export const articleTypes = ['article', 'faq', 'about']; + +export interface ArticleContent { + heading: string; + description: string; + content: string; + type: string; +} diff --git a/libs/domain/content/src/models/content.model.ts b/libs/domain/content/src/models/content.model.ts index 2a11c68e3..9c836971d 100644 --- a/libs/domain/content/src/models/content.model.ts +++ b/libs/domain/content/src/models/content.model.ts @@ -1,6 +1,9 @@ declare global { interface ContentFields { component: undefined; + article: undefined; + faq: undefined; + about: undefined; } } diff --git a/libs/domain/content/src/models/index.ts b/libs/domain/content/src/models/index.ts index 7ea3764ce..8638841a1 100644 --- a/libs/domain/content/src/models/index.ts +++ b/libs/domain/content/src/models/index.ts @@ -1,3 +1,4 @@ +export * from './article.model'; export * from './content.model'; /** diff --git a/libs/template/labs/src/articles/resolvers/article-page-description-meta.resolver.ts b/libs/domain/content/src/resolvers/article-page-description-meta.resolver.ts similarity index 90% rename from libs/template/labs/src/articles/resolvers/article-page-description-meta.resolver.ts rename to libs/domain/content/src/resolvers/article-page-description-meta.resolver.ts index aa64670d8..0fc9fee47 100644 --- a/libs/template/labs/src/articles/resolvers/article-page-description-meta.resolver.ts +++ b/libs/domain/content/src/resolvers/article-page-description-meta.resolver.ts @@ -1,8 +1,3 @@ -import { - ContentContext, - ContentQualifier, - ContentService, -} from '@oryx-frontend/content'; import { ContextService, ElementResolver, @@ -11,7 +6,8 @@ import { import { inject } from '@oryx-frontend/di'; import { RouterService } from '@oryx-frontend/router'; import { Observable, combineLatest, map, of, switchMap } from 'rxjs'; -import { ArticleContent } from '../article.model'; +import { ArticleContent, ContentQualifier } from '../models'; +import { ContentContext, ContentService } from '../services'; export class ArticlePageDescriptionMetaResolver implements PageMetaResolver { constructor( diff --git a/libs/template/labs/src/articles/resolvers/article-page-title-meta.resolver.ts b/libs/domain/content/src/resolvers/article-page-title-meta.resolver.ts similarity index 90% rename from libs/template/labs/src/articles/resolvers/article-page-title-meta.resolver.ts rename to libs/domain/content/src/resolvers/article-page-title-meta.resolver.ts index 8cb0ee089..d80f46491 100644 --- a/libs/template/labs/src/articles/resolvers/article-page-title-meta.resolver.ts +++ b/libs/domain/content/src/resolvers/article-page-title-meta.resolver.ts @@ -1,8 +1,3 @@ -import { - ContentContext, - ContentQualifier, - ContentService, -} from '@oryx-frontend/content'; import { ContextService, ElementResolver, @@ -11,7 +6,8 @@ import { import { inject } from '@oryx-frontend/di'; import { RouterService } from '@oryx-frontend/router'; import { Observable, combineLatest, map, of, switchMap } from 'rxjs'; -import { ArticleContent } from '../article.model'; +import { ArticleContent, ContentQualifier } from '../models'; +import { ContentContext, ContentService } from '../services'; export class ArticlePageTitleMetaResolver implements PageMetaResolver { constructor( diff --git a/libs/template/labs/src/articles/resolvers/index.ts b/libs/domain/content/src/resolvers/index.ts similarity index 100% rename from libs/template/labs/src/articles/resolvers/index.ts rename to libs/domain/content/src/resolvers/index.ts diff --git a/libs/template/labs/src/articles/article-context.ts b/libs/domain/content/src/services/article-context.ts similarity index 91% rename from libs/template/labs/src/articles/article-context.ts rename to libs/domain/content/src/services/article-context.ts index 2c96fcc89..38d9f33a9 100644 --- a/libs/template/labs/src/articles/article-context.ts +++ b/libs/domain/content/src/services/article-context.ts @@ -1,8 +1,8 @@ -import { ContentContext } from '@oryx-frontend/content'; import { ContextFallback } from '@oryx-frontend/core'; import { inject, Provider } from '@oryx-frontend/di'; import { RouterService } from '@oryx-frontend/router'; import { combineLatest, map } from 'rxjs'; +import { ContentContext } from './content-context'; export const ArticleQualifierContextFallback: Provider = { provide: `${ContextFallback}${ContentContext.Content}`, diff --git a/libs/domain/content/src/services/content.providers.ts b/libs/domain/content/src/services/content.providers.ts index abb28ba93..29e4a93d6 100644 --- a/libs/domain/content/src/services/content.providers.ts +++ b/libs/domain/content/src/services/content.providers.ts @@ -1,7 +1,10 @@ -import { provideEntity } from '@oryx-frontend/core'; +import { PageMetaResolver, provideEntity } from '@oryx-frontend/core'; import { Provider } from '@oryx-frontend/di'; import { ExperienceAdapter } from '@oryx-frontend/experience'; -import { ContentExperienceAdapter } from './adapter'; +import { articleTypes, Content, ContentQualifier } from '../models'; +import { ArticlePageDescriptionMetaResolver, ArticlePageTitleMetaResolver } from '../resolvers'; +import { ContentConfig, ContentExperienceAdapter } from './adapter'; +import { ArticleQualifierContextFallback } from './article-context'; import { contentfulProviders, storyblokProviders, @@ -32,4 +35,36 @@ export const contentProviders: Provider[] = [ service: ContentService, context: ContentContext.Content, }), + ArticleQualifierContextFallback, + { + provide: PageMetaResolver, + useClass: ArticlePageTitleMetaResolver, + }, + { + provide: PageMetaResolver, + useClass: ArticlePageDescriptionMetaResolver, + }, + { + provide: ContentConfig, + useValue: { + storyblok: { + types: ['component', 'faq', 'contents'], + }, + strapi: { + types: ['component', 'about', 'contents'], + defaultType: 'about', + }, + contentful: { + types: ['component', 'article', 'contents'], + }, + }, + }, + ...articleTypes.map((type) => + provideEntity(type, { + service: ContentService, + context: type, + get: (service, qualifier) => + (service as ContentService).get({ ...qualifier, type }), + }) + ), ]; diff --git a/libs/template/labs/src/articles/article-page.ts b/libs/template/labs/src/articles/article-page.ts deleted file mode 100644 index 91b53088d..000000000 --- a/libs/template/labs/src/articles/article-page.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { ExperienceComponent } from '@oryx-frontend/experience'; -import { SuggestionField } from '@oryx-frontend/search'; -import { articleTypes } from './article-types'; - -export const experienceArticlePages = [ - { - merge: { - selector: 'legal-links', - type: 'patch', - }, - type: 'oryx-composition', - components: [ - { - type: 'oryx-content-text', - content: { data: { text: `©️ ${new Date().getFullYear()} Spryker` } }, - }, - { - type: 'oryx-content-list', - options: { - tags: 'legal', - rules: [ - { - layout: { - type: 'flex', - divider: true, - }, - width: 'auto', - }, - ], - }, - }, - ], - }, - ...articleTypes - .map( - (type) => - [ - { - type: 'Page', - id: `${type}-list`, - meta: { - title: `${type} List`, - route: `/${type}/:id`, - routeType: type, - }, - components: [ - { ref: 'header' }, - { - type: 'oryx-composition', - options: { - rules: [{ layout: { type: 'split' }, padding: '30px 0' }], - }, - components: [ - { - type: 'oryx-site-breadcrumb', - options: { rules: [{ colSpan: 2 }] }, - }, - { - type: 'oryx-search-box', - options: { - rules: [{ margin: 'auto', width: '580px' }], - [SuggestionField.Suggestions]: null, - [SuggestionField.Categories]: null, - [SuggestionField.Contents]: null, - [SuggestionField.Products]: null, - [type]: { max: 8 }, - }, - }, - { - type: 'oryx-content-list', - options: { - rules: [{ layout: { type: 'list' } }], - }, - }, - ], - }, - { ref: 'footer' }, - ], - }, - { - type: 'Page', - id: type, - meta: { - title: type, - route: `/${type}/:id`, - routeType: 'content', - }, - components: [ - { ref: 'header' }, - { - type: 'oryx-composition', - options: { - rules: [{ layout: { type: 'split' }, padding: '30px 0' }], - }, - components: [ - { - type: 'oryx-site-breadcrumb', - options: { rules: [{ colSpan: 2 }] }, - }, - - { - type: 'oryx-data-text', - options: { - field: 'content', - }, - }, - ], - }, - { ref: 'footer' }, - ], - }, - ] as ExperienceComponent[] - ) - .flat(), -]; diff --git a/libs/template/labs/src/articles/article-providers.ts b/libs/template/labs/src/articles/article-providers.ts deleted file mode 100644 index 251f0e7e0..000000000 --- a/libs/template/labs/src/articles/article-providers.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - Content, - ContentConfig, - ContentQualifier, - ContentService, -} from '@oryx-frontend/content'; -import { PageMetaResolver, provideEntity } from '@oryx-frontend/core'; -import { Provider } from '@oryx-frontend/di'; -import { provideExperienceData } from '@oryx-frontend/experience'; -import { ArticleQualifierContextFallback } from './article-context'; -import { experienceArticlePages } from './article-page'; -import { articleTypes } from './article-types'; -import { - ArticlePageDescriptionMetaResolver, - ArticlePageTitleMetaResolver, -} from './resolvers'; - -export const articleProviders: Provider[] = [ - ArticleQualifierContextFallback, - provideExperienceData(experienceArticlePages), - { - provide: PageMetaResolver, - useClass: ArticlePageTitleMetaResolver, - }, - { - provide: PageMetaResolver, - useClass: ArticlePageDescriptionMetaResolver, - }, - { - provide: ContentConfig, - useValue: { - storyblok: { - types: ['component', 'faq', 'contents'], - }, - strapi: { - types: ['component', 'about', 'contents'], - defaultType: 'about', - }, - contentful: { - types: ['component', 'article', 'contents'], - }, - }, - }, - ...articleTypes.map((type) => - provideEntity(type, { - service: ContentService, - context: type, - get: (service, qualifier) => - (service as ContentService).get({ ...qualifier, type }), - }) - ), -]; diff --git a/libs/template/labs/src/articles/article-types.ts b/libs/template/labs/src/articles/article-types.ts deleted file mode 100644 index 05fe25502..000000000 --- a/libs/template/labs/src/articles/article-types.ts +++ /dev/null @@ -1 +0,0 @@ -export const articleTypes = ['article', 'faq', 'about']; diff --git a/libs/template/labs/src/articles/article.model.ts b/libs/template/labs/src/articles/article.model.ts deleted file mode 100644 index 8c57c80be..000000000 --- a/libs/template/labs/src/articles/article.model.ts +++ /dev/null @@ -1,14 +0,0 @@ -declare global { - interface ContentFields { - article: undefined; - about: undefined; - faq: undefined; - } -} - -export interface ArticleContent { - heading: string; - description: string; - content: string; - type: string; -} diff --git a/libs/template/labs/src/articles/index.ts b/libs/template/labs/src/articles/index.ts deleted file mode 100644 index 1560b8543..000000000 --- a/libs/template/labs/src/articles/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './article-context'; -export * from './article-page'; -export * from './article-providers'; -export * from './article.model'; -export * from './resolvers'; diff --git a/libs/template/labs/src/articles/resolvers/article-page-description-meta.resolver.spec.ts b/libs/template/labs/src/articles/resolvers/article-page-description-meta.resolver.spec.ts deleted file mode 100644 index 055253739..000000000 --- a/libs/template/labs/src/articles/resolvers/article-page-description-meta.resolver.spec.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { ContentService } from '@oryx-frontend/content'; -import { ContextService } from '@oryx-frontend/core'; -import { createInjector, destroyInjector } from '@oryx-frontend/di'; -import { RouterService } from '@oryx-frontend/router'; -import { of } from 'rxjs'; -import { ArticlePageDescriptionMetaResolver } from './article-page-description-meta.resolver'; - -const mockContentService = { - get: vi.fn(), -}; - -const mockContextService = { - get: vi.fn(), -}; - -const mockRouterService = { - currentRoute: vi.fn(), -}; - -describe('ArticlePageDescriptionMetaResolver', () => { - let service: ArticlePageDescriptionMetaResolver; - - beforeEach(() => { - const testInjector = createInjector({ - providers: [ - { - provide: ArticlePageDescriptionMetaResolver, - useClass: ArticlePageDescriptionMetaResolver, - }, - { - provide: ContextService, - useValue: mockContextService, - }, - { - provide: ContentService, - useValue: mockContentService, - }, - { - provide: RouterService, - useValue: mockRouterService, - }, - ], - }); - - service = testInjector.inject(ArticlePageDescriptionMetaResolver); - }); - - afterEach(() => { - destroyInjector(); - vi.resetAllMocks(); - }); - - describe('getScore', () => { - it('should return proper value if article exist', () => { - const callback = vi.fn(); - mockContextService.get.mockReturnValueOnce(of('id')); - mockContextService.get.mockReturnValue(of('article')); - mockRouterService.currentRoute.mockReturnValue(of(`/article/saf`)); - service.getScore().subscribe(callback); - expect(callback).toHaveBeenCalledWith(['id', 'article', true]); - }); - - it('should return proper value if article is not exist', () => { - const callback = vi.fn(); - mockContextService.get.mockReturnValue(of(undefined)); - mockRouterService.currentRoute.mockReturnValue(of('')); - - service.getScore().subscribe(callback); - expect(callback).toHaveBeenCalledWith([undefined, undefined, false]); - }); - }); - - describe('resolve', () => { - it('should return proper object with article description', () => { - const callback = vi.fn(); - mockContextService.get.mockReturnValueOnce(of('id')); - mockContextService.get.mockReturnValue(of('type')); - mockContentService.get.mockReturnValue( - of({ - fields: { - description: 'Description A', - }, - }) - ); - service.resolve().subscribe(callback); - expect(mockContentService.get).toHaveBeenCalledWith({ - id: 'id', - type: 'type', - entities: ['type'], - }); - expect(callback).toHaveBeenCalledWith({ - description: 'Description A', - }); - }); - }); -}); diff --git a/libs/template/labs/src/articles/resolvers/article-page-title-meta.resolver.spec.ts b/libs/template/labs/src/articles/resolvers/article-page-title-meta.resolver.spec.ts deleted file mode 100644 index df3d16e4b..000000000 --- a/libs/template/labs/src/articles/resolvers/article-page-title-meta.resolver.spec.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { ContentService } from '@oryx-frontend/content'; -import { ContextService } from '@oryx-frontend/core'; -import { createInjector, destroyInjector } from '@oryx-frontend/di'; -import { RouterService } from '@oryx-frontend/router'; -import { of } from 'rxjs'; -import { ArticlePageTitleMetaResolver } from './article-page-title-meta.resolver'; - -const mockContentService = { - get: vi.fn(), -}; - -const mockContextService = { - get: vi.fn(), -}; - -const mockRouterService = { - currentRoute: vi.fn(), -}; - -describe('ArticlePageTitleMetaResolver', () => { - let service: ArticlePageTitleMetaResolver; - - beforeEach(() => { - const testInjector = createInjector({ - providers: [ - { - provide: ArticlePageTitleMetaResolver, - useClass: ArticlePageTitleMetaResolver, - }, - { - provide: ContextService, - useValue: mockContextService, - }, - { - provide: ContentService, - useValue: mockContentService, - }, - { - provide: RouterService, - useValue: mockRouterService, - }, - ], - }); - - service = testInjector.inject(ArticlePageTitleMetaResolver); - }); - - afterEach(() => { - destroyInjector(); - vi.resetAllMocks(); - }); - - describe('getScore', () => { - it('should return proper value if article exist', () => { - const callback = vi.fn(); - mockContextService.get.mockReturnValueOnce(of('id')); - mockContextService.get.mockReturnValue(of('article')); - mockRouterService.currentRoute.mockReturnValue(of(`/article/saf`)); - service.getScore().subscribe(callback); - expect(callback).toHaveBeenCalledWith(['id', 'article', true]); - }); - - it('should return proper value if article is not exist', () => { - const callback = vi.fn(); - mockContextService.get.mockReturnValue(of(undefined)); - mockRouterService.currentRoute.mockReturnValue(of('')); - - service.getScore().subscribe(callback); - expect(callback).toHaveBeenCalledWith([undefined, undefined, false]); - }); - }); - - describe('resolve', () => { - it('should return proper object with article title', () => { - const callback = vi.fn(); - mockContextService.get.mockReturnValueOnce(of('id')); - mockContextService.get.mockReturnValue(of('type')); - mockContentService.get.mockReturnValue( - of({ - fields: { - heading: 'Name A', - }, - }) - ); - service.resolve().subscribe(callback); - expect(mockContentService.get).toHaveBeenCalledWith({ - id: 'id', - type: 'type', - entities: ['type'], - }); - expect(callback).toHaveBeenCalledWith({ - title: 'Name A', - }); - }); - }); -}); diff --git a/libs/template/labs/src/feature.ts b/libs/template/labs/src/feature.ts index 5d403c269..d2ed41a20 100644 --- a/libs/template/labs/src/feature.ts +++ b/libs/template/labs/src/feature.ts @@ -1,5 +1,4 @@ import { AppFeature } from '@oryx-frontend/core'; -import { articleProviders } from './articles'; import { bazaarVoiceComponentMapping } from './bazaarvoice'; import { cloudinaryImageConverter } from './cloudinary'; import * as components from './components'; @@ -24,7 +23,6 @@ export const labsFeatures: AppFeature[] = [ providers: [ cloudinaryImageConverter, bazaarVoiceComponentMapping, - ...articleProviders, ...i18nLabsProviders, ], }, diff --git a/libs/template/labs/src/index.ts b/libs/template/labs/src/index.ts index 78d78a254..42a9f556a 100644 --- a/libs/template/labs/src/index.ts +++ b/libs/template/labs/src/index.ts @@ -1,2 +1 @@ -export * from './articles'; export * from './feature'; diff --git a/libs/template/presets/storefront/experience/footer.ts b/libs/template/presets/storefront/experience/footer.ts index bec6e59d9..8141e0280 100644 --- a/libs/template/presets/storefront/experience/footer.ts +++ b/libs/template/presets/storefront/experience/footer.ts @@ -29,17 +29,44 @@ const legalLinks: ExperienceComponent = { type: 'oryx-composition', name: 'legal links', id: 'legal-links', - components: [ - { - type: 'oryx-content-text', - content: { data: { text: `©️ ${new Date().getFullYear()} Spryker` } }, - }, - link('Imprint', '/faq/imprint'), - link('Terms & conditions', '/article/terms-and-conditions'), - link('Privacy Notice', '/article/privacy'), - link('Data preference'), - link('Condition of use'), - ], + components: + featureVersion >= '1.5' + ? [ + { + type: 'oryx-content-text', + content: { + data: { text: `©️ ${new Date().getFullYear()} Spryker` }, + }, + }, + { + type: 'oryx-content-list', + options: { + tags: 'legal', + rules: [ + { + layout: { + type: 'flex', + divider: true, + }, + width: 'auto', + }, + ], + }, + }, + ] + : [ + { + type: 'oryx-content-text', + content: { + data: { text: `©️ ${new Date().getFullYear()} Spryker` }, + }, + }, + link('Imprint', '/faq/imprint'), + link('Terms & conditions', '/article/terms-and-conditions'), + link('Privacy Notice', '/article/privacy'), + link('Data preference'), + link('Condition of use'), + ], options: { rules: [ { diff --git a/libs/template/presets/storefront/experience/pages/article-page.ts b/libs/template/presets/storefront/experience/pages/article-page.ts new file mode 100644 index 000000000..6195ef775 --- /dev/null +++ b/libs/template/presets/storefront/experience/pages/article-page.ts @@ -0,0 +1,37 @@ +import { articleTypes } from '@oryx-frontend/content'; +import { ExperienceComponent } from '@oryx-frontend/experience'; + +export const experienceArticlePages: ExperienceComponent[] = articleTypes.map((type) => [ + { + type: 'Page', + id: type, + meta: { + title: type, + route: `/${type}/:id`, + routeType: 'content', + }, + components: [ + { ref: 'header' }, + { + type: 'oryx-composition', + options: { + rules: [{ layout: { type: 'split' }, padding: '30px 0' }], + }, + components: [ + { + type: 'oryx-site-breadcrumb', + options: { rules: [{ colSpan: 2 }] }, + }, + + { + type: 'oryx-data-text', + options: { + field: 'content', + }, + }, + ], + }, + { ref: 'footer' }, + ], + }, +]); diff --git a/libs/template/presets/storefront/experience/pages/index.ts b/libs/template/presets/storefront/experience/pages/index.ts index 6ca95dcf3..8ea867bf1 100644 --- a/libs/template/presets/storefront/experience/pages/index.ts +++ b/libs/template/presets/storefront/experience/pages/index.ts @@ -1,3 +1,4 @@ +export * from './article-page'; export * from './cart-page'; export * from './category-page'; export * from './checkout-page'; @@ -9,3 +10,4 @@ export * from './order-confirmation-page'; export * from './product-page'; export * from './registration-page'; export * from './search-page'; + From c0deb83ff6814d34773ae70e075840e09526390e Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Fri, 30 Aug 2024 09:47:58 +0300 Subject: [PATCH 02/10] fix: renaming --- libs/domain/content/link/link.component.ts | 1 + .../content/src/models/article.model.ts | 9 ---- libs/domain/content/src/models/cms.model.ts | 18 +++++++ .../content/src/models/content.model.ts | 3 -- libs/domain/content/src/models/index.ts | 2 +- ... => cms-page-description-meta.resolver.ts} | 6 +-- ...ver.ts => cms-page-title-meta.resolver.ts} | 6 +-- libs/domain/content/src/resolvers/index.ts | 5 +- .../cms-context.ts} | 4 +- .../content/src/services/cms/cms-providers.ts | 48 +++++++++++++++++ libs/domain/content/src/services/cms/index.ts | 3 ++ .../content/src/services/content.providers.ts | 49 ++--------------- .../storefront/experience/experience-data.ts | 2 + .../presets/storefront/experience/footer.ts | 53 +++++++------------ .../pages/{article-page.ts => cms-pages.ts} | 4 +- .../storefront/experience/pages/index.ts | 2 +- 16 files changed, 110 insertions(+), 105 deletions(-) delete mode 100644 libs/domain/content/src/models/article.model.ts create mode 100644 libs/domain/content/src/models/cms.model.ts rename libs/domain/content/src/resolvers/{article-page-description-meta.resolver.ts => cms-page-description-meta.resolver.ts} (88%) rename libs/domain/content/src/resolvers/{article-page-title-meta.resolver.ts => cms-page-title-meta.resolver.ts} (88%) rename libs/domain/content/src/services/{article-context.ts => cms/cms-context.ts} (82%) create mode 100644 libs/domain/content/src/services/cms/cms-providers.ts rename libs/template/presets/storefront/experience/pages/{article-page.ts => cms-pages.ts} (83%) diff --git a/libs/domain/content/link/link.component.ts b/libs/domain/content/link/link.component.ts index 971186437..38699d939 100644 --- a/libs/domain/content/link/link.component.ts +++ b/libs/domain/content/link/link.component.ts @@ -35,6 +35,7 @@ export class ContentLinkComponent extends ContentMixin< protected $link = computed(() => { const { url, type, id, qualifier, params } = this.$options(); + if (url) return of(url); if (type) return this.semanticLinkService.get({ diff --git a/libs/domain/content/src/models/article.model.ts b/libs/domain/content/src/models/article.model.ts deleted file mode 100644 index 47ae2c7c2..000000000 --- a/libs/domain/content/src/models/article.model.ts +++ /dev/null @@ -1,9 +0,0 @@ -// TODO: create dynamic types and dependable dynamic pages. -export const articleTypes = ['article', 'faq', 'about']; - -export interface ArticleContent { - heading: string; - description: string; - content: string; - type: string; -} diff --git a/libs/domain/content/src/models/cms.model.ts b/libs/domain/content/src/models/cms.model.ts new file mode 100644 index 000000000..664aa2296 --- /dev/null +++ b/libs/domain/content/src/models/cms.model.ts @@ -0,0 +1,18 @@ +// TODO: create dynamic types and dependable dynamic pages. +export const cmsTypes = ['article', 'faq', 'about']; + +declare global { + interface ContentFields { + article: undefined; + faq: undefined; + about: undefined; + } +} + +export interface CmsContent { + heading: string; + description: string; + content: string; + type: string; + [key: string]: unknown; +} diff --git a/libs/domain/content/src/models/content.model.ts b/libs/domain/content/src/models/content.model.ts index 9c836971d..2a11c68e3 100644 --- a/libs/domain/content/src/models/content.model.ts +++ b/libs/domain/content/src/models/content.model.ts @@ -1,9 +1,6 @@ declare global { interface ContentFields { component: undefined; - article: undefined; - faq: undefined; - about: undefined; } } diff --git a/libs/domain/content/src/models/index.ts b/libs/domain/content/src/models/index.ts index 8638841a1..b01644602 100644 --- a/libs/domain/content/src/models/index.ts +++ b/libs/domain/content/src/models/index.ts @@ -1,4 +1,4 @@ -export * from './article.model'; +export * from './cms.model'; export * from './content.model'; /** diff --git a/libs/domain/content/src/resolvers/article-page-description-meta.resolver.ts b/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts similarity index 88% rename from libs/domain/content/src/resolvers/article-page-description-meta.resolver.ts rename to libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts index 0fc9fee47..baa57aa21 100644 --- a/libs/domain/content/src/resolvers/article-page-description-meta.resolver.ts +++ b/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts @@ -6,10 +6,10 @@ import { import { inject } from '@oryx-frontend/di'; import { RouterService } from '@oryx-frontend/router'; import { Observable, combineLatest, map, of, switchMap } from 'rxjs'; -import { ArticleContent, ContentQualifier } from '../models'; +import { CmsContent, ContentQualifier } from '../models'; import { ContentContext, ContentService } from '../services'; -export class ArticlePageDescriptionMetaResolver implements PageMetaResolver { +export class CmsPageDescriptionMetaResolver implements PageMetaResolver { constructor( protected context = inject(ContextService), protected content = inject(ContentService), @@ -37,7 +37,7 @@ export class ArticlePageDescriptionMetaResolver implements PageMetaResolver { if (!id || !type) return of({}); return this.content - .get({ + .get({ id, type, entities: [type], diff --git a/libs/domain/content/src/resolvers/article-page-title-meta.resolver.ts b/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts similarity index 88% rename from libs/domain/content/src/resolvers/article-page-title-meta.resolver.ts rename to libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts index d80f46491..82e35b534 100644 --- a/libs/domain/content/src/resolvers/article-page-title-meta.resolver.ts +++ b/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts @@ -6,10 +6,10 @@ import { import { inject } from '@oryx-frontend/di'; import { RouterService } from '@oryx-frontend/router'; import { Observable, combineLatest, map, of, switchMap } from 'rxjs'; -import { ArticleContent, ContentQualifier } from '../models'; +import { CmsContent, ContentQualifier } from '../models'; import { ContentContext, ContentService } from '../services'; -export class ArticlePageTitleMetaResolver implements PageMetaResolver { +export class CmsPageTitleMetaResolver implements PageMetaResolver { constructor( protected context = inject(ContextService), protected router = inject(RouterService), @@ -37,7 +37,7 @@ export class ArticlePageTitleMetaResolver implements PageMetaResolver { if (!id || !type) return of({}); return this.content - .get({ + .get({ id, type, entities: [type], diff --git a/libs/domain/content/src/resolvers/index.ts b/libs/domain/content/src/resolvers/index.ts index 0029694fe..5a6630837 100644 --- a/libs/domain/content/src/resolvers/index.ts +++ b/libs/domain/content/src/resolvers/index.ts @@ -1,2 +1,3 @@ -export * from './article-page-description-meta.resolver'; -export * from './article-page-title-meta.resolver'; +export * from './cms-page-description-meta.resolver'; +export * from './cms-page-title-meta.resolver'; + diff --git a/libs/domain/content/src/services/article-context.ts b/libs/domain/content/src/services/cms/cms-context.ts similarity index 82% rename from libs/domain/content/src/services/article-context.ts rename to libs/domain/content/src/services/cms/cms-context.ts index 38d9f33a9..5e5fd3915 100644 --- a/libs/domain/content/src/services/article-context.ts +++ b/libs/domain/content/src/services/cms/cms-context.ts @@ -2,9 +2,9 @@ import { ContextFallback } from '@oryx-frontend/core'; import { inject, Provider } from '@oryx-frontend/di'; import { RouterService } from '@oryx-frontend/router'; import { combineLatest, map } from 'rxjs'; -import { ContentContext } from './content-context'; +import { ContentContext } from '../content-context'; -export const ArticleQualifierContextFallback: Provider = { +export const CmsQualifierContextFallback: Provider = { provide: `${ContextFallback}${ContentContext.Content}`, useFactory: () => combineLatest([ diff --git a/libs/domain/content/src/services/cms/cms-providers.ts b/libs/domain/content/src/services/cms/cms-providers.ts new file mode 100644 index 000000000..9cb02228c --- /dev/null +++ b/libs/domain/content/src/services/cms/cms-providers.ts @@ -0,0 +1,48 @@ +import { PageMetaResolver, provideEntity } from '@oryx-frontend/core'; +import { Provider } from '@oryx-frontend/di'; +import { cmsTypes, Content, ContentQualifier } from '../../models'; +import { CmsPageDescriptionMetaResolver, CmsPageTitleMetaResolver } from '../../resolvers'; +import { ContentConfig } from '../adapter'; +import { ContentService } from '../content.service'; +import { CmsQualifierContextFallback } from './cms-context'; +import { contentfulProviders } from './contentful'; +import { storyblokProviders } from './storyblok'; +import { strapiProviders } from './strapi'; + +export const cmsProviders: Provider[] = [ + ...contentfulProviders, + ...storyblokProviders, + ...strapiProviders, + CmsQualifierContextFallback, + { + provide: PageMetaResolver, + useClass: CmsPageTitleMetaResolver, + }, + { + provide: PageMetaResolver, + useClass: CmsPageDescriptionMetaResolver, + }, + { + provide: ContentConfig, + useValue: { + storyblok: { + types: ['component', 'faq', 'contents'], + }, + strapi: { + types: ['component', 'about', 'contents'], + defaultType: 'about', + }, + contentful: { + types: ['component', 'article', 'contents'], + }, + }, + }, + ...cmsTypes.map((type) => + provideEntity(type, { + service: ContentService, + context: type, + get: (service, qualifier) => + (service as ContentService).get({ ...qualifier, type }), + }) + ), +]; diff --git a/libs/domain/content/src/services/cms/index.ts b/libs/domain/content/src/services/cms/index.ts index 184e49469..6664391f7 100644 --- a/libs/domain/content/src/services/cms/index.ts +++ b/libs/domain/content/src/services/cms/index.ts @@ -1,3 +1,6 @@ +export * from './cms-context'; +export * from './cms-providers'; export * from './contentful'; export * from './storyblok'; export * from './strapi'; + diff --git a/libs/domain/content/src/services/content.providers.ts b/libs/domain/content/src/services/content.providers.ts index 29e4a93d6..2184f5e6b 100644 --- a/libs/domain/content/src/services/content.providers.ts +++ b/libs/domain/content/src/services/content.providers.ts @@ -1,15 +1,8 @@ -import { PageMetaResolver, provideEntity } from '@oryx-frontend/core'; +import { provideEntity } from '@oryx-frontend/core'; import { Provider } from '@oryx-frontend/di'; import { ExperienceAdapter } from '@oryx-frontend/experience'; -import { articleTypes, Content, ContentQualifier } from '../models'; -import { ArticlePageDescriptionMetaResolver, ArticlePageTitleMetaResolver } from '../resolvers'; -import { ContentConfig, ContentExperienceAdapter } from './adapter'; -import { ArticleQualifierContextFallback } from './article-context'; -import { - contentfulProviders, - storyblokProviders, - strapiProviders, -} from './cms'; +import { ContentExperienceAdapter } from './adapter'; +import { cmsProviders } from './cms'; import { ContentContext } from './content-context'; import { ContentService } from './content.service'; import { DefaultContentService } from './default-content.service'; @@ -28,43 +21,9 @@ export const contentProviders: Provider[] = [ provide: FontService, useClass: DefaultFontService, }, - ...contentfulProviders, - ...storyblokProviders, - ...strapiProviders, provideEntity('content', { service: ContentService, context: ContentContext.Content, }), - ArticleQualifierContextFallback, - { - provide: PageMetaResolver, - useClass: ArticlePageTitleMetaResolver, - }, - { - provide: PageMetaResolver, - useClass: ArticlePageDescriptionMetaResolver, - }, - { - provide: ContentConfig, - useValue: { - storyblok: { - types: ['component', 'faq', 'contents'], - }, - strapi: { - types: ['component', 'about', 'contents'], - defaultType: 'about', - }, - contentful: { - types: ['component', 'article', 'contents'], - }, - }, - }, - ...articleTypes.map((type) => - provideEntity(type, { - service: ContentService, - context: type, - get: (service, qualifier) => - (service as ContentService).get({ ...qualifier, type }), - }) - ), + ...cmsProviders, ]; diff --git a/libs/template/presets/storefront/experience/experience-data.ts b/libs/template/presets/storefront/experience/experience-data.ts index 8faf4b8e4..0c21c13bf 100644 --- a/libs/template/presets/storefront/experience/experience-data.ts +++ b/libs/template/presets/storefront/experience/experience-data.ts @@ -10,6 +10,7 @@ import { cartsPage, categoryPage, checkoutPage, + cmsPages, contactPage, createAddressPage, editAddressPage, @@ -40,6 +41,7 @@ export const StaticExperienceFeature: AppFeature = { editAddressPage, ...(featureVersion >= '1.1' ? [registrationPage] : []), ...(featureVersion >= '1.4' ? [cartsPage, cartCreatePage] : []), + ...cmsPages, ]), ], }; diff --git a/libs/template/presets/storefront/experience/footer.ts b/libs/template/presets/storefront/experience/footer.ts index 8141e0280..548d2b735 100644 --- a/libs/template/presets/storefront/experience/footer.ts +++ b/libs/template/presets/storefront/experience/footer.ts @@ -29,44 +29,29 @@ const legalLinks: ExperienceComponent = { type: 'oryx-composition', name: 'legal links', id: 'legal-links', - components: - featureVersion >= '1.5' - ? [ - { - type: 'oryx-content-text', - content: { - data: { text: `©️ ${new Date().getFullYear()} Spryker` }, - }, - }, - { - type: 'oryx-content-list', - options: { - tags: 'legal', - rules: [ - { - layout: { - type: 'flex', - divider: true, - }, - width: 'auto', - }, - ], - }, - }, - ] - : [ + components: [ + { + type: 'oryx-content-text', + content: { + data: { text: `©️ ${new Date().getFullYear()} Spryker` }, + }, + }, + { + type: 'oryx-content-list', + options: { + tags: 'legal', + rules: [ { - type: 'oryx-content-text', - content: { - data: { text: `©️ ${new Date().getFullYear()} Spryker` }, + layout: { + type: 'flex', + divider: true, }, + width: 'auto', }, - link('Imprint', '/faq/imprint'), - link('Terms & conditions', '/article/terms-and-conditions'), - link('Privacy Notice', '/article/privacy'), - link('Data preference'), - link('Condition of use'), ], + }, + }, + ], options: { rules: [ { diff --git a/libs/template/presets/storefront/experience/pages/article-page.ts b/libs/template/presets/storefront/experience/pages/cms-pages.ts similarity index 83% rename from libs/template/presets/storefront/experience/pages/article-page.ts rename to libs/template/presets/storefront/experience/pages/cms-pages.ts index 6195ef775..d734a6659 100644 --- a/libs/template/presets/storefront/experience/pages/article-page.ts +++ b/libs/template/presets/storefront/experience/pages/cms-pages.ts @@ -1,7 +1,7 @@ -import { articleTypes } from '@oryx-frontend/content'; +import { cmsTypes } from '@oryx-frontend/content'; import { ExperienceComponent } from '@oryx-frontend/experience'; -export const experienceArticlePages: ExperienceComponent[] = articleTypes.map((type) => [ +export const cmsPages: ExperienceComponent[] = cmsTypes.map((type) => [ { type: 'Page', id: type, diff --git a/libs/template/presets/storefront/experience/pages/index.ts b/libs/template/presets/storefront/experience/pages/index.ts index 8ea867bf1..31eecb200 100644 --- a/libs/template/presets/storefront/experience/pages/index.ts +++ b/libs/template/presets/storefront/experience/pages/index.ts @@ -1,7 +1,7 @@ -export * from './article-page'; export * from './cart-page'; export * from './category-page'; export * from './checkout-page'; +export * from './cms-pages'; export * from './contact-page'; export * from './home-page'; export * from './login-page'; From 7a8acc498c9a9feb9b1a2ac0ff95cd7394e02845 Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Fri, 30 Aug 2024 11:57:14 +0300 Subject: [PATCH 03/10] fix: normalize cms --- libs/domain/content/link/link.component.ts | 2 +- .../resolvers/cms-page-description-meta.resolver.ts | 2 +- .../src/resolvers/cms-page-title-meta.resolver.ts | 4 ++-- libs/domain/content/src/services/cms/cms-providers.ts | 2 +- .../default-page-meta-resolver.service.ts | 8 ++++---- .../presets/storefront/experience/pages/cms-pages.ts | 11 +++++------ 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/libs/domain/content/link/link.component.ts b/libs/domain/content/link/link.component.ts index 38699d939..72fbbd9bb 100644 --- a/libs/domain/content/link/link.component.ts +++ b/libs/domain/content/link/link.component.ts @@ -39,7 +39,7 @@ export class ContentLinkComponent extends ContentMixin< if (url) return of(url); if (type) return this.semanticLinkService.get({ - type: type, + type, id, qualifier, params, diff --git a/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts b/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts index baa57aa21..6ea262adf 100644 --- a/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts +++ b/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts @@ -22,7 +22,7 @@ export class CmsPageDescriptionMetaResolver implements PageMetaResolver { combineLatest([ this.context.get(null, ContentContext.Content), this.router.currentRoute(), - ]).pipe(map(([type, route]) => route.includes(`/${type}/`))), + ]).pipe(map(([qualifier, route]) => route.includes(`/${qualifier?.type}/${qualifier?.id}`))), ]); } diff --git a/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts b/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts index 82e35b534..96569703e 100644 --- a/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts +++ b/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts @@ -5,7 +5,7 @@ import { } from '@oryx-frontend/core'; import { inject } from '@oryx-frontend/di'; import { RouterService } from '@oryx-frontend/router'; -import { Observable, combineLatest, map, of, switchMap } from 'rxjs'; +import { combineLatest, map, Observable, of, switchMap } from 'rxjs'; import { CmsContent, ContentQualifier } from '../models'; import { ContentContext, ContentService } from '../services'; @@ -22,7 +22,7 @@ export class CmsPageTitleMetaResolver implements PageMetaResolver { combineLatest([ this.context.get(null, ContentContext.Content), this.router.currentRoute(), - ]).pipe(map(([type, route]) => route.includes(`/${type}/`))), + ]).pipe(map(([qualifier, route]) => route.includes(`/${qualifier?.type}/${qualifier?.id}`))), ]); } diff --git a/libs/domain/content/src/services/cms/cms-providers.ts b/libs/domain/content/src/services/cms/cms-providers.ts index 9cb02228c..b5a5e9d56 100644 --- a/libs/domain/content/src/services/cms/cms-providers.ts +++ b/libs/domain/content/src/services/cms/cms-providers.ts @@ -40,7 +40,7 @@ export const cmsProviders: Provider[] = [ ...cmsTypes.map((type) => provideEntity(type, { service: ContentService, - context: type, + context: 'content', get: (service, qualifier) => (service as ContentService).get({ ...qualifier, type }), }) diff --git a/libs/platform/core/src/services/page-meta/page-meta-resolver/default-page-meta-resolver.service.ts b/libs/platform/core/src/services/page-meta/page-meta-resolver/default-page-meta-resolver.service.ts index 7ff7775f4..6af0db5cc 100644 --- a/libs/platform/core/src/services/page-meta/page-meta-resolver/default-page-meta-resolver.service.ts +++ b/libs/platform/core/src/services/page-meta/page-meta-resolver/default-page-meta-resolver.service.ts @@ -35,12 +35,12 @@ export class DefaultPageMetaResolverService implements PageMetaResolverService { ]) ) ).pipe( - map((data) => - data - .filter(([score]) => score !== ResolverScore.NotUsed) + map((data) => data + .filter(([score, data]) => score !== ResolverScore.NotUsed && Object.keys(data).length) .sort(([aScore], [bScore]) => aScore - bScore) .reduce((acc, [_, elements]) => ({ ...acc, ...elements }), {}) - ) + ), + ) ).pipe(shareReplay({ bufferSize: 1, refCount: true })); protected newData$ = this.data$.pipe( diff --git a/libs/template/presets/storefront/experience/pages/cms-pages.ts b/libs/template/presets/storefront/experience/pages/cms-pages.ts index d734a6659..eb9fbb72a 100644 --- a/libs/template/presets/storefront/experience/pages/cms-pages.ts +++ b/libs/template/presets/storefront/experience/pages/cms-pages.ts @@ -1,14 +1,14 @@ import { cmsTypes } from '@oryx-frontend/content'; import { ExperienceComponent } from '@oryx-frontend/experience'; -export const cmsPages: ExperienceComponent[] = cmsTypes.map((type) => [ - { +export const cmsPages: ExperienceComponent[] = cmsTypes.map((type) => + ({ type: 'Page', id: type, meta: { title: type, route: `/${type}/:id`, - routeType: 'content', + routeType: type, }, components: [ { ref: 'header' }, @@ -22,7 +22,6 @@ export const cmsPages: ExperienceComponent[] = cmsTypes.map((type) => [ type: 'oryx-site-breadcrumb', options: { rules: [{ colSpan: 2 }] }, }, - { type: 'oryx-data-text', options: { @@ -33,5 +32,5 @@ export const cmsPages: ExperienceComponent[] = cmsTypes.map((type) => [ }, { ref: 'footer' }, ], - }, -]); + }), +); From e5c030c6652d58a9253a8450f58fbafb915a1cad Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Fri, 30 Aug 2024 12:40:24 +0300 Subject: [PATCH 04/10] chore: format --- .../content/src/models/content.model.ts | 3 + .../cms-page-description-meta.resolver.ts | 6 +- .../resolvers/cms-page-title-meta.resolver.ts | 8 ++- libs/domain/content/src/resolvers/index.ts | 1 - .../content/src/services/cms/cms-providers.ts | 7 +- libs/domain/content/src/services/cms/index.ts | 1 - .../default-page-meta-resolver.service.ts | 11 ++-- .../data-text/data-text.component.ts | 1 + .../storefront/experience/pages/cms-pages.ts | 60 +++++++++-------- .../storefront/experience/pages/home-page.ts | 64 +++++++++++++------ .../storefront/experience/pages/index.ts | 1 - 11 files changed, 99 insertions(+), 64 deletions(-) diff --git a/libs/domain/content/src/models/content.model.ts b/libs/domain/content/src/models/content.model.ts index 2a11c68e3..973b6d632 100644 --- a/libs/domain/content/src/models/content.model.ts +++ b/libs/domain/content/src/models/content.model.ts @@ -1,5 +1,8 @@ declare global { interface ContentFields { + /** + * Page or component config. // ExperienceComponent + */ component: undefined; } } diff --git a/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts b/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts index 6ea262adf..cb5179568 100644 --- a/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts +++ b/libs/domain/content/src/resolvers/cms-page-description-meta.resolver.ts @@ -22,7 +22,11 @@ export class CmsPageDescriptionMetaResolver implements PageMetaResolver { combineLatest([ this.context.get(null, ContentContext.Content), this.router.currentRoute(), - ]).pipe(map(([qualifier, route]) => route.includes(`/${qualifier?.type}/${qualifier?.id}`))), + ]).pipe( + map(([qualifier, route]) => + route.includes(`/${qualifier?.type}/${qualifier?.id}`) + ) + ), ]); } diff --git a/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts b/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts index 96569703e..1426d71af 100644 --- a/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts +++ b/libs/domain/content/src/resolvers/cms-page-title-meta.resolver.ts @@ -5,7 +5,7 @@ import { } from '@oryx-frontend/core'; import { inject } from '@oryx-frontend/di'; import { RouterService } from '@oryx-frontend/router'; -import { combineLatest, map, Observable, of, switchMap } from 'rxjs'; +import { Observable, combineLatest, map, of, switchMap } from 'rxjs'; import { CmsContent, ContentQualifier } from '../models'; import { ContentContext, ContentService } from '../services'; @@ -22,7 +22,11 @@ export class CmsPageTitleMetaResolver implements PageMetaResolver { combineLatest([ this.context.get(null, ContentContext.Content), this.router.currentRoute(), - ]).pipe(map(([qualifier, route]) => route.includes(`/${qualifier?.type}/${qualifier?.id}`))), + ]).pipe( + map(([qualifier, route]) => + route.includes(`/${qualifier?.type}/${qualifier?.id}`) + ) + ), ]); } diff --git a/libs/domain/content/src/resolvers/index.ts b/libs/domain/content/src/resolvers/index.ts index 5a6630837..6c2a01c34 100644 --- a/libs/domain/content/src/resolvers/index.ts +++ b/libs/domain/content/src/resolvers/index.ts @@ -1,3 +1,2 @@ export * from './cms-page-description-meta.resolver'; export * from './cms-page-title-meta.resolver'; - diff --git a/libs/domain/content/src/services/cms/cms-providers.ts b/libs/domain/content/src/services/cms/cms-providers.ts index b5a5e9d56..658c36868 100644 --- a/libs/domain/content/src/services/cms/cms-providers.ts +++ b/libs/domain/content/src/services/cms/cms-providers.ts @@ -1,7 +1,10 @@ import { PageMetaResolver, provideEntity } from '@oryx-frontend/core'; import { Provider } from '@oryx-frontend/di'; -import { cmsTypes, Content, ContentQualifier } from '../../models'; -import { CmsPageDescriptionMetaResolver, CmsPageTitleMetaResolver } from '../../resolvers'; +import { Content, ContentQualifier, cmsTypes } from '../../models'; +import { + CmsPageDescriptionMetaResolver, + CmsPageTitleMetaResolver, +} from '../../resolvers'; import { ContentConfig } from '../adapter'; import { ContentService } from '../content.service'; import { CmsQualifierContextFallback } from './cms-context'; diff --git a/libs/domain/content/src/services/cms/index.ts b/libs/domain/content/src/services/cms/index.ts index 6664391f7..afde5c7f5 100644 --- a/libs/domain/content/src/services/cms/index.ts +++ b/libs/domain/content/src/services/cms/index.ts @@ -3,4 +3,3 @@ export * from './cms-providers'; export * from './contentful'; export * from './storyblok'; export * from './strapi'; - diff --git a/libs/platform/core/src/services/page-meta/page-meta-resolver/default-page-meta-resolver.service.ts b/libs/platform/core/src/services/page-meta/page-meta-resolver/default-page-meta-resolver.service.ts index 6af0db5cc..d697300de 100644 --- a/libs/platform/core/src/services/page-meta/page-meta-resolver/default-page-meta-resolver.service.ts +++ b/libs/platform/core/src/services/page-meta/page-meta-resolver/default-page-meta-resolver.service.ts @@ -35,12 +35,15 @@ export class DefaultPageMetaResolverService implements PageMetaResolverService { ]) ) ).pipe( - map((data) => data - .filter(([score, data]) => score !== ResolverScore.NotUsed && Object.keys(data).length) + map((data) => + data + .filter( + ([score, data]) => + score !== ResolverScore.NotUsed && Object.keys(data).length + ) .sort(([aScore], [bScore]) => aScore - bScore) .reduce((acc, [_, elements]) => ({ ...acc, ...elements }), {}) - ), - + ) ) ).pipe(shareReplay({ bufferSize: 1, refCount: true })); protected newData$ = this.data$.pipe( diff --git a/libs/platform/experience/data-text/data-text.component.ts b/libs/platform/experience/data-text/data-text.component.ts index fc0741bf2..804d5402a 100644 --- a/libs/platform/experience/data-text/data-text.component.ts +++ b/libs/platform/experience/data-text/data-text.component.ts @@ -20,6 +20,7 @@ export class DataTextComponent extends TextMixin( protected $data = computed(() => { const { entity: type, field } = this.$options(); + console.log(type, field); return this.entityService .getField({ element: this, type, field }) .pipe(catchError(() => of())); diff --git a/libs/template/presets/storefront/experience/pages/cms-pages.ts b/libs/template/presets/storefront/experience/pages/cms-pages.ts index eb9fbb72a..100f01c5e 100644 --- a/libs/template/presets/storefront/experience/pages/cms-pages.ts +++ b/libs/template/presets/storefront/experience/pages/cms-pages.ts @@ -1,36 +1,34 @@ import { cmsTypes } from '@oryx-frontend/content'; import { ExperienceComponent } from '@oryx-frontend/experience'; -export const cmsPages: ExperienceComponent[] = cmsTypes.map((type) => - ({ - type: 'Page', - id: type, - meta: { - title: type, - route: `/${type}/:id`, - routeType: type, - }, - components: [ - { ref: 'header' }, - { - type: 'oryx-composition', - options: { - rules: [{ layout: { type: 'split' }, padding: '30px 0' }], +export const cmsPages: ExperienceComponent[] = cmsTypes.map((type) => ({ + type: 'Page', + id: type, + meta: { + title: type, + route: `/${type}/:id`, + routeType: type, + }, + components: [ + { ref: 'header' }, + { + type: 'oryx-composition', + options: { + rules: [{ layout: { type: 'split' }, padding: '30px 0' }], + }, + components: [ + { + type: 'oryx-site-breadcrumb', + options: { rules: [{ colSpan: 2 }] }, }, - components: [ - { - type: 'oryx-site-breadcrumb', - options: { rules: [{ colSpan: 2 }] }, - }, - { - type: 'oryx-data-text', - options: { - field: 'content', - }, + { + type: 'oryx-data-text', + options: { + field: 'content', }, - ], - }, - { ref: 'footer' }, - ], - }), -); + }, + ], + }, + { ref: 'footer' }, + ], +})); diff --git a/libs/template/presets/storefront/experience/pages/home-page.ts b/libs/template/presets/storefront/experience/pages/home-page.ts index a28a756d5..79ad3442a 100644 --- a/libs/template/presets/storefront/experience/pages/home-page.ts +++ b/libs/template/presets/storefront/experience/pages/home-page.ts @@ -28,6 +28,12 @@ export const homePage: ExperienceComponent = { type: 'oryx-composition', id: 'home-hero', options: { + context: { + content: { + entities: ['article'], + id: 'home-hero', + }, + }, rules: [ { height: '550px', @@ -45,17 +51,25 @@ export const homePage: ExperienceComponent = { }, components: [ { - type: 'oryx-content-image', - name: 'hero', - content: { - data: { - link: `/category/12`, - alt: 'hero image', - image: - 'https://images.unsplash.com/photo-1670272505340-d906d8d77d03?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2370&q=80', - }, - }, + ...(featureVersion >= '1.5' + ? { + type: 'oryx-data-image', + } + : { + type: 'oryx-content-image', + name: 'hero', + content: { + data: { + link: `/category/12`, + alt: 'hero image', + image: + 'https://images.unsplash.com/photo-1670272505340-d906d8d77d03?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2370&q=80', + }, + }, + }), options: { + field: 'picture', + entity: 'article', ...(featureVersion >= '1.4' ? {} : { position: 'center 20%' }), rules: [ { @@ -70,18 +84,26 @@ export const homePage: ExperienceComponent = { }, }, { - type: 'oryx-content-text', - content: { - data: { - text: ` - CANON EOS R7 System camera -

Discover everything

-
EOS R7 wows with its ability to track fast-moving subjects with its Deep-learning Dual Pixel CMOS AF II focus system.
- Shop now - `, - }, - }, + ...(featureVersion >= '1.5' + ? { + type: 'oryx-data-text', + } + : { + type: 'oryx-content-text', + content: { + data: { + text: ` + CANON EOS R7 System camera +

Discover everything

+
EOS R7 wows with its ability to track fast-moving subjects with its Deep-learning Dual Pixel CMOS AF II focus system.
+ Shop now + `, + }, + }, + }), options: { + field: 'content', + entity: 'article', rules: [ { padding: '40px', diff --git a/libs/template/presets/storefront/experience/pages/index.ts b/libs/template/presets/storefront/experience/pages/index.ts index 31eecb200..ab973394b 100644 --- a/libs/template/presets/storefront/experience/pages/index.ts +++ b/libs/template/presets/storefront/experience/pages/index.ts @@ -10,4 +10,3 @@ export * from './order-confirmation-page'; export * from './product-page'; export * from './registration-page'; export * from './search-page'; - From f7e8484014c24e8b85b857545a02aa79bcb2d316 Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Fri, 30 Aug 2024 12:48:17 +0300 Subject: [PATCH 05/10] chore: log --- libs/platform/experience/data-text/data-text.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/platform/experience/data-text/data-text.component.ts b/libs/platform/experience/data-text/data-text.component.ts index 804d5402a..fa1d6ca8e 100644 --- a/libs/platform/experience/data-text/data-text.component.ts +++ b/libs/platform/experience/data-text/data-text.component.ts @@ -20,7 +20,7 @@ export class DataTextComponent extends TextMixin( protected $data = computed(() => { const { entity: type, field } = this.$options(); - console.log(type, field); + return this.entityService .getField({ element: this, type, field }) .pipe(catchError(() => of())); From 81ce8f051d5d7014ea1fc70cca75155afaa2b542 Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Fri, 30 Aug 2024 12:56:35 +0300 Subject: [PATCH 06/10] chore: add fallback --- .../presets/storefront/experience/footer.ts | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/libs/template/presets/storefront/experience/footer.ts b/libs/template/presets/storefront/experience/footer.ts index 548d2b735..5b5b039e5 100644 --- a/libs/template/presets/storefront/experience/footer.ts +++ b/libs/template/presets/storefront/experience/footer.ts @@ -36,21 +36,31 @@ const legalLinks: ExperienceComponent = { data: { text: `©️ ${new Date().getFullYear()} Spryker` }, }, }, - { - type: 'oryx-content-list', - options: { - tags: 'legal', - rules: [ + ...(featureVersion >= '1.5' + ? [ { - layout: { - type: 'flex', - divider: true, + type: 'oryx-content-list', + options: { + tags: 'legal', + rules: [ + { + layout: { + type: 'flex', + divider: true, + }, + width: 'auto', + }, + ], }, - width: 'auto', }, - ], - }, - }, + ] + : [ + link('Imprint', '/faq/imprint'), + link('Terms & conditions', '/article/terms-and-conditions'), + link('Privacy Notice', '/article/privacy'), + link('Data preference'), + link('Condition of use'), + ]), ], options: { rules: [ From 0345a7f79ba65129d22a86556a3fb9d97d42293a Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Fri, 30 Aug 2024 13:45:46 +0300 Subject: [PATCH 07/10] ci From 577f4641dec409bb95efc388d3c209912b121b36 Mon Sep 17 00:00:00 2001 From: Oleksii Bilan Date: Tue, 3 Sep 2024 14:15:30 +0300 Subject: [PATCH 08/10] Update libs/template/presets/storefront/experience/pages/cms-pages.ts Co-authored-by: Alexander Kovalenko --- libs/template/presets/storefront/experience/pages/cms-pages.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/template/presets/storefront/experience/pages/cms-pages.ts b/libs/template/presets/storefront/experience/pages/cms-pages.ts index 100f01c5e..26111bef7 100644 --- a/libs/template/presets/storefront/experience/pages/cms-pages.ts +++ b/libs/template/presets/storefront/experience/pages/cms-pages.ts @@ -1,7 +1,7 @@ import { cmsTypes } from '@oryx-frontend/content'; import { ExperienceComponent } from '@oryx-frontend/experience'; -export const cmsPages: ExperienceComponent[] = cmsTypes.map((type) => ({ +export const cmsPage: ExperienceComponent[] = cmsTypes.map((type) => ({ type: 'Page', id: type, meta: { From 4a908231b32fcca0f601d3d55779e436807abd11 Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Wed, 4 Sep 2024 10:55:42 +0300 Subject: [PATCH 09/10] fix: fix naming --- .../template/presets/storefront/experience/experience-data.ts | 4 ++-- .../storefront/experience/pages/{cms-pages.ts => cms-page.ts} | 0 libs/template/presets/storefront/experience/pages/index.ts | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) rename libs/template/presets/storefront/experience/pages/{cms-pages.ts => cms-page.ts} (100%) diff --git a/libs/template/presets/storefront/experience/experience-data.ts b/libs/template/presets/storefront/experience/experience-data.ts index 0c21c13bf..24681933d 100644 --- a/libs/template/presets/storefront/experience/experience-data.ts +++ b/libs/template/presets/storefront/experience/experience-data.ts @@ -10,7 +10,7 @@ import { cartsPage, categoryPage, checkoutPage, - cmsPages, + cmsPage, contactPage, createAddressPage, editAddressPage, @@ -41,7 +41,7 @@ export const StaticExperienceFeature: AppFeature = { editAddressPage, ...(featureVersion >= '1.1' ? [registrationPage] : []), ...(featureVersion >= '1.4' ? [cartsPage, cartCreatePage] : []), - ...cmsPages, + ...cmsPage, ]), ], }; diff --git a/libs/template/presets/storefront/experience/pages/cms-pages.ts b/libs/template/presets/storefront/experience/pages/cms-page.ts similarity index 100% rename from libs/template/presets/storefront/experience/pages/cms-pages.ts rename to libs/template/presets/storefront/experience/pages/cms-page.ts diff --git a/libs/template/presets/storefront/experience/pages/index.ts b/libs/template/presets/storefront/experience/pages/index.ts index ab973394b..472e732f8 100644 --- a/libs/template/presets/storefront/experience/pages/index.ts +++ b/libs/template/presets/storefront/experience/pages/index.ts @@ -1,7 +1,7 @@ export * from './cart-page'; export * from './category-page'; export * from './checkout-page'; -export * from './cms-pages'; +export * from './cms-page'; export * from './contact-page'; export * from './home-page'; export * from './login-page'; @@ -10,3 +10,4 @@ export * from './order-confirmation-page'; export * from './product-page'; export * from './registration-page'; export * from './search-page'; + From 18556dfd2712b0a098536a9c96d6f1f95d2f08a7 Mon Sep 17 00:00:00 2001 From: Aleksey Belan Date: Wed, 4 Sep 2024 11:36:25 +0300 Subject: [PATCH 10/10] chore: format --- libs/template/presets/storefront/experience/pages/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/template/presets/storefront/experience/pages/index.ts b/libs/template/presets/storefront/experience/pages/index.ts index 472e732f8..6f0bb01f7 100644 --- a/libs/template/presets/storefront/experience/pages/index.ts +++ b/libs/template/presets/storefront/experience/pages/index.ts @@ -10,4 +10,3 @@ export * from './order-confirmation-page'; export * from './product-page'; export * from './registration-page'; export * from './search-page'; -