-
Notifications
You must be signed in to change notification settings - Fork 4.5k
DataViews: perPageSizes
tweaks
#71004
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
Conversation
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. |
function ItemsPerPageControl() { | ||
const { view, perPageSizes, onChangeView } = useContext( DataViewsContext ); | ||
const pageSizeValues = perPageSizes ?? PAGE_SIZE_VALUES; | ||
if ( perPageSizes.length === 0 ) { |
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.
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 think it could even be if ( perPageSizes.length < 2 ) {
. If there's only one option it should already be set and the user wouldn't be able to change it. Offering a toggle button like that might be confusing.
@@ -54,7 +54,7 @@ type DataViewsContextType< Item > = { | |||
filters: NormalizedFilter[]; | |||
isShowingFilter: boolean; | |||
setIsShowingFilter: ( value: boolean ) => void; | |||
perPageSizes?: [ number, number, number, number ]; | |||
perPageSizes: number[]; |
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.
Why did we limit the page sizes to 4 in #70604? Can't it be 3 or 5? This change moves that decision to the consumer level.
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.
The component might get a bit crammed with a lot of options, but 3 or 5 seems alright. The component could also adapt to a dropdown when there are lots of options.
A min/max might make more sense.
BTW, there's also some docs here to update - https://github.com/WordPress/gutenberg/tree/trunk/packages/dataviews#perpagesizes--number-number-number-number-
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.
My thought was to align with the existing design. I don't think a randomly generated number set would fit well with the current design. That said, I do agree with using min/max values
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.
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've capped it to 2-6, otherwise the control is not displayed 👍
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.
Left a couple of very minor comments, but change generally looks good. Changelog entry also needed.
Tests might also be good, but could have been part of the initial PR.
@@ -54,7 +54,7 @@ type DataViewsContextType< Item > = { | |||
filters: NormalizedFilter[]; | |||
isShowingFilter: boolean; | |||
setIsShowingFilter: ( value: boolean ) => void; | |||
perPageSizes?: [ number, number, number, number ]; | |||
perPageSizes: number[]; |
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.
The component might get a bit crammed with a lot of options, but 3 or 5 seems alright. The component could also adapt to a dropdown when there are lots of options.
A min/max might make more sense.
BTW, there's also some docs here to update - https://github.com/WordPress/gutenberg/tree/trunk/packages/dataviews#perpagesizes--number-number-number-number-
function ItemsPerPageControl() { | ||
const { view, perPageSizes, onChangeView } = useContext( DataViewsContext ); | ||
const pageSizeValues = perPageSizes ?? PAGE_SIZE_VALUES; | ||
if ( perPageSizes.length === 0 ) { |
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 think it could even be if ( perPageSizes.length < 2 ) {
. If there's only one option it should already be set and the user wouldn't be able to change it. Offering a toggle button like that might be confusing.
Follow-up to #70604.
What?
CustomPerPageSizes
story and add an argument to theDefault
storyScreen.Recording.2025-07-31.at.17.58.49.mov
Testing Instructions
Open the storybook and verify you can modify the sizes and the control respond to the changes. Check the empty case works.
npm install && npm storybook:dev