Skip to content

Commit 7a1c9d1

Browse files
added check if the highlights.json file is missing
1 parent a3f45d4 commit 7a1c9d1

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/redux/highlights/reducer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import actions from "./actions";
33
const initState = {
44
loading: false,
55
filename: "highlights.json",
6+
highlightsMissing: true,
67
data: null,
78
error: null,
89
};
@@ -14,18 +15,21 @@ export default function appReducer(state = initState, action) {
1415
...state,
1516
error: null,
1617
data: null,
18+
highlightsMissing: true,
1719
loading: true,
1820
};
1921
case actions.FETCH_HIGHLIGHTS_DATA_SUCCESS:
2022
return {
2123
...state,
2224
data: action.data,
25+
highlightsMissing: action.highlightsMissing,
2326
loading: false,
2427
};
2528
case actions.FETCH_HIGHLIGHTS_DATA_FAILED:
2629
return {
2730
...state,
2831
error: action.error,
32+
highlightsMissing: true,
2933
data: null,
3034
loading: false,
3135
};

src/redux/highlights/saga.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@ function* fetchHighlightsData(action) {
99
const { dataset } = currentState.Settings;
1010
const { filename } = currentState.Highlights;
1111
const { id } = currentState.CaseReport;
12+
const highlightsUrl = `${dataset.dataPath}${id}/${filename}`;
13+
1214
try {
13-
let responseData = yield call(
14-
axios.get,
15-
`${dataset.dataPath}${id}/${filename}`,
16-
{ cancelToken: getCancelToken() }
17-
);
15+
yield call(axios.head, highlightsUrl);
16+
// File exists, proceed to fetch as before
17+
} catch (e) {
18+
// File is missing, break and dispatch highlightsMissing: true
19+
yield put({
20+
type: actions.FETCH_HIGHLIGHTS_DATA_SUCCESS,
21+
data: null,
22+
highlightsMissing: true,
23+
});
24+
return;
25+
}
26+
27+
try {
28+
let responseData = yield call(axios.get, highlightsUrl, {
29+
cancelToken: getCancelToken(),
30+
});
1831

1932
yield put({
2033
type: actions.FETCH_HIGHLIGHTS_DATA_SUCCESS,
2134
data: responseData.data,
35+
highlightsMissing: false,
2236
});
2337
} catch (error) {
2438
console.log(error);

src/tabs/summaryTab/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import HighlightsPanel from "../../components/highlightsPanel";
2121

2222
class SummaryTab extends Component {
2323
render() {
24-
const { t, loading, metadata, plots, tumorPlots } = this.props;
24+
const { t, loading, metadata, plots, tumorPlots, highlightsMissing } =
25+
this.props;
2526
const { tags } = metadata;
2627

2728
let plotsList = chunks(plots.filter((d) => !isNaN(metadata[d.id])));
@@ -32,8 +33,12 @@ class SummaryTab extends Component {
3233
return (
3334
<Wrapper>
3435
<Skeleton active loading={loading}>
35-
<HighlightsPanel title={t("components.highlights-panel.title")} />
36-
<br />
36+
{!highlightsMissing && (
37+
<>
38+
<HighlightsPanel title={t("components.highlights-panel.title")} />
39+
<br />
40+
</>
41+
)}
3742
{tagsList.length > 0 && (
3843
<Card
3944
size="small"
@@ -115,6 +120,7 @@ SummaryTab.defaultProps = {};
115120
const mapDispatchToProps = (dispatch) => ({});
116121
const mapStateToProps = (state) => ({
117122
loading: state.PopulationStatistics.loading,
123+
highlightsMissing: state.Highlights.highlightsMissing,
118124
metadata: state.CaseReport.metadata,
119125
plots: state.PopulationStatistics.general,
120126
tumorPlots: state.PopulationStatistics.tumor,

0 commit comments

Comments
 (0)