Keep the online activities filters when changing page - #3668
Merged
Merged
Conversation
The pagination links are ordinary hrefs, so clicking page two is a full browser navigation. Neither filter was in the URL and mount() reset both on every request, so the new page came back unfiltered. Carry the language and month in the query string, append them to the page links, and mark the matching option selected so the dropdowns agree with the list. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The report
From the ambassadors:
Reproduced and fixed.
Why it happened
The pagination partial renders plain links:
So moving to page two is a full browser navigation, not a Livewire round trip. Two things then conspired:
$selectedLanguagenor$selectedDatewas in the query string, so the new request had no idea a filter was in force.mount()ran again on that fresh request and explicitly reset both properties.pagesurvived because Livewire'sWithPaginationalready tracks it in the URL. The filters did not.The change
#[Url(as: 'language')]and#[Url(as: 'month')]put both filters in the query string, so they survive a page load and the URL becomes shareable.mount(). They only restated the property defaults, and they overwrote whatever arrived from the URL.->appends($this->activeFilters())so the generated page links carry the filters.Livewire::originalPath()returns a bare path, so without this the links would drop them again.<option>now rendersselectedwhen it matches. Otherwise page two would show a correctly filtered list under a dropdown reading "All Languages", which looks like the same bug.?language=and?month=do not collide with anything else on the route; the locale middleware reads?lang=.Tests
tests/Feature/OnlineActivitiesFilterPaginationTest.php, six tests. All six fail on master and pass with this change:the_language_filter_survives_a_jump_to_the_second_page— the reported case, 25 English activities plus one German, requesting page two with the language filter.choosing_a_language_then_paginating_keeps_the_language— the same in the order a user hits it: set the dropdown through Livewire, then follow the rendered page-two link as a browser would.the_month_filter_survives_a_jump_to_the_second_pagepagination_links_carry_the_active_filtersthe_dropdowns_show_the_filter_that_is_in_forcethe_filters_are_read_from_the_query_stringThe 16 existing tests in
OnlineEventsWorkflowTeststill pass.Made with Cursor