Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 6x | import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { RxState } from '@rx-angular/state';
import { combineLatest, map } from 'rxjs';
import { CheckoutFacade } from 'ish-core/facades/checkout.facade';
import { CustomFields, CustomFieldsComponentInput } from 'ish-core/models/custom-field/custom-field.model';
/**
* The Line Item Custom Fields Component displays the custom fields of a line item.
*/
@Component({
selector: 'ish-line-item-custom-fields',
templateUrl: './line-item-custom-fields.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class LineItemCustomFieldsComponent
extends RxState<{
fields: CustomFieldsComponentInput[];
customFields: CustomFields;
editable: boolean;
}>
implements OnInit
{
@Input({ required: true }) set lineItem(val: { customFields?: CustomFields }) {
this.set('customFields', () => val.customFields || {});
}
@Input() set editable(val: boolean) {
this.set('editable', () => val);
}
constructor(private checkoutFacade: CheckoutFacade) {
super();
}
ngOnInit(): void {
this.connect(
'fields',
combineLatest([this.select('customFields'), this.checkoutFacade.customFieldsForScope$('BasketLineItem')]).pipe(
map(([customFields, definitions]) =>
definitions.map(({ name, editable }) => ({
name,
editable,
value: customFields[name],
}))
)
)
);
}
}
|