-
Notifications
You must be signed in to change notification settings - Fork 26
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
Remove the vote-table modal if it exists, on vote, to force a refresh #2045
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.
I did both manual tests and it works fine.
Looked at the changed files, but am still way behind on understanding js etc., so I have nothing to add.
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 tests consistently fail locally with this failure, which seems relevant to the fixes in this PR:
joe@Josephs-iMac mushroom-observer % rails test:all
...
[Screenshot Image]: /Users/joe/mushroom-observer/tmp/capybara/failures_test_identify_index_naming_and_vote_ui.png
FAIL HelpIdentifySystemTest#test_identify_index_naming_and_vote_ui (167.08s)
expected to find css "#modal_obs_247545329_naming" but there were no matches
test/system/help_identify_system_test.rb:30:in `test_identify_index_naming_and_vote_ui'
...
Fails even when run on its own.
% rails t test/system/help_identify_system_test.rb:30
Started with run options --seed 25344
[Screenshot Image]: /Users/joe/mushroom-observer/tmp/capybara/failures_test_identify_index_naming_and_vote_ui.png
FAIL HelpIdentifySystemTest#test_identify_index_naming_and_vote_ui (15.50s)
expected to find css "#modal_obs_247545329_naming" but there were no matches
test/system/help_identify_system_test.rb:30:in `test_identify_index_naming_and_vote_ui'
Updating the table in the modal
The table wasn't refreshing because we're using
modal_link_to
, which re-opens a modal if it exists. This behavior is helpful and expected in the case of a form in progress, but here it's preventing reload of the modal content.Just needed to add something to the Stimulus
naming-vote_controller
so that whenever the user casts a vote, we delete themodal_naming_votes_#{naming.id}
modal if it's in the DOM.To test:
Refreshing the page more simply
An update to the Namings table is a case of a Turbo partial page refresh: the namings table should be updated, as well as possibly the title of the obs, and the name info panel, but nothing else on the page should change, and the page should not "jump" back to the top - it should retain scroll position.
Before Turbo 8 the DOM elements had to be explicitly changed in a turbo_stream template.
Turbo 8 allows us to simply redirect to the same action for a refresh. Turbo detects that it's the same page, loads the HTML of the page without reloading Rails, detects the differences in DOM elements (having IDs) with a diffing algorithm, and "morphs" changed DOM elements into the page, all without a page refresh.
This means we don't need to write a special turbo_stream updating template, and in some cases we don't even need any separate Turbo response. We can just redirect to the page, as we used to do in Rails 4.
To maintain scroll position, i had to add a
meta
tag to thehead
element.To test: