-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin: ensure Jetpack settings can be accessed in Offline mode. (#19815)
- Loading branch information
Showing
5 changed files
with
233 additions
and
66 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
projects/plugins/jetpack/_inc/client/components/masthead/header-nav.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { connect } from 'react-redux'; | ||
import React, { useCallback } from 'react'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import analytics from 'lib/analytics'; | ||
import Button from 'components/button'; | ||
import ButtonGroup from 'components/button-group'; | ||
import { | ||
getSiteConnectionStatus, | ||
hasConnectedOwner as hasConnectedOwnerSelector, | ||
isCurrentUserLinked as isCurrentUserLinkedSelector, | ||
isSiteRegistered, | ||
} from 'state/connection'; | ||
import { userCanEditPosts, userCanManageOptions } from 'state/initial-state'; | ||
import { getActiveModules } from 'state/modules'; | ||
|
||
const HeaderNavComponent = props => { | ||
const { | ||
activeModules, | ||
canEditPosts, | ||
canManageOptions, | ||
hasConnectedOwner, | ||
isCurrentUserLinked, | ||
isSiteConnected, | ||
location = { pathname: '' }, | ||
siteConnectionStatus, | ||
} = props; | ||
|
||
const { pathname } = location; | ||
|
||
const isDashboardView = | ||
[ '/', '/dashboard', '/my-plan', '/plans' ].includes( pathname ) || | ||
pathname.includes( '/recommendations' ); | ||
const isStatic = '' === pathname; | ||
|
||
const onTrackDashClick = useCallback( () => { | ||
analytics.tracks.recordJetpackClick( { | ||
target: 'masthead', | ||
path: 'nav_dashboard', | ||
} ); | ||
}, [] ); | ||
|
||
const onTrackSettingsClick = useCallback( () => { | ||
analytics.tracks.recordJetpackClick( { | ||
target: 'masthead', | ||
path: 'nav_settings', | ||
} ); | ||
}, [] ); | ||
|
||
if ( isStatic ) { | ||
return null; | ||
} | ||
|
||
if ( ! siteConnectionStatus ) { | ||
return null; | ||
} | ||
|
||
/** | ||
* Determine whether a user can access the Jetpack Settings page. | ||
* | ||
* Rules are: | ||
* - We're not on the /setup page route | ||
* - user is allowed to see the Jetpack Admin | ||
* - site is connected or in offline mode | ||
* - non-admins only need access to the settings when there are modules they can manage. | ||
*/ | ||
if ( pathname.startsWith( '/setup' ) ) { | ||
return null; | ||
} | ||
|
||
if ( ! canEditPosts ) { | ||
return null; | ||
} | ||
|
||
if ( siteConnectionStatus !== 'offline' && ! isSiteConnected ) { | ||
return null; | ||
} | ||
|
||
if ( siteConnectionStatus !== 'offline' && ! canManageOptions ) { | ||
if ( ! hasConnectedOwner ) { | ||
return null; | ||
} | ||
|
||
if ( ! isCurrentUserLinked ) { | ||
return null; | ||
} | ||
|
||
// Are there any modules accessible by non-admins active? | ||
const activeNonAdminModules = activeModules.some( module => | ||
[ 'post-by-email', 'publicize' ].includes( module ) | ||
); | ||
|
||
if ( ! activeNonAdminModules ) { | ||
return null; | ||
} | ||
} | ||
|
||
return ( | ||
<div className="jp-masthead__nav"> | ||
<ButtonGroup> | ||
<Button | ||
compact={ true } | ||
href="#/dashboard" | ||
primary={ isDashboardView && ! isStatic } | ||
onClick={ onTrackDashClick } | ||
> | ||
{ __( 'Dashboard', 'jetpack' ) } | ||
</Button> | ||
<Button | ||
compact={ true } | ||
href="#/settings" | ||
primary={ ! isDashboardView && ! isStatic } | ||
onClick={ onTrackSettingsClick } | ||
> | ||
{ __( 'Settings', 'jetpack' ) } | ||
</Button> | ||
</ButtonGroup> | ||
</div> | ||
); | ||
}; | ||
|
||
const HeaderNav = connect( state => { | ||
return { | ||
canEditPosts: userCanEditPosts( state ), | ||
canManageOptions: userCanManageOptions( state ), | ||
hasConnectedOwner: hasConnectedOwnerSelector( state ), | ||
isCurrentUserLinked: isCurrentUserLinkedSelector( state ), | ||
isSiteConnected: isSiteRegistered( state ), | ||
activeModules: getActiveModules( state ), | ||
siteConnectionStatus: getSiteConnectionStatus( state ), | ||
}; | ||
} )( HeaderNavComponent ); | ||
|
||
export { HeaderNav }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/fix-settings-access-offline-mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: bugfix | ||
|
||
Dashboard: ensure that the Jetpack settings page can be accessed when using Jetpack's Offline mode. |