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 { IconType } from '@msfa-enums/icon-type.enum';
|
||||||
import { EmployeeCompactResponse } from '@msfa-models/api/employee.response.model';
|
import { EmployeeCompactResponse } from '@msfa-models/api/employee.response.model';
|
||||||
import { Employee, EmployeesData } from '@msfa-models/employee.model';
|
import { Employee, EmployeesData } from '@msfa-models/employee.model';
|
||||||
@@ -12,7 +12,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
|
|||||||
styleUrls: ['./employees.component.scss'],
|
styleUrls: ['./employees.component.scss'],
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class EmployeesComponent {
|
export class EmployeesComponent implements OnDestroy {
|
||||||
private _searchValue$ = new BehaviorSubject<string>('');
|
private _searchValue$ = new BehaviorSubject<string>('');
|
||||||
onlyEmployeesWithoutAuthorization$: Observable<boolean> = this.employeeService.onlyEmployeesWithoutAuthorization$;
|
onlyEmployeesWithoutAuthorization$: Observable<boolean> = this.employeeService.onlyEmployeesWithoutAuthorization$;
|
||||||
employeesData$: Observable<EmployeesData> = this.employeeService.employeesData$;
|
employeesData$: Observable<EmployeesData> = this.employeeService.employeesData$;
|
||||||
@@ -22,6 +22,10 @@ export class EmployeesComponent {
|
|||||||
|
|
||||||
constructor(private employeeService: EmployeeService) {}
|
constructor(private employeeService: EmployeeService) {}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.employeeService.resetParams();
|
||||||
|
}
|
||||||
|
|
||||||
get searchValue(): string {
|
get searchValue(): string {
|
||||||
return this._searchValue$.getValue();
|
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 { DeltagareCompact, DeltagareCompactData } from '@msfa-models/deltagare.model';
|
||||||
import { Sort } from '@msfa-models/sort.model';
|
import { Sort } from '@msfa-models/sort.model';
|
||||||
import { DeltagareService } from '@msfa-services/deltagare.service';
|
import { DeltagareService } from '@msfa-services/deltagare.service';
|
||||||
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
|||||||
styleUrls: ['./deltagare-list.component.scss'],
|
styleUrls: ['./deltagare-list.component.scss'],
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class DeltagareListComponent {
|
export class DeltagareListComponent implements OnDestroy {
|
||||||
allDeltagareData$: Observable<DeltagareCompactData> = this.deltagareService.allDeltagareData$;
|
allDeltagareData$: Observable<DeltagareCompactData> = this.deltagareService.allDeltagareData$;
|
||||||
sort$: Observable<Sort<keyof DeltagareCompact>> = this.deltagareService.sort$;
|
sort$: Observable<Sort<keyof DeltagareCompact>> = this.deltagareService.sort$;
|
||||||
onlyMyDeltagare$: Observable<boolean> = this.deltagareService.onlyMyDeltagare$;
|
onlyMyDeltagare$: Observable<boolean> = this.deltagareService.onlyMyDeltagare$;
|
||||||
@@ -19,6 +19,10 @@ export class DeltagareListComponent {
|
|||||||
|
|
||||||
constructor(private deltagareService: DeltagareService) {}
|
constructor(private deltagareService: DeltagareService) {}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.deltagareService.resetParams();
|
||||||
|
}
|
||||||
|
|
||||||
handleDeltagareSort(key: keyof DeltagareCompact): void {
|
handleDeltagareSort(key: keyof DeltagareCompact): void {
|
||||||
this.deltagareService.setSort(key);
|
this.deltagareService.setSort(key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,20 +23,22 @@ import { ErrorService } from '@msfa-services/error.service';
|
|||||||
import { BehaviorSubject, combineLatest, Observable, of, throwError } from 'rxjs';
|
import { BehaviorSubject, combineLatest, Observable, of, throwError } from 'rxjs';
|
||||||
import { catchError, distinctUntilChanged, filter, map, switchMap, take, tap } from 'rxjs/operators';
|
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({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class EmployeeService extends UnsubscribeDirective {
|
export class EmployeeService extends UnsubscribeDirective {
|
||||||
private _apiBaseUrl = `${environment.api.url}/users`;
|
private _apiBaseUrl = `${environment.api.url}/users`;
|
||||||
private _currentEmployeeId$ = new BehaviorSubject<string>(null);
|
private _currentEmployeeId$ = new BehaviorSubject<string>(null);
|
||||||
private _params$ = new BehaviorSubject<EmployeeParams>({
|
private _params$ = new BehaviorSubject<EmployeeParams>(DEFAULT_PARAMS);
|
||||||
page: 1,
|
|
||||||
limit: 10,
|
|
||||||
sort: 'name',
|
|
||||||
order: SortOrder.ASC,
|
|
||||||
search: '',
|
|
||||||
onlyEmployeesWithoutAuthorization: false,
|
|
||||||
});
|
|
||||||
public sort$: Observable<Sort<keyof EmployeeCompactResponse>> = this._params$.pipe(
|
public sort$: Observable<Sort<keyof EmployeeCompactResponse>> = this._params$.pipe(
|
||||||
map(({ sort, order }) => ({ key: sort, order }))
|
map(({ sort, order }) => ({ key: sort, order }))
|
||||||
);
|
);
|
||||||
@@ -78,6 +80,10 @@ export class EmployeeService extends UnsubscribeDirective {
|
|||||||
switchMap(([params]) => this._fetchEmployees$(params))
|
switchMap(([params]) => this._fetchEmployees$(params))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public resetParams(): void {
|
||||||
|
this._params$.next(DEFAULT_PARAMS);
|
||||||
|
}
|
||||||
|
|
||||||
public setCurrentEmployeeId(currentEmployeeId: string): void {
|
public setCurrentEmployeeId(currentEmployeeId: string): void {
|
||||||
if (this._currentEmployeeId$.getValue() !== currentEmployeeId) {
|
if (this._currentEmployeeId$.getValue() !== currentEmployeeId) {
|
||||||
this._employee$.next(null);
|
this._employee$.next(null);
|
||||||
|
|||||||
@@ -10,17 +10,18 @@ import { HandledareApiService } from './api/handledare.api.service';
|
|||||||
|
|
||||||
type Step = 1 | 2 | 3 | 4;
|
type Step = 1 | 2 | 3 | 4;
|
||||||
|
|
||||||
|
const DEFAULT_PARAMS: AvropParams = {
|
||||||
|
page: 1,
|
||||||
|
limit: 5,
|
||||||
|
filteredTjanster: null,
|
||||||
|
filteredUtforandeVerksamheter: null,
|
||||||
|
filteredKommuner: null,
|
||||||
|
};
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class AvropService {
|
export class AvropService {
|
||||||
private _params$ = new BehaviorSubject<AvropParams>({
|
private _params$ = new BehaviorSubject<AvropParams>(DEFAULT_PARAMS);
|
||||||
page: 1,
|
|
||||||
limit: 5,
|
|
||||||
filteredTjanster: null,
|
|
||||||
filteredUtforandeVerksamheter: null,
|
|
||||||
filteredKommuner: null,
|
|
||||||
});
|
|
||||||
private _selectedAvrop$ = new BehaviorSubject<AvropCompact[]>([]);
|
private _selectedAvrop$ = new BehaviorSubject<AvropCompact[]>([]);
|
||||||
private _avropIsLocked$ = new BehaviorSubject<boolean>(null);
|
private _avropIsLocked$ = new BehaviorSubject<boolean>(null);
|
||||||
private _selectedHandledareId$ = new BehaviorSubject<string>(null);
|
private _selectedHandledareId$ = new BehaviorSubject<string>(null);
|
||||||
@@ -193,12 +194,16 @@ export class AvropService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public setSelectedAvrop(deltagare: AvropCompact[]): void {
|
private _resetParams(): void {
|
||||||
this._selectedAvrop$.next(deltagare);
|
this._params$.next(DEFAULT_PARAMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(private avropApiService: AvropApiService, private handledareApiService: HandledareApiService) {}
|
constructor(private avropApiService: AvropApiService, private handledareApiService: HandledareApiService) {}
|
||||||
|
|
||||||
|
public setSelectedAvrop(deltagare: AvropCompact[]): void {
|
||||||
|
this._selectedAvrop$.next(deltagare);
|
||||||
|
}
|
||||||
|
|
||||||
public resetError(): void {
|
public resetError(): void {
|
||||||
this._error$.next(null);
|
this._error$.next(null);
|
||||||
}
|
}
|
||||||
@@ -271,6 +276,7 @@ export class AvropService {
|
|||||||
this._avropIsLocked$.next(false);
|
this._avropIsLocked$.next(false);
|
||||||
this._handledareIsConfirmed$.next(false);
|
this._handledareIsConfirmed$.next(false);
|
||||||
this._avropIsSubmitted$.next(false);
|
this._avropIsSubmitted$.next(false);
|
||||||
|
this._resetParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeKommun(kommunToRemove: MultiselectFilterOption): void {
|
public removeKommun(kommunToRemove: MultiselectFilterOption): void {
|
||||||
|
|||||||
@@ -7,17 +7,18 @@ import { BehaviorSubject, Observable } from 'rxjs';
|
|||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { DeltagareApiService } from './api/deltagare.api.service';
|
import { DeltagareApiService } from './api/deltagare.api.service';
|
||||||
|
|
||||||
|
const DEFAULT_PARAMS: DeltagareParams = {
|
||||||
|
page: 1,
|
||||||
|
limit: 20,
|
||||||
|
sort: 'fullName',
|
||||||
|
order: SortOrder.ASC,
|
||||||
|
onlyMyDeltagare: false,
|
||||||
|
};
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class DeltagareService {
|
export class DeltagareService {
|
||||||
private _params$ = new BehaviorSubject<DeltagareParams>({
|
private _params$ = new BehaviorSubject<DeltagareParams>(DEFAULT_PARAMS);
|
||||||
page: 1,
|
|
||||||
limit: 20,
|
|
||||||
sort: 'fullName',
|
|
||||||
order: SortOrder.ASC,
|
|
||||||
onlyMyDeltagare: false,
|
|
||||||
});
|
|
||||||
public sort$: Observable<Sort<keyof DeltagareCompact>> = this._params$.pipe(
|
public sort$: Observable<Sort<keyof DeltagareCompact>> = this._params$.pipe(
|
||||||
map(({ sort, order }) => ({ key: sort, order }))
|
map(({ sort, order }) => ({ key: sort, order }))
|
||||||
);
|
);
|
||||||
@@ -30,6 +31,10 @@ export class DeltagareService {
|
|||||||
|
|
||||||
constructor(private deltagareApiService: DeltagareApiService) {}
|
constructor(private deltagareApiService: DeltagareApiService) {}
|
||||||
|
|
||||||
|
public resetParams(): void {
|
||||||
|
this._params$.next(DEFAULT_PARAMS);
|
||||||
|
}
|
||||||
|
|
||||||
public setSort(sort: keyof DeltagareCompact): void {
|
public setSort(sort: keyof DeltagareCompact): void {
|
||||||
const params = this._params$.getValue();
|
const params = this._params$.getValue();
|
||||||
const order = params.sort === sort && params.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
|
const order = params.sort === sort && params.order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC;
|
||||||
|
|||||||
Reference in New Issue
Block a user