Skip to content

Gallery: Refactor "Settings" panel of Gallery block to use ToolsPanel instead of PanelBody #67904

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 15 commits into from
Jul 3, 2025

Conversation

yogeshbhutkar
Copy link
Contributor

@yogeshbhutkar yogeshbhutkar commented Dec 13, 2024

Fixes: #67893

What?

This PR introduces the usage of ToolsPanel instead of PanelBody inside the Settings panel of Gallery Block.

Why?

This PR is a part of #67813 which standardizes the usage of ToolsPanel inside Block Inspector Settings

How?

PanelBody is replaced with the corresponding ToolsPanel component.

Testing Instructions

  1. Insert a Gallery Block.
  2. Notice the presence of ToolsPanel component.
  3. Try to reset the updated values to test the reset functions.

Screencast

Screen.Recording.2024-12-13.at.1.04.16.PM.mov

@yogeshbhutkar yogeshbhutkar marked this pull request as ready for review December 13, 2024 08:55
Copy link

github-actions bot commented Dec 13, 2024

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: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@yogeshbhutkar
Copy link
Contributor Author

This PR is now ready to be reviewed.

CC: @fabiankaegy

@fabiankaegy fabiankaegy added [Type] Enhancement A suggestion for improvement. [Block] Gallery Affects the Gallery Block - used to display groups of images labels Dec 13, 2024
@yogeshbhutkar
Copy link
Contributor Author

Fixed failing unit tests for mobile.

Credits: #67957 (review)
CC: @fabiankaegy

@yogeshbhutkar
Copy link
Contributor Author

Hi @Mamaduka,
Would you mind taking a moment to review this PR when you have the chance? Thanks 🚀!

@Mamaduka
Copy link
Member

Sorry, @yogeshbhutkar! Somehow, I missed the ping. Do you mind rebasing this branch on top of the latest trunk?

@yogeshbhutkar yogeshbhutkar force-pushed the 67893-gallery-block-refactor branch from 2e92776 to c4eafe5 Compare May 29, 2025 03:44
@yogeshbhutkar
Copy link
Contributor Author

Thanks for taking a look, @Mamaduka.

I’ve rebased the branch on the latest trunk. If possible, could we also include @Mayank-Tripathi32 in the props list for the efforts that went into #67957?

@yogeshbhutkar yogeshbhutkar requested a review from Mamaduka June 2, 2025 03:19
@yogeshbhutkar
Copy link
Contributor Author

@Mamaduka, the suggested changes have been implemented. When you have a moment, could you please review the PR again?

@yogeshbhutkar yogeshbhutkar force-pushed the 67893-gallery-block-refactor branch 2 times, most recently from e9b4558 to 5ef39b9 Compare July 2, 2025 04:26
@Mamaduka

This comment was marked as outdated.

@Mamaduka
Copy link
Member

Mamaduka commented Jul 2, 2025

@yogeshbhutkar, I've noticed that the Gallery resolution is sometimes resettable, even for a freshly inserted block. Could be related to our previous conversation - #67904 (review).

Besides that, everything looks good.

Screenshot

CleanShot 2025-07-02 at 13 54 02

@yogeshbhutkar
Copy link
Contributor Author

yogeshbhutkar commented Jul 2, 2025

When I freshly inserted a block, I noticed, it's not the Resolution corresponding to Gallery that's resettable, but rather, the Resolution corresponding to the Image block nested within Gallery.

Ref:

ref.mov

I was able to reproduce this on the latest Trunk as well, when either an image or cover block is inserted, the resolution remains resettable, even on fresh insertions.

I see that in multiple places where we're handling images, we are defaulting the image sizes to full.

Ref:

// Try to use the previous selected image size if its available
// otherwise try the default image size or fallback to "full"
let newSize = DEFAULT_MEDIA_SIZE_SLUG;

However, the Image and Cover blocks use imageDefaultSize to set the initial sizeSlug post selection. Therefore, we might also need to update the following places accordingly if we decide to proceed with full as the default Image size:

imageDefaultSize: 'large',

https://github.com/WordPress/wordpress-develop/blob/740006d500b0d0a68ccb240bc79a56efb6d03b41/src/wp-includes/block-editor.php#L221C42-L221C60

cc: @Mamaduka

@Mamaduka
Copy link
Member

Mamaduka commented Jul 3, 2025

When I freshly inserted a block, I noticed, it's not the Resolution corresponding to Gallery that's resettable, but rather, the Resolution corresponding to the Image block nested within Gallery.

Try selecting an image that has no "Large" size; anything below 1000px should work.

The imageDefaultSize is retrieved from the server; it's a WordPress option that defaults to 'large'. We can't change that value without breaking backward compatibility in WP. The blocks that use that value treat DEFAULT_MEDIA_SIZE_SLUG as a final fallback when imageDefaultSize or the provided slug isn't available, which is logical to me.

I think we need to make sizeSlug fallback logic consistent across the media blocks, but it's out of the scope of this PR. Let's just resolve the final remaining issue.

It's not required to check if sizeSlug exists within imageSizeOptions, as the user would make the selection from within imageSizeOptions itself.
Apart from setting the sizeSlug attribute, the inner blocks must be updated on "resetAll" as well
* When resetting all, don't reset linkTo as it's not controlled by ToolsPanel
* Whenever inner blocks are also going to be updated, like for sizeSlug and linkTarget, use the dedicated function within resetAll instead of just setting them to undefined
* Resolution control and loading indicator are rendered in different places.
* Resolution control loads instantly when the block is selected, even on slow networks.
@yogeshbhutkar yogeshbhutkar force-pushed the 67893-gallery-block-refactor branch from 25fe5e6 to 92ae92d Compare July 3, 2025 07:39
@@ -4,3 +4,4 @@ export const LINK_DESTINATION_LIGHTBOX = 'lightbox';
export const LINK_DESTINATION_ATTACHMENT = 'attachment';
export const LINK_DESTINATION_MEDIA_WP_CORE = 'file';
export const LINK_DESTINATION_ATTACHMENT_WP_CORE = 'post';
export const DEFAULT_MEDIA_SIZE_SLUG = 'large';
Copy link
Contributor Author

@yogeshbhutkar yogeshbhutkar Jul 3, 2025

Choose a reason for hiding this comment

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

This should ideally be set to full to match the defaults corresponding to the Image block; currently, this is synced with the default provided within the block.json for the Gallery block.

I tried updating all such defaults, but, ideally, a deprecation object should be created, and certain fixtures/snapshots should be updated, which felt out of scope for this PR. I believe it's best implemented as a follow-up.

@Mamaduka, the reset bug mentioned here should now be fixed. Could you give this another test?

P.S. The failing test seems unrelated.

Copy link
Member

Choose a reason for hiding this comment

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

I tried updating all such defaults, but, ideally, a deprecation object should be created, and certain fixtures/snapshots should be updated, which felt out of scope for this PR. I believe it's best implemented as a follow-up.

I don't think it's worth yet another block deprecation. Additionally, defaulting to the full-size images in the Gallery block can have a negative impact on performance. Let's keep large as the default here.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thanks for bringing this over the finish line, @yogeshbhutkar!

@Mamaduka Mamaduka merged commit 8a5a63a into WordPress:trunk Jul 3, 2025
94 of 96 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.2 milestone Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor "Settings" panel of Gallery block to use ToolsPanel instead of PanelBody
3 participants