mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
#1076 Sync User State Processes With NgrxProcesses & Set Filters ForEach
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ProcessingStatusPipe } from './processing-status.pipe';
|
||||
import { OrderItemProcessingStatusValue } from '@swagger/oms/lib';
|
||||
import { OrderItemProcessingStatusValue } from '@swagger/oms';
|
||||
|
||||
fdescribe('ProcessingStatusPipe', () => {
|
||||
let pipe: ProcessingStatusPipe;
|
||||
@@ -17,7 +17,9 @@ fdescribe('ProcessingStatusPipe', () => {
|
||||
|
||||
it('should return an empty string if the status code is not found', () => {
|
||||
const notExistingStatusCode = 17;
|
||||
const result = pipe.transform(notExistingStatusCode as OrderItemProcessingStatusValue);
|
||||
const result = pipe.transform(
|
||||
notExistingStatusCode as OrderItemProcessingStatusValue
|
||||
);
|
||||
|
||||
expect(result).toEqual('');
|
||||
});
|
||||
|
||||
@@ -6,7 +6,6 @@ import { Observable } from 'rxjs';
|
||||
import {
|
||||
StrictHttpResponse,
|
||||
ResponseArgsOfIEnumerableOfInputDTO,
|
||||
OrderService,
|
||||
InputDTO,
|
||||
ListResponseArgsOfOrderItemListItemDTO,
|
||||
AbholfachService,
|
||||
@@ -315,4 +314,40 @@ fdescribe('#SearchEffects', () => {
|
||||
expect(searchEffects.fetchResultDone$).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('syncInititalProcesses', async () => {
|
||||
it('should be called when effects are initiated', () => {
|
||||
spyOn(searchEffects, 'syncInititalProcesses').and.callThrough();
|
||||
searchEffects.ngrxOnInitEffects();
|
||||
expect(searchEffects.syncInititalProcesses).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should create a search process for all actions', async () => {
|
||||
spyOn(store, 'dispatch').and.callThrough();
|
||||
|
||||
const processes: {
|
||||
[id: number]: Process;
|
||||
} = {
|
||||
[1]: { id: 1, name: 'Prozess 1' } as Process,
|
||||
[2]: { id: 1, name: 'Prozess 1' } as Process,
|
||||
};
|
||||
const addSearchProcessAction = (process) =>
|
||||
actions.addSearchProcess({ id: process.id });
|
||||
searchEffects.syncInititalProcesses();
|
||||
|
||||
await ngxsStore
|
||||
.dispatch(new processActions.ReloadProcessData({ ...processes }, []))
|
||||
.pipe(first())
|
||||
.toPromise();
|
||||
|
||||
expect(store.dispatch).toHaveBeenCalledWith(
|
||||
addSearchProcessAction(processes[1])
|
||||
);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(
|
||||
addSearchProcessAction(processes[2])
|
||||
);
|
||||
|
||||
expect(store.dispatch).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,9 +2,20 @@ import { Injectable } from '@angular/core';
|
||||
import { Action, Store } from '@ngrx/store';
|
||||
import { Actions, createEffect, ofType, OnInitEffects } from '@ngrx/effects';
|
||||
import { Actions as NgxsActions, ofActionDispatched } from '@ngxs/store';
|
||||
import { AddProcess, DeleteProcess } from 'apps/sales/src/app/core/store/actions/process.actions';
|
||||
import {
|
||||
AddProcess,
|
||||
DeleteProcess,
|
||||
ReloadProcessData,
|
||||
} from 'apps/sales/src/app/core/store/actions/process.actions';
|
||||
import * as actions from './search.actions';
|
||||
import { switchMap, withLatestFrom, catchError, map, flatMap } from 'rxjs/operators';
|
||||
import {
|
||||
switchMap,
|
||||
withLatestFrom,
|
||||
catchError,
|
||||
map,
|
||||
flatMap,
|
||||
shareReplay,
|
||||
} from 'rxjs/operators';
|
||||
import {
|
||||
StrictHttpResponse,
|
||||
ListResponseArgsOfOrderItemListItemDTO,
|
||||
@@ -13,7 +24,10 @@ import {
|
||||
} from '@swagger/oms';
|
||||
import { SearchStateFacade } from './search.facade';
|
||||
import { of, NEVER } from 'rxjs';
|
||||
import { inputDtoToSelectedFilters, inputDtoToPrimaryFilterOption } from './mappers';
|
||||
import {
|
||||
inputDtoToSelectedFilters,
|
||||
inputDtoToPrimaryFilterOption,
|
||||
} from './mappers';
|
||||
import { SelectFilter } from 'apps/sales/src/app/modules/filter';
|
||||
import { PrimaryFilterOption } from 'apps/sales/src/app/modules/shelf/defs';
|
||||
import { isNullOrUndefined, isNumber } from 'util';
|
||||
@@ -43,7 +57,10 @@ export class SearchEffects implements OnInitEffects {
|
||||
ofType(actions.fetchResult),
|
||||
switchMap((a) =>
|
||||
of(a).pipe(
|
||||
withLatestFrom(this.searchStateFacade.getProcess$(a.id), this.searchStateFacade.selectedFilter$),
|
||||
withLatestFrom(
|
||||
this.searchStateFacade.getProcess$(a.id),
|
||||
this.searchStateFacade.selectedFilter$
|
||||
),
|
||||
flatMap(([_, process, filter]) =>
|
||||
this.abholfach
|
||||
.AbholfachWarenausgabeResponse({
|
||||
@@ -57,8 +74,14 @@ export class SearchEffects implements OnInitEffects {
|
||||
take: isNumber(a.take) ? a.take : 20,
|
||||
})
|
||||
.pipe(
|
||||
catchError((err) => of<StrictHttpResponse<ListResponseArgsOfOrderItemListItemDTO>>(err)),
|
||||
map((response) => actions.fetchResultDone({ id: a.id, response }))
|
||||
catchError((err) =>
|
||||
of<
|
||||
StrictHttpResponse<ListResponseArgsOfOrderItemListItemDTO>
|
||||
>(err)
|
||||
),
|
||||
map((response) =>
|
||||
actions.fetchResultDone({ id: a.id, response })
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -74,7 +97,9 @@ export class SearchEffects implements OnInitEffects {
|
||||
const result = action.response.body;
|
||||
const shouldSetTimestamp = !!result.skip;
|
||||
return [
|
||||
...(shouldSetTimestamp ? [actions.setTimestamp({ id: action.id })] : []),
|
||||
...(shouldSetTimestamp
|
||||
? [actions.setTimestamp({ id: action.id })]
|
||||
: []),
|
||||
actions.setHits({ id: action.id, hits: result.hits || 0 }),
|
||||
actions.addResult({ id: action.id, result: result.result || [] }),
|
||||
];
|
||||
@@ -86,7 +111,12 @@ export class SearchEffects implements OnInitEffects {
|
||||
|
||||
clearResult$ = createEffect(() => {
|
||||
return this.actions$.pipe(
|
||||
ofType(actions.resetPrimaryFilters, actions.resetSelectFilters, actions.setSelectFilters, actions.setInput),
|
||||
ofType(
|
||||
actions.resetPrimaryFilters,
|
||||
actions.resetSelectFilters,
|
||||
actions.setSelectFilters,
|
||||
actions.setInput
|
||||
),
|
||||
map((action) => actions.clearResults({ id: action.id }))
|
||||
);
|
||||
});
|
||||
@@ -96,8 +126,13 @@ export class SearchEffects implements OnInitEffects {
|
||||
ofType(actions.fetchFilters),
|
||||
flatMap((action) =>
|
||||
this.abholfach.AbholfachGetWarenausgabeFilterResponse().pipe(
|
||||
catchError((err) => of<StrictHttpResponse<ResponseArgsOfIEnumerableOfInputDTO>>(err)),
|
||||
map((response) => actions.fetchFiltersDone({ id: action.id, response }))
|
||||
shareReplay(),
|
||||
catchError((err) =>
|
||||
of<StrictHttpResponse<ResponseArgsOfIEnumerableOfInputDTO>>(err)
|
||||
),
|
||||
map((response) =>
|
||||
actions.fetchFiltersDone({ id: action.id, response })
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -110,12 +145,20 @@ export class SearchEffects implements OnInitEffects {
|
||||
if (action.response.ok) {
|
||||
const result = action.response.body;
|
||||
|
||||
const selectedFiltersRaw = result.result.filter((filter) => !!filter.options);
|
||||
const primaryFiltersRaw = result.result.filter((filter) => isNullOrUndefined(filter.options));
|
||||
const selectedFiltersRaw = result.result.filter(
|
||||
(filter) => !!filter.options
|
||||
);
|
||||
const primaryFiltersRaw = result.result.filter((filter) =>
|
||||
isNullOrUndefined(filter.options)
|
||||
);
|
||||
|
||||
const selectFilters: SelectFilter[] = selectedFiltersRaw.map((input) => inputDtoToSelectedFilters(input));
|
||||
const selectFilters: SelectFilter[] = selectedFiltersRaw.map(
|
||||
(input) => inputDtoToSelectedFilters(input)
|
||||
);
|
||||
|
||||
const primaryFilters: PrimaryFilterOption[] = primaryFiltersRaw.map((input) => inputDtoToPrimaryFilterOption(input));
|
||||
const primaryFilters: PrimaryFilterOption[] = primaryFiltersRaw.map(
|
||||
(input) => inputDtoToPrimaryFilterOption(input)
|
||||
);
|
||||
|
||||
return [
|
||||
actions.setSelectFilters({
|
||||
@@ -135,22 +178,45 @@ export class SearchEffects implements OnInitEffects {
|
||||
);
|
||||
|
||||
initAddProcess() {
|
||||
this.ngxsActions$.pipe(ofActionDispatched(AddProcess)).subscribe((action) => {
|
||||
if (action instanceof AddProcess) {
|
||||
this.store.dispatch(actions.addSearchProcess({ id: action.payload.id }));
|
||||
this.ngxsActions$
|
||||
.pipe(ofActionDispatched(AddProcess))
|
||||
.subscribe((action) => {
|
||||
if (action instanceof AddProcess) {
|
||||
this.store.dispatch(
|
||||
actions.addSearchProcess({ id: action.payload.id })
|
||||
);
|
||||
|
||||
this.searchStateFacade.fetchFilters(action.payload.id);
|
||||
}
|
||||
});
|
||||
this.searchStateFacade.fetchFilters(action.payload.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngrxOnInitEffects(): Action {
|
||||
this.syncInititalProcesses();
|
||||
return actions.cleanup();
|
||||
}
|
||||
|
||||
initRemoveProcess() {
|
||||
this.ngxsActions$.pipe(ofActionDispatched(DeleteProcess)).subscribe((action: DeleteProcess) => {
|
||||
this.store.dispatch(actions.removeSearchProcess({ id: action.payload.id }));
|
||||
});
|
||||
this.ngxsActions$
|
||||
.pipe(ofActionDispatched(DeleteProcess))
|
||||
.subscribe((action: DeleteProcess) => {
|
||||
this.store.dispatch(
|
||||
actions.removeSearchProcess({ id: action.payload.id })
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
syncInititalProcesses() {
|
||||
this.ngxsActions$
|
||||
.pipe(ofActionDispatched(ReloadProcessData))
|
||||
.subscribe((action) => {
|
||||
if (action instanceof ReloadProcessData && action.processes) {
|
||||
const processes = Object.values(action.processes);
|
||||
|
||||
processes.forEach((process) =>
|
||||
this.store.dispatch(actions.addSearchProcess({ id: process.id }))
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user