Skip to content

Commit

Permalink
Use props.period to handle instances where modules do not have summar…
Browse files Browse the repository at this point in the history
…y pages.
  • Loading branch information
timmyc committed Mar 9, 2016
1 parent a60622f commit 02a18cd
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions client/my-sites/stats/stats-module/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ export default React.createClass( {
},

viewAllHandler( event ) {
var summaryPageLink = '/stats/' + this.props.period.period + '/' + this.props.path + '/' + this.props.site.slug + '?startDate=' + this.props.date;
var summaryPageLink;

event.preventDefault();
if ( this.props.period && this.props.path && this.props.site ) {
summaryPageLink = '/stats/' + this.props.period.period + '/' + this.props.path + '/' + this.props.site.slug + '?startDate=' + this.props.date;

if ( this.props.beforeNavigate ) {
this.props.beforeNavigate();
event.preventDefault();

if ( this.props.beforeNavigate ) {
this.props.beforeNavigate();
}
page( summaryPageLink );
}
page( summaryPageLink );
},

getModuleLabel() {
Expand All @@ -62,6 +66,19 @@ export default React.createClass( {
return ( <DatePicker period={ this.props.period.period } date={ this.props.period.startOf } summary={ true } /> );
},

renderViewAllButton() {
// Some modules do not have view all abilities
if ( ! this.props.summary && this.props.period ) {
return (
<Button compact borderless onClick={ this.viewAllHandler }>
<Gridicon icon="stats-alt" />
</Button>
);
}

return null;
},

render() {
var data = this.data(),
noData = this.props.dataList.isEmpty(),
Expand All @@ -86,13 +103,7 @@ export default React.createClass( {

<SectionHeader label={ this.getModuleLabel() }>
{ ! this.props.summary
? ( <Button
compact
borderless
onClick={ this.viewAllHandler }
>
<Gridicon icon="stats-alt" />
</Button> )
? this.renderViewAllButton()
: ( <DownloadCsv period={ this.props.period } path={ this.props.path } site={ this.props.site } dataList={ this.props.dataList } /> ) }
</SectionHeader>
<Card compact className={ classes }>
Expand Down

0 comments on commit 02a18cd

Please sign in to comment.