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

next release #1193

Merged
merged 41 commits into from
Aug 3, 2020
Merged

next release #1193

merged 41 commits into from
Aug 3, 2020

Conversation

jameshadfield
Copy link
Member

This branch contains a somewhat complicated merge of #1172 and #1164 into master. There are a couple of things which require attention before it actually becomes master (and some more testing too!)

cc @eharkins if you have any time to check these that'd be great!

salvatore-fxpig and others added 30 commits June 10, 2020 18:24
using redux to cache JSONs
this completes a bunch of TODOs (search TODO:1071 for remaining items):
1. clear the json cache when unmounting narrative component
2. rerender mounted react components with new dataset
upon redux state update
this is achieved using react "key" props
(https://reactjs.org/docs/lists-and-keys.html#keys)
3. wait for all datasets to be fetched using promise.all
4. fix loading narratives from not the first page
5. use the appropriate dataset when leaving
the narrative page to explore a dataset
also rework narrative json fetching code, fixes bug with:
 "explore the data yourself" and "return to narrative" buttons
… file

This is in preparation for client-side parsing of narrative files. A optional `type` URL query allows the same API to return the markdown file (see the documentation changes in this commit for more details).

There are other possibilities, such as using the content-type field in the header, but I felt this was the clearest.
Here we add the framework to (eventually) parse the response from `getNarrative` as a markdown file and interpret this client-side.

To facilitate backward compatibility in the cases where a server does not respect the `?type=md` query and continues to return a JSON, if the file doesn't look like markdown we will attempt to parse it as JSON.

To mimic such a server, we explicitly request "type=json" in this commit, as the code to actually do the client-side md-parsing is not yet implemented.
This commit shifts the parsing of the markdown file (md + yaml frontmatter) into a centralised function which is imported by both the server and the client, allowing us to maintain backward compatible server-side parsing as well as client-side parsing, whilst avoiding code duplication and the inevitable divergence of functionality.

Our approach to conversion of YAML frontmatter -> markdown is essentially unchanged. The algorithm for parsing of the main body has been rewritten to be more robust.

Unit tests are added to cover the various ways we can define authors, links & affiliations in the YAML frontmatter of narratives.
Parsing of the narrative (YAML) frontmatter produces markdown with `<sup>` and `<sub>` HTML elements to render affiliations using superscripts. (This behavior is unchanged from parsing server-side.) The client-side markdown sanitizer settings, however, were stricter than those employed on the server, and were removing these HTML elements causing the affiliations not to be displayed. These settings are relaxed in this commit.
The move to client-parsing of narratives has caused two changes to bundle structure.

Firstly, since the `loadJSON` function now references the markdown parsing code, the dependency graph tries to pull in the related libraries into the chunk with most of the Auspice code (currently chunk 5). Previously these were a separate chunk lazily loaded with (e.g.) the footer parsing component. Since it's very common to display markdown footers, it makes life simple to include these libraries in the other-vendors bundle. It is possible to lazily load the markdown parsing function as needed, but more complicated.

Secondly, the YAML frontmatter parser (previously server-side only) has a dependency on `js-yaml` which itself has dependency on "esprima" and others. Esprima is unnecessary for our purposes and we use a webpack loader to ignore it. For simplicity, we shift `js-yaml` to the other-vendors bundle. An alternative approach would be to bundle  pre-minified 'js-yaml' bundle.
For unknown reasons, the core-vendors and other-vendors chunks have different hashes when building locally compared with via GitHub CI. This is after running `npm ci` to mimic the CI conditions. An issue should be created to better understand this, as it implies that the contents differ.
* parse-narrative-in-client:
  [client-narratives] update bundlesize config
  [client-narratives] change bundle structure to accommodate YAML parsing
  [client-narratives] modify markdown parser settings
  [client narratives] update documentation
  [client-narratives] parse markdown client-side
  [client-narratives] Allow client to gracefully fall-back to JSON
  [client-narratives] Allow narrative API to return unmodified markdown file
* 1050-mult-narratives: (26 commits)
  narrative fetching error handling
  Add back in CACHE_JSONS
  remove unused action CLEAR_JSON_CACHE
  Only clear jsonCache on CLEAN_START;
  linting
  Update loadData.js
  throw 404 when dataset is not available, compatibility fallback for old narratives
  async fetching of additional datasets, remove _.uniq
  fetch unique set of datasets for narratives
  TODOs
  fix package lock to same as master
  mostly clarifying comments
  WIP: remove listeners in components when unmounted
  clean up + jsonCache redux sensible default
  mult-dataset narratives working;
  changing narrative datasets: how to best rerender?
  WIP: mult-dataset narratives partly working
  WIP allow multiple dataset narratives;
  Update recomputeReduxState.js
  Update recomputeReduxState.js
  ...
@jameshadfield jameshadfield temporarily deployed to auspice-next-ukaqeculqvtgs3jg3 July 29, 2020 06:14 Inactive
This commit was prompted by a bug resulting from the URL query representing two different concepts: what is displayed in the URL and the app state that this drives.

Previously we approached this with two arguments to the state-setting-function: `query` and `queryToDisplay`. Here we remove the latter and interpret the former as synonymous with the URL. This results in simplified logic where the logic for interpreting what app state a narrative page desires (e.g. `query={n: 3}` -> `{c: "region", ...}) now resides within the `createStateFromQueryOrJSONs` function.
This commit represents a simplification of the page-change logic when navigating between pages (the `EXPERIMENTAL_showMainDisplayMarkdown` action is unnecessary as the `changePage` action will correctly set the panels).

Additionally we rename the react component to remove the "experimental" prefix as this has been in widespread use for a number of months now.
@jameshadfield jameshadfield temporarily deployed to auspice-next-ukaqeculqvtgs3jg3 July 30, 2020 04:58 Inactive
@jameshadfield
Copy link
Member Author

@eharkins would you mind looking at the just-added commits, especially

I plan on releasing and pushing this up to dev.nextstrain.org for some final testing over the coming days.

Multiple-datasets-in-narratives are really cool and we should write a blog-post / how-to guide for these -- if you're keen, then please jump in, otherwise I'll try to get to it as soon as this is released.

@emmahodcroft
Copy link
Member

emmahodcroft commented Jul 30, 2020 via email

@jameshadfield
Copy link
Member Author

Awesome, thanks @emmahodcroft -- given the scale of the code-changes to narratives I expect this to be up on dev.nextstrain.org for at least a few days of testing before release. A blog / example nCoV narrative would be fantastic, and there's absolutely no reason it has to be concurrent with the auspice release.

@eharkins
Copy link
Contributor

@jameshadfield sounds good, I'm planning to devote time tomorrow to take a look at those recent commits and any other remaining to-dos.

@eharkins eharkins temporarily deployed to auspice-next-ukaqeculqvtgs3jg3 August 1, 2020 01:02 Inactive
@eharkins
Copy link
Contributor

eharkins commented Aug 1, 2020

@jameshadfield

  • ba623e1 makes sense; nice job simplifying things! Can't find any changes to behavior it introduces from the user's perspective.
  • 6df515c seems to be working; I added a few commits above which have more details in their messages, but they basically
  1. Make mobile match the behavior desktop in that when you click "leave the narrative and explore the data yourself" on the End Of Narrative (EON) slide it should take you to the dataset corresponding to second to last slide (1 before EON)
  2. Remove a dispatched path/query change from the narrative desktop component's componentWillUnmount which was breaking the multiple dataset narratives when unmounting that component. We should be sure that I am right that we don't need that dispatch before merging this, and please revert if you find that commit to have broken something good that dispatch was doing!

P.S. I didn't test using the nextstrain.org server since I equated this with testing on dev.nextstrain.org but if this isn't the case then I'm happy to do that next week!

@eharkins eharkins temporarily deployed to auspice-next-ukaqeculqvtgs3jg3 August 1, 2020 01:11 Inactive
This commit represents a big simplification of how we toggle into and out of narrative mode. This happens in two places: the "exit narrative mode" button on the last narrative slide and the "explore the data" button (desktop only). The desired behavior is that we switch to "interactive mode" (i.e. with the controls sidebar) but with a "return to narrative" button (desktop only). The URL should change from a narrative pathname and n=<slide_number> query to the pathname of the dataset & query describing the view settings.

The code is simplified to use a consistent action for all the above behavior ("TOGGLE_NARRATIVE").  This allows multiple datasets to work appropriately, as well as window resizing triggering a switch to mobile display (or vice versa). 

This resolves a long-standing development paper-cut where the narrative URL would disappear when hot-reloading (due to the unmounting behavior). 


Co-authored-by: eharkins <eli.harkins@gmail.com>
@jameshadfield jameshadfield temporarily deployed to auspice-next-ukaqeculqvtgs3jg3 August 3, 2020 02:04 Inactive
@jameshadfield
Copy link
Member Author

Thanks @eharkins 🙌 I hadn't tested the exit-narrative functionality enough. I've made a couple of further simplifications - see commit message for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants