From a65a2d17f78423dc549398fbe842301c74bcde61 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 8 Aug 2018 14:48:45 -0400 Subject: [PATCH 1/9] Connect checklist share to dispatch actions --- client/my-sites/checklist/main.jsx | 12 ++---------- client/my-sites/checklist/share.jsx | 8 +++++++- client/my-sites/stats/checklist-banner/index.jsx | 6 +----- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index 63b4d771f3439..0887cde81304e 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -25,7 +25,6 @@ import SidebarNavigation from 'my-sites/sidebar-navigation'; import { getCurrentUser } from 'state/current-user/selectors'; import { getSelectedSiteId } from 'state/ui/selectors'; import { isJetpackSite, isNewSite, getSiteSlug } from 'state/sites/selectors'; -import { recordTracksEvent } from 'state/analytics/actions'; import isSiteOnFreePlan from 'state/selectors/is-site-on-free-plan'; /** @@ -127,11 +126,7 @@ class ChecklistMain extends PureComponent { "You have completed all your tasks. Now let's tell people about it. Share your site." ) } /> - + ); } @@ -239,7 +234,4 @@ const mapStateToProps = state => { }; }; -export default connect( - mapStateToProps, - { recordTracksEvent } -)( localize( ChecklistMain ) ); +export default connect( mapStateToProps )( localize( ChecklistMain ) ); diff --git a/client/my-sites/checklist/share.jsx b/client/my-sites/checklist/share.jsx index 560b5db97607e..d42f0e5816712 100644 --- a/client/my-sites/checklist/share.jsx +++ b/client/my-sites/checklist/share.jsx @@ -5,15 +5,17 @@ */ import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; /** * Internal dependencies */ import ShareButton from 'components/share-button'; +import { recordTracksEvent } from 'state/analytics/actions'; const services = [ 'facebook', 'twitter', 'linkedin', 'google-plus', 'pinterest' ]; -export default class ChecklistShowShare extends PureComponent { +class ChecklistShowShare extends PureComponent { static propTypes = { siteSlug: PropTypes.string.isRequired, recordTracksEvent: PropTypes.func, @@ -57,3 +59,7 @@ export default class ChecklistShowShare extends PureComponent { ); } } +export default connect( + null, + { recordTracksEvent } +)( ChecklistShowShare ); diff --git a/client/my-sites/stats/checklist-banner/index.jsx b/client/my-sites/stats/checklist-banner/index.jsx index 290794781730b..921548c93f675 100644 --- a/client/my-sites/stats/checklist-banner/index.jsx +++ b/client/my-sites/stats/checklist-banner/index.jsx @@ -121,11 +121,7 @@ export class ChecklistBanner extends Component { renderShareButtons() { return ( - + ); } From b3f9f7d8a218205c16bbb7c259ebfe5b36bb8363 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 8 Aug 2018 14:54:35 -0400 Subject: [PATCH 2/9] Use ternary over conditional method --- client/my-sites/checklist/main.jsx | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index 0887cde81304e..85f703a68bb2d 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -76,16 +76,6 @@ class ChecklistMain extends PureComponent { } } - getHeaderTitle() { - const { translate, siteHasFreePlan } = this.props; - - if ( siteHasFreePlan ) { - return translate( 'Your site has been created!' ); - } - - return translate( 'Thank you for your purchase!' ); - } - getSubHeaderText( displayMode ) { const { translate } = this.props; @@ -141,7 +131,11 @@ class ChecklistMain extends PureComponent { alt="" /> From ea798913e68d67a8fa6defddc366854bc8486c5a Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 8 Aug 2018 14:57:08 -0400 Subject: [PATCH 3/9] Use ternary over conditional method --- client/my-sites/checklist/main.jsx | 40 +++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index 85f703a68bb2d..98d3c4a23ba46 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -76,28 +76,6 @@ class ChecklistMain extends PureComponent { } } - getSubHeaderText( displayMode ) { - const { translate } = this.props; - - if ( displayMode === 'gsuite' ) { - return translate( - 'We emailed %(email)s with instructions to complete your G Suite setup. ' + - 'In the mean time, let’s get your new site ready for you to share. ' + - 'We’ve prepared a list of things that will help you get there quickly.', - { - args: { - email: this.props.user.email, - }, - } - ); - } - - return translate( - "Now that your site has been created, it's time to get it ready for you to share. " + - "We've prepared a list of things that will help you get there quickly." - ); - } - renderHeader( completed, displayMode ) { const { translate, isNewlyCreatedSite } = this.props; @@ -136,7 +114,23 @@ class ChecklistMain extends PureComponent { ? translate( 'Your site has been created!' ) : translate( 'Thank you for your purchase!' ) } - subHeaderText={ this.getSubHeaderText( displayMode ) } + subHeaderText={ + 'gsuite' === displayMode + ? translate( + 'We emailed %(email)s with instructions to complete your G Suite setup. ' + + 'In the mean time, let’s get your new site ready for you to share. ' + + 'We’ve prepared a list of things that will help you get there quickly.', + { + args: { + email: this.props.user.email, + }, + } + ) + : translate( + "Now that your site has been created, it's time to get it ready for you to share. " + + "We've prepared a list of things that will help you get there quickly." + ) + } /> ); From fc7a44a6716b9a4018071a5794f2b1d2049a93fc Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Wed, 8 Aug 2018 14:59:23 -0400 Subject: [PATCH 4/9] Inline simple jsx --- client/my-sites/checklist/main.jsx | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index 98d3c4a23ba46..60ffe3012c6b1 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -146,21 +146,9 @@ class ChecklistMain extends PureComponent { ); } - renderChecklist() { - const { displayMode, siteId, tasks } = this.props; - const completed = tasks && ! find( tasks, { completed: false } ); - - return ( - - { siteId && } - { this.renderHeader( completed, displayMode ) } - - - ); - } - render() { - const { checklistAvailable, displayMode, translate } = this.props; + const { checklistAvailable, displayMode, siteId, tasks, translate } = this.props; + const completed = tasks && ! find( tasks, { completed: false } ); let translatedTitle = translate( 'Site Checklist' ); let title = 'Site Checklist'; @@ -177,7 +165,11 @@ class ChecklistMain extends PureComponent { { checklistAvailable ? ( - this.renderChecklist() + + { siteId && } + { this.renderHeader( completed, displayMode ) } + + ) : ( ) } From d651d5d0e71c944ce254b772351c1489a9194265 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 9 Aug 2018 07:45:03 -0400 Subject: [PATCH 5/9] Shorten mapStateToProps --- client/my-sites/checklist/main.jsx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index 60ffe3012c6b1..4b320f4c0a561 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -178,13 +178,10 @@ class ChecklistMain extends PureComponent { } } -const mapStateToProps = state => { +export default connect( state => { const siteId = getSelectedSiteId( state ); - const siteSlug = getSiteSlug( state, siteId ); - const siteHasFreePlan = isSiteOnFreePlan( state, siteId ); const isAtomic = isSiteAutomatedTransfer( state, siteId ); const isJetpack = isJetpackSite( state, siteId ); - const isNewlyCreatedSite = isNewSite( state, siteId ); /** * Included to fix regression. @@ -199,10 +196,10 @@ const mapStateToProps = state => { checklistAvailable: ! isAtomic && ( config.isEnabled( 'jetpack/checklist' ) || ! isJetpack ), isAtomic, isJetpack, - isNewlyCreatedSite, + isNewlyCreatedSite: isNewSite( state, siteId ), + siteHasFreePlan: isSiteOnFreePlan( state, siteId ), siteId, - siteSlug, - siteHasFreePlan, + siteSlug: getSiteSlug( state, siteId ), user: getCurrentUser( state ), /** @@ -212,6 +209,4 @@ const mapStateToProps = state => { */ tasks: tasksFromServer ? mergeObjectIntoArrayById( tasks, tasksFromServer ) : null, }; -}; - -export default connect( mapStateToProps )( localize( ChecklistMain ) ); +} )( localize( ChecklistMain ) ); From a51d7cfd921e998800df3366cd8c0ef7b19064b6 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 9 Aug 2018 07:45:59 -0400 Subject: [PATCH 6/9] Use named isEnabled export --- client/my-sites/checklist/main.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index 4b320f4c0a561..94d3f9bf507bd 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -13,7 +13,7 @@ import { localize } from 'i18n-calypso'; */ import ChecklistShow from './checklist-show'; import ChecklistShowShare from './share'; -import config from 'config'; +import { isEnabled } from 'config'; import DocumentHead from 'components/data/document-head'; import EmptyContent from 'components/empty-content'; import FormattedHeader from 'components/formatted-header'; @@ -62,7 +62,7 @@ class ChecklistMain extends PureComponent { * Only send Jetpack users to plans if a checklist will be presented. Otherwise, * let the "Not available" view render. */ - config.isEnabled( 'jetpack/checklist' ) && + isEnabled( 'jetpack/checklist' ) && this.props.siteSlug && false === this.props.isAtomic && this.props.isJetpack && @@ -193,7 +193,7 @@ export default connect( state => { const tasksFromServer = siteChecklist && siteChecklist.tasks; return { - checklistAvailable: ! isAtomic && ( config.isEnabled( 'jetpack/checklist' ) || ! isJetpack ), + checklistAvailable: ! isAtomic && ( isEnabled( 'jetpack/checklist' ) || ! isJetpack ), isAtomic, isJetpack, isNewlyCreatedSite: isNewSite( state, siteId ), From e96b74d91ea747cdb1bcb1192fbf6816ad025334 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Thu, 9 Aug 2018 07:46:12 -0400 Subject: [PATCH 7/9] Alphabetize imports --- client/my-sites/checklist/main.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index 94d3f9bf507bd..e9cf827bc4a82 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -13,19 +13,19 @@ import { localize } from 'i18n-calypso'; */ import ChecklistShow from './checklist-show'; import ChecklistShowShare from './share'; -import { isEnabled } from 'config'; import DocumentHead from 'components/data/document-head'; import EmptyContent from 'components/empty-content'; import FormattedHeader from 'components/formatted-header'; import isSiteAutomatedTransfer from 'state/selectors/is-site-automated-transfer'; +import isSiteOnFreePlan from 'state/selectors/is-site-on-free-plan'; import Main from 'components/main'; import PageViewTracker from 'lib/analytics/page-view-tracker'; import QuerySiteChecklist from 'components/data/query-site-checklist'; import SidebarNavigation from 'my-sites/sidebar-navigation'; import { getCurrentUser } from 'state/current-user/selectors'; import { getSelectedSiteId } from 'state/ui/selectors'; -import { isJetpackSite, isNewSite, getSiteSlug } from 'state/sites/selectors'; -import isSiteOnFreePlan from 'state/selectors/is-site-on-free-plan'; +import { getSiteSlug, isJetpackSite, isNewSite } from 'state/sites/selectors'; +import { isEnabled } from 'config'; /** * Included to fix regression. From deba47add7d1886a3e31b999b4cafe6b76d0d44f Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 14 Aug 2018 09:30:22 -0400 Subject: [PATCH 8/9] Use some over find --- client/my-sites/checklist/main.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index e9cf827bc4a82..f86d26b079464 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -5,8 +5,8 @@ import page from 'page'; import React, { Fragment, PureComponent } from 'react'; import { connect } from 'react-redux'; -import { find, some } from 'lodash'; import { localize } from 'i18n-calypso'; +import { some } from 'lodash'; /** * Internal dependencies @@ -148,7 +148,7 @@ class ChecklistMain extends PureComponent { render() { const { checklistAvailable, displayMode, siteId, tasks, translate } = this.props; - const completed = tasks && ! find( tasks, { completed: false } ); + const completed = tasks && ! some( tasks, { completed: false } ); let translatedTitle = translate( 'Site Checklist' ); let title = 'Site Checklist'; From e40788f6395fda9c0d9e0b3faa85db3b465ee050 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 14 Aug 2018 09:32:45 -0400 Subject: [PATCH 9/9] Use props in render method, don't pass as arguments --- client/my-sites/checklist/main.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/my-sites/checklist/main.jsx b/client/my-sites/checklist/main.jsx index f86d26b079464..9d92dd03a3a04 100644 --- a/client/my-sites/checklist/main.jsx +++ b/client/my-sites/checklist/main.jsx @@ -76,8 +76,9 @@ class ChecklistMain extends PureComponent { } } - renderHeader( completed, displayMode ) { - const { translate, isNewlyCreatedSite } = this.props; + renderHeader() { + const { displayMode, isNewlyCreatedSite, tasks, translate } = this.props; + const completed = tasks && ! some( tasks, { completed: false } ); if ( completed ) { return ( @@ -147,8 +148,7 @@ class ChecklistMain extends PureComponent { } render() { - const { checklistAvailable, displayMode, siteId, tasks, translate } = this.props; - const completed = tasks && ! some( tasks, { completed: false } ); + const { checklistAvailable, displayMode, siteId, translate } = this.props; let translatedTitle = translate( 'Site Checklist' ); let title = 'Site Checklist'; @@ -167,7 +167,7 @@ class ChecklistMain extends PureComponent { { checklistAvailable ? ( { siteId && } - { this.renderHeader( completed, displayMode ) } + { this.renderHeader() } ) : (