| | import { isEnabled } from '@automattic/calypso-config'; |
| | import { useSelector } from 'react-redux'; |
| | import { useCurrentRoute } from 'calypso/components/route'; |
| | import domainOnlyFallbackMenu from 'calypso/my-sites/sidebar/static-data/domain-only-fallback-menu'; |
| | import { getAdminMenu } from 'calypso/state/admin-menu/selectors'; |
| | import { getShouldShowGlobalSidebar } from 'calypso/state/global-sidebar/selectors'; |
| | import { getPluginOnSite } from 'calypso/state/plugins/installed/selectors'; |
| | import { canAnySiteHavePlugins } from 'calypso/state/selectors/can-any-site-have-plugins'; |
| | import { canCurrentUser } from 'calypso/state/selectors/can-current-user'; |
| | import { getCurrentRoute } from 'calypso/state/selectors/get-current-route'; |
| | import { hasSiteWithP2 } from 'calypso/state/selectors/has-site-with-p2'; |
| | import isDomainOnlySite from 'calypso/state/selectors/is-domain-only-site'; |
| | import isAtomicSite from 'calypso/state/selectors/is-site-automated-transfer'; |
| | import isSiteWpcomStaging from 'calypso/state/selectors/is-site-wpcom-staging'; |
| | import isSiteWPForTeams from 'calypso/state/selectors/is-site-wpforteams'; |
| | import { getSiteDomain, isJetpackSite } from 'calypso/state/sites/selectors'; |
| | import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors'; |
| | import allSitesMenu from './static-data/all-sites-menu'; |
| | import buildFallbackResponse from './static-data/fallback-menu'; |
| | import globalSidebarMenu from './static-data/global-sidebar-menu'; |
| | import jetpackMenu from './static-data/jetpack-fallback-menu'; |
| |
|
| | const useSiteMenuItems = () => { |
| | const currentRoute = useSelector( ( state ) => getCurrentRoute( state ) ); |
| | const selectedSiteId = useSelector( getSelectedSiteId ); |
| | const siteDomain = useSelector( ( state ) => getSiteDomain( state, selectedSiteId ) ); |
| | const menuItems = useSelector( ( state ) => getAdminMenu( state, selectedSiteId ) ); |
| | const isJetpack = useSelector( ( state ) => isJetpackSite( state, selectedSiteId ) ); |
| | const isAtomic = useSelector( ( state ) => isAtomicSite( state, selectedSiteId ) ); |
| | const isStagingSite = useSelector( ( state ) => isSiteWpcomStaging( state, selectedSiteId ) ); |
| | const isPlanExpired = useSelector( ( state ) => !! getSelectedSite( state )?.plan?.expired ); |
| | const isAllDomainsView = '/domains/manage' === currentRoute; |
| | const { currentSection, currentRoute: route } = useCurrentRoute(); |
| | const shouldShowGlobalSidebar = useSelector( ( state ) => { |
| | return getShouldShowGlobalSidebar( { |
| | state, |
| | siteId: selectedSiteId, |
| | section: currentSection, |
| | route, |
| | } ); |
| | } ); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const shouldShowWooCommerce = useSelector( |
| | ( state ) => !! ( isJetpack && getPluginOnSite( state, selectedSiteId, 'woocommerce' )?.active ) |
| | ); |
| | const shouldShowThemes = useSelector( ( state ) => |
| | canCurrentUser( state, selectedSiteId, 'edit_theme_options' ) |
| | ); |
| |
|
| | const isP2 = useSelector( ( state ) => !! isSiteWPForTeams( state, selectedSiteId ) ); |
| | const isDomainOnly = useSelector( ( state ) => isDomainOnlySite( state, selectedSiteId ) ); |
| |
|
| | const shouldShowMailboxes = ! isP2; |
| |
|
| | const shouldShowAddOns = ! isAtomic && ! isStagingSite; |
| |
|
| | const hasSiteWithPlugins = useSelector( canAnySiteHavePlugins ); |
| | const showP2s = useSelector( hasSiteWithP2 ); |
| |
|
| | const hasUnifiedImporter = isEnabled( 'importer/unified' ); |
| |
|
| | if ( shouldShowGlobalSidebar ) { |
| | return globalSidebarMenu( { showP2s: showP2s } ); |
| | } |
| |
|
| | |
| | |
| | |
| | if ( ! siteDomain || isAllDomainsView ) { |
| | return allSitesMenu( { showManagePlugins: hasSiteWithPlugins } ); |
| | } |
| |
|
| | |
| | |
| | |
| | if ( isJetpack && ! isAtomic && ! menuItems ) { |
| | return jetpackMenu( { siteDomain, hasUnifiedImporter } ); |
| | } |
| |
|
| | |
| | |
| | |
| | if ( isDomainOnly && ! menuItems ) { |
| | return domainOnlyFallbackMenu( { siteDomain } ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | const fallbackDataOverrides = { |
| | siteDomain, |
| | isAtomic, |
| | isPlanExpired, |
| | shouldShowWooCommerce, |
| | shouldShowThemes, |
| | shouldShowMailboxes, |
| | shouldShowAddOns, |
| | showSiteMonitoring: isAtomic, |
| | }; |
| |
|
| | return menuItems ?? buildFallbackResponse( fallbackDataOverrides ); |
| | }; |
| |
|
| | export default useSiteMenuItems; |
| |
|