Skip to content

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Jul 31, 2025

Follow-up to #70604.

What?

  • Consider the empty case: if an empty array is passed, the page size control is not rendered.
  • Do not limit page sizes to 4 exact values.
  • Storybook: remove the CustomPerPageSizes story and add an argument to the Default story
Screen.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

Copy link

github-actions bot commented Jul 31, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: arthur791004 <arthur791004@git.wordpress.org>

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 ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This covers the empty case. Otherwise, we'd have something like this when you pass an empty array:

Screenshot 2025-07-31 at 18 01 02

Copy link
Contributor

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[];
Copy link
Member Author

@oandregal oandregal Jul 31, 2025

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.

Copy link
Contributor

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-

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I tested adding lots of options in the storybook:
Screenshot 2025-08-01 at 1 05 43 pm

That's definitely a bit of a stretch and I'm not sure many people would actually add that many options. 6 items feels like a good max, you can easily fit three digit numbers without it looking too busy:
Screenshot 2025-08-01 at 1 10 29 pm

Copy link
Member Author

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 👍

@oandregal oandregal self-assigned this Jul 31, 2025
@oandregal oandregal added [Type] Enhancement A suggestion for improvement. [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Jul 31, 2025
Copy link
Contributor

@talldan talldan left a 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[];
Copy link
Contributor

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 ) {
Copy link
Contributor

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.

@oandregal oandregal merged commit 3c59022 into trunk Aug 1, 2025
59 checks passed
@oandregal oandregal deleted the update/per-page-sizes branch August 1, 2025 09:26
@github-actions github-actions bot added this to the Gutenberg 21.4 milestone Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants