Skip to content

Commit

Permalink
Merge pull request #1804 from nextstrain/download-error
Browse files Browse the repository at this point in the history
Only support downloading Auspice JSONs if dataset name can be parsed
  • Loading branch information
joverlee521 authored Aug 6, 2024
2 parents 84a1548 + 91d98b1 commit 077020e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Fix bug where app crashed if measurements JSON did not define thresholds ([#1802](https://github.com/nextstrain/auspice/pull/1802))
* Fix bug where measurements display did not honor the default `measurements_display` ([#1802](https://github.com/nextstrain/auspice/pull/1802))
* Only display download-JSON button if the dataset name can be parsed from pathname ([#1804](https://github.com/nextstrain/auspice/pull/1804))

## version 2.56.0 - 2024/07/01

Expand Down
9 changes: 7 additions & 2 deletions src/components/download/downloadButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { materialButton } from "../../globalStyles";
import * as helpers from "./helperFunctions";
import { getFullAuthorInfoFromNode } from "../../util/treeMiscHelpers";
import { getNumSelectedTips } from "../../util/treeVisibilityHelpers";
import { getDatasetNamesFromUrl } from "../../actions/loadData";

const RectangularTreeIcon = withTheme(icons.RectangularTree);
const PanelsGridIcon = withTheme(icons.PanelsGrid);
Expand Down Expand Up @@ -35,6 +36,10 @@ export const DownloadButtons = ({dispatch, t, tree, entropy, metadata, colorBy,
}
}
}
/* Verify that we can parse dataset name from URL to support Auspice JSON download */
const datasetNames = getDatasetNamesFromUrl(window.location.pathname);
const supportAuspiceJsonDownload = !gisaidProvenance && datasetNames.some(Boolean);

const entropyBar = entropy?.selectedCds===nucleotide_gene ? "nucleotide" : "codon";

return (
Expand All @@ -48,12 +53,12 @@ export const DownloadButtons = ({dispatch, t, tree, entropy, metadata, colorBy,
<p/>
{partialData ? `Currently ${selectedTipsCount}/${totalTipCount} tips are displayed and will be downloaded.` : `Currently the entire dataset (${totalTipCount} tips) will be downloaded.`}
</div>
{!gisaidProvenance && (
{supportAuspiceJsonDownload && (
<Button
name="Auspice (Nextstrain) JSON"
description={`The main Auspice dataset JSON(s) for the current view`}
icon={<DatasetIcon width={iconWidth} selected />}
onClick={() => helpers.auspiceJSON(dispatch)}
onClick={() => helpers.auspiceJSON(dispatch, datasetNames)}
/>
)}
<Button
Expand Down
16 changes: 10 additions & 6 deletions src/components/download/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NODE_VISIBLE, nucleotide_gene } from "../../util/globals";
import { datasetSummary } from "../info/datasetSummary";
import { isColorByGenotype } from "../../util/getGenotype";
import { EmptyNewickTreeCreated } from "../../util/exceptions";
import { getDatasetNamesFromUrl, Dataset } from "../../actions/loadData";
import { Dataset } from "../../actions/loadData";

export const isPaperURLValid = (d) => {
return (
Expand Down Expand Up @@ -623,15 +623,19 @@ export const entropyTSV = (dispatch, filePrefix, entropy) => {
/**
* Write out Auspice JSON(s) for the current view. We do this by re-fetching the original
* JSON because we don't keep a copy of the unprocessed data around.
*
*
* Sidecar files are not fetched, but we can also download them if desired.
*
*
* Note that we are not viewing a narrative, as the download button functionality is disabled
* for narratives.
*/
export const auspiceJSON = (dispatch) => {
export const auspiceJSON = (dispatch, datasetNames) => {
const filenames = [];
for (const datasetName of getDatasetNamesFromUrl(window.location.pathname)) {
if (!datasetNames.some(Boolean)) {
console.error(`Unable to fetch empty dataset names: ${JSON.stringify(datasetNames)}`);
return dispatch(errorNotification({message: "Unable to download Auspice JSON (see console for more info)"}))
}
for (const datasetName of datasetNames) {
if (!datasetName) continue; // e.g. no 2nd tree
const filename = datasetName.replace('/', '_') + '.json';
filenames.push(filename);
Expand All @@ -647,4 +651,4 @@ export const auspiceJSON = (dispatch) => {
});
}
dispatch(infoNotification({message: `Preparing Auspice JSON(s) for download: ${filenames.join(', ')}`}));
};
};
2 changes: 1 addition & 1 deletion src/middleware/changeURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const changeURLMiddleware = (store) => (next) => (action) => {
/* second switch: path change */
switch (action.type) {
case types.CLEAN_START:
if (action.pathnameShouldBe && !action.narrative) {
if (typeof action.pathnameShouldBe === "string" && !action.narrative) {
pathname = action.pathnameShouldBe;
break;
}
Expand Down

0 comments on commit 077020e

Please sign in to comment.