-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
DataViews Pagination: improve pagination logic to handle empty pages #68709
DataViews Pagination: improve pagination logic to handle empty pages #68709
Conversation
The failing test cases seems to be unrelated to the changes made in the PR. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Works for me! 👍
Hi @Mamaduka, can you please review this PR when you get a moment? |
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'm unsure about this "fix". Redirecting users because data for rendering is no longer available can have unexpected side effects.
The redirection can also cause a focus loss, which will regress a11y of this component.
When a user deletes all items on a page, displaying 'No results' messages seems correct since that page does not have any results. The current post/page list view (wp-admin/edit.php
) behaves similarly.
// If the current page is not the first page, and there are no items on the current page, go to the previous page. | ||
useEffect( () => { | ||
if ( currentPage !== 1 && ! data.length ) { | ||
onChangeView( { | ||
...view, | ||
page: currentPage - 1, | ||
} ); | ||
} | ||
}, [ data.length, currentPage, view, onChangeView ] ); |
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 effect isn't reliable. What happens when you're not on the first page and data is fetching? The condition will be true
, and the user will be redirected to the previous page.
P.S. I know the current page state doesn't persist in the URL, but that will change.
I initially perceived this as a bug because the page number displayed in such cases is incorrect. Would it be more worthwhile to address the issue by correcting the page number display instead of implementing a redirection?
Or maybe whenever this change is made, such a scenario can be factored in. Dataviews.Pagination.Issue.68707.mov |
As mentioned in the previous comments, this might not be the intended behavior and might cause accessibility issues down the line. Moreover, the incorrect page number reflected when no results are found should be fixed when the page state persists in the URL. For these reasons, it's better to close this PR. Please feel free to close the parent issue if it seems unrelated or unplanned. |
Thanks, @yogeshbhutkar! |
What, Why and How?
This PR addresses an issue in the
DataViewsPagination
component where deleting the last item on a page results in a 'No results found' message instead of navigating to the previous page.Changes Made:
Testing Instructions
site editor
.Patterns
.Screencasts
patterns-video.mov
templates-video.mov
Closes: #68707