Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions client/my-sites/checklist/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import page from 'page';
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { localize } from 'i18n-calypso';
import { some } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -60,11 +59,9 @@ class ChecklistMain extends PureComponent {
this.props.siteSlug &&
false === this.props.isAtomic &&
this.props.isJetpack &&
some( [
this.props.siteSlug !== prevProps.siteSlug,
this.props.isAtomic !== prevProps.isAtomic,
this.props.isJetpack !== prevProps.isJetpack,
] )
( this.props.siteSlug !== prevProps.siteSlug ||
this.props.isAtomic !== prevProps.isAtomic ||
this.props.isJetpack !== prevProps.isJetpack )
) {
page.redirect( `/plans/my-plan/${ this.props.siteSlug }` );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PropTypes from 'prop-types';
import React, { Children, Component } from 'react';
import store from 'store';
import { connect } from 'react-redux';
import { find, get, reduce } from 'lodash';
import { get } from 'lodash';
import { localize } from 'i18n-calypso';

/**
Expand Down Expand Up @@ -65,21 +65,17 @@ export class ChecklistBanner extends Component {
}

render() {
const { translate } = this.props;

if ( ! this.canShow() ) {
return null;
}

const { translate, taskList } = this.props;

const childrenArray = Children.toArray( this.props.children );
const total = childrenArray.length;
const completeCount = reduce(
childrenArray,
( sum, child ) => ( !! child.props.completed ? sum + 1 : sum ),
0
);
const isFinished = completeCount >= total;
const completePercentage = Math.round( ! total ? 0 : ( completeCount / total ) * 100 );
const { total, completed, percentage } = taskList.getCompletionStatus();

const firstIncomplete = taskList.getFirstIncompleteTask();
const isFinished = ! firstIncomplete;

return (
<Card className="checklist-banner">
Expand All @@ -89,7 +85,7 @@ export class ChecklistBanner extends Component {
width={ 152 }
height={ 152 }
lineWidth={ 18 }
percentage={ completePercentage }
percentage={ percentage }
metric={ translate( 'completed' ) }
colors={ [ '#ffffff', '#47b766' ] }
/>
Expand All @@ -98,7 +94,7 @@ export class ChecklistBanner extends Component {
<span className="checklist-banner__progress-title">{ translate( 'Site setup' ) }</span>
<span className="checklist-banner__progress-desc">
{ translate( '%(percentage)s%% completed', {
args: { percentage: completePercentage },
args: { percentage: percentage },
} ) }

{ isFinished && (
Expand All @@ -111,7 +107,7 @@ export class ChecklistBanner extends Component {
</Button>
) }
</span>
<ProgressBar value={ completeCount } total={ total } color="#47b766" />
<ProgressBar value={ completed } total={ total } color="#47b766" />
</div>
{ isFinished ? (
<>
Expand All @@ -137,7 +133,7 @@ export class ChecklistBanner extends Component {
</Button>
</>
) : (
find( childrenArray, child => ! child.props.completed )
childrenArray.find( child => child.props.id === firstIncomplete.id )
) }
</Card>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* External dependencies
*/
import PropTypes from 'prop-types';
import React, { Children, Component } from 'react';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { find, reduce } from 'lodash';
import classNames from 'classnames';
import { localize } from 'i18n-calypso';

Expand All @@ -31,36 +30,25 @@ export class ChecklistNavigation extends Component {
};

handleClick = () => {
// The redux state for getSiteChecklist() is injected from an API response
// so the selector's results and the task list will not always match
// Therefore, we're accessing the child Tasks directly for accuracy

const childrenArray = Children.toArray( this.props.children );
const task = find( childrenArray, child => ! child.props.completed );
const task = this.props.taskList.getFirstIncompleteTask();

if ( task ) {
this.props.setStoredTask( task.key );
this.props.setStoredTask( task.id );
}
this.props.setNotification( false );
this.props.closePopover();
this.props.recordTracksEvent( 'calypso_inlinehelp_checklist_click' );
};

render() {
const { siteSlug, translate, showNotification, children, canShowChecklist } = this.props;
const { siteSlug, translate, showNotification, canShowChecklist, taskList } = this.props;

const buttonClasses = {
'has-notification': showNotification,
'checklist-navigation__count': true,
};
const childrenArray = Children.toArray( children );
const total = childrenArray.length;
const completeCount = reduce(
childrenArray,
( sum, child ) => ( !! child.props.completed ? sum + 1 : sum ),
0
);
const isFinished = completeCount >= total;
const { total, completed } = taskList.getCompletionStatus();
const isFinished = ! taskList.getFirstIncompleteTask();
const checklistLink = '/checklist/' + siteSlug;

if ( ! canShowChecklist || isFinished ) {
Expand All @@ -83,14 +71,14 @@ export class ChecklistNavigation extends Component {
{ translate( '%(complete)d/%(total)d', {
comment: 'Numerical progress indicator, like 5/9',
args: {
complete: completeCount,
complete: completed,
total: total,
},
} ) }
</span>

<div className="checklist-navigation__progress-bar-margin">
<ProgressBar total={ total } value={ completeCount } compact />
<ProgressBar total={ total } value={ completed } compact />
</div>
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
/**
* External dependencies
*/
import { Children, Component } from 'react';
import { find, reduce } from 'lodash';
import { Component } from 'react';

export class ChecklistNotification extends Component {
componentDidMount() {
Expand All @@ -15,31 +14,17 @@ export class ChecklistNotification extends Component {
}

shouldShowNotification = () => {
const { storedTask, canShowChecklist, children } = this.props;

// The redux state for getSiteChecklist() is injected from an API response
// so the selector's results and the task list will not always match
// Therefore, we're accessing the child Tasks directly for accuracy

const childrenArray = Children.toArray( children );
const task = find( childrenArray, child => ! child.props.completed );
const total = childrenArray.length;
const completeCount = reduce(
childrenArray,
( sum, child ) => ( !! child.props.completed ? sum + 1 : sum ),
0
);
const isFinished = completeCount >= total;

this.props.setNotification( false );
const { storedTask, canShowChecklist, taskList } = this.props;
const firstIncomplete = taskList.getFirstIncompleteTask();

if (
task &&
( storedTask !== task.key || storedTask === null ) &&
! isFinished &&
firstIncomplete &&
( storedTask !== firstIncomplete.id || storedTask === null ) &&
canShowChecklist
) {
this.props.setNotification( true );
} else {
this.props.setNotification( false );
}
};

Expand Down
Loading