#3853 Gelbe Seiten - Auf Erledigt gesetzte Posten bleiben auf die Liste

This commit is contained in:
Lorenz Hilpert
2023-02-22 13:30:58 +01:00
parent f30ae91854
commit bcff2272ab

View File

@@ -3,7 +3,12 @@ import { DomainPrinterService } from '@domain/printer';
import { DomainProductListService } from '@domain/product-list';
import { PrintModalComponent, PrintModalData } from '@modal/printer';
import { ComponentStore, OnStoreInit, tapResponse } from '@ngrx/component-store';
import { ListResponseArgsOfProductListItemDTO, ProductListItemDTO, QuerySettingsDTO } from '@swagger/wws';
import {
BatchResponseArgsOfProductListItemDTOAndString,
ListResponseArgsOfProductListItemDTO,
ProductListItemDTO,
QuerySettingsDTO,
} from '@swagger/wws';
import { UiFilter } from '@ui/filter';
import { UiModalService } from '@ui/modal';
import { isNil } from 'lodash';
@@ -103,11 +108,9 @@ export class PriceUpdateComponentStore extends ComponentStore<PriceUpdateCompone
complete = this.effect(($) =>
$.pipe(
tap(() => this.beforeComplete()),
withLatestFrom(this.items$, this.selectedItemUids$),
switchMap(([_, items, selectedItemUids]) =>
this._productListService
.completeProductListItems(selectedItemUids)
.pipe(tapResponse((response) => this.onCompleteResponse({ selectedItemUids, items }), this.onCompleteError))
withLatestFrom(this.selectedItemUids$),
switchMap(([_, selectedItemUids]) =>
this._productListService.completeProductListItems(selectedItemUids).pipe(tapResponse(this.onCompleteResponse, this.onCompleteError))
)
)
);
@@ -137,15 +140,25 @@ export class PriceUpdateComponentStore extends ComponentStore<PriceUpdateCompone
beforeFetchingItems() {
this.setFetching(true);
this.setItems([]);
this.patchState({ selectedItemUids: [] });
}
onCompleteResponse = ({ selectedItemUids, items }: { selectedItemUids: string[]; items: ProductListItemDTO[] }) => {
let filteredItems: ProductListItemDTO[];
for (let uId of selectedItemUids) {
filteredItems = items.filter((item) => item.uId !== uId);
onCompleteResponse = (response: BatchResponseArgsOfProductListItemDTOAndString) => {
let items = this.items;
if (response.error) {
this._uiModal.error('Setzen der Produkte auf Erledigt enthält fehlerhafte Einträge.', new Error(response.message));
} else if (response.successful) {
items = items.filter((item) => !response.successful.some((s) => s.key === item.uId));
} else {
this._uiModal.error(
'Setzen der Produkte auf Erledigt enthält keine erfolgreichen Einträge.',
new Error('Keine erfolgreichen Einträge')
);
}
this.patchState({ selectedItemUids: [] });
this.setItems(filteredItems);
this.setItems(items);
this.setLoading(false);
};