From 382d697e95a3504d041d2055721ca4c5c9af5690 Mon Sep 17 00:00:00 2001 From: shaed-parkar <41630528+shaed-parkar@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:09:54 +0000 Subject: [PATCH] VIH-11224 call reference data get hearing types for allocation filter menu (#1457) * VIH-11224 call reference data get hearing types for allocation filter menu * clone the array from the venue type rather than manipulating the original array --- .../hearing-schedule.component.ts | 2 +- .../venues-menu/venues-menu.component.ts | 2 +- .../allocate-hearings.component.spec.ts | 9 ++-- .../allocate-hearings.component.ts | 47 ++++++++++++++----- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/hearing-schedule/hearing-schedule.component.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/hearing-schedule/hearing-schedule.component.ts index 51bdbf65b..470e1bda1 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/hearing-schedule/hearing-schedule.component.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/booking/hearing-schedule/hearing-schedule.component.ts @@ -423,7 +423,7 @@ export class HearingScheduleComponent extends BookingBaseComponent implements On this.refDataService.getCourts().subscribe({ next: data => { - this.availableCourts = data; + this.availableCourts = [...data]; this.logger.debug(`${this.loggerPrefix} Updating list of available courts.`, { courts: data.length }); const pleaseSelect = new HearingVenueResponse(); pleaseSelect.name = Constants.PleaseSelect; diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/shared/menus/venues-menu/venues-menu.component.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/shared/menus/venues-menu/venues-menu.component.ts index eff5d1015..e4bfaed46 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/shared/menus/venues-menu/venues-menu.component.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/shared/menus/venues-menu/venues-menu.component.ts @@ -35,7 +35,7 @@ export class VenuesMenuComponent extends MenuBase { loadItems(): void { this.refDataService.getCourts().subscribe({ next: (data: HearingVenueResponse[]) => { - this.venues = this.items = data; + this.venues = this.items = [...data]; this.logger.debug(`${this.loggerPrefix} Updating list of venues.`, { venues: data.length }); }, error: error => this.handleListError(error, 'venues') diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/work-allocation/allocate-hearings/allocate-hearings.component.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/work-allocation/allocate-hearings/allocate-hearings.component.spec.ts index fffcd40e2..56d2b8b53 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/work-allocation/allocate-hearings/allocate-hearings.component.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/work-allocation/allocate-hearings/allocate-hearings.component.spec.ts @@ -14,11 +14,12 @@ import { Constants } from 'src/app/common/constants'; import { DatePipe } from '@angular/common'; import { HttpClient, HttpHandler } from '@angular/common/http'; import { JusticeUsersService } from 'src/app/services/justice-users.service'; -import { VideoHearingsService } from 'src/app/services/video-hearings.service'; import { SharedModule } from '../../shared/shared.module'; import { Logger } from 'src/app/services/logger'; import { SelectComponent, SelectOption } from 'src/app/shared/select'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; +import { ReferenceDataService } from 'src/app/services/reference-data.service'; +import { MockValues } from 'src/app/testing/data/test-objects'; describe('AllocateHearingsComponent', () => { let component: AllocateHearingsComponent; @@ -29,7 +30,7 @@ describe('AllocateHearingsComponent', () => { let testData: AllocationHearingsResponse[]; const loggerMock = jasmine.createSpyObj('Logger', ['debug']); - const hearingServiceMock = jasmine.createSpyObj('VideoHearingsService', ['getUsers', 'getHearingTypes']); + const referenceDataServiceMock = jasmine.createSpyObj('ReferenceDataService', ['getHearingTypes']); const allUsers$ = new BehaviorSubject([]); beforeEach(async () => { justiceUsersServiceSpy = jasmine.createSpyObj('JusticeUsersService', [ @@ -74,7 +75,7 @@ describe('AllocateHearingsComponent', () => { { provide: ActivatedRoute, useValue: activatedRoute }, { provide: AllocateHearingsService, useValue: allocateServiceSpy }, { provide: JusticeUsersService, useValue: justiceUsersServiceSpy }, - { provide: VideoHearingsService, useValue: hearingServiceMock }, + { provide: ReferenceDataService, useValue: referenceDataServiceMock }, { provide: Logger, useValue: loggerMock } ], imports: [SharedModule, FontAwesomeModule] @@ -91,7 +92,7 @@ describe('AllocateHearingsComponent', () => { describe('ngOnInit', () => { let searchForHearingsSpy; - hearingServiceMock.getHearingTypes.and.returnValue(of(['Type1', 'Type2'])); + referenceDataServiceMock.getHearingTypes.and.returnValue(of(MockValues.HearingTypesList)); beforeEach(() => { searchForHearingsSpy = spyOn(component, 'searchForHearings'); diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/work-allocation/allocate-hearings/allocate-hearings.component.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/work-allocation/allocate-hearings/allocate-hearings.component.ts index ee9228d88..371f0fb70 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/work-allocation/allocate-hearings/allocate-hearings.component.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/work-allocation/allocate-hearings/allocate-hearings.component.ts @@ -1,6 +1,6 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { AllocateHearingsService } from '../services/allocate-hearings.service'; -import { AllocationHearingsResponse, JusticeUserResponse } from '../../services/clients/api-client'; +import { AllocationHearingsResponse, HearingTypeResponse, JusticeUserResponse } from '../../services/clients/api-client'; import { faCircleExclamation, faHourglassStart, faTriangleExclamation, faClock } from '@fortawesome/free-solid-svg-icons'; import { AllocateHearingItemModel, AllocateHearingModel } from './models/allocate-hearing.model'; import { Transform } from '@fortawesome/fontawesome-svg-core'; @@ -10,23 +10,24 @@ import { SelectComponent, SelectOption } from 'src/app/shared/select/select.comp import { JusticeUsersService } from 'src/app/services/justice-users.service'; import { FormBuilder, Validators, FormGroup } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; -import { VideoHearingsService } from 'src/app/services/video-hearings.service'; import { BookingPersistService } from 'src/app/services/bookings-persist.service'; -import { map, tap } from 'rxjs/operators'; +import { map, takeUntil, tap } from 'rxjs/operators'; +import { ReferenceDataService } from 'src/app/services/reference-data.service'; +import { Subject } from 'rxjs'; @Component({ selector: 'app-allocate-hearings', templateUrl: './allocate-hearings.component.html', styleUrls: ['./allocate-hearings.component.scss'] }) -export class AllocateHearingsComponent implements OnInit { +export class AllocateHearingsComponent implements OnInit, OnDestroy { constructor( private readonly route: ActivatedRoute, private readonly fb: FormBuilder, private readonly allocateService: AllocateHearingsService, private readonly datePipe: DatePipe, private readonly justiceUserService: JusticeUsersService, - private readonly videoHearingService: VideoHearingsService, + private readonly referenceDataService: ReferenceDataService, private readonly bookingPersistService: BookingPersistService ) { this.form = fb.group({ @@ -65,6 +66,8 @@ export class AllocateHearingsComponent implements OnInit { caseTypesSelectOptions: SelectOption[]; selectedCaseTypeIds: string[] = []; + private readonly destroy$ = new Subject(); + ngOnInit() { this.route.queryParams.subscribe(params => { const fromDt = params['fromDt'] ?? null; @@ -83,19 +86,32 @@ export class AllocateHearingsComponent implements OnInit { } }); - this.form.get('isUnallocated').valueChanges.subscribe(val => { - if (val) { - this.onIsAllocatedCheckboxChecked(); - } else { - this.onIsAllocatedCheckboxUnchecked(); - } - }); + this.form + .get('isUnallocated') + .valueChanges.pipe(takeUntil(this.destroy$)) + .subscribe(val => { + if (val) { + this.onIsAllocatedCheckboxChecked(); + } else { + this.onIsAllocatedCheckboxUnchecked(); + } + }); this.selectedJusticeUserIds = this.bookingPersistService.selectedUsers; this.selectedCaseTypeIds = this.bookingPersistService.selectedCaseTypes; + this.referenceDataService + .getHearingTypes() + .pipe(takeUntil(this.destroy$)) + .subscribe((data: HearingTypeResponse[]) => { + this.caseTypesSelectOptions = data + .map(item => item.group) + .sort((a, b) => a.localeCompare(b)) + .map(group => ({ entityId: group, label: group })); + }); this.justiceUserService.allUsers$ .pipe( + takeUntil(this.destroy$), map(users => users.filter(user => !user.deleted)), tap(() => this.selectFilterCso?.clear()) ) @@ -109,6 +125,11 @@ export class AllocateHearingsComponent implements OnInit { }); } + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + } + searchForHearings(keepExistingMessage: boolean = false) { const retrieveDate = (date: any): Date => (date === null || date === '' ? null : new Date(date));