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:
@@ -1,4 +1,4 @@
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, OnDestroy } from '@angular/core';
|
||||
import { IconType } from '@msfa-enums/icon-type.enum';
|
||||
import { EmployeeCompactResponse } from '@msfa-models/api/employee.response.model';
|
||||
import { Employee, EmployeesData } from '@msfa-models/employee.model';
|
||||
@@ -12,7 +12,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
|
||||
styleUrls: ['./employees.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class EmployeesComponent {
|
||||
export class EmployeesComponent implements OnDestroy {
|
||||
private _searchValue$ = new BehaviorSubject<string>('');
|
||||
onlyEmployeesWithoutAuthorization$: Observable<boolean> = this.employeeService.onlyEmployeesWithoutAuthorization$;
|
||||
employeesData$: Observable<EmployeesData> = this.employeeService.employeesData$;
|
||||
@@ -22,6 +22,10 @@ export class EmployeesComponent {
|
||||
|
||||
constructor(private employeeService: EmployeeService) {}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.employeeService.resetParams();
|
||||
}
|
||||
|
||||
get searchValue(): string {
|
||||
return this._searchValue$.getValue();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, OnDestroy } from '@angular/core';
|
||||
import { DeltagareCompact, DeltagareCompactData } from '@msfa-models/deltagare.model';
|
||||
import { Sort } from '@msfa-models/sort.model';
|
||||
import { DeltagareService } from '@msfa-services/deltagare.service';
|
||||
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
||||
styleUrls: ['./deltagare-list.component.scss'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class DeltagareListComponent {
|
||||
export class DeltagareListComponent implements OnDestroy {
|
||||
allDeltagareData$: Observable<DeltagareCompactData> = this.deltagareService.allDeltagareData$;
|
||||
sort$: Observable<Sort<keyof DeltagareCompact>> = this.deltagareService.sort$;
|
||||
onlyMyDeltagare$: Observable<boolean> = this.deltagareService.onlyMyDeltagare$;
|
||||
@@ -19,6 +19,10 @@ export class DeltagareListComponent {
|
||||
|
||||
constructor(private deltagareService: DeltagareService) {}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.deltagareService.resetParams();
|
||||
}
|
||||
|
||||
handleDeltagareSort(key: keyof DeltagareCompact): void {
|
||||
this.deltagareService.setSort(key);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user