-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Enter focus mode when single Navigation is edited on "listing" Navigation browse mode route #51795
Changes from 1 commit
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,40 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
|
||
import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components'; | ||
import { useEntityRecords } from '@wordpress/core-data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PRELOADED_NAVIGATION_MENUS_QUERY } from './constants'; | ||
import SidebarNavigationItem from '../sidebar-navigation-item'; | ||
import { useLink } from '../routes/link'; | ||
|
||
export default function SidebarNavigationScreenNavigationMenuButton( props ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works but we're also moving the fetching logic to the main screen. We'll be executing this as soon as we land on the site editor, the logic is no longer fetched lazily. I think this is okay but probably worth double-checking with someone more experienced with the navigation code (like you!). Maybe we're already doing this or prefetching it too, then it should not be a problem! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a good spot. Luckily this query is already preloaded on the PHP side. So it's safe to preload this data here to determine the correct route. Other than this solution I can't see another way to enable this kind of selective routing to single/listing 🤷♂️ |
||
const { records: navigationMenus } = useEntityRecords( | ||
'postType', | ||
`wp_navigation`, | ||
PRELOADED_NAVIGATION_MENUS_QUERY | ||
); | ||
|
||
const hasSingleNavigationMenu = navigationMenus?.length === 1; | ||
const firstNavigationMenu = navigationMenus?.[ 0 ]; | ||
|
||
const linkInfo = useLink( { | ||
postId: firstNavigationMenu?.id, | ||
postType: 'wp_navigation', | ||
} ); | ||
|
||
// If there is a single Navigation then link directly to it. | ||
if ( hasSingleNavigationMenu ) { | ||
return <SidebarNavigationItem { ...linkInfo } { ...props } />; | ||
} | ||
|
||
return ( | ||
<NavigatorButton { ...props } path="/navigation"> | ||
{ props.children } | ||
</NavigatorButton> | ||
); | ||
} |
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.
We probably want
replace
here so that it doesn't add an additional stack to the history?