From 70d1a20eb7ede59fb809b538816d50f03bdc1f5e Mon Sep 17 00:00:00 2001 From: ntsekouras Date: Fri, 12 May 2023 10:59:30 +0300 Subject: [PATCH] [Site Editor]: Always show the `styles` navigation item --- .../index.js | 37 +++++++++++- .../sidebar-navigation-screen-main/index.js | 60 +++++++------------ 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js index b15ed6c5276f0..06e486739ed74 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-global-styles/index.js @@ -3,7 +3,9 @@ */ import { __ } from '@wordpress/i18n'; import { edit } from '@wordpress/icons'; -import { useDispatch } from '@wordpress/data'; +import { useSelect, useDispatch } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; +import { __experimentalNavigatorButton as NavigatorButton } from '@wordpress/components'; /** * Internal dependencies @@ -13,6 +15,39 @@ import StyleVariationsContainer from '../global-styles/style-variations-containe import { unlock } from '../../private-apis'; import { store as editSiteStore } from '../../store'; import SidebarButton from '../sidebar-button'; +import SidebarNavigationItem from '../sidebar-navigation-item'; + +export function SidebarNavigationItemGlobalStyles( props ) { + const { openGeneralSidebar } = useDispatch( editSiteStore ); + const { setCanvasMode } = unlock( useDispatch( editSiteStore ) ); + const hasGlobalStyleVariations = useSelect( + ( select ) => + !! select( + coreStore + ).__experimentalGetCurrentThemeGlobalStylesVariations()?.length, + [] + ); + if ( hasGlobalStyleVariations ) { + return ( + + ); + } + return ( + { + // switch to edit mode. + setCanvasMode( 'edit' ); + // open global styles sidebar. + openGeneralSidebar( 'edit-site/global-styles' ); + } } + /> + ); +} export default function SidebarNavigationScreenGlobalStyles() { const { openGeneralSidebar } = useDispatch( editSiteStore ); diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js index a35e07220d52c..7c9e4b3bf9196 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-main/index.js @@ -15,35 +15,24 @@ import { store as coreStore } from '@wordpress/core-data'; */ import SidebarNavigationScreen from '../sidebar-navigation-screen'; import SidebarNavigationItem from '../sidebar-navigation-item'; +import { SidebarNavigationItemGlobalStyles } from '../sidebar-navigation-screen-global-styles'; export default function SidebarNavigationScreenMain() { - const { hasNavigationMenus, hasGlobalStyleVariations } = useSelect( - ( select ) => { - const { - getEntityRecords, - __experimentalGetCurrentThemeGlobalStylesVariations, - } = select( coreStore ); - // The query needs to be the same as in the "SidebarNavigationScreenNavigationMenus" component, - // to avoid double network calls. - const navigationMenus = getEntityRecords( - 'postType', - 'wp_navigation', - { - per_page: 1, - status: 'publish', - order: 'desc', - orderby: 'date', - } - ); - return { - hasNavigationMenus: !! navigationMenus?.length, - hasGlobalStyleVariations: - !! __experimentalGetCurrentThemeGlobalStylesVariations() - ?.length, - }; - }, - [] - ); + const hasNavigationMenus = useSelect( ( select ) => { + // The query needs to be the same as in the "SidebarNavigationScreenNavigationMenus" component, + // to avoid double network calls. + const navigationMenus = select( coreStore ).getEntityRecords( + 'postType', + 'wp_navigation', + { + per_page: 1, + status: 'publish', + order: 'desc', + orderby: 'date', + } + ); + return !! navigationMenus?.length; + }, [] ); const showNavigationScreen = process.env.IS_GUTENBERG_PLUGIN ? hasNavigationMenus : false; @@ -66,17 +55,12 @@ export default function SidebarNavigationScreenMain() { { __( 'Navigation' ) } ) } - { hasGlobalStyleVariations && ( - - { __( 'Styles' ) } - - ) } - + + { __( 'Styles' ) } +