1- import { Component , inject , signal } from '@angular/core' ;
1+ import { Component , computed , inject , signal } from '@angular/core' ;
22import { FormBuilder , FormGroup , Validators , ReactiveFormsModule } from '@angular/forms' ;
33import { MatDialogRef , MAT_DIALOG_DATA , MatDialogModule } from '@angular/material/dialog' ;
44import { CommonModule } from '@angular/common' ;
55import { FormsModule } from '@angular/forms' ;
66import { noWhitespaceValidator , noLeadingTrailingSpacesValidator } from '../validators/validators' ;
77import { MatMenuModule } from "@angular/material/menu" ;
88import { HelpButtonComponent } from "../util/helpbutton/help-button.component" ;
9+ import { ConfigService } from '../services/config.service' ;
10+ import { toSignal } from '@angular/core/rxjs-interop' ;
911
1012
1113@Component ( {
@@ -23,25 +25,28 @@ import { HelpButtonComponent } from "../util/helpbutton/help-button.component";
2325 styleUrls : [ './cohortdialog.component.css' ] ,
2426} )
2527export class CohortDialogComponent {
26- form : FormGroup ;
27-
28+
2829 showPasteArea = signal ( false ) ;
2930 pastedText = signal < string | null > ( null ) ;
3031 private fb = inject ( FormBuilder ) ;
3132 public dialogRef = inject ( MatDialogRef < CohortDialogComponent > ) ;
32- public data = inject ( MAT_DIALOG_DATA ) as { title : string } ;
33- constructor (
34- ) {
35- this . form = this . fb . group ( {
33+ public data = inject ( MAT_DIALOG_DATA ) as { title : string } ;
34+ private configService = inject ( ConfigService ) ;
35+
36+ form : FormGroup = this . fb . group ( {
3637 diseaseId : [ '' , [ Validators . required , Validators . pattern ( / ^ O M I M : \d { 6 } $ / ) ] ] ,
3738 diseaseLabel : [ '' , [ Validators . required , noLeadingTrailingSpacesValidator ] ] ,
3839 cohortAcronym : [ '' , [ Validators . required , noWhitespaceValidator ] ] ,
3940 hgnc : [ '' , [ Validators . required , Validators . pattern ( / ^ H G N C : \d + $ / ) ] ] ,
4041 symbol : [ '' , [ Validators . required , noWhitespaceValidator ] ] ,
4142 transcript : [ '' , [ Validators . required , Validators . pattern ( / ^ [ \w ] + \. \d + $ / ) ] ] ,
4243 } ) ;
43- }
44-
44+ symbolValue = toSignal ( this . form . get ( 'symbol' ) ! . valueChanges , { initialValue : '' } ) ;
45+ canFetch = computed ( ( ) => {
46+ const s = this . symbolValue ( ) ;
47+ return s && s . trim ( ) . length > 0 ;
48+ } ) ;
49+ isLoading = signal ( false ) ;
4550
4651 cancel ( ) {
4752 this . dialogRef . close ( null ) ;
@@ -85,4 +90,32 @@ public data = inject(MAT_DIALOG_DATA) as { title: string };
8590 togglePaste ( ) {
8691 this . showPasteArea . update ( v => ! v ) ;
8792 }
93+
94+ async fetchHgncData ( symbol : string ) : Promise < { hgncId : string , maneSelect : string } | null > {
95+ try {
96+ return await this . configService . fetchHgncData ( symbol ) ;
97+ } catch ( error ) {
98+ console . error ( `Error fetching gene ${ symbol } : ${ error } ` ) ;
99+ return null ; // Return null so your UI can show a "Gene not found" message
100+ }
101+ }
102+
103+ async fetchAndFillHgnc ( ) {
104+ const symbol = this . symbolValue ( ) ;
105+ if ( ! symbol ) return ;
106+
107+ this . isLoading . set ( true ) ;
108+ const result = await this . fetchHgncData ( symbol ) ;
109+ this . isLoading . set ( false ) ;
110+
111+ if ( result ) {
112+ this . form . patchValue ( {
113+ hgnc : result . hgncId ,
114+ transcript : result . maneSelect
115+ } ) ;
116+ } else {
117+ // Optional: Toast or specific error handling if gene not found
118+ alert ( `Could not find data for symbol: ${ symbol } ` ) ;
119+ }
120+ }
88121}
0 commit comments