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

Fix: narrative dataset filters #1493

Merged
merged 2 commits into from
Mar 25, 2022
Merged

Fix: narrative dataset filters #1493

merged 2 commits into from
Mar 25, 2022

Conversation

joverlee521
Copy link
Contributor

@joverlee521 joverlee521 commented Mar 22, 2022

When users change the slide in a narrative, the controls state gets
reset to its default state which updates the filters state to an empty
object. This leads to the bug described in #1492.

This commit extracts the filters creation from modifyStateViaMetadata
into its own function so that it can be reused to recreate the filters
when users change the slide within a narrative.

Resolves #1492.

@nextstrain-bot nextstrain-bot temporarily deployed to auspice-fix-narrative-f-5ukh9j March 22, 2022 23:23 Inactive
@jameshadfield
Copy link
Member

jameshadfield commented Mar 23, 2022

Nice find on the 🐛 @joverlee521!

Notes looking at the codepaths involved here as part of review:

  1. Loading datasets / changing narrative slides happens via a call to changePage, which has 3 cases (description):
    • The initial load is "case3" and doesn't result in the 🐛
    • Moving to a narrative slide which changes the dataset is "case 2" and doesn't result in the 🐛
    • Moving to a narrative slide where the dataset doesn't change is "case 1" and we have the 🐛
  2. "case1" triggers a call to createStateFromQueryOrJSONs which supplies existing redux state and a (URL) query and asks for the state to update accordingly
  3. This results in the controls state being calculated via:
controls = cloneDeep(oldState.controls);
controls = restoreQueryableStateToDefaults(controls); # only ever called here
controls = modifyStateViaURLQuery(controls, query);
  1. Running restoreQueryableStateToDefaults will set controls.filters = {} (src) but it won't affect controls.filtersInFooter as that's not part of controls.defaults (probably by mistake, but oh well!). Logging the state change in this function when we change slides shows:
controls.filters was {"clade_membership":[],"region":[]...} and is now {}
controls.filtersInFooter was [clade_membership,region,...] and is now [clade_membership,region...]
  1. An empty controls.filters means that there are no available filters, so the dropdown doesn't work!

The root cause of the bug is in restoreQueryableStateToDefaults. The "default" in this case is not correct, as it is restoring to the "default app state before we have any data" rather than the "default state as determined by the dataset JSON". One way to fix this is to mimic what we do when we first load JSONs, which is a 1-line change here to:

controls = restoreQueryableStateToDefaults(controls);
controls = modifyStateViaMetadata(controls, metadata); # add this line

However a better fix would be (might be?) to rewrite restoreQueryableStateToDefaults. This is along the lines of what you're doing in this PR, but it's the code inside restoreQueryableStateToDefaults which should be changed, rather than modifying it afterwards.

@joverlee521
Copy link
Contributor Author

Thanks for writing out the codepath notes @jameshadfield, it's really helpful to see it all!

I'm in favor of just doing the 1-line change of adding modifyStateViaMetadata. This ensures that we restore all dataset default controls without worrying about missing something within restoreQueryableStateToDefaults.

@jameshadfield pointed out in review that `filtersInFooter` was missing
from the default control states.
When users change to a slide in a narrative that has the same dataset as
the previous slide, `restoreQueryableStateToDefaults` resets controls
to the _app_ default state which updates the filters state to an empty
object. This leads to the bug described in #1492.

Calling `modifyStateViaMetadata` after `restoreQueryableStateToDefaults`
ensures that all _dataset_ default controls are restored as well.

Resolves #1492.
@joverlee521 joverlee521 temporarily deployed to auspice-fix-narrative-f-5ukh9j March 23, 2022 18:14 Inactive
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!

@jameshadfield jameshadfield merged commit ca59615 into master Mar 25, 2022
@jameshadfield jameshadfield deleted the fix-narrative-filters branch March 25, 2022 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Narrative: No filter options in "Explore the data"
3 participants