Skip to content

Commit

Permalink
Merge pull request #365 from sancsoft/364-psr-header-not-updating-aft…
Browse files Browse the repository at this point in the history
…er-changing-editing-time

Added shared refresh service between calculations and time list
  • Loading branch information
rmaffitsancsoft authored Sep 6, 2024
2 parents 7f28c11 + d8aa758 commit 3894ebd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/angular/hq/src/app/psr/Services/psr-refresh.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

@Injectable({
providedIn: 'root',
})
export class PsrRefreshService {
private refreshSubject = new BehaviorSubject<boolean>(false);

triggerRefresh() {
this.refreshSubject.next(true);
}

getRefreshObservable() {
return this.refreshSubject.asObservable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import {
combineLatest,
debounceTime,
map,
merge,
shareReplay,
switchMap,
} from 'rxjs';
import { GetPSRRecordV1 } from '../../models/PSR/get-PSR-v1';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { HQService } from '../../services/hq.service';
import { Period } from '../../enums/period';
import { PsrRefreshService } from '../Services/psr-refresh.service';

@Component({
selector: 'hq-psr-details-header',
Expand All @@ -26,14 +28,23 @@ export class PsrDetailsHeaderComponent {
constructor(
private activatedRoute: ActivatedRoute,
private hqService: HQService,
private psrRefreshService: PsrRefreshService,
) {
this.projectReportId$ = activatedRoute.paramMap.pipe(
map((params) => params.get('psrId')),
);
const request$ = combineLatest({
id: this.projectReportId$,
});
const response$ = request$.pipe(

const requestTrigger$ = merge(
request$,
this.psrRefreshService
.getRefreshObservable()
.pipe(switchMap(() => request$)),
);

const response$ = requestTrigger$.pipe(
debounceTime(500),
switchMap((request) => this.hqService.getPSRV1(request)),
shareReplay({ bufferSize: 1, refCount: false }),
Expand All @@ -45,7 +56,6 @@ export class PsrDetailsHeaderComponent {
}),
);
}

getPeriodName(period: Period) {
return Period[period];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PsrRefreshService } from './../Services/psr-refresh.service';
import { SelectInputOptionDirective } from './../../core/directives/select-input-option.directive';
import { HQConfirmationModalService } from './../../common/confirmation-modal/services/hq-confirmation-modal-service';
import { HQSnackBarService } from './../../common/hq-snack-bar/services/hq-snack-bar-service';
Expand Down Expand Up @@ -124,6 +125,7 @@ export class PSRTimeListComponent implements OnInit, OnDestroy {
private modalService: ModalService,
private toastService: ToastService,
private oidcSecurityService: OidcSecurityService,
private psrRefreshService: PsrRefreshService,
) {
this.sortOption$ = new BehaviorSubject<SortColumn>(SortColumn.Date);
this.sortDirection$ = new BehaviorSubject<SortDirection>(SortDirection.Asc);
Expand Down Expand Up @@ -228,7 +230,10 @@ export class PSRTimeListComponent implements OnInit, OnDestroy {

const refresh$ = this.refresh$.pipe(
switchMap(() => apiResponse$),
tap(() => this.deselectAll()),
tap(() => {
this.deselectAll();
this.psrRefreshService.triggerRefresh();
}),
);

const response$ = merge(apiResponse$, refresh$).pipe(
Expand Down

0 comments on commit 3894ebd

Please sign in to comment.