Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity Log: Tasklist restict the task list to 3 items on page load #26710

Merged
merged 1 commit into from
Aug 15, 2018
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
91 changes: 64 additions & 27 deletions client/my-sites/stats/activity-log-tasklist/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/** @format */
/* eslint-disable wpcalypso/i18n-mismatched-placeholders */
/**
* External dependencies
*/
Expand Down Expand Up @@ -47,6 +48,8 @@ const isItemUpdating = updatables =>
*/
const isItemEnqueued = ( updateSlug, updateQueue ) => !! find( updateQueue, { slug: updateSlug } );

const MaxUpdatedToShow = 3;

class ActivityLogTasklist extends Component {
static propTypes = {
siteId: PropTypes.number,
Expand Down Expand Up @@ -85,6 +88,7 @@ class ActivityLogTasklist extends Component {
state = {
dismissed: [],
queued: [],
expandedView: false,
};

/**
Expand Down Expand Up @@ -202,6 +206,16 @@ class ActivityLogTasklist extends Component {
this.continueQueue
);
};
/**
* Expand the list of updates to show all of them
*
* @param {object} event Synthetic event
*/
showAllUpdates = event => {
recordTracksEvent( 'calypso_activitylog_tasklist_expand_view' );
this.setState( { expandedView: true } );
event.preventDefault();
};

/**
* Starts the update process for a specified plugin/theme. Displays an informational notice.
Expand Down Expand Up @@ -305,6 +319,47 @@ class ActivityLogTasklist extends Component {
} );
}

showAllItemsToUpdate( itemsToUpdate ) {
// Show if plugin update didn't start, is still running or errored,
// but hide plugin if it was updated successfully.
return itemsToUpdate.map( item => {
return (
<ActivityLogTaskUpdate
key={ item.slug }
toUpdate={ item }
name={ item.name }
slug={ item.slug }
version={ item.version }
type={ item.type }
linked={ 'core' !== item.type }
goToPage={ this.goToPage }
siteSlug={ this.props.siteSlug }
enqueue={ this.enqueue }
dismiss={ this.dismiss }
disable={ isItemEnqueued( item.slug, this.state.queued ) }
/>
);
} );
}

showFooterToExpandAll( numberOfUpdates ) {
const { translate } = this.props;
const updatesHidden = numberOfUpdates - MaxUpdatedToShow;
return (
<div className="activity-log-tasklist__footer">
<span>
{ translate( 'One more update available', ' %(updates)s more updates available', {
count: updatesHidden,
args: { updates: updatesHidden },
} ) }
</span>
<a onClick={ this.showAllUpdates } href="?expandedView" borderless>
{ translate( 'Show All' ) }
</a>
</div>
);
}

render() {
const itemsToUpdate = union(
this.props.coreWithUpdate,
Expand All @@ -319,6 +374,7 @@ class ActivityLogTasklist extends Component {
const { translate } = this.props;
const numberOfUpdates = itemsToUpdate.length;
const queued = this.state.queued;
const showExpandedView = this.state.expandedView || numberOfUpdates <= MaxUpdatedToShow;
return (
<Card className="activity-log-tasklist" highlight="warning">
<TrackComponentView eventName={ 'calypso_activitylog_tasklist_update_impression' } />
Expand Down Expand Up @@ -359,33 +415,14 @@ class ActivityLogTasklist extends Component {
</SplitButton>
) }
</div>
{ // Show if plugin update didn't start, is still running or errored,
// but hide plugin if it was updated successfully.
itemsToUpdate.map( item => {
let updateType = translate( 'Plugin update available' );
if ( 'theme' === item.type ) {
updateType = translate( 'Theme update available' );
} else if ( 'core' === item.type ) {
updateType = translate( 'Core update available' );
}
return (
<ActivityLogTaskUpdate
key={ item.slug }
toUpdate={ item }
name={ item.name }
slug={ item.slug }
version={ item.version }
type={ item.type }
updateType={ updateType }
linked={ 'core' !== item.type }
goToPage={ this.goToPage }
siteSlug={ this.props.siteSlug }
enqueue={ this.enqueue }
dismiss={ this.dismiss }
disable={ isItemEnqueued( item.slug, queued ) }
/>
);
} ) }
{ showExpandedView && this.showAllItemsToUpdate( itemsToUpdate ) }
{ ! showExpandedView &&
this.showAllItemsToUpdate( [
itemsToUpdate[ 0 ],
itemsToUpdate[ 1 ],
itemsToUpdate[ 2 ],
] ) }
{ ! showExpandedView && this.showFooterToExpandAll( numberOfUpdates ) }
</Card>
);
}
Expand Down
12 changes: 12 additions & 0 deletions client/my-sites/stats/activity-log-tasklist/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@
.activity-log-tasklist__unlinked {
cursor: default;
}

.activity-log-tasklist__footer {
display: flex;
justify-content: space-between;
box-shadow: 0 -1px 0 transparentize( $gray-lighten-20, .5 );
padding: 16px 0;
color: $gray-text-min;

a {
text-decoration: underline;
}
}
21 changes: 9 additions & 12 deletions client/my-sites/stats/activity-log-tasklist/update.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ActivityLogTaskUpdate extends Component {
slug: PropTypes.string,
version: PropTypes.string,
type: PropTypes.string,
updateType: PropTypes.string,

linked: PropTypes.bool,
goToPage: PropTypes.func,
Expand All @@ -42,17 +41,15 @@ class ActivityLogTaskUpdate extends Component {
handleNameClick = () => this.props.goToPage( this.props.slug, this.props.type );

render() {
const {
translate,
name,
version,
type,
updateType,
disable,
linked,
slug,
siteSlug,
} = this.props;
const { translate, name, version, type, disable, linked, slug, siteSlug } = this.props;

let updateType = translate( 'Plugin update available' );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I've found a possible matching string that has already been translated 19 times:
translate( 'Plugin update available', 'Plugin updates available' ) ES Score: 16
See 1 additional suggestion in the PR translation status page

Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).

if ( 'theme' === type ) {
updateType = translate( 'Theme update available' );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! I've found a possible matching string that has already been translated 21 times:
translate( 'Theme update available', 'Theme updates available' ) ES Score: 13

Help me improve these suggestions: react with 👎 if the suggestion doesn't make any sense, or with 👍 if it's a particularly good one (even if not implemented).

} else if ( 'core' === type ) {
updateType = translate( 'Core update available' );
}

const url =
'plugin' === type ? `/plugins/${ slug }/${ siteSlug }` : `/theme/${ slug }/${ siteSlug }`;
return (
Expand Down