Skip to content

Commit

Permalink
Sites dashboard: redirect to My Home without flashing preview panel
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Dec 6, 2024
1 parent db6e07b commit ffd943a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 87 deletions.
10 changes: 2 additions & 8 deletions client/layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions client/me/sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 2 additions & 8 deletions client/my-sites/navigation/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions client/my-sites/sidebar/use-site-menu-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
7 changes: 1 addition & 6 deletions client/reader/notifications/controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions client/reader/sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down
8 changes: 8 additions & 0 deletions client/sites/components/sites-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
75 changes: 30 additions & 45 deletions client/state/global-sidebar/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,74 @@ 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 =
isSitesDashboard &&
!! 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 =
Expand All @@ -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 ) )
Expand Down

0 comments on commit ffd943a

Please sign in to comment.