diff --git a/client/layout/index.jsx b/client/layout/index.jsx index 2ac273e4d48030..c517ebc2c825f3 100644 --- a/client/layout/index.jsx +++ b/client/layout/index.jsx @@ -455,17 +455,11 @@ export default withCurrentRoute( const isWooPasswordlessJPC = [ 'jetpack-connect', 'login' ].includes( sectionName ) && isWooPasswordlessJPCFlow( state ); const isBlazePro = getIsBlazePro( state ); - const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( - state, - siteId, - sectionGroup, - sectionName - ); + const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( state, siteId, sectionGroup ); const shouldShowCollapsedGlobalSidebar = getShouldShowCollapsedGlobalSidebar( state, siteId, - sectionGroup, - sectionName + sectionGroup ); const shouldShowUnifiedSiteSidebar = getShouldShowUnifiedSiteSidebar( state, diff --git a/client/me/sidebar/index.jsx b/client/me/sidebar/index.jsx index a023be95969b9a..03a49c10bd65ba 100644 --- a/client/me/sidebar/index.jsx +++ b/client/me/sidebar/index.jsx @@ -251,14 +251,8 @@ export default withCurrentRoute( connect( ( state, { currentSection } ) => { const sectionGroup = currentSection?.group ?? null; - const sectionName = currentSection?.name ?? null; const siteId = getSelectedSiteId( state ); - const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( - state, - siteId, - sectionGroup, - sectionName - ); + const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( state, siteId, sectionGroup ); return { currentUser: getCurrentUser( state ), shouldShowGlobalSidebar, diff --git a/client/my-sites/navigation/index.jsx b/client/my-sites/navigation/index.jsx index 6e5dec4aa9d780..8fc4288099c4d4 100644 --- a/client/my-sites/navigation/index.jsx +++ b/client/my-sites/navigation/index.jsx @@ -112,17 +112,11 @@ export default withCurrentRoute( const sectionName = currentSection?.name ?? null; const siteId = getSelectedSiteId( state ); const siteDomain = getSiteDomain( state, siteId ); - const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( - state, - siteId, - sectionGroup, - sectionName - ); + const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( state, siteId, sectionGroup ); const shouldShowCollapsedGlobalSidebar = getShouldShowCollapsedGlobalSidebar( state, siteId, - sectionGroup, - sectionName + sectionGroup ); const shouldShowUnifiedSiteSidebar = getShouldShowUnifiedSiteSidebar( state, diff --git a/client/my-sites/sidebar/use-site-menu-items.js b/client/my-sites/sidebar/use-site-menu-items.js index a4ba433d0b65b2..ec18e5d44fcd32 100644 --- a/client/my-sites/sidebar/use-site-menu-items.js +++ b/client/my-sites/sidebar/use-site-menu-items.js @@ -37,12 +37,7 @@ const useSiteMenuItems = () => { const isAllDomainsView = '/domains/manage' === currentRoute; const { currentSection } = useCurrentRoute(); const shouldShowGlobalSidebar = useSelector( ( state ) => { - return getShouldShowGlobalSidebar( - state, - selectedSiteId, - currentSection?.group, - currentSection?.name - ); + return getShouldShowGlobalSidebar( state, selectedSiteId, currentSection?.group ); } ); useEffect( () => { if ( selectedSiteId && siteDomain ) { diff --git a/client/reader/notifications/controller.jsx b/client/reader/notifications/controller.jsx index 69d436f54da0e4..daedae96cd086c 100644 --- a/client/reader/notifications/controller.jsx +++ b/client/reader/notifications/controller.jsx @@ -13,12 +13,7 @@ export function notifications( context, next ) { const basePath = sectionify( context.path ); const mcKey = 'notifications'; const state = context.store.getState(); - const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( - state, - null, - 'reader', - 'notifications' - ); + const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( state, null, 'reader' ); const isGlobalNotificationsOpen = getIsNotificationsOpen( state ); // Close the global notifications panel if it's already open. diff --git a/client/reader/sidebar/index.jsx b/client/reader/sidebar/index.jsx index faee472c6c34b4..e3ceedba9831df 100644 --- a/client/reader/sidebar/index.jsx +++ b/client/reader/sidebar/index.jsx @@ -346,14 +346,8 @@ export default withCurrentRoute( connect( ( state, { currentSection } ) => { const sectionGroup = currentSection?.group ?? null; - const sectionName = currentSection?.name ?? null; const siteId = getSelectedSiteId( state ); - const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( - state, - siteId, - sectionGroup, - sectionName - ); + const shouldShowGlobalSidebar = getShouldShowGlobalSidebar( state, siteId, sectionGroup ); return { isListsOpen: isListsOpen( state ), diff --git a/client/sites/components/sites-dashboard.tsx b/client/sites/components/sites-dashboard.tsx index c675c93a169704..aa9dc5798e318d 100644 --- a/client/sites/components/sites-dashboard.tsx +++ b/client/sites/components/sites-dashboard.tsx @@ -32,6 +32,7 @@ import { handleQueryParamChange, } from 'calypso/sites-dashboard/components/sites-content-controls'; import { useSelector } from 'calypso/state'; +import { shouldShowSiteDashboard } from 'calypso/state/global-sidebar/selectors'; import { useSitesSorting } from 'calypso/state/sites/hooks/use-sites-sorting'; import { getSelectedSite } from 'calypso/state/ui/selectors'; import { useInitializeDataViewsPage } from '../hooks/use-initialize-dataviews-page'; @@ -350,6 +351,13 @@ const SitesDashboard = ( { } }; + const showSiteDashboard = useSelector( ( state ) => + shouldShowSiteDashboard( state, selectedSite?.ID ?? null ) + ); + if ( !! selectedSite && ! showSiteDashboard ) { + return null; + } + // todo: temporary mock data const hideListing = false; const isNarrowView = false; diff --git a/client/state/global-sidebar/selectors.ts b/client/state/global-sidebar/selectors.ts index 7fe451c2779620..9de8db2ca3180e 100644 --- a/client/state/global-sidebar/selectors.ts +++ b/client/state/global-sidebar/selectors.ts @@ -5,81 +5,66 @@ import isScheduledUpdatesMultisiteRoute, { import { isAdminInterfaceWPAdmin } from '../sites/selectors'; import type { AppState } from 'calypso/types'; -// Calypso pages (section name => route) for which we show the Site Dashboard. -// Calypso pages not listed here will be shown in nav unification instead. +// Calypso routes for which we show the Site Dashboard. +// Calypso routes not listed here will be shown in nav unification instead. // See: pfsHM7-Dn-p2. -const SITE_DASHBOARD_ROUTES = { - 'hosting-overview': '/overview/', - hosting: '/hosting-config/', - 'github-deployments': '/github-deployments/', - 'site-monitoring': '/site-monitoring/', - 'site-performance': '/sites/performance/', - 'site-logs': '/site-logs/', - 'hosting-features': '/hosting-features/', - 'staging-site': '/staging-site/', +const SITE_DASHBOARD_ROUTES = [ + '/overview/', + '/hosting-config/', + '/github-deployments/', + '/site-monitoring/', + '/sites/performance/', + '/site-logs/', + '/hosting-features/', + '/staging-site/', // New Information Architecture - 'site-overview': '/sites/overview', - 'site-marketing': '/sites/marketing', - 'site-tools': '/sites/tools', - 'site-settings': '/sites/settings', + '/sites/overview', + '/sites/marketing', + '/sites/tools', + '/sites/settings', // Domain Management - 'all-domain-management': '/domains/manage/all/overview', - 'all-email-management': '/domains/manage/all/email', -}; - -function isInSection( sectionName: string, sectionNames: string[] ) { - return sectionNames.includes( sectionName ); -} + '/domains/manage/all/overview', + '/domains/manage/all/email', +]; function isInRoute( state: AppState, routes: string[] ) { return routes.some( ( route ) => state.route.path?.current?.startsWith( route ) ); } -function shouldShowSiteDashboard( state: AppState, siteId: number | null, sectionName: string ) { - return ( - !! siteId && - ( isInSection( sectionName, Object.keys( SITE_DASHBOARD_ROUTES ) ) || - isInRoute( state, Object.values( SITE_DASHBOARD_ROUTES ) ) ) - ); +function shouldShowSitesDashboard( state: AppState ) { + return isInRoute( state, [ '/sites', '/p2s', ...SITE_DASHBOARD_ROUTES ] ); } -export const getShouldShowSiteDashboard = ( - state: AppState, - siteId: number | null, - sectionGroup: string, - sectionName: string -) => { - return sectionGroup === 'sites' && shouldShowSiteDashboard( state, siteId, sectionName ); -}; +export function shouldShowSiteDashboard( state: AppState, siteId: number | null ) { + return !! siteId && isInRoute( state, SITE_DASHBOARD_ROUTES ); +} export const getShouldShowGlobalSidebar = ( state: AppState, siteId: number | null, - sectionGroup: string, - sectionName: string + sectionGroup: string ) => { const pluginsScheduledUpdates = isScheduledUpdatesMultisiteRoute( state ); return ( sectionGroup === 'me' || sectionGroup === 'reader' || - sectionGroup === 'sites-dashboard' || + ( sectionGroup === 'sites-dashboard' && shouldShowSitesDashboard( state ) ) || ( sectionGroup === 'sites' && ! siteId ) || ( sectionGroup === 'sites' && pluginsScheduledUpdates ) || - getShouldShowSiteDashboard( state, siteId, sectionGroup, sectionName ) + ( sectionGroup === 'sites' && shouldShowSiteDashboard( state, siteId ) ) ); }; export const getShouldShowCollapsedGlobalSidebar = ( state: AppState, siteId: number | null, - sectionGroup: string, - sectionName: string + sectionGroup: string ) => { const isSitesDashboard = sectionGroup === 'sites-dashboard'; - const isSiteDashboard = getShouldShowSiteDashboard( state, siteId, sectionGroup, sectionName ); + const isSiteDashboard = sectionGroup === 'sites' && shouldShowSiteDashboard( state, siteId ); // A site is just clicked and the global sidebar is in collapsing animation. const isSiteJustSelectedFromSitesDashboard = @@ -87,7 +72,7 @@ export const getShouldShowCollapsedGlobalSidebar = ( !! siteId && isInRoute( state, [ '/sites', // started collapsing when still in sites dashboard - ...Object.values( SITE_DASHBOARD_ROUTES ), // has just stopped collapsing when in one of the paths in site dashboard + ...SITE_DASHBOARD_ROUTES, // has just stopped collapsing when in one of the paths in site dashboard ] ); const isPluginsScheduledUpdatesEditMode = @@ -109,7 +94,7 @@ export const getShouldShowUnifiedSiteSidebar = ( ( isAdminInterfaceWPAdmin( state, siteId ) && sectionGroup === 'sites' && sectionName !== 'plugins' && - ! shouldShowSiteDashboard( state, siteId, sectionName ) ) || + ! shouldShowSiteDashboard( state, siteId ) ) || ( isAdminInterfaceWPAdmin( state, siteId ) && sectionName === 'plugins' && ! isScheduledUpdatesMultisiteRoute( state ) )