Skip to content

Button Block: Add draft page creation capability #69368

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

Conversation

dhruvikpatel18
Copy link
Contributor

@dhruvikpatel18 dhruvikpatel18 commented Feb 28, 2025

Closes #56163

What?

This PR adds the ability to create draft pages directly from the button block in the navigation editor, similar to how it already works in the navigation link block.

Why?

Currently, users can create a draft page from the custom link block in the navigation editor if the page doesn't exist, but this functionality isn't available in the button block. This PR addresses this inconsistency by implementing the same feature in the button block, providing a more consistent editing experience.

How?

  1. Adds draft page creation functionality to the button block's LinkControl component
  2. Imports necessary components and utilities from WordPress core
  3. Adds permission checks to control when the draft creation feature is available
  4. Uses the same pattern already implemented in the navigation link block

Testing Instructions

  1. Create a new post or page
  2. Insert a navigation block
  3. Add a button block to the navigation
  4. Click on the link icon in the toolbar to edit the link
  5. In the link search field, enter a page name that doesn't exist yet
  6. Verify that an option appears to "Create draft page: [your search term]"
  7. Click on this option and verify that a draft page is created and linked

Screenshots or screencast

Before

Screen.Recording.2025-02-28.at.2.21.54.PM.mov

After

Screen.Recording.2025-02-28.at.2.34.04.PM.mov

@dhruvikpatel18 dhruvikpatel18 marked this pull request as ready for review February 28, 2025 11:21
Copy link

github-actions bot commented Feb 28, 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: dhruvikpatel18 <dhruvik18@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ajlende <ajlende@git.wordpress.org>

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

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Block] Buttons Affects the Buttons Block labels Mar 4, 2025
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 contributing, @dhruvikpatel18!

I think we can reduce boilerplate code here by using the same approach as the Link format. See the InlineLinkUI component for details.

@dhruvikpatel18
Copy link
Contributor Author

I think we can reduce boilerplate code here by using the same approach as the Link format. See the InlineLinkUI component for details.

@Mamaduka Thanks for the feedbacks, I have refactored the code and reduced boilerplate code by leveraging existing LinkControl.

@dhruvikpatel18 dhruvikpatel18 requested a review from Mamaduka March 6, 2025 10:53
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 the follow-up, @dhruvikpatel18!

Do you mind rebasing this branch on top of the latest trunk? I've also left two suggestions.

Comment on lines 276 to 277
const { getSettings } = select( blockEditorStore );
const _settings = getSettings();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const { getSettings } = select( blockEditorStore );
const _settings = getSettings();
const _settings = select( blockEditorStore ).getSettings();

Suggestion (non-blocking): This could be a one liner.

Comment on lines 487 to 491
showInitialSuggestions
suggestionsQuery={ getSuggestionsQuery(
'page',
'post-type'
) }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
showInitialSuggestions
suggestionsQuery={ getSuggestionsQuery(
'page',
'post-type'
) }

Let's disable initial suggestions for now and only display them when the user starts typing/searching.

@Mamaduka
Copy link
Member

Hi, @dhruvikpatel18

Do you have time to follow up on the remaining suggestions? Also, let's rebase this branch on top of the latest trunk.

@dhruvikpatel18 dhruvikpatel18 force-pushed the feat/add-draft-page-from-button-block branch from 71daa11 to a992f46 Compare March 13, 2025 05:42
@dhruvikpatel18
Copy link
Contributor Author

dhruvikpatel18 commented Mar 13, 2025

Hi @Mamaduka, I've implemented your suggestion and removed the showInitialSuggestions prop from the LinkControl component. I've also rebased my branch on top of the latest trunk. The changes are now ready for review. Thank you for your feedback!

@dhruvikpatel18 dhruvikpatel18 requested a review from Mamaduka March 13, 2025 05:46
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.

Thank you, @dhruvikpatel18!

The enhancement implementation looks good ✅

@Mamaduka Mamaduka merged commit 5c5b5d9 into WordPress:trunk Mar 13, 2025
61 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.5 milestone Mar 13, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
Co-authored-by: dhruvikpatel18 <dhruvik18@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ajlende <ajlende@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Buttons Affects the Buttons Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: Add a draft page from button block in navigation
2 participants