Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only support downloading Auspice JSONs if dataset name can be parsed #1804

Merged
merged 4 commits into from
Aug 6, 2024

Conversation

joverlee521
Copy link
Contributor

@joverlee521 joverlee521 commented Jul 31, 2024

Description of proposed changes

Only supports downloading Auspice JSON if the dataset name can be parsed from the URL pathname.
This mainly hides the download Auspice JSON option in auspice.us.

Related issue(s)

Resolves #1803

Checklist

src/components/download/helperFunctions.js Outdated Show resolved Hide resolved
@joverlee521

This comment was marked as resolved.

@joverlee521 joverlee521 temporarily deployed to auspice-download-error-fml9yf6 July 31, 2024 20:27 Inactive
for (const datasetName of getDatasetNamesFromUrl(window.location.pathname)) {
if (!datasetNames.every(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)"}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datasetNames is always an array of length 2. So for /zika it's [ "zika", undefined ], and thus we end up showing a error notification and not downloading the JSON.

Perhaps the intention here was .all(Boolean)? But that's unnecessary because of the conditions under which auspiceJSON() gets called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for catching that. I meant .some(Boolean) to verify at least one of them is truthy.

But that's unnecessary because of the conditions under which auspiceJSON() gets called.

Yeah, I added this guard to get error notifications on unexpected use of auspiceJSON() instead of just letting it hang on the "Preparing Auspice JSON..." notification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed up in force-push

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for catching that. I meant .some(Boolean) to verify at least one of them is truthy.

Nice one. I don't know what I meant by suggesting .all, which isn't even an array prototype method!

@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bug in auspice.us (?) where dragging on two trees results in them being added to the URL. As such, datasetNames contains 2 truthy values, and we allow the download, which then fails.

Using dev_multi_h3n2.json and ebola.json (any two JSONs will do) we get a URL of https://auspice-us-nextstrain-b-q2kkxc.herokuapp.com/dev/multi/h3n2:ebola, and the following error when trying to download:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I did not realize that the URL gets updated in auspice.us when there's a two trees.
Looks like it's coming from the changeURLMiddleware in auspice:

/* we also double check that if there are 2 trees both are represented
in the URL */
if (action.tree.name && action.treeToo && action.treeToo.name && !action.narrative) {
const treeUrlShouldBe = `${action.tree.name}:${action.treeToo.name}`;
if (!window.location.pathname.includes(treeUrlShouldBe)) {
pathname = treeUrlShouldBe;
}
}

I assume the URL should never be updated in auspice.us if you are calling this a bug? How is that configured?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we just shouldn't rely on the URL parsing here to determine if download is supported. We can add a disableAuspiceJsonDownload config param to the extensions and have auspice.us explicitly disable the downloads.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the URL should never be updated in auspice.us if you are calling this a bug? How is that configured?

auspice.us, once it's parsed the dropped files, initialises the Auspice viz via:

  /* load (into redux state) the main dataset(s) */
  try {
    dispatch({
      type: "CLEAN_START",
      pathnameShouldBe: "",
      ...createStateFromQueryOrJSONs({

and the intention is that Auspice updates the pathname (URL) to the empty string via:

case types.CLEAN_START:
if (action.pathnameShouldBe && !action.narrative) {
pathname = action.pathnameShouldBe;
break;

and then the switch statement ends. But "" is falsey, so we keep going in the switch statement and then, when there are two trees, we hit the case you linked above. I think checking if pathnameShouldBe is a property on the action rather than just the truthyness of its value is the correct fix.

Hmm, maybe we just shouldn't rely on the URL parsing here to determine if download is supported. We can add a disableAuspiceJsonDownload config param to the extensions and have auspice.us explicitly disable the downloads.

I think once the bugs identified here are fixed the URL parsing will still be appropriate. (The particular bug in this thread is, strictly speaking, separate to this PR, but it'd be good to just fix it here.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in a9c4610.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed in auspice.us test app that the URL does not update with multiple trees.

An extra guard against empty dataset names during Auspice JSON downloads
Related to <#1803>
Prompted by @jameshadfield's review comment.¹
Fixes bug where ` pathnameShouldBe: ""` was ignored because `""` is
falsey. I chose to check `typeof` instead of `action.hasOwnProperty`
because I found cases where `pathnameShouldBe` can potentially
be set to `undefined`.²

¹ <#1804 (comment)>
² <https://github.com/nextstrain/auspice/blob/84a15484acabee10a65d2d4138f83e51ae068b51/src/actions/loadData.js#L128>
Copy link
Member

@jameshadfield jameshadfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joverlee521!

@joverlee521 joverlee521 merged commit 077020e into master Aug 6, 2024
23 of 24 checks passed
@joverlee521 joverlee521 deleted the download-error branch August 6, 2024 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notify when no datasets are available for download
4 participants