-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(experience): Added data list component (#1050)
The data list component can be used to render a list of components for a given entity. Each data item is wrapped and supports a link to the entity. The components rendered for the item are based on the composition components. closes: [HRZ-90985](https://spryker.atlassian.net/browse/HRZ-90985) [HRZ-90985]: https://spryker.atlassian.net/browse/HRZ-90985?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: dunqan <[email protected]>
- Loading branch information
1 parent
dab4da1
commit 1464fc9
Showing
33 changed files
with
433 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './merchant-list.normalizer'; | ||
export * from './merchant.normalizer'; | ||
export * from './models'; | ||
export * from './offer.normalizer'; |
18 changes: 18 additions & 0 deletions
18
libs/domain/merchant/services/src/adapter/normalizers/merchant-list.normalizer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { TransformerService } from '@spryker-oryx/core'; | ||
import { | ||
ApiMerchantModel, | ||
Merchant, | ||
MerchantNormalizer, | ||
} from '@spryker-oryx/merchant'; | ||
import { Observable, combineLatest, of } from 'rxjs'; | ||
|
||
export function merchantListNormalizer( | ||
data: ApiMerchantModel.Merchant[], | ||
transformer: TransformerService | ||
): Observable<Merchant[]> { | ||
return data.length | ||
? combineLatest( | ||
data.map((cart) => transformer.transform(cart, MerchantNormalizer)) | ||
) | ||
: of([]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 9 additions & 1 deletion
10
libs/domain/merchant/src/services/adapter/merchant.adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
import { Transformer } from '@spryker-oryx/core'; | ||
import { Observable } from 'rxjs'; | ||
import { Merchant, MerchantQualifier, ProductOffer } from '../../models'; | ||
import { | ||
Merchant, | ||
MerchantListQualifier, | ||
MerchantQualifier, | ||
ProductOffer, | ||
} from '../../models'; | ||
|
||
export const MerchantAdapter = 'oryx.MerchantAdapter'; | ||
export const MerchantNormalizer = 'oryx.MerchantNormalizer*'; | ||
export const MerchantListNormalizer = 'oryx.MerchantListNormalizer*'; | ||
|
||
export const OfferNormalizer = 'oryx.OfferNormalizer*'; | ||
|
||
export interface MerchantAdapter { | ||
get(qualifier: MerchantQualifier): Observable<Merchant>; | ||
getList(qualifier?: MerchantListQualifier): Observable<Merchant[]>; | ||
} | ||
|
||
declare global { | ||
interface InjectionTokensContractMap { | ||
[MerchantAdapter]: MerchantAdapter; | ||
[MerchantNormalizer]: Transformer<Merchant>; | ||
[MerchantListNormalizer]: Transformer<Merchant[]>; | ||
[OfferNormalizer]: Transformer<ProductOffer>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import { provideQuery, Query } from '@spryker-oryx/core'; | ||
import { inject } from '@spryker-oryx/di'; | ||
import { LocaleChanged } from '@spryker-oryx/i18n'; | ||
import { Merchant, MerchantQualifier } from '../../models'; | ||
import { | ||
Merchant, | ||
MerchantListQualifier, | ||
MerchantQualifier, | ||
} from '../../models'; | ||
import { MerchantAdapter } from '../adapter'; | ||
|
||
export const MerchantQuery = 'oryx.merchantQuery'; | ||
export const MerchantListQuery = 'oryx.merchantListQuery'; | ||
|
||
export type MerchantQuery = Query<Merchant, MerchantQualifier>; | ||
export type MerchantListQuery = Query<Merchant[], MerchantListQuery>; | ||
|
||
export const merchantQueries = [ | ||
provideQuery(MerchantQuery, (adapter = inject(MerchantAdapter)) => ({ | ||
loader: (q: MerchantQualifier) => adapter.get(q), | ||
refreshOn: [LocaleChanged], | ||
})), | ||
|
||
provideQuery(MerchantListQuery, (adapter = inject(MerchantAdapter)) => ({ | ||
loader: (q: MerchantListQualifier) => adapter.getList(q), | ||
refreshOn: [LocaleChanged], | ||
})), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
ContextController, | ||
EntityContext, | ||
EntityService, | ||
} from '@spryker-oryx/core'; | ||
import { resolve } from '@spryker-oryx/di'; | ||
import { ContentMixin, LayoutMixin } from '@spryker-oryx/experience'; | ||
import { | ||
computed, | ||
elementEffect, | ||
hydrate, | ||
signalAware, | ||
} from '@spryker-oryx/utilities'; | ||
import { LitElement, TemplateResult, html } from 'lit'; | ||
import { repeat } from 'lit/directives/repeat.js'; | ||
import { of } from 'rxjs'; | ||
import { DataListOptions } from './data-list.model'; | ||
|
||
@hydrate() | ||
@signalAware() | ||
export class DataListComponent extends LayoutMixin( | ||
ContentMixin<DataListOptions>(LitElement) | ||
) { | ||
protected contextController: ContextController = new ContextController(this); | ||
|
||
@elementEffect() | ||
protected setContext = (): void => { | ||
this.contextController.provide(EntityContext, this.$options().entity); | ||
}; | ||
|
||
protected entityService = resolve(EntityService); | ||
|
||
protected $list = computed(() => | ||
this.$options().entity | ||
? this.entityService.getListQualifiers({ type: this.$options().entity }) | ||
: of([]).pipe() | ||
); | ||
|
||
protected override render(): TemplateResult | void { | ||
const list = this.$list(); | ||
|
||
if (!list?.length) return; | ||
|
||
return this.renderLayout({ | ||
template: html`${repeat( | ||
list, | ||
(item) => | ||
html`<oryx-data-wrapper | ||
.options=${{ link: this.$options().link }} | ||
.qualifier=${item} | ||
> | ||
<oryx-composition .uid=${this.uid}></oryx-composition> | ||
</oryx-data-wrapper>` | ||
)}`, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { componentDef } from '@spryker-oryx/utilities'; | ||
|
||
export const dataList = componentDef({ | ||
name: 'oryx-data-list', | ||
impl: () => import('./data-list.component').then((m) => m.DataListComponent), | ||
schema: () => import('./data-list.schema').then((m) => m.dataListSchema), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface DataListOptions { | ||
entity?: string; | ||
link?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ContentComponentSchema } from '@spryker-oryx/experience'; | ||
import { DataListComponent } from './data-list.component'; | ||
|
||
export const dataListSchema: ContentComponentSchema<DataListComponent> = { | ||
name: 'Data list', | ||
group: 'Experience', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './data-list.component'; | ||
export * from './data-list.model'; | ||
export * from './data-list.schema'; |
Oops, something went wrong.