-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add View button to navigation link blocks #70986
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
Changes from 5 commits
906701f
355f423
7f66d08
4255fe3
8d53012
1be3cee
9ba1ce7
4dfc628
793c1e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,87 @@ | ||||||||||||||||
| /** | ||||||||||||||||
| * WordPress dependencies | ||||||||||||||||
| */ | ||||||||||||||||
| import { addFilter } from '@wordpress/hooks'; | ||||||||||||||||
| import { createHigherOrderComponent } from '@wordpress/compose'; | ||||||||||||||||
| import { useCallback } from '@wordpress/element'; | ||||||||||||||||
| import { __ } from '@wordpress/i18n'; | ||||||||||||||||
| import { | ||||||||||||||||
| __unstableBlockToolbarLastItem as BlockToolbarLastItem, | ||||||||||||||||
| store as blockEditorStore, | ||||||||||||||||
| } from '@wordpress/block-editor'; | ||||||||||||||||
| import { ToolbarButton, ToolbarGroup } from '@wordpress/components'; | ||||||||||||||||
| import { useSelect } from '@wordpress/data'; | ||||||||||||||||
|
|
||||||||||||||||
| // Target blocks that should have the View button | ||||||||||||||||
| const SUPPORTED_BLOCKS = [ 'core/navigation-link', 'core/navigation-submenu' ]; | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Component that renders the View button for navigation blocks | ||||||||||||||||
| * | ||||||||||||||||
| * @param {Object} props Component props. | ||||||||||||||||
| * @param {Object} props.attributes Block attributes. | ||||||||||||||||
| */ | ||||||||||||||||
getdave marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| function NavigationViewButton( { attributes } ) { | ||||||||||||||||
| const { kind, id, type } = attributes; | ||||||||||||||||
|
|
||||||||||||||||
| const onNavigateToEntityRecord = useSelect( | ||||||||||||||||
| ( select ) => | ||||||||||||||||
| select( blockEditorStore ).getSettings().onNavigateToEntityRecord, | ||||||||||||||||
| [] | ||||||||||||||||
| ); | ||||||||||||||||
|
|
||||||||||||||||
| const onViewPage = useCallback( () => { | ||||||||||||||||
| if ( kind === 'post-type' && type === 'page' && id ) { | ||||||||||||||||
| onNavigateToEntityRecord( { | ||||||||||||||||
| postId: id, | ||||||||||||||||
| postType: type, | ||||||||||||||||
| focusMode: false, | ||||||||||||||||
|
||||||||||||||||
| const isFocusMode = | |
| location.query.focusMode || | |
| ( location?.params?.postId && | |
| FOCUSABLE_ENTITIES.includes( location?.params?.postType ) ); | |
| const didComeFromEditorCanvas = | |
| previousLocation?.query.canvas === 'edit'; | |
| const showBackButton = isFocusMode && didComeFromEditorCanvas; |
The Back button appears in focus mode when you've navigated from the main editor canvas (canvas=edit) to a focused entity. It's controlled by URL parameters and browser history.
I think the Back button is pretty important so I'm going to remove the changes I made and allow it to land with the border.
However, we'll probably want to invent some new mechanic that allows for the Back button to appear in non-focus contexts.
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.
However, we'll probably want to invent some new mechanic that allows for the Back button to appear in non-focus contexts.
Agreed — currently if you're viewing a page within focus mode there's a couple of other peculiarities, for example if you select to "Show template" from within focus mode while iewing a page, then the Back button in the DocumentBar will overlap with the template icon. But that's something to fix in the DocumentBar component, I believe:
It'd be nice to have a param we can set that enables navigating back without the focus mode border, so we'll wind up needing to fix that DocumentBar issue anyway.
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.
For fixing up the DocumentBar and overlapping Back button, I've opened up: #71183
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.
Tiny update: I've merged #71183, so the DocumentBar will be fixed once this is either rebased or merged.

Uh oh!
There was an error while loading. Please reload this page.