Skip to content

Commit c653ccc

Browse files
committed
fix: uses defaultSearchLibrary to set library in custom search form.
Rather than hard code the value for the default library, the search form now looks for a key in the stores called defaultSearchLibrary. If found, this is the value that is set as the default target image collection.
1 parent d687281 commit c653ccc

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/components/MaskSelection.jsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState, useCallback } from "react";
1+
import React, { useEffect, useState, useCallback, useContext } from "react";
22
import { Redirect, useHistory } from "react-router-dom";
33
import PropTypes from "prop-types";
44
import { Auth, Storage, API, graphqlOperation } from "aws-amplify";
@@ -10,9 +10,27 @@ import ColorDepthSearchParameters from "./ColorDepthSearchParameters";
1010
import * as queries from "../graphql/queries";
1111
import * as mutations from "../graphql/mutations";
1212
import config from "../config";
13+
import { AppContext } from "../containers/AppContext";
1314

1415
const { 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+
1634
export 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

Comments
 (0)