Skip to content

fix: resets pagination when search term changes in drawer list #5599

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

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

PatrikKozak
Copy link
Contributor

Description

fix: resets pagination to page 1 every time the search term changes

  • I have read and understand the CONTRIBUTING.md document in this repository.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • Existing test suite passes locally with my changes

@PatrikKozak
Copy link
Contributor Author

@jacobsfletch I think you'd be best to help review this with me. When you have some time could we look at this PR together? Thanks!

@@ -198,6 +198,10 @@ export const ListDrawerContent: React.FC<ListDrawerProps> = ({
setPreference(preferenceKey, newPreferences, true)
}, [sort, limit, setPreference, preferenceKey])

useEffect(() => {
Copy link
Member

@jacobsfletch jacobsfletch Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, this isn't quite right. Instead of adding a new useEffect, you should be able to tie into the methods that the SearchFilter component exposed via props. The drawer sets modifySearchParams to false, which is where the page reset is being bypassed. Basically just need to thread the page reset back into the search before it's set, instead of after its set.

Copy link
Contributor Author

@PatrikKozak PatrikKozak Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes:

  • Consolidate all 5 useState s in the ListDrawer component
  • Replace them with a new params state, and completely remove the useEffect
  • This would mean that the filter options injected into the where query, and the conditions formatted from the search string, need to become methods that properly set params
  • This is exactly what a reducer is for, might as well use it. We can create reducer actions like setSearch which properly formats conditions and resets page, and setWhere, setParams to blindy set any of them, etc.
  • This all makes it so that the usePayloadAPI hook (which makes an API request) is only fired once no matter what params change and when

@denolfe denolfe added the v2 label Dec 3, 2024
@PatrikKozak PatrikKozak added the keep Prevents from being marked stale or auto-closed. label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
created-by: Payload team keep Prevents from being marked stale or auto-closed. v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drawer to pick uploaded media does not reset pagination when search change
3 participants