Skip to content

Add command: View page/post#66720

Open
benazeer-ben wants to merge 6 commits intoWordPress:trunkfrom
benazeer-ben:enhancement/command-palette-view-page
Open

Add command: View page/post#66720
benazeer-ben wants to merge 6 commits intoWordPress:trunkfrom
benazeer-ben:enhancement/command-palette-view-page

Conversation

@benazeer-ben
Copy link
Contributor

@benazeer-ben benazeer-ben commented Nov 4, 2024

What?

Fixes #55806

Why?

Currently view page/post command is not available.

How?

Added command for viewing page/ post from command box.

Testing Instructions

  • Open the WordPress Editor
  • Go to Posts or Pages in the WordPress admin.
  • Open a new or existing post/page to enter the block editor.
  • Confirm Command Labels for Published Content
  • Publish the post or page if it's not already published.
  • In the block editor, open the Command Palette (by pressing Cmd + K on Mac).
  • Check for the following commands:
    • View page (if editing a page).
    • View post (if editing a post).
  • Select the command and confirm it opens the published post or page in a new tab.
  • If the post/page is not already in draft, click Save as Draft or Preview to set it to a non-published state.
  • Open the Command Palette again and check for the following commands:
    • Preview page (if editing a page).
    • Preview post (if editing a post).
  • Select the command and confirm it opens the preview of the draft post or page in a new tab.

Screenshots or screencast

view-page-post.mp4

@github-actions
Copy link

github-actions bot commented Nov 4, 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: benazeer-ben <benazeer@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: carolinan <poena@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

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

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Nov 4, 2024
@github-actions
Copy link

github-actions bot commented Nov 4, 2024

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @benazeer-ben! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@akasunil akasunil added [Type] Enhancement A suggestion for improvement. [Package] Editor /packages/editor labels Nov 11, 2024
Copy link
Member

@ramonjd ramonjd left a comment

Choose a reason for hiding this comment

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

This is working really well, thank you!

I tested posts and pages in the site editor (published and non-published), and also pages in the site editor.

The command appears as expected with the correct label, depending on the post status. ✅

I think for the first iteration it might be safer to limit the postType to page or post for now.

What do you think?

@ramonjd
Copy link
Member

ramonjd commented Nov 13, 2024

Looks like this PR needs a quick rebase too.

@benazeer-ben
Copy link
Contributor Author

Hi @ramonjd

Thanks for your review and suggestions.

I think for the first iteration it might be safer to limit the postType to page or post for now.

Yes, right. As per the ticket definition it is mentioning support for pages.

So this PR is mainly developed for pages and posts, we can consider the other postTypes later as you suggested.

benazeer-ben and others added 2 commits November 13, 2024 17:16
Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
@ramonjd
Copy link
Member

ramonjd commented Dec 18, 2024

I think it just needs a quick rebase and we're good to go 👍🏻

} );
}
if ( isViewable ) {
if ( postType === 'post' || postType === 'page' ) {
Copy link
Member

Choose a reason for hiding this comment

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

I appreciate your work on this @benazeer-ben Thank you!

Sorry, this wasn't known to me before, but I think a command already exists to preview in the editor:

https://github.com/WordPress/gutenberg/blob/trunk/packages/editor/src/components/commands/index.js#L275

Here they are together:

Screenshot 2024-12-19 at 11 37 12 am

It's been there for some time.

I think this PR's command adds a little sugar by checking post status and having a "view" link, but the existing command will work for all posts, plus it also saves before previewing using __unstableSaveForPreview.

So, with this knowledge, maybe we need to combine. One option would be to rather use the existing command, and add a generic View in a new tab if the post is published (so don't gate for pages or posts). I'm not sure.

cc @jameskoster @youknowriad (who added the existing command)

Copy link
Contributor Author

@benazeer-ben benazeer-ben Dec 19, 2024

Choose a reason for hiding this comment

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

Thanks for highlighting this! @ramonjd

This PR adds some useful refinement by incorporating checks for the post status and providing a "View" link specifically for published posts, which could serve as a valuable enhancement.

With this in mind, rather than combining the commands, would it make sense to focus solely on the 'View' functionality in this PR and omit the preview option? This could simplify the implementation while keeping the focus clear.

I’d love to hear thoughts from other reviewers on this approach as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd welcome more feedback on this idea but perhaps there's room for both commands? 'Preview' could be about checking a draft, or unsaved changes to a published record. 'View' could be about viewing a published record ignoring any unsaved changes.

  • Editing a draft: "Preview in a new tab"
  • Editing a published record
    • With no changes: "View in new tab"
    • With changes: "View in new tab" and "Preview unsaved changes in new tab"

I'd also question whether the "in new tab" text needs to be visible, I think the icon already communicates that behavior. If visually hidden we might simplify the commands; "Preview $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.

With this in mind, rather than combining the commands, would it make sense to focus solely on the 'View' functionality in this PR and omit the preview option?

I think that's a good compromise for the first iteration.

'Preview' could be about checking a draft, or unsaved changes to a published record. 'View' could be about viewing a published record ignoring any unsaved changes.

Does that imply that we'd gate the existing preview command with a getEditedPostAttribute( 'status' ) check (not published), similar to what @benazeer-ben has done in this PR?

Then the changes in PR could be reduced in scope to editing a published record as mentioned.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that imply that we'd gate the existing preview command with a getEditedPostAttribute( 'status' ) check (not published), similar to what @benazeer-ben has done in this PR?

I think 'Preview' could also appear if the page is published and there are unsaved changes. In that case the command would read "Preview unsaved changes".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @ramonjd @jameskoster

If there are any finalized suggestions, we can proceed with implementing them.

@carolinan
Copy link
Contributor

Hi
What is the status of this PR?
Is it waiting for a decision about whether to reduce the scope to published records?

I think we can reduce the scope and then consider opening another issue for the existing preview command if the text needs to be updated for that command.

On the other hand, is there a reason this is limited to posts and pages and not viewable custom post types?

The PR also needs another rebase.

@t-hamano
Copy link
Contributor

t-hamano commented Sep 4, 2025

Hi @benazeer-ben, sorry for the late reply.

I think this PR is almost ready to ship, but could you rebase this PR on top of the trunk branch? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Editor /packages/editor [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command Palette: Suggest a "View page" action when editing a page

6 participants