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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

setPage(1)
}, [search])

const onCreateNew = useCallback(
({ doc }) => {
if (typeof onSelect === 'function') {
Expand Down
Loading