File size: 2,884 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import { isPlansPageUntangled } from 'calypso/lib/plans/untangling-plans-experiment';
import {
isScheduledUpdatesMultisiteCreateRoute,
isScheduledUpdatesMultisiteEditRoute,
} from 'calypso/state/selectors/is-scheduled-updates-multisite-route';
import { isAdminInterfaceWPAdmin } from '../sites/selectors';
import type { AppState } from 'calypso/types';
export enum SidebarType {
None = 'none',
Global = 'global',
GlobalCollapsed = 'global-collapsed',
UnifiedSiteDefault = 'unified-site-default',
UnifiedSiteClassic = 'unified-site-classic',
}
interface GetSidebarTypeParams {
state: AppState;
siteId: number | null;
section: { group?: string };
route: string;
}
export function getSidebarType( params: GetSidebarTypeParams ): SidebarType {
const { state, siteId, section, route } = params;
const { group } = section;
if ( shouldShowSiteDashboard( params ) || shouldShowPluginDashboard( params ) ) {
return SidebarType.GlobalCollapsed;
}
if (
group === 'me' ||
group === 'reader' ||
group === 'sites-dashboard' ||
( group === 'sites' && ! siteId ) ||
( group === 'sites' && siteId && route === '/domains/manage' )
) {
return SidebarType.Global;
}
if ( group === 'sites' ) {
return isAdminInterfaceWPAdmin( state, siteId )
? SidebarType.UnifiedSiteClassic
: SidebarType.UnifiedSiteDefault;
}
return SidebarType.None;
}
export function getShouldShowGlobalSidebar( params: GetSidebarTypeParams ) {
const sidebarType = getSidebarType( params );
return sidebarType === SidebarType.Global || sidebarType === SidebarType.GlobalCollapsed;
}
export function getShouldShowCollapsedGlobalSidebar( params: GetSidebarTypeParams ) {
const sidebarType = getSidebarType( params );
return sidebarType === SidebarType.GlobalCollapsed;
}
export function shouldShowSiteDashboard( { state, route }: GetSidebarTypeParams ) {
return isInRoute( route, getSiteDashboardRoutes( state ) );
}
function shouldShowPluginDashboard( { route }: GetSidebarTypeParams ) {
return (
isScheduledUpdatesMultisiteCreateRoute( route ) || isScheduledUpdatesMultisiteEditRoute( route )
);
}
// 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.
function getSiteDashboardRoutes( state: AppState ) {
return [
'/overview/',
'/hosting-config/',
'/github-deployments/',
'/site-monitoring/',
'/sites/performance/',
'/site-logs/',
'/hosting-features/',
'/staging-site/',
'/sites/settings',
...( isPlansPageUntangled( state ) ? [ '/plans' ] : [] ),
// Domain Management
'/domains/manage/all/overview',
'/domains/manage/all/email',
'/domains/manage/all/contact-info',
// Bulk Plugins management
'/plugins/manage/sites',
];
}
function isInRoute( route: string, routes: string[] ) {
return routes.some( ( r ) => route?.startsWith( r ) );
}
|