-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Displays a button with an external icon to open a new window with the published post type
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button } from '@wordpress/components'; | ||
import { external } from '@wordpress/icons'; | ||
import { store as editorStore } from '@wordpress/editor'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { useSelect } from '@wordpress/data'; | ||
|
||
export default function ViewLink() { | ||
const { permalink, isPublished, label } = useSelect( ( select ) => { | ||
// Grab post type to retrieve the view_item label. | ||
const postTypeSlug = select( editorStore ).getCurrentPostType(); | ||
const postType = select( coreStore ).getPostType( postTypeSlug ); | ||
|
||
return { | ||
permalink: select( editorStore ).getPermalink(), | ||
isPublished: select( editorStore ).isCurrentPostPublished(), | ||
label: postType?.labels.view_item, | ||
}; | ||
}, [] ); | ||
|
||
// Only render the view button if the post is published and has a permalink. | ||
if ( ! isPublished || ! permalink ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Button | ||
icon={ external } | ||
label={ label || __( 'View post' ) } | ||
href={ permalink } | ||
target="_blank" | ||
/> | ||
); | ||
} |
9046f21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in 9046f21.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4873681679
📝 Reported issues:
specs/editor/various/autosave.test.js