-
Notifications
You must be signed in to change notification settings - Fork 77
Add pagination info in the query parameter #1417
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
Changes from all commits
f76cc85
35e567b
7785e38
878f5b8
2d7d63f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import useQueryRef from './query-ref'; | ||
|
|
||
| /** | ||
| * @param {number[]} pageSizeOptions - An array of exactly three numbers representing | ||
| * the available page size options in ascending order (e.g., [250, 500, 1000]). | ||
| */ | ||
| export default (pageSizeOptions) => { | ||
| const pageNumber = useQueryRef({ | ||
| fromQuery: (query) => { | ||
| const num = Number.parseInt(query['page-number'], 10); | ||
| if (!num || num < 1) return 0; | ||
| return num - 1; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should I update the query parameter here? if the given value is out of valid range? we don't do that for invalid values of filters, right?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's right. If filter query parameters are supplied invalid values, those values are generally ignored. The URL isn't changed/corrected, but nothing explodes either. The invalid values fall back to something reasonable. In some cases, we can't know right away whether a value is valid. For example, specifying a submitter ID that doesn't exist: we can't know that it's wrong until we receive the response for the list of submitters (async).
I'm open to it, but it feels more complex to me. It seems simpler not to change the route if we don't need to. It should be pretty rare that someone specifies an invalid value.
"Out of valid range" just refers to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess page number starting from 1 is more acceptable than 0. |
||
| }, | ||
| toQuery: (value) => ({ 'page-number': value === 0 ? null : value + 1 }) | ||
| }); | ||
|
|
||
| const pageSize = useQueryRef({ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expecting absolute value for page sizes like 250, 500, 1000 instead of index of options here. |
||
| fromQuery: (query) => { | ||
| const size = Number.parseInt(query['page-size'], 10); | ||
|
|
||
| if (!size || size < pageSizeOptions[0]) return pageSizeOptions[0]; | ||
| if (size >= pageSizeOptions[2]) return pageSizeOptions[2]; | ||
| if (size >= pageSizeOptions[1]) return pageSizeOptions[1]; | ||
| return pageSizeOptions[0]; | ||
| }, | ||
| toQuery: (value) => ({ 'page-size': value }) | ||
| }); | ||
|
|
||
| return { | ||
| pageNumber, | ||
| pageSize | ||
| }; | ||
| }; | ||
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 using
page-numberfor the readability sake, we can also go with justpage.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 definitely prefer
pageoverpage-number. It's much shorter, and I see it on many sites.page+page-sizesounds like a nice combo to me. I don't have the strongest feelings about it though, we could run withpage-numberfor now and see if anyone else on the team voices an opinion.