Merged PR 1447: #3643 API Calls in der WA und WE reduziert

#3643 API Calls in der WA und WE reduziert
This commit is contained in:
Lorenz Hilpert
2022-11-21 16:46:19 +00:00
committed by Andreas Schickinger
parent 80c425aa6f
commit daae9323e8
2 changed files with 31 additions and 19 deletions

View File

@@ -8,13 +8,15 @@ import {
Input,
OnChanges,
SimpleChanges,
OnDestroy,
} from '@angular/core';
import { CrmCustomerService } from '@domain/crm';
import { DomainOmsService } from '@domain/oms';
import { NotificationChannel } from '@swagger/crm';
import { KeyValueDTOOfStringAndString, OrderDTO, OrderItemListItemDTO } from '@swagger/oms';
import { DateAdapter } from '@ui/common';
import { cloneDeep } from 'lodash';
import { BehaviorSubject, combineLatest, of } from 'rxjs';
import { BehaviorSubject, combineLatest, Subject } from 'rxjs';
import { catchError, filter, first, map, shareReplay, switchMap } from 'rxjs/operators';
import { SharedGoodsInOutOrderDetailsComponent } from '../goods-in-out-order-details.component';
@@ -24,7 +26,7 @@ import { SharedGoodsInOutOrderDetailsComponent } from '../goods-in-out-order-det
styleUrls: ['goods-in-out-order-details-header.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SharedGoodsInOutOrderDetailsHeaderComponent implements OnChanges {
export class SharedGoodsInOutOrderDetailsHeaderComponent implements OnChanges, OnDestroy {
@Output()
editClick = new EventEmitter<OrderItemListItemDTO>();
@@ -45,18 +47,11 @@ export class SharedGoodsInOutOrderDetailsHeaderComponent implements OnChanges {
preferredPickUpDate$ = new BehaviorSubject<Date>(undefined);
notificationsChannel$ = this.orderItem$.pipe(
switchMap((oi) => {
if (oi?.orderId) {
return this.omsService.getNotifications(oi?.orderId).pipe(
map((res) => res.selected),
catchError(() => of(0))
);
}
return of({ selected: 0 });
})
);
notificationsChannel$ = new Subject<{
selected: NotificationChannel;
email: string;
mobile: string;
}>();
changeDateLoader$ = new BehaviorSubject<boolean>(false);
changePreferredDateLoader$ = new BehaviorSubject<boolean>(false);
@@ -90,12 +85,27 @@ export class SharedGoodsInOutOrderDetailsHeaderComponent implements OnChanges {
private cdr: ChangeDetectorRef
) {}
ngOnChanges(): void {
if (this.order) {
ngOnChanges(changes: SimpleChanges): void {
if (changes.order) {
this.findLatestPreferredPickUpDate();
this.computeNotificationChannel();
}
}
ngOnDestroy(): void {
this.notificationsChannel$.complete();
}
computeNotificationChannel() {
const order = this.order;
this.notificationsChannel$.next({
selected: order?.notificationChannels ?? 0,
email: order?.buyer?.communicationDetails?.email ?? '',
mobile: order?.buyer?.communicationDetails?.mobile ?? '',
});
}
async updatePickupDeadline(deadline: Date) {
this.changeDateLoader$.next(true);
this.changeStatusDisabled$.next(true);
@@ -185,10 +195,10 @@ export class SharedGoodsInOutOrderDetailsHeaderComponent implements OnChanges {
findLatestPreferredPickUpDate() {
let latestDate;
const subsetItems = this.order.items
const subsetItems = this.order?.items
?.flatMap((item) => item?.data?.subsetItems)
?.filter((a) => !!a.data.preferredPickUpDate && (!this.selectedOrderItemId || this.selectedOrderItemId === a.data.id));
if (subsetItems.length > 0) {
if (subsetItems?.length > 0) {
latestDate = new Date(
subsetItems?.reduce((a, b) => {
return new Date(a.data.preferredPickUpDate) > new Date(b.data.preferredPickUpDate) ? a : b;

View File

@@ -56,7 +56,6 @@ export class SharedGoodsInOutOrderDetailsItemComponent extends ComponentStore<Sh
if (this.get((s) => s.selected)) {
this._host.selectOrderItem(this.orderItem, true);
}
this.loadReceipts();
}
}
@@ -204,6 +203,9 @@ export class SharedGoodsInOutOrderDetailsItemComponent extends ComponentStore<Sh
setMore(more: boolean) {
this.patchState({ more });
if (more && this.receipts.length === 0) {
this.loadReceipts();
}
}
openHistory() {