diff --git a/apps/mina-sidor-fa/src/app/pages/avrop/components/avrop-filters/avrop-filters.component.html b/apps/mina-sidor-fa/src/app/pages/avrop/components/avrop-filters/avrop-filters.component.html
index 5c39cde..1aee0bf 100644
--- a/apps/mina-sidor-fa/src/app/pages/avrop/components/avrop-filters/avrop-filters.component.html
+++ b/apps/mina-sidor-fa/src/app/pages/avrop/components/avrop-filters/avrop-filters.component.html
@@ -1,4 +1,4 @@
-
+
!!(kommuner && tjanster && uv)));
+ ]).pipe(map(([kommuner, tjanster, uv]) => !(kommuner && tjanster && uv)));
constructor(private avropService: AvropService) {}
diff --git a/apps/mina-sidor-fa/src/app/pages/avrop/components/avrop-list/avrop-list.component.html b/apps/mina-sidor-fa/src/app/pages/avrop/components/avrop-list/avrop-list.component.html
index 9d4989a..bb73b84 100644
--- a/apps/mina-sidor-fa/src/app/pages/avrop/components/avrop-list/avrop-list.component.html
+++ b/apps/mina-sidor-fa/src/app/pages/avrop/components/avrop-list/avrop-list.component.html
@@ -1,5 +1,5 @@
-
-
+
+
-
(5);
- private _page$ = new BehaviorSubject(1);
- private _filteredTjanster$ = new BehaviorSubject(null);
- private _filteredUtforandeVerksamheter$ = new BehaviorSubject(null);
- private _filteredKommuner$ = new BehaviorSubject(null);
+ private _params$ = new BehaviorSubject({
+ page: 1,
+ limit: 5,
+ filteredTjanster: null,
+ filteredUtforandeVerksamheter: null,
+ filteredKommuner: null,
+ });
private _selectedAvrop$ = new BehaviorSubject([]);
private _avropIsLocked$ = new BehaviorSubject(null);
private _selectedHandledareId$ = new BehaviorSubject(null);
@@ -26,12 +28,23 @@ export class AvropService {
private _error$ = new BehaviorSubject(null);
private _avropLoading$ = new BehaviorSubject(false);
public avropLoading$: Observable = this._avropLoading$.asObservable();
+ public handledareIsConfirmed$: Observable = this._handledareIsConfirmed$.asObservable();
+ public avropIsSubmitted$: Observable = this._avropIsSubmitted$.asObservable();
+ public error$: Observable = this._error$.asObservable();
+ public showUnauthorizedError$: Observable = this.avropApiService.showUnauthorizedError$;
- public filteredTjanster$: Observable = this._filteredTjanster$.asObservable();
- public filteredUtforandeVerksamheter$: Observable<
- MultiselectFilterOption[]
- > = this._filteredUtforandeVerksamheter$.asObservable();
- public filteredKommuner$: Observable = this._filteredKommuner$.asObservable();
+ public filteredTjanster$: Observable = this._params$.pipe(
+ map(({ filteredTjanster }) => filteredTjanster),
+ distinctUntilChanged()
+ );
+ public filteredUtforandeVerksamheter$: Observable = this._params$.pipe(
+ map(({ filteredUtforandeVerksamheter }) => filteredUtforandeVerksamheter),
+ distinctUntilChanged((prevFilter, currFilter) => JSON.stringify(prevFilter) === JSON.stringify(currFilter))
+ );
+ public filteredKommuner$: Observable = this._params$.pipe(
+ map(({ filteredKommuner }) => filteredKommuner),
+ distinctUntilChanged()
+ );
public selectedAvrop$: Observable = this._selectedAvrop$.asObservable();
public avropIsLocked$: Observable = this._avropIsLocked$.asObservable();
public selectedHandledare$: Observable = this._selectedHandledareId$.pipe(
@@ -43,21 +56,10 @@ export class AvropService {
: of(null as null)
)
);
- public handledareIsConfirmed$: Observable = this._handledareIsConfirmed$.asObservable();
- public avropIsSubmitted$: Observable = this._avropIsSubmitted$.asObservable();
- public error$: Observable = this._error$.asObservable();
- public showUnauthorizedError$: Observable = this.avropApiService.showUnauthorizedError$;
- public avropData$: Observable = combineLatest([
- this._filteredTjanster$,
- this._filteredUtforandeVerksamheter$,
- this._filteredKommuner$,
- this._page$,
- this._limit$,
- this._avropIsSubmitted$,
- ]).pipe(
+ public avropData$: Observable = combineLatest([this._avropIsSubmitted$, this._params$]).pipe(
switchMap(() => {
this._avropLoading$.next(true);
- return this.avropApiService.fetchAvrop$(this.filtersForAvrop).pipe(
+ return this.avropApiService.fetchAvrop$(this._filtersForAvrop).pipe(
tap(() => {
this._avropLoading$.next(false);
})
@@ -65,22 +67,35 @@ export class AvropService {
})
);
- public availableTjanster$: Observable = combineLatest([
- this._filteredUtforandeVerksamheter$,
- this._filteredKommuner$,
- ]).pipe(switchMap(() => this.avropApiService.fetchAvailableTjanster$(this.filtersForTjanster)));
-
- public availableUtforandeVerksamheter$: Observable = combineLatest([
- this._filteredTjanster$,
- this._filteredKommuner$,
- ]).pipe(
- switchMap(() => this.avropApiService.fetchAvailableUtforandeVerksamheter$(this.filtersForUtforandeVerksamheter))
+ public availableTjanster$: Observable = this._params$.pipe(
+ distinctUntilChanged(
+ (prevParams, currParams) =>
+ prevParams.filteredKommuner === currParams.filteredKommuner &&
+ prevParams.filteredUtforandeVerksamheter === currParams.filteredUtforandeVerksamheter
+ ),
+ switchMap(() => this.avropApiService.fetchAvailableTjanster$(this._filtersForTjanster)),
+ shareReplay(1)
);
- public availableKommuner$: Observable = combineLatest([
- this._filteredTjanster$,
- this._filteredUtforandeVerksamheter$,
- ]).pipe(switchMap(() => this.avropApiService.fetchAvailableKommuner$(this.filtersForKommuner)));
+ public availableUtforandeVerksamheter$: Observable = this._params$.pipe(
+ distinctUntilChanged(
+ (prevParams, currParams) =>
+ prevParams.filteredKommuner === currParams.filteredKommuner &&
+ prevParams.filteredTjanster === currParams.filteredTjanster
+ ),
+ switchMap(() => this.avropApiService.fetchAvailableUtforandeVerksamheter$(this._filtersForUtforandeVerksamheter)),
+ shareReplay(1)
+ );
+
+ public availableKommuner$: Observable = this._params$.pipe(
+ distinctUntilChanged(
+ (prevParams, currParams) =>
+ prevParams.filteredUtforandeVerksamheter === currParams.filteredUtforandeVerksamheter &&
+ prevParams.filteredTjanster === currParams.filteredTjanster
+ ),
+ switchMap(() => this.avropApiService.fetchAvailableKommuner$(this._filtersForKommuner)),
+ shareReplay(1)
+ );
private _lockedAvrop$: Observable = combineLatest([this.selectedAvrop$, this.avropIsLocked$]).pipe(
map(([selectedAvrop, isLocked]) => (isLocked ? selectedAvrop : null))
@@ -97,14 +112,18 @@ export class AvropService {
this._avropIsSubmitted$,
]).pipe(
map(([confirmedHandledare, avropIsLocked, avropIsSubmitted]) =>
- AvropService.calculateStep(confirmedHandledare, avropIsLocked, avropIsSubmitted)
+ AvropService._getCalculatedStep(confirmedHandledare, avropIsLocked, avropIsSubmitted)
),
tap(() => {
window.scrollTo(0, 0);
})
);
- private static calculateStep(confirmedHandledare: boolean, avropIsLocked: boolean, avropIsSubmitted: boolean): Step {
+ private static _getCalculatedStep(
+ confirmedHandledare: boolean,
+ avropIsLocked: boolean,
+ avropIsSubmitted: boolean
+ ): Step {
if (avropIsLocked) {
if (confirmedHandledare) {
if (avropIsSubmitted) {
@@ -118,56 +137,56 @@ export class AvropService {
return 1;
}
- private get tjanstKoder(): { tjanstKoder: string[] } | null {
- return this._filteredTjanster$.value?.length
- ? { tjanstKoder: this._filteredTjanster$.value.map(tjanst => tjanst.id) }
- : null;
+ private get _tjanstKoder(): { tjanstKoder: string[] } | null {
+ const params = this._params$.getValue();
+ return params.filteredTjanster?.length ? { tjanstKoder: params.filteredTjanster.map(tjanst => tjanst.id) } : null;
}
- private get kommunKoder(): { kommunKoder: string[] } | null {
- return this._filteredKommuner$.value?.length
- ? { kommunKoder: this._filteredKommuner$.value.map(kommun => kommun.id) }
- : null;
+ private get _kommunKoder(): { kommunKoder: string[] } | null {
+ const params = this._params$.getValue();
+ return params.filteredKommuner?.length ? { kommunKoder: params.filteredKommuner.map(kommun => kommun.id) } : null;
}
- private get utforandeverksamhetIds(): { utforandeverksamhetIds: string[] } | null {
- return this._filteredUtforandeVerksamheter$.value?.length
+ private get _utforandeverksamhetIds(): { utforandeverksamhetIds: string[] } | null {
+ const params = this._params$.getValue();
+ return params.filteredUtforandeVerksamheter?.length
? {
- utforandeverksamhetIds: this._filteredUtforandeVerksamheter$.value.map(
+ utforandeverksamhetIds: params.filteredUtforandeVerksamheter.map(
utforandeVerksamhet => utforandeVerksamhet.id
),
}
: null;
}
- private get filtersForAvrop(): Params {
+ private get _filtersForAvrop(): Params {
+ const { page, limit } = this._params$.getValue();
return {
- ...this.tjanstKoder,
- ...this.kommunKoder,
- ...this.utforandeverksamhetIds,
- page: this._page$.value.toString(),
- limit: this._limit$.value.toString(),
+ ...this._tjanstKoder,
+ ...this._kommunKoder,
+ ...this._utforandeverksamhetIds,
+ page: page.toString(),
+ limit: limit.toString(),
};
}
- private get filtersForTjanster(): Params {
+ private get _filtersForTjanster(): Params {
return {
- ...this.kommunKoder,
- ...this.utforandeverksamhetIds,
+ ...this._kommunKoder,
+ ...this._utforandeverksamhetIds,
};
}
- private get filtersForUtforandeVerksamheter(): Params {
+ private get _filtersForUtforandeVerksamheter(): Params {
return {
- ...this.tjanstKoder,
- ...this.kommunKoder,
+ ...this._tjanstKoder,
+ ...this._kommunKoder,
};
}
- private get filtersForKommuner(): Params {
+ private get _filtersForKommuner(): Params {
return {
- ...this.tjanstKoder,
- ...this.utforandeverksamhetIds,
+ ...this._tjanstKoder,
+ ...this._utforandeverksamhetIds,
};
}
@@ -232,15 +251,15 @@ export class AvropService {
}
public setSelectedTjanster(selectedFilterOptions: MultiselectFilterOption[]): void {
- this._filteredTjanster$.next(selectedFilterOptions);
+ this._params$.next({ ...this._params$.getValue(), filteredTjanster: selectedFilterOptions, page: 1 });
}
public setSelectedUtforandeVerksamheter(selectedFilterOptions: MultiselectFilterOption[]): void {
- this._filteredUtforandeVerksamheter$.next(selectedFilterOptions);
+ this._params$.next({ ...this._params$.getValue(), filteredUtforandeVerksamheter: selectedFilterOptions, page: 1 });
}
public setSelectedKommuner(selectedFilterOptions: MultiselectFilterOption[]): void {
- this._filteredKommuner$.next(selectedFilterOptions);
+ this._params$.next({ ...this._params$.getValue(), filteredKommuner: selectedFilterOptions, page: 1 });
}
public goToStep1(): void {
@@ -252,22 +271,25 @@ export class AvropService {
}
public removeKommun(kommunToRemove: MultiselectFilterOption): void {
- this.setSelectedKommuner(this._filteredKommuner$.value.filter(selectedKommun => selectedKommun !== kommunToRemove));
+ const params = this._params$.getValue();
+ this.setSelectedKommuner(params.filteredKommuner.filter(selectedKommun => selectedKommun !== kommunToRemove));
}
public removeUtforandeVerksamhet(utforandeVerksamhetToRemove: MultiselectFilterOption): void {
+ const params = this._params$.getValue();
this.setSelectedUtforandeVerksamheter(
- this._filteredUtforandeVerksamheter$.value.filter(
+ params.filteredUtforandeVerksamheter.filter(
selectedUtforandeVerksamhet => selectedUtforandeVerksamhet !== utforandeVerksamhetToRemove
)
);
}
public removeTjanst(tjanstToRemove: MultiselectFilterOption): void {
- this.setSelectedTjanster(this._filteredTjanster$.value.filter(selectedTjanst => selectedTjanst !== tjanstToRemove));
+ const params = this._params$.getValue();
+ this.setSelectedTjanster(params.filteredTjanster.filter(selectedTjanst => selectedTjanst !== tjanstToRemove));
}
public setPage(page: number): void {
- this._page$.next(page);
+ this._params$.next({ ...this._params$.getValue(), page });
}
}