@@ -17,7 +17,11 @@ import {
17
17
} from "@mui/material" ;
18
18
import { Autocomplete } from "@mui/material" ;
19
19
import { GenomeSearchProps , Result } from "./types" ;
20
- import { QueryClient , QueryClientProvider , useQuery } from "@tanstack/react-query" ;
20
+ import {
21
+ QueryClient ,
22
+ QueryClientProvider ,
23
+ useQuery ,
24
+ } from "@tanstack/react-query" ;
21
25
22
26
/**
23
27
* An autocomplete search component for genomic landmarks such as genes, SNPs, ICRs, and CCRs.
@@ -31,6 +35,7 @@ import { QueryClient, QueryClientProvider, useQuery } from "@tanstack/react-quer
31
35
const Search : React . FC < GenomeSearchProps > = ( {
32
36
queries,
33
37
assembly,
38
+ showiCREFlag,
34
39
geneLimit,
35
40
snpLimit,
36
41
icreLimit,
@@ -43,13 +48,6 @@ const Search: React.FC<GenomeSearchProps> = ({
43
48
slotProps,
44
49
...autocompleteProps
45
50
} ) => {
46
- // Boolean flags for each query
47
- const searchGene = queries . includes ( "Gene" ) ;
48
- const searchSnp = queries . includes ( "SNP" ) ;
49
- const searchICRE = queries . includes ( "iCRE" ) ;
50
- const searchCCRE = queries . includes ( "cCRE" ) ;
51
- const searchCoordinate = queries . includes ( "Coordinate" ) ;
52
-
53
51
// State variables
54
52
const [ inputValue , setInputValue ] = useState ( "" ) ;
55
53
const [ selection , setSelection ] = useState < Result > ( { } as Result ) ;
@@ -58,6 +56,12 @@ const Search: React.FC<GenomeSearchProps> = ({
58
56
) ;
59
57
const [ isLoading , setIsLoading ] = useState ( false ) ;
60
58
59
+ const searchGene = queries . includes ( "Gene" ) ;
60
+ const searchSnp = queries . includes ( "SNP" ) ;
61
+ const searchICRE = queries . includes ( "iCRE" ) ;
62
+ const searchCCRE = queries . includes ( "cCRE" ) ;
63
+ const searchCoordinate = queries . includes ( "Coordinate" ) ;
64
+
61
65
const {
62
66
data : icreData ,
63
67
refetch : refetchICREs ,
@@ -74,7 +78,7 @@ const Search: React.FC<GenomeSearchProps> = ({
74
78
isFetching : ccreFetching ,
75
79
} = useQuery ( {
76
80
queryKey : [ "ccres" , inputValue ] ,
77
- queryFn : ( ) => getCCREs ( inputValue , assembly , ccreLimit || 3 ) ,
81
+ queryFn : ( ) => getCCREs ( inputValue , assembly , ccreLimit || 3 , showiCREFlag || false ) ,
78
82
enabled : false ,
79
83
} ) ;
80
84
@@ -130,31 +134,44 @@ const Search: React.FC<GenomeSearchProps> = ({
130
134
useEffect ( ( ) => {
131
135
if ( isLoading ) return ;
132
136
const resultsList = [ ] ;
133
- if ( geneData ) {
137
+ if ( geneData && searchGene ) {
134
138
resultsList . push ( ...geneResultList ( geneData . data . gene , geneLimit || 3 ) ) ;
135
139
}
136
- if ( icreData && inputValue . toLowerCase ( ) . startsWith ( "eh" ) ) {
140
+ if ( icreData && searchICRE && inputValue . toLowerCase ( ) . startsWith ( "eh" ) ) {
137
141
resultsList . push (
138
142
...icreResultList ( icreData . data . iCREQuery , icreLimit || 3 )
139
143
) ;
140
144
}
141
- if ( ccreData && inputValue . toLowerCase ( ) . startsWith ( "eh" ) ) {
145
+ if ( ccreData && searchCCRE && inputValue . toLowerCase ( ) . startsWith ( "eh" ) ) {
146
+ console . log ( ccreData . data . cCREAutocompleteQuery )
142
147
resultsList . push (
143
- ...ccreResultList ( ccreData . data . cCREQuery , ccreLimit || 3 )
148
+ ...ccreResultList ( ccreData . data . cCREAutocompleteQuery , ccreLimit || 3 )
144
149
) ;
145
150
}
146
- if ( snpData && inputValue . toLowerCase ( ) . startsWith ( "rs" ) ) {
151
+ if ( snpData && searchSnp && inputValue . toLowerCase ( ) . startsWith ( "rs" ) ) {
147
152
resultsList . push (
148
153
...snpResultList ( snpData . data . snpAutocompleteQuery , snpLimit || 3 )
149
154
) ;
150
155
}
151
- if ( searchCoordinate && isDomain ( inputValue ) ) {
156
+ if ( isDomain ( inputValue ) && searchCoordinate ) {
152
157
resultsList . push ( ...getCoordinates ( inputValue , assembly ) ) ;
153
158
}
154
159
155
160
if ( resultsList . length === 0 ) setResults ( null ) ;
156
161
else setResults ( resultsList ) ;
157
- } , [ isLoading , icreData , ccreData , geneData , snpData ] ) ;
162
+ } , [
163
+ isLoading ,
164
+ icreData ,
165
+ ccreData ,
166
+ geneData ,
167
+ snpData ,
168
+ searchGene ,
169
+ searchICRE ,
170
+ searchCCRE ,
171
+ searchSnp ,
172
+ searchCoordinate ,
173
+ inputValue ,
174
+ ] ) ;
158
175
159
176
// Handle submit
160
177
const onSubmit = useCallback ( ( ) => {
@@ -184,10 +201,10 @@ const Search: React.FC<GenomeSearchProps> = ({
184
201
return (
185
202
< Box
186
203
display = "flex"
187
- flexDirection = "row"
204
+ flexDirection = "row"
188
205
gap = { 2 }
189
206
style = { { ...style } }
190
- sx = { { ...sx } }
207
+ sx = { { ...sx } }
191
208
{ ...slotProps ?. box }
192
209
>
193
210
< Autocomplete
@@ -256,31 +273,32 @@ const Search: React.FC<GenomeSearchProps> = ({
256
273
*/
257
274
function renderGroup ( params : any , inputValue : string ) {
258
275
// Sort items within each group by title match relevance
259
- const sortedOptions = Array . isArray ( params . children ) && ! isDomain ( inputValue )
260
- ? params . children . sort ( ( a : any , b : any ) => {
261
- const aTitle = (
262
- a . props ?. children ?. props ?. children ?. [ 0 ] ?. props ?. children || ""
263
- ) . toLowerCase ( ) ;
264
- const bTitle = (
265
- b . props ?. children ?. props ?. children ?. [ 0 ] ?. props ?. children || ""
266
- ) . toLowerCase ( ) ;
267
- const query = inputValue . toLowerCase ( ) ;
268
- // Exact matches first
269
- if ( aTitle === query && bTitle !== query ) return - 1 ;
270
- if ( bTitle === query && aTitle !== query ) return 1 ;
276
+ const sortedOptions =
277
+ Array . isArray ( params . children ) && ! isDomain ( inputValue )
278
+ ? params . children . sort ( ( a : any , b : any ) => {
279
+ const aTitle = (
280
+ a . props ?. children ?. props ?. children ?. [ 0 ] ?. props ?. children || ""
281
+ ) . toLowerCase ( ) ;
282
+ const bTitle = (
283
+ b . props ?. children ?. props ?. children ?. [ 0 ] ?. props ?. children || ""
284
+ ) . toLowerCase ( ) ;
285
+ const query = inputValue . toLowerCase ( ) ;
286
+ // Exact matches first
287
+ if ( aTitle === query && bTitle !== query ) return - 1 ;
288
+ if ( bTitle === query && aTitle !== query ) return 1 ;
271
289
272
- // Starts with query second
273
- if ( aTitle . startsWith ( query ) && ! bTitle . startsWith ( query ) ) return - 1 ;
274
- if ( bTitle . startsWith ( query ) && ! aTitle . startsWith ( query ) ) return 1 ;
290
+ // Starts with query second
291
+ if ( aTitle . startsWith ( query ) && ! bTitle . startsWith ( query ) ) return - 1 ;
292
+ if ( bTitle . startsWith ( query ) && ! aTitle . startsWith ( query ) ) return 1 ;
275
293
276
- // Contains query third
277
- if ( aTitle . includes ( query ) && ! bTitle . includes ( query ) ) return - 1 ;
278
- if ( bTitle . includes ( query ) && ! aTitle . includes ( query ) ) return 1 ;
294
+ // Contains query third
295
+ if ( aTitle . includes ( query ) && ! bTitle . includes ( query ) ) return - 1 ;
296
+ if ( bTitle . includes ( query ) && ! aTitle . includes ( query ) ) return 1 ;
279
297
280
- // Alphabetical order for equal relevance
281
- return aTitle . localeCompare ( bTitle ) ;
282
- } )
283
- : params . children ;
298
+ // Alphabetical order for equal relevance
299
+ return aTitle . localeCompare ( bTitle ) ;
300
+ } )
301
+ : params . children ;
284
302
285
303
return (
286
304
< div key = { params . key } >
0 commit comments