diff --git a/src/app/core/models/project-options-with-label.model.ts b/src/app/core/models/project-options-with-label.model.ts new file mode 100644 index 0000000000..64a79e3c73 --- /dev/null +++ b/src/app/core/models/project-options-with-label.model.ts @@ -0,0 +1,7 @@ +import { ExtendedProject } from './v2/extended-project.model'; + +export interface ProjectOptionTypeWithLabel { + label: string; + value: ExtendedProject; + selected?: boolean; +} diff --git a/src/app/core/models/project-options.model.ts b/src/app/core/models/project-options.model.ts index 8e1fb82d2e..3a8365def9 100644 --- a/src/app/core/models/project-options.model.ts +++ b/src/app/core/models/project-options.model.ts @@ -1,11 +1,3 @@ -import { ExtendedProject } from './v2/extended-project.model'; - export interface ProjectOptionType { value: string; } - -export interface ProjectOptionTypeWithLabel { - label: string; - value: ExtendedProject; - selected?: boolean; -} diff --git a/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.ts b/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.ts index da923a1d83..3e80732053 100644 --- a/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.ts +++ b/src/app/shared/components/fy-select-project/fy-select-modal/fy-select-project-modal.component.ts @@ -1,13 +1,4 @@ -import { - Component, - OnInit, - AfterViewInit, - ViewChild, - ElementRef, - Input, - ChangeDetectorRef, - TemplateRef, -} from '@angular/core'; +import { Component, AfterViewInit, ViewChild, ElementRef, Input, ChangeDetectorRef, TemplateRef } from '@angular/core'; import { Observable, fromEvent, iif, of, from } from 'rxjs'; import { ModalController } from '@ionic/angular'; import { map, startWith, distinctUntilChanged, switchMap, concatMap, finalize } from 'rxjs/operators'; @@ -20,14 +11,15 @@ import { UtilityService } from 'src/app/core/services/utility.service'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { OrgUserSettingsService } from 'src/app/core/services/org-user-settings.service'; import { OrgUserSettings } from 'src/app/core/models/org_user_settings.model'; -import { ProjectOptionType, ProjectOptionTypeWithLabel } from 'src/app/core/models/project-options.model'; +import { ProjectOptionType } from 'src/app/core/models/project-options.model'; +import { ProjectOptionTypeWithLabel } from 'src/app/core/models/project-options-with-label.model'; @Component({ selector: 'app-fy-select-modal', templateUrl: './fy-select-project-modal.component.html', styleUrls: ['./fy-select-project-modal.component.scss'], }) -export class FyProjectSelectModalComponent implements OnInit, AfterViewInit { +export class FyProjectSelectModalComponent implements AfterViewInit { @ViewChild('searchBar') searchBarRef: ElementRef; @Input() currentSelection: ExtendedProject | [ExtendedProject]; @@ -63,13 +55,7 @@ export class FyProjectSelectModalComponent implements OnInit, AfterViewInit { private orgSettingsService: OrgSettingsService ) {} - ngOnInit(): void { - return; - } - - getProjects( - searchNameText: string - ): Observable<{ label: string | undefined; value: ExtendedProject | ExtendedProject[] }[]> { + getProjects(searchNameText: string): Observable<{ label: string; value: ExtendedProject | ExtendedProject[] }[]> { // set isLoading to true this.isLoading = true; // run ChangeDetectionRef.detectChanges to avoid 'expression has changed after it was checked error'. @@ -131,7 +117,7 @@ export class FyProjectSelectModalComponent implements OnInit, AfterViewInit { const currentElement = []; if ( this.currentSelection && - !projects.some((project) => project.project_id === (this.currentSelection as ExtendedProject).project_id) // Cast this.currentSelection to ExtendedProject + !projects.some((project) => project.project_id === (this.currentSelection as ExtendedProject).project_id) ) { currentElement.push({ label: (this.currentSelection as ExtendedProject).project_name, @@ -176,8 +162,8 @@ export class FyProjectSelectModalComponent implements OnInit, AfterViewInit { } ngAfterViewInit(): void { - this.filteredOptions$ = fromEvent(this.searchBarRef.nativeElement, 'keyup').pipe( - map((event: KeyboardEvent) => (event.target as HTMLInputElement).value), + this.filteredOptions$ = fromEvent<{ target: HTMLInputElement }>(this.searchBarRef.nativeElement, 'keyup').pipe( + map((event) => event.target.value), startWith(''), distinctUntilChanged(), switchMap((searchText: string) => this.getProjects(searchText)), @@ -186,13 +172,16 @@ export class FyProjectSelectModalComponent implements OnInit, AfterViewInit { if (isEqual(project.value, this.currentSelection)) { project.selected = true; } - return project as { label: string; value: ExtendedProject; selected?: boolean }; + return project as ProjectOptionTypeWithLabel; }) ) ); - this.recentrecentlyUsedItems$ = fromEvent(this.searchBarRef.nativeElement, 'keyup').pipe( - map((event: KeyboardEvent) => (event.target as HTMLInputElement).value), + this.recentrecentlyUsedItems$ = fromEvent<{ target: HTMLInputElement }>( + this.searchBarRef.nativeElement, + 'keyup' + ).pipe( + map((event) => event.target.value), startWith(''), distinctUntilChanged(), switchMap((searchText: string) =>