-
Notifications
You must be signed in to change notification settings - Fork 899
feat: add usePaginatedQuery hook #10803
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
Merged
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
b4211f3
wip: commit current progress on usePaginatedQuery
Parkreiner 173e823
chore: add cacheTime to users query
Parkreiner d715d73
chore: update cache logic for UsersPage usersQuery
Parkreiner 8a199b7
wip: commit progress on Pagination
Parkreiner 98ae96d
chore: add function overloads to prepareQuery
Parkreiner 37ea50b
wip: commit progress on usePaginatedQuery
Parkreiner 2c1e9e3
docs: add clarifying comment about implementation
Parkreiner b3a9ab4
chore: remove optional prefetch property from query options
Parkreiner 39a2ced
chore: redefine queryKey
Parkreiner 4dcfd29
refactor: consolidate how queryKey/queryFn are called
Parkreiner 86f8437
refactor: clean up pagination code more
Parkreiner f612d8f
fix: remove redundant properties
Parkreiner 5878326
refactor: clean up code
Parkreiner 5cc1c2d
wip: commit progress on usePaginatedQuery
Parkreiner 0138f21
wip: commit current pagination progress
Parkreiner a38fd30
docs: clean up comments for clarity
Parkreiner 22d6c24
wip: get type signatures compatible (breaks runtime logic slightly)
Parkreiner e717da1
refactor: clean up type definitions
Parkreiner 7624d94
chore: add support for custom onInvalidPage functions
Parkreiner 2623131
refactor: clean up type definitions more for clarity reasons
Parkreiner 29242e9
chore: delete Pagination component (separate PR)
Parkreiner 5a9aa2d
chore: remove cacheTime fixes (to be resolved in future PR)
Parkreiner 3d67304
docs: add clarifying/intellisense comments for DX
Parkreiner d977060
refactor: link users queries to same queryKey implementation
Parkreiner 9224624
docs: remove misleading comment
Parkreiner 540c779
docs: more comments
Parkreiner 4b42b6f
chore: update onInvalidPage params for more flexibility
Parkreiner 5bc43c9
fix: remove explicit any
Parkreiner bd146a1
refactor: clean up type definitions
Parkreiner 983b83f
refactor: rename query params for consistency
Parkreiner a43e294
refactor: clean up input validation for page changes
Parkreiner db03f3e
refactor/fix: update hook to be aware of async data
Parkreiner 1b825f1
chore: add contravariance to dictionary
Parkreiner 9631a27
refactor: increase type-safety of usePaginatedQuery
Parkreiner 4ea0cba
docs: more comments
Parkreiner 3f63ec7
chore: move usePaginatedQuery file
Parkreiner 614e4ff
fix: add back cacheTime
Parkreiner b0c8d48
Merge branch 'main' into mes/pagination-2
Parkreiner e994532
chore: swap in usePaginatedQuery for users table
Parkreiner 9502044
chore: add goToFirstPage to usePaginatedQuery
Parkreiner 8dbbfd3
fix: make page redirects work properly
Parkreiner 88d0a5f
refactor: clean up clamp logic
Parkreiner 132f5b1
chore: swap in usePaginatedQuery for Audits table
Parkreiner 33bf4e8
refactor: move dependencies around
Parkreiner 218da68
fix: remove deprecated properties from hook
Parkreiner 54f01f1
refactor: clean up code more
Parkreiner ede2abc
docs: add todo comment
Parkreiner 9ecab16
chore: update testing fixtures
Parkreiner 0c81d1c
wip: commit current progress for tests
Parkreiner 3aa714c
fix: update useEffectEvent to sync via layout effects
Parkreiner 2893630
wip: commit more progress on tests
Parkreiner ef900d4
wip: stub out all expected test cases
Parkreiner 23dc583
wip: more test progress
Parkreiner 24361d1
wip: more test progress
Parkreiner 755f8c0
wip: commit more test progress
Parkreiner 8bff0d3
wip: AHHHHHHHH
Parkreiner 1fae773
chore: finish two more test cases
Parkreiner be82728
wip: add in all tests (still need to investigate prefetching
Parkreiner 848fa0f
refactor: clean up code slightly
Parkreiner c89e8e3
fix: remove math bugs when calculating pages
Parkreiner 3624a6d
fix: wrap up all testing and clean up cases
Parkreiner 13e2f30
docs: update comments for clarity
Parkreiner 8f83673
fix: update error-handling for invalid page handling
Parkreiner 5fb0643
fix: apply suggestions
Parkreiner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"coderdenttest", | ||
"coderdtest", | ||
"codersdk", | ||
"contravariance", | ||
"cronstrue", | ||
"databasefake", | ||
"dbmem", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { getAuditLogs } from "api/api"; | ||
import { type AuditLogResponse } from "api/typesGenerated"; | ||
import { useFilterParamsKey } from "components/Filter/filter"; | ||
import { type UsePaginatedQueryOptions } from "hooks/usePaginatedQuery"; | ||
|
||
export function paginatedAudits( | ||
searchParams: URLSearchParams, | ||
): UsePaginatedQueryOptions<AuditLogResponse, string> { | ||
return { | ||
searchParams, | ||
queryPayload: () => searchParams.get(useFilterParamsKey) ?? "", | ||
queryKey: ({ payload, pageNumber }) => { | ||
return ["auditLogs", payload, pageNumber] as const; | ||
}, | ||
queryFn: ({ payload, limit, offset }) => { | ||
return getAuditLogs({ | ||
offset, | ||
limit, | ||
q: payload, | ||
}); | ||
}, | ||
}; | ||
} |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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 function is still being used in one other place that doesn't require paginated data, so I can't get rid of it just yet
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 trying to review kind of quickly since I'm on a time crunch this morning and have made you wait a couple days, but I just wanna make sure that this aligns with the caching stuff @BrunoQuaresma said he's doing
Uh oh!
There was an error while loading. Please reload this page.
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.
Just double-checked, and the caching PR has been committed, so these can be safely removed. There wouldn't be any conflicts – they'd just be redundant