| | import isA8CForAgencies from 'calypso/lib/a8c-for-agencies/is-a8c-for-agencies'; |
| | import isJetpackCloud from 'calypso/lib/jetpack/is-jetpack-cloud'; |
| |
|
| | const pathIncludes = ( currentPath, term, position ) => |
| | currentPath.split( /[/,?]/ )?.[ position ]?.includes( term ); |
| |
|
| | const fragmentIsEqual = ( path, currentPath, position ) => |
| | currentPath.split( /[/,?]/ )?.[ position ] === path.split( /[/,?]/ )?.[ position ]; |
| |
|
| | const isManageAllSitesPluginsPath = ( path ) => |
| | path.match( /^\/plugins\/(?:manage|active|inactive|updates|scheduled-updates)/ ) !== null; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | export const itemLinkMatches = ( path, currentPath ) => { |
| | |
| | if ( pathIncludes( currentPath, 'types', 1 ) ) { |
| | return fragmentIsEqual( path, currentPath, 2 ); |
| | } |
| | |
| | if ( pathIncludes( currentPath, 'taxonomies', 2 ) ) { |
| | return fragmentIsEqual( path, currentPath, 3 ); |
| | } |
| |
|
| | if ( pathIncludes( currentPath, 'people', 1 ) ) { |
| | if ( pathIncludes( currentPath, 'new', 2 ) ) { |
| | return fragmentIsEqual( path, currentPath, 2 ); |
| | } else if ( |
| | pathIncludes( currentPath, 'add-subscribers', 2 ) && |
| | pathIncludes( path, 'team', 2 ) |
| | ) { |
| | return fragmentIsEqual( path, currentPath, 2 ); |
| | } else if ( pathIncludes( currentPath, 'subscribers', 2 ) && pathIncludes( path, 'team', 2 ) ) { |
| | return fragmentIsEqual( path, currentPath, 1 ); |
| | } |
| | } |
| |
|
| | if ( pathIncludes( currentPath, 'plugins', 1 ) ) { |
| | if ( pathIncludes( currentPath, 'scheduled-updates', 2 ) ) { |
| | return pathIncludes( path, 'plugins', 1 ) && pathIncludes( path, 'scheduled-updates', 2 ); |
| | } |
| |
|
| | return pathIncludes( path, 'plugins', 1 ) && fragmentIsEqual( path, currentPath, 1 ); |
| | } |
| |
|
| | if ( pathIncludes( currentPath, 'settings', 1 ) ) { |
| | |
| | if ( isJetpackCloud() || isA8CForAgencies() ) { |
| | return fragmentIsEqual( path, currentPath, 1 ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | if ( pathIncludes( currentPath, 'settings', 1 ) && pathIncludes( path, 'taxonomies', 2 ) ) { |
| | return false; |
| | } |
| |
|
| | |
| | if ( pathIncludes( currentPath, 'settings', 1 ) ) { |
| | return fragmentIsEqual( path, currentPath, 2 ); |
| | } |
| | } |
| |
|
| | |
| | |
| | if ( isJetpackCloud() && pathIncludes( currentPath, 'partner-portal', 1 ) ) { |
| | const isAssignLicensePath = pathIncludes( currentPath, 'assign-license', 2 ); |
| |
|
| | |
| | if ( isAssignLicensePath ) { |
| | return fragmentIsEqual( path, '/partner-portal/licenses', 2 ); |
| | } |
| |
|
| | return fragmentIsEqual( path, currentPath, 2 ); |
| | } |
| |
|
| | |
| | if ( |
| | isA8CForAgencies() && |
| | ( pathIncludes( currentPath, 'purchases', 1 ) || |
| | pathIncludes( currentPath, 'marketplace', 1 ) || |
| | pathIncludes( currentPath, 'client', 1 ) ) |
| | ) { |
| | return fragmentIsEqual( path, currentPath, 2 ); |
| | } |
| |
|
| | |
| | if ( isManageAllSitesPluginsPath( currentPath ) ) { |
| | return isManageAllSitesPluginsPath( path ); |
| | } |
| |
|
| | |
| | if ( |
| | currentPath.startsWith( '/store/stats/' ) || |
| | currentPath.startsWith( '/google-my-business/stats/' ) |
| | ) { |
| | return path.startsWith( '/stats/' ); |
| | } |
| |
|
| | |
| | if ( pathIncludes( currentPath, 'theme', 1 ) ) { |
| | return pathIncludes( path, 'themes', 1 ); |
| | } |
| |
|
| | if ( |
| | currentPath.startsWith( '/earn/jetpack-monetize/' ) || |
| | path.startsWith( '/earn/jetpack-monetize/' ) |
| | ) { |
| | return fragmentIsEqual( path, currentPath, 2 ); |
| | } |
| |
|
| | if ( |
| | currentPath.startsWith( '/subscribers/jetpack-subscribers/' ) || |
| | path.startsWith( '/subscribers/jetpack-subscribers/' ) |
| | ) { |
| | return fragmentIsEqual( path, currentPath, 2 ); |
| | } |
| |
|
| | return fragmentIsEqual( path, currentPath, 1 ); |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export const isItemSelected = ( menuItem, path, site, isP2Site = false ) => { |
| | let isSelected = menuItem?.url && itemLinkMatches( menuItem.url, path ); |
| |
|
| | if ( |
| | isSelected || |
| | ! [ 'sites', 'sites-p2' ].includes( menuItem.slug ) || |
| | ! site || |
| | path.startsWith( '/domains' ) |
| | ) { |
| | return isSelected; |
| | } |
| |
|
| | |
| | if ( menuItem.slug === 'sites' && ! isP2Site ) { |
| | isSelected = true; |
| | } else if ( menuItem.slug === 'sites-p2' && isP2Site ) { |
| | isSelected = true; |
| | } |
| |
|
| | return isSelected; |
| | }; |
| |
|