1- import React , { useEffect , useState , useCallback } from "react" ;
1+ import React , { useEffect , useState , useCallback , useContext } from "react" ;
22import { Redirect , useHistory } from "react-router-dom" ;
33import PropTypes from "prop-types" ;
44import { Auth , Storage , API , graphqlOperation } from "aws-amplify" ;
@@ -10,9 +10,27 @@ import ColorDepthSearchParameters from "./ColorDepthSearchParameters";
1010import * as queries from "../graphql/queries" ;
1111import * as mutations from "../graphql/mutations" ;
1212import config from "../config" ;
13+ import { AppContext } from "../containers/AppContext" ;
1314
1415const { Title, Paragraph } = Typography ;
1516
17+ // Get the default search library from stores based on anatomical region
18+ function getDefaultLibrary ( stores , anatomicalRegion ) {
19+ let defaultLibrary = undefined ;
20+ if ( stores && anatomicalRegion ) {
21+ const matchingStore = Object . values ( stores ) . find (
22+ ( store ) =>
23+ anatomicalRegion . toLowerCase ( ) ===
24+ store . anatomicalArea . toLowerCase ( )
25+ ) ;
26+ if ( matchingStore ?. customSearch ?. defaultSearchLibrary ) {
27+ defaultLibrary = matchingStore . customSearch . defaultSearchLibrary ;
28+ }
29+ }
30+ return defaultLibrary ;
31+ }
32+
33+
1634export default function MaskSelection ( { match } ) {
1735 const searchId = match . params . id ;
1836 const [ searchMeta , setSearchMeta ] = useState ( null ) ;
@@ -22,6 +40,7 @@ export default function MaskSelection({ match }) {
2240 const [ channelImgSrc , setChannelImgSrc ] = useState ( null ) ;
2341 const [ submitting , setSubmitting ] = useState ( false ) ;
2442 const history = useHistory ( ) ;
43+ const { appState } = useContext ( AppContext ) ;
2544
2645 useEffect ( ( ) => {
2746 if ( searchId ) {
@@ -173,8 +192,6 @@ export default function MaskSelection({ match }) {
173192 }
174193 }
175194
176- console . log ( searchMeta ) ;
177-
178195 return (
179196 < div >
180197 < Title component = "h2" > Mask selection</ Title >
@@ -193,13 +210,13 @@ export default function MaskSelection({ match }) {
193210 anatomicalRegion = { anatomicalRegion }
194211 />
195212 < Divider />
196- { searchMeta ? (
213+ { searchMeta && appState ?. dataConfig ?. stores && Object . keys ( appState . dataConfig . stores ) . length > 0 ? (
197214 < Form
198215 labelCol = { { span : 8 } }
199216 wrapperCol = { { span : 16 } }
200217 name = "basic"
201218 initialValues = { {
202- selectedLibraries : searchMeta . searchType || "FlyLight_Gen1_MCFO" ,
219+ selectedLibraries : searchMeta . searchType || getDefaultLibrary ( appState ?. dataConfig ?. stores , searchMeta . anatomicalRegion ) || undefined ,
203220 dataThreshold : searchMeta . dataThreshold || 100 ,
204221 maskThreshold : searchMeta . maskThreshold || 100 ,
205222 xyShift : searchMeta . xyShift || 0 ,
0 commit comments