Skip to content

Commit a3f45d4

Browse files
added a check on whether the imageFile is present within the snvplicity saga to decide whether to show or hide the SNVplicity plots
1 parent 5f6cb33 commit a3f45d4

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/redux/snvplicity/reducer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import actions from "./actions";
33
const initState = {
44
loading: false,
55
data: null,
6+
imageFile: "multiplicity.png",
7+
imagePresent: false,
68
error: null,
79
};
810

@@ -13,18 +15,21 @@ export default function appReducer(state = initState, action) {
1315
...state,
1416
error: null,
1517
data: null,
18+
imagePresent: false,
1619
loading: true,
1720
};
1821
case actions.FETCH_SNVPLICITY_DATA_SUCCESS:
1922
return {
2023
...state,
2124
data: action.data,
25+
imagePresent: action.imagePresent,
2226
loading: false,
2327
};
2428
case actions.FETCH_SNVPLICITY_DATA_FAILED:
2529
return {
2630
...state,
2731
error: action.error,
32+
imagePresent: false,
2833
data: null,
2934
loading: false,
3035
};

src/redux/snvplicity/saga.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ export function* fetchSnvplicityData(action) {
1010
const currentState = yield select(getCurrentState);
1111
const { dataset } = currentState.Settings;
1212
const { id } = currentState.CaseReport;
13+
const { imageFile } = currentState.Snvplicity;
14+
15+
// 2) Check if the image file is present
16+
const imageUrl = `${dataset.dataPath}${id}/${imageFile}`;
17+
try {
18+
yield call(axios.head, imageUrl);
19+
// If present, dispatch success with imagePresent: true and return
20+
yield put({
21+
type: actions.FETCH_SNVPLICITY_DATA_SUCCESS,
22+
data: null,
23+
imagePresent: true,
24+
});
25+
return;
26+
} catch (e) {
27+
// If not present, continue with the rest of the saga as before
28+
}
1329

1430
try {
1531
// 2) Prepare parallel requests
@@ -57,6 +73,7 @@ export function* fetchSnvplicityData(action) {
5773
yield put({
5874
type: actions.FETCH_SNVPLICITY_DATA_SUCCESS,
5975
data: binnedData,
76+
imagePresent: false,
6077
});
6178
} catch (error) {
6279
// This catch block typically only runs if there was a fatal error

src/tabs/binQCTab/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import SnvplicityPlotPanel from "../../components/snvplicityPlotPanel";
88

99
class BinQcTab extends Component {
1010
render() {
11-
const { dataset, id } = this.props;
11+
const { dataset, id, imagePresent, imageFile } = this.props;
1212
return (
1313
<Wrapper>
1414
<Row
@@ -24,7 +24,14 @@ class BinQcTab extends Component {
2424
gutter={16}
2525
>
2626
<Col className="gutter-row" span={24}>
27-
<SnvplicityPlotPanel />
27+
{imagePresent && imageFile ? (
28+
<Image
29+
src={`${dataset.dataPath}${id}/${imageFile}`}
30+
fallback="https://placehold.co/600x400?text=Image+not+found"
31+
/>
32+
) : (
33+
<SnvplicityPlotPanel />
34+
)}
2835
</Col>
2936
</Row>
3037
<Row
@@ -54,6 +61,8 @@ const mapDispatchToProps = (dispatch) => ({});
5461
const mapStateToProps = (state) => ({
5562
metadata: state.CaseReport.metadata,
5663
dataset: state.Settings.dataset,
64+
imagePresent: state.Snvplicity.imagePresent,
65+
imageFile: state.Snvplicity.imageFile,
5766
id: state.CaseReport.id,
5867
});
5968
export default connect(

0 commit comments

Comments
 (0)