-
Notifications
You must be signed in to change notification settings - Fork 162
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
Handle non-valid dataset paths #1129
Handle non-valid dataset paths #1129
Conversation
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 for this! Moving the server to use redirects is great, however the changes to the client present some problems for nextstrain.org.
- This PR reorders the options in each select menu such that the selected entry is on the top. I can see why this is nice, especially for vanilla auspice where the options are alphabetically ordered (arriving via the
getAvailiable
API call). However the nextstrain.org server returns these options in a particular order, and thus moving the selected entry to the top is not desirable, 👇
- This PR modifies the client behavior such that if an "incomplete" dataset is asked for (e.g. you're viewing "zika" and you use the drop-downs to select "flu") then the partial path is filled out on the client side and a resulting API call is made for the "flu/avian/h5n1/ha" dataset. Instead, we want to send the incomplete path to the server and let the server redirect as necessary (functionality which this PR also adds). This allows custom servers (e.g. the nextstrain.org server) to complete partial dataset paths in a bespoke way -- for instance the above action on nextstrain.org should go to the server as "/flu" which will result in a redirect to "flu/seasonal/h3n2/ha" (as opposed to a request to the server for "flu/avian/h5n1/ha" as in this PR).
cli/server/getDatasetHelpers.js
Outdated
/* TODO currently there must be an _exact_ match in the available datasets */ | ||
if (!availableDatasets.map((d) => d.request).includes(requestStrToMatch)) { | ||
throw new Error(`${requestStrToMatch} not in available datasets`); | ||
const extendDataPathsToMatchAvailable = (res, info, availableDatasets) => { |
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.
This is great! Could you please rename the function to better reflect the functionality -- along the lines of fc824fc (can just cherry-pick that if you're happy with it)
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.
The cherry-pick merged without any conflict so I kept it 👍
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.
For the rest, the new commit should take care of the changes requested.
I wrote in a slightly different, more compact form but if you prefer I can rewrite it with a for cycle, it may be better for readability.
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.
Tested using this repo & nextstrain.org's customised auspice build and works well. Thanks!
Description of proposed changes
Currently the dataset selector leads to invalid paths when used for example to switch to dengue, (because /dengue does not exist, /dengue/denv1 does, and /dengue/denv2 etc).
On the current master build of auspice this is not handled, on nextstrain.org this is handled with a res.redirect on the getDataset endpoint.
Additionally the selector switches dataset even when same dataset is reselected (useless loading).
With this PR, the selector automatically loads fully valid paths, paths identical to the current path are not reloaded, and incomplete paths are handled by auspice's server directly.
Testing
In dev mode, test for example
http://localhost:4000/dengue
http://localhost:4000/zika/nothanksjeff
http://localhost:4000/VirusThatDontExist
Also try fiddling with Dataset Selector
Thank you for contributing to Nextstrain!