fix(deltagare, employee, avrop): Resetting params after destroy to avoid state issues. (TV-756)

Squashed commit of the following:

commit 4cd30d9dafd2cbd17e5192142e5ba8116345fd18
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date:   Tue Oct 12 19:55:32 2021 +0200

    Added reset on destroy for all params when fetching lists
This commit is contained in:
Erik Tiekstra
2021-10-13 11:05:55 +02:00
parent ccf3eb5458
commit bdb1d16115
5 changed files with 53 additions and 28 deletions

View File

@@ -23,20 +23,22 @@ import { ErrorService } from '@msfa-services/error.service';
import { BehaviorSubject, combineLatest, Observable, of, throwError } from 'rxjs';
import { catchError, distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators';
const DEFAULT_PARAMS: EmployeeParams = {
page: 1,
limit: 10,
sort: 'name',
order: SortOrder.ASC,
search: '',
onlyEmployeesWithoutAuthorization: false,
};
@Injectable({
providedIn: 'root',
})
export class EmployeeService extends UnsubscribeDirective {
private _apiBaseUrl = `${environment.api.url}/users`;
private _currentEmployeeId$ = new BehaviorSubject<string>(null);
private _params$ = new BehaviorSubject<EmployeeParams>({
page: 1,
limit: 10,
sort: 'name',
order: SortOrder.ASC,
search: '',
onlyEmployeesWithoutAuthorization: false,
});
private _params$ = new BehaviorSubject<EmployeeParams>(DEFAULT_PARAMS);
public sort$: Observable<Sort<keyof EmployeeCompactResponse>> = this._params$.pipe(
map(({ sort, order }) => ({ key: sort, order }))
);
@@ -78,6 +80,10 @@ export class EmployeeService extends UnsubscribeDirective {
switchMap(([params]) => this._fetchEmployees$(params))
);
public resetParams(): void {
this._params$.next(DEFAULT_PARAMS);
}
public setCurrentEmployeeId(currentEmployeeId: string): void {
if (this._currentEmployeeId$.getValue() !== currentEmployeeId) {
this._employee$.next(null);

View File

@@ -10,17 +10,18 @@ import { HandledareApiService } from './api/handledare.api.service';
type Step = 1 | 2 | 3 | 4;
const DEFAULT_PARAMS: AvropParams = {
page: 1,
limit: 5,
filteredTjanster: null,
filteredUtforandeVerksamheter: null,
filteredKommuner: null,
};
@Injectable({
providedIn: 'root',
})
export class AvropService {
private _params$ = new BehaviorSubject<AvropParams>({
page: 1,
limit: 5,
filteredTjanster: null,
filteredUtforandeVerksamheter: null,
filteredKommuner: null,
});
private _params$ = new BehaviorSubject<AvropParams>(DEFAULT_PARAMS);
private _selectedAvrop$ = new BehaviorSubject<AvropCompact[]>([]);
private _avropIsLocked$ = new BehaviorSubject<boolean>(null);
private _selectedHandledareId$ = new BehaviorSubject<string>(null);
@@ -193,12 +194,16 @@ export class AvropService {
};
}
public setSelectedAvrop(deltagare: AvropCompact[]): void {
this._selectedAvrop$.next(deltagare);
private _resetParams(): void {
this._params$.next(DEFAULT_PARAMS);
}
constructor(private avropApiService: AvropApiService, private handledareApiService: HandledareApiService) {}
public setSelectedAvrop(deltagare: AvropCompact[]): void {
this._selectedAvrop$.next(deltagare);
}
public resetError(): void {
this._error$.next(null);
}
@@ -271,6 +276,7 @@ export class AvropService {
this._avropIsLocked$.next(false);
this._handledareIsConfirmed$.next(false);
this._avropIsSubmitted$.next(false);
this._resetParams();
}
public removeKommun(kommunToRemove: MultiselectFilterOption): void {

View File

@@ -7,17 +7,18 @@ import { BehaviorSubject, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { DeltagareApiService } from './api/deltagare.api.service';
const DEFAULT_PARAMS: DeltagareParams = {
page: 1,
limit: 20,
sort: 'fullName',
order: SortOrder.ASC,
onlyMyDeltagare: false,
};
@Injectable({
providedIn: 'root',
})
export class DeltagareService {
private _params$ = new BehaviorSubject<DeltagareParams>({
page: 1,
limit: 20,
sort: 'fullName',
order: SortOrder.ASC,
onlyMyDeltagare: false,
});
private _params$ = new BehaviorSubject<DeltagareParams>(DEFAULT_PARAMS);
public sort$: Observable<Sort<keyof DeltagareCompact>> = this._params$.pipe(
map(({ sort, order }) => ({ key: sort, order }))
);
@@ -30,6 +31,10 @@ export class DeltagareService {
constructor(private deltagareApiService: DeltagareApiService) {}
public resetParams(): void {
this._params$.next(DEFAULT_PARAMS);
}
public setSort(sort: keyof DeltagareCompact): void {
const params = this._params$.getValue();
const order = params.sort === sort && params.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;