-
Notifications
You must be signed in to change notification settings - Fork 161
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
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
c573870
to
45bd85d
Compare
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)"})) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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:
auspice/src/middleware/changeURL.js
Lines 236 to 243 in 6955728
/* 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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
auspice/src/middleware/changeURL.js
Lines 231 to 234 in 6955728
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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in a9c4610.
There was a problem hiding this comment.
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>
45bd85d
to
dbfce23
Compare
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @joverlee521!
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