Shelf State Data FetchResults

This commit is contained in:
Lorenz Hilpert
2020-06-26 10:42:42 +02:00
parent 03bb8c3484
commit affdf6fe05
2 changed files with 30 additions and 15 deletions

View File

@@ -24,22 +24,26 @@ export class SearchEffects {
this.initRemoveProcess();
}
fetchResult$ = createEffect(() =>
fetchResults$ = createEffect(() =>
this.actions$.pipe(
ofType(actions.fetchResult),
withLatestFrom(((a) => this.searchStateFacade.getProcess$(a.id))()),
switchMap(([a, process]) =>
this.orderService
.OrderWarenausgabeResponse({
branchNumber: this.branchService.getCurrentBranchNumber(),
input: process.input,
skip: process.hits || 0,
take: 20,
})
.pipe(
catchError((err) => of<StrictHttpResponse<ListResponseArgsOfOrderItemListItemDTO>>(err)),
map((response) => actions.fetchResultDone({ id: a.id, response }))
switchMap((a) =>
of(a).pipe(
withLatestFrom(this.searchStateFacade.getProcess$(a.id)),
flatMap(([_, process]) =>
this.orderService
.OrderWarenausgabeResponse({
branchNumber: this.branchService.getCurrentBranchNumber(),
input: process.input,
skip: process.result.length || 0,
take: 20,
})
.pipe(
catchError((err) => of<StrictHttpResponse<ListResponseArgsOfOrderItemListItemDTO>>(err)),
map((response) => actions.fetchResultDone({ id: a.id, response }))
)
)
)
)
)
);

View File

@@ -4,7 +4,7 @@ import { Store as NgxsStore } from '@ngxs/store';
import * as actions from './search.actions';
import * as selectors from './search.selectors';
import { SharedSelectors } from 'apps/sales/src/app/core/store/selectors/shared.selectors';
import { map, first, switchMap } from 'rxjs/operators';
import { map, first, switchMap, filter } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { OrderItemListItemDTO } from '@swagger/oms';
import { GroupedByCustomer } from './defs';
@@ -38,7 +38,10 @@ export class SearchStateFacade {
constructor(private store: Store<any>, private ngxsStore: NgxsStore) {}
getProcessId$() {
return this.ngxsStore.select(SharedSelectors.getCurrentProcess).pipe(map((currentProcess) => currentProcess.id));
return this.ngxsStore.select(SharedSelectors.getCurrentProcess).pipe(
filter((process) => !!process && !!process.id),
map((currentProcess) => currentProcess.id)
);
}
getProcessId() {
@@ -105,4 +108,12 @@ export class SearchStateFacade {
}
this.store.dispatch(actions.fetchResult({ id: processId }));
}
async clearResult(id?: number) {
let processId = id;
if (typeof processId !== 'number') {
processId = await this.getProcessId();
}
this.store.dispatch(actions.clearResults({ id: processId }));
}
}