Skip to content

Author Block: Refactor Settings panel to use Toolspanel #67965

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 12 commits into from
Jun 9, 2025

Conversation

im3dabasia
Copy link
Contributor

@im3dabasia im3dabasia commented Dec 13, 2024

Part of: #67813
Fixes: #67941

What?

Refactored Author Block code to include ToolsPanel instead of PanelBody.

Screenshots

Trunk In this PR
image Screenshot 2024-12-13 at 3 09 23 PM Screenshot 2024-12-13 at 3 09 12 PM

@im3dabasia im3dabasia changed the title Author Block: Refactor "Settings" panel to use Toolspanel Author Block: Refactor Settings panel to use Toolspanel Dec 13, 2024
@fabiankaegy fabiankaegy added [Type] Enhancement A suggestion for improvement. [Block] Post Author Affects the Post Author Block labels Dec 13, 2024
@im3dabasia im3dabasia marked this pull request as ready for review December 20, 2024 11:54
Copy link

github-actions bot commented Dec 20, 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: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@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.

@Mamaduka
Copy link
Member

@im3dabasia, do you mind rebasing this PR on top of the latest trunk?

@im3dabasia
Copy link
Contributor Author

im3dabasia commented May 28, 2025

@Mamaduka , I have merged the latest trunk branch into the current one.

Please check at your convenience and looking forward for your feedback.

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 refreshing the branch, @im3dabasia!

The refactoring looks good, but it still needs some work.

  • The ToolsPanel needs useToolsPanelDropdownMenuProps.
  • The hasValue conditions need to be fixed and correctly represent default values. Otherwise, the freshly inserted block already has values to reset.
  • The author selection isn't a block-level attribute, but modifies the actual post author; it would be difficult to define what default is and make it resettable. We might have to avoid using ToolsPanelItem for it. @t-hamano, had to make similar changes for a couple of other blocks, here's the recent one #70210.

Screenshot

CleanShot 2025-05-28 at 17 44 00

@Mamaduka
Copy link
Member

Thanks for the follow-ups, @im3dabasia! I did a quick test, and I think we're moving in the right direction.

I believe the last item from my previous comment still needs resolution - #67965 (review).

@im3dabasia
Copy link
Contributor Author

I believe the last item from my previous comment still needs resolution - #67965 (review).

Thank you for the feedbacks @Mamaduka .

I think I have handled the last feedback as well, the suggestion was to remove ToolsPanelItem from the Author Selection control, I have rightly done this. Also removing the ToolsPanelItem top level component means that we no longer save attribute which does not exist in the block.json, which is corrected in this commit acd8cac

Please Let me know if I am missing something.

Author Selection Snippet without ToolsPanelItem
{ showAuthorControl && (
    <VStack
	    spacing={ 4 }
	    style={ { gridColumn: '1 / -1' } }
    >
	    { ( showCombobox && (
		    <ComboboxControl
			    __next40pxDefaultSize
			    __nextHasNoMarginBottom
			    label={ __( 'Author' ) }
			    options={ authorOptions }
			    value={ authorId }
			    onChange={ handleSelect }
			    allowReset={ false }
		    />
	    ) ) || (
		    <SelectControl
			    __next40pxDefaultSize
			    __nextHasNoMarginBottom
			    label={ __( 'Author' ) }
			    value={ authorId }
			    options={ authorOptions }
			    onChange={ handleSelect }
		    />
	    ) }
    </VStack>
) }

@im3dabasia im3dabasia requested a review from t-hamano June 3, 2025 06:38
<ToolsPanelItem
label={ __( 'Link author name' ) }
isShownByDefault
hasValue={ () => isLink !== false }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
hasValue={ () => isLink !== false }
hasValue={ () => !! isLink }

Copy link
Contributor Author

@im3dabasia im3dabasia Jun 6, 2025

Choose a reason for hiding this comment

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

@t-hamano , isLink is by default false basis on the block.json, I was wondering if we could simply go for something like this

hasValue={ () =>  isLink }

Copy link
Contributor

Choose a reason for hiding this comment

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

There are no hard and fast rules, so I think either approach is fine.

@im3dabasia im3dabasia requested a review from t-hamano June 6, 2025 09:10
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@t-hamano t-hamano dismissed Mamaduka’s stale review June 9, 2025 10:55

All requested changes have been addressed.

@t-hamano t-hamano merged commit 9205301 into WordPress:trunk Jun 9, 2025
62 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.1 milestone Jun 9, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
)

* refactor: Used ToolsPanel instead of PanelBody

* feat: Remove ToolsPanel for the author selection control and added VStack for styling

* feat: Add useToolsPanelDropdownMenuProps in the ToolsPanel as a prop

* fix: Handle reset menu items properly in hasValue

* fix: Improved code quality and showBio handling

* chore: avatarSize code quality improvement

* fix: Maintain consistency in label for Link Author Name

* feat: Remove redudant CSS styles and file for editor.scss

* fix: Update hasValue notations for the Avatar and Link controls

* fix: Failing e2e, unit test cases due to wrong import

Co-authored-by: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Author Affects the Post Author Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor "Settings" panel of Author block to use ToolsPanel instead of PanelBody
4 participants