Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
SahilK-027 committed May 2, 2024
1 parent 29c12c8 commit 92f9701
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
7 changes: 7 additions & 0 deletions src/app/core/models/project-options-with-label.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ExtendedProject } from './v2/extended-project.model';

export interface ProjectOptionTypeWithLabel {
label: string;
value: ExtendedProject;
selected?: boolean;
}
8 changes: 0 additions & 8 deletions src/app/core/models/project-options.model.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<HTMLInputElement>;

@Input() currentSelection: ExtendedProject | [ExtendedProject];
Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)),
Expand All @@ -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) =>
Expand Down

0 comments on commit 92f9701

Please sign in to comment.