From 55798bb0a2cef3555fef5fdb64908f5148cd002d Mon Sep 17 00:00:00 2001 From: Elio Rivero Date: Tue, 21 Feb 2017 15:40:53 -0300 Subject: [PATCH 1/2] Settings UI: if site is not connected and user can't do it, show notice prompting user to ask an admin to connect. Don't show link button. --- .../components/jetpack-notices/index.jsx | 29 +++++++++++++------ _inc/client/main.jsx | 12 +++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/_inc/client/components/jetpack-notices/index.jsx b/_inc/client/components/jetpack-notices/index.jsx index 2e77b323c2864..546040ebe584e 100644 --- a/_inc/client/components/jetpack-notices/index.jsx +++ b/_inc/client/components/jetpack-notices/index.jsx @@ -12,8 +12,8 @@ import NoticesList from 'components/global-notices'; * Internal dependencies */ import JetpackStateNotices from './state-notices'; -import { getSiteConnectionStatus, getSiteDevMode, isStaging, isInIdentityCrisis } from 'state/connection'; -import { isDevVersion } from 'state/initial-state'; +import { getSiteConnectionStatus, getSiteDevMode, isStaging, isInIdentityCrisis, isCurrentUserLinked } from 'state/connection'; +import { isDevVersion, userCanManageModules, getUsername } from 'state/initial-state'; import DismissableNotices from './dismissable'; import { getConnectUrl as _getConnectUrl } from 'state/connection'; import QueryConnectUrl from 'components/data/query-connect-url'; @@ -159,15 +159,13 @@ export const UserUnlinked = React.createClass( { render() { if ( - ! window.Initial_State.userData.currentUser.isConnected && + ! this.props.isLinked && this.props.connectUrl && this.props.siteConnected ) { - let text; - - text = __( 'You, %(userName)s, are not connected to WordPress.com.', { + const text = __( 'You, %(userName)s, are not connected to WordPress.com.', { args: { - userName: window.Initial_State.userData.currentUser.username + userName: this.props.username } } ); @@ -215,7 +213,18 @@ const JetpackNotices = React.createClass( { + siteConnected={ true === this.props.siteConnectionStatus } + isLinked={ this.props.isLinked } + username={ this.props.username } /> + { + ( ! this.props.siteConnectionStatus && ! this.props.userCanManageModules ) && ( + + ) + } ); } @@ -226,11 +235,13 @@ export default connect( return { connectUrl: _getConnectUrl( state ), siteConnectionStatus: getSiteConnectionStatus( state ), + userCanManageModules: userCanManageModules( state ), + username: getUsername( state ), + isLinked: isCurrentUserLinked( state ), isDevVersion: isDevVersion( state ), siteDevMode: getSiteDevMode( state ), isStaging: isStaging( state ), isInIdentityCrisis: isInIdentityCrisis( state ) - }; } )( JetpackNotices ); diff --git a/_inc/client/main.jsx b/_inc/client/main.jsx index a639ff6ca88a4..d2d274a390d84 100644 --- a/_inc/client/main.jsx +++ b/_inc/client/main.jsx @@ -19,7 +19,7 @@ import SearchableSettings from 'settings/index.jsx'; import JetpackConnect from 'components/jetpack-connect'; import JumpStart from 'components/jumpstart'; import { getJumpStartStatus, isJumpstarting } from 'state/jumpstart'; -import { getSiteConnectionStatus } from 'state/connection'; +import { getSiteConnectionStatus, isCurrentUserLinked } from 'state/connection'; import { setInitialState, getSiteRawUrl, @@ -154,11 +154,14 @@ const Main = React.createClass( { analytics.tracks.recordEvent( 'jetpack_wpa_page_view', { path: route } ); if ( ! this.props.userCanManageModules ) { - return + if ( ! this.props.siteConnectionStatus ) { + return false; + } + return ; } if ( ! this.props.siteConnectionStatus ) { - return + return ; } if ( this.props.jumpStartStatus ) { @@ -166,7 +169,7 @@ const Main = React.createClass( { const history = createHistory(); history.push( window.location.pathname + '?page=jetpack#/jumpstart' ); } else if ( '/jumpstart' === route ) { - return + return ; } } @@ -241,6 +244,7 @@ export default connect( jumpStartStatus: getJumpStartStatus( state ), isJumpstarting: isJumpstarting( state ), siteConnectionStatus: getSiteConnectionStatus( state ), + isLinked: isCurrentUserLinked( state ), siteRawUrl: getSiteRawUrl( state ), siteAdminUrl: getSiteAdminUrl( state ), searchTerm: getSearchTerm( state ), From 18ed27c868b7111fc5d885f39791253fbc81016f Mon Sep 17 00:00:00 2001 From: oskosk Date: Wed, 22 Feb 2017 09:17:11 -0300 Subject: [PATCH 2/2] Make the Main component update itself if the user's linked status has changed. The Main component implements a shouldComponentUpdate() lifecycle method to check whether it should re-render under certain conditions. We were not including the user linked state among these conditions. --- _inc/client/main.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/_inc/client/main.jsx b/_inc/client/main.jsx index d2d274a390d84..fef1ac07acb0d 100644 --- a/_inc/client/main.jsx +++ b/_inc/client/main.jsx @@ -116,6 +116,7 @@ const Main = React.createClass( { return nextProps.siteConnectionStatus !== this.props.siteConnectionStatus || nextProps.jumpStartStatus !== this.props.jumpStartStatus || + nextProps.isLinked !== this.props.isLinked || nextProps.route.path !== this.props.route.path || nextProps.searchTerm !== this.props.searchTerm; },