2018-05-03 18:23:17 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2018-06-29 18:27:18 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { ToggleControl, withAPIData } from '@wordpress/components';
|
2018-05-03 18:23:17 +00:00
|
|
|
import { Component, compose } from '@wordpress/element';
|
|
|
|
|
2018-05-10 19:23:41 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Card from 'components/card';
|
2018-05-14 15:47:42 +00:00
|
|
|
import { EllipsisMenu, MenuItem, MenuTitle } from 'components/ellipsis-menu';
|
2018-06-29 18:27:18 +00:00
|
|
|
import { SummaryList, SummaryNumber } from 'components/summary';
|
|
|
|
import './style.scss';
|
2018-05-10 19:23:41 +00:00
|
|
|
|
2018-07-02 18:08:50 +00:00
|
|
|
class StorePerformance extends Component {
|
2018-05-14 15:47:42 +00:00
|
|
|
constructor() {
|
|
|
|
super( ...arguments );
|
|
|
|
this.state = {
|
|
|
|
showCustomers: true,
|
|
|
|
showProducts: true,
|
|
|
|
showOrders: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.toggle = this.toggle.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle( type ) {
|
|
|
|
return () => {
|
|
|
|
this.setState( state => ( { [ type ]: ! state[ type ] } ) );
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
renderMenu() {
|
|
|
|
return (
|
2018-07-10 12:48:06 +00:00
|
|
|
<EllipsisMenu label={ __( 'Choose which analytics to display', 'wc-admin' ) }>
|
|
|
|
<MenuTitle>{ __( 'Display Stats:', 'wc-admin' ) }</MenuTitle>
|
2018-05-14 15:47:42 +00:00
|
|
|
<MenuItem onInvoke={ this.toggle( 'showCustomers' ) }>
|
|
|
|
<ToggleControl
|
2018-07-10 12:48:06 +00:00
|
|
|
label={ __( 'Show Customers', 'wc-admin' ) }
|
2018-05-14 15:47:42 +00:00
|
|
|
checked={ this.state.showCustomers }
|
|
|
|
onChange={ this.toggle( 'showCustomers' ) }
|
|
|
|
/>
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem onInvoke={ this.toggle( 'showProducts' ) }>
|
|
|
|
<ToggleControl
|
2018-07-10 12:48:06 +00:00
|
|
|
label={ __( 'Show Products', 'wc-admin' ) }
|
2018-05-14 15:47:42 +00:00
|
|
|
checked={ this.state.showProducts }
|
|
|
|
onChange={ this.toggle( 'showProducts' ) }
|
|
|
|
/>
|
|
|
|
</MenuItem>
|
|
|
|
<MenuItem onInvoke={ this.toggle( 'showOrders' ) }>
|
|
|
|
<ToggleControl
|
2018-07-10 12:48:06 +00:00
|
|
|
label={ __( 'Show Orders', 'wc-admin' ) }
|
2018-05-14 15:47:42 +00:00
|
|
|
checked={ this.state.showOrders }
|
|
|
|
onChange={ this.toggle( 'showOrders' ) }
|
|
|
|
/>
|
|
|
|
</MenuItem>
|
|
|
|
</EllipsisMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-03 18:23:17 +00:00
|
|
|
render() {
|
|
|
|
const { orders, products } = this.props;
|
2018-05-10 19:23:41 +00:00
|
|
|
const totalOrders = ( orders.data && orders.data.length ) || 0;
|
|
|
|
const totalProducts = ( products.data && products.data.length ) || 0;
|
2018-05-14 15:47:42 +00:00
|
|
|
const { showCustomers, showProducts, showOrders } = this.state;
|
|
|
|
|
2018-05-03 18:23:17 +00:00
|
|
|
return (
|
2018-06-29 18:27:18 +00:00
|
|
|
<Card
|
2018-07-10 12:48:06 +00:00
|
|
|
title={ __( 'Store Performance', 'wc-admin' ) }
|
2018-06-29 18:27:18 +00:00
|
|
|
menu={ this.renderMenu() }
|
|
|
|
className="woocommerce-dashboard__store-performance"
|
|
|
|
>
|
|
|
|
<SummaryList>
|
2018-05-14 15:47:42 +00:00
|
|
|
{ showCustomers && (
|
2018-07-10 12:48:06 +00:00
|
|
|
<SummaryNumber value={ '2' } label={ __( 'New Customers', 'wc-admin' ) } delta={ 15 } />
|
2018-05-14 15:47:42 +00:00
|
|
|
) }
|
|
|
|
{ showProducts && (
|
2018-07-10 12:48:06 +00:00
|
|
|
<SummaryNumber value={ totalProducts } label={ __( 'Total Products', 'wc-admin' ) } />
|
2018-06-29 18:27:18 +00:00
|
|
|
) }
|
|
|
|
{ showOrders && (
|
|
|
|
<SummaryNumber
|
|
|
|
value={ totalOrders }
|
|
|
|
selected
|
2018-07-10 12:48:06 +00:00
|
|
|
label={ __( 'Total Orders', 'wc-admin' ) }
|
2018-06-29 18:27:18 +00:00
|
|
|
delta={ -6 }
|
|
|
|
/>
|
2018-05-14 15:47:42 +00:00
|
|
|
) }
|
2018-06-29 18:27:18 +00:00
|
|
|
</SummaryList>
|
2018-05-10 19:23:41 +00:00
|
|
|
</Card>
|
2018-05-03 18:23:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose( [
|
|
|
|
withAPIData( () => ( {
|
|
|
|
orders: '/wc/v2/orders?status=processing',
|
|
|
|
products: '/wc/v2/products',
|
|
|
|
} ) ),
|
2018-07-02 18:08:50 +00:00
|
|
|
] )( StorePerformance );
|