Skip to content

Commit

Permalink
Only support downloading Auspice JSONs if dataset name can be parsed
Browse files Browse the repository at this point in the history
Resolves <#1803>
  • Loading branch information
joverlee521 committed Jul 31, 2024
1 parent 6955728 commit b7c165b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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
12 changes: 6 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,15 @@ 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)) {
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 +647,4 @@ export const auspiceJSON = (dispatch) => {
});
}
dispatch(infoNotification({message: `Preparing Auspice JSON(s) for download: ${filenames.join(', ')}`}));
};
};

0 comments on commit b7c165b

Please sign in to comment.