1- import React , { useEffect , useState } from 'react'
1+ import React , { useEffect , useMemo , useState } from 'react'
22
33import { Feature , getContainingView } from '@jbrowse/core/util'
44import DeleteIcon from '@mui/icons-material/Delete'
@@ -24,6 +24,31 @@ import type { CachedBlastResult } from '../../../utils/blastCache'
2424import type { AbstractTrackModel } from '@jbrowse/core/util'
2525import type { LinearGenomeViewModel } from '@jbrowse/plugin-linear-genome-view'
2626
27+ function getGeneIdentifiers ( feature : Feature ) : string [ ] {
28+ const ids = [
29+ feature . id ( ) ,
30+ feature . get ( 'id' ) ,
31+ feature . get ( 'name' ) ,
32+ feature . get ( 'gene_id' ) ,
33+ feature . get ( 'gene_name' ) ,
34+ ] . filter ( ( id ) : id is string => ! ! id )
35+ return [ ...new Set ( ids ) ]
36+ }
37+
38+ function getResultDisplayName ( result : CachedBlastResult ) : string {
39+ const parts = [ ]
40+ if ( result . geneName ) {
41+ parts . push ( result . geneName )
42+ }
43+ if ( result . transcriptName && result . transcriptName !== result . geneName ) {
44+ parts . push ( result . transcriptName )
45+ }
46+ if ( parts . length === 0 ) {
47+ parts . push ( result . geneId ?? result . transcriptId ?? 'Unknown' )
48+ }
49+ return parts . join ( ' - ' )
50+ }
51+
2752const CachedBlastResults = observer ( function ( {
2853 model,
2954 handleClose,
@@ -37,19 +62,20 @@ const CachedBlastResults = observer(function ({
3762 const [ loading , setLoading ] = useState ( true )
3863 const view = getContainingView ( model ) as LinearGenomeViewModel
3964
40- const geneId = feature . get ( 'id' )
65+ const geneIds = useMemo ( ( ) => getGeneIdentifiers ( feature ) , [ feature ] )
66+
4167 useEffect ( ( ) => {
4268 // eslint-disable-next-line @typescript-eslint/no-floating-promises
4369 ; ( async ( ) => {
4470 try {
4571 const cached = await getAllCachedResults ( )
46- setResults ( cached . filter ( r => r . geneId === geneId ) )
72+ setResults ( cached . filter ( r => r . geneId && geneIds . includes ( r . geneId ) ) )
4773 setLoading ( false )
4874 } catch ( e ) {
4975 console . error ( e )
5076 }
5177 } ) ( )
52- } , [ geneId ] )
78+ } , [ geneIds ] )
5379
5480 const handleDelete = async ( id : string ) => {
5581 await deleteCachedResult ( id )
@@ -65,7 +91,7 @@ const CachedBlastResults = observer(function ({
6591 blastLaunchViewFromCache ( {
6692 view,
6793 cached,
68- newViewTitle : `BLAST - ${ cached . geneId ?? cached . transcriptId ?? 'Unknown gene' } ` ,
94+ newViewTitle : `BLAST - ${ getResultDisplayName ( cached ) } ` ,
6995 } )
7096 handleClose ( )
7197 }
@@ -132,7 +158,7 @@ const CachedBlastResults = observer(function ({
132158 } }
133159 >
134160 < ListItemText
135- primary = { `${ result . geneId ?? result . transcriptId ?? 'Unknown' } - ${ result . blastDatabase } /${ result . blastProgram } (${ result . msaAlgorithm } )` }
161+ primary = { `${ getResultDisplayName ( result ) } - ${ result . blastDatabase } /${ result . blastProgram } (${ result . msaAlgorithm } )` }
136162 secondary = { `${ new Date ( result . timestamp ) . toLocaleString ( ) } - Seq: ${ result . proteinSequence . slice ( 0 , 30 ) } ...` }
137163 />
138164 </ ListItemButton >
0 commit comments