Hook customers report table summary up to stats endpoint.

This commit is contained in:
Jeff Stieler 2019-01-21 08:46:21 -07:00
parent 07cbaae2a5
commit 4a6f2652b6
3 changed files with 38 additions and 2 deletions

View File

@ -25,6 +25,7 @@ export default class CustomersReportTable extends Component {
this.getHeadersContent = this.getHeadersContent.bind( this );
this.getRowsContent = this.getRowsContent.bind( this );
this.getSummary = this.getSummary.bind( this );
}
getHeadersContent() {
@ -187,6 +188,30 @@ export default class CustomersReportTable extends Component {
} );
}
getSummary( totals ) {
if ( ! totals ) {
return [];
}
return [
{
label: __( 'customers', 'wc-admin' ),
value: numberFormat( totals.customers_count ),
},
{
label: __( 'average orders', 'wc-admin' ),
value: numberFormat( totals.avg_orders_count ),
},
{
label: __( 'average lifetime spend', 'wc-admin' ),
value: formatCurrency( totals.avg_total_spend ),
},
{
label: __( 'average order value', 'wc-admin' ),
value: formatCurrency( totals.avg_avg_order_value ),
},
];
}
render() {
const { query } = this.props;
@ -195,6 +220,7 @@ export default class CustomersReportTable extends Component {
endpoint="customers"
getHeadersContent={ this.getHeadersContent }
getRowsContent={ this.getRowsContent }
getSummary={ this.getSummary }
itemIdField="id"
query={ query }
labels={ { placeholder: __( 'Search by customer name', 'wc-admin' ) } }

View File

@ -16,7 +16,15 @@ import { getResourceIdentifier, getResourcePrefix } from '../../utils';
import { NAMESPACE } from '../../constants';
import { SWAGGERNAMESPACE } from 'store/constants';
const statEndpoints = [ 'coupons', 'downloads', 'orders', 'products', 'revenue', 'taxes' ];
const statEndpoints = [
'coupons',
'downloads',
'orders',
'products',
'revenue',
'taxes',
'customers',
];
// TODO: Remove once swagger endpoints are phased out.
const swaggerEndpoints = [ 'categories' ];
@ -28,6 +36,7 @@ const typeEndpointMap = {
'report-stats-query-downloads': 'downloads',
'report-stats-query-coupons': 'coupons',
'report-stats-query-taxes': 'taxes',
'report-stats-query-customers': 'customers',
};
function read( resourceNames, fetch = apiFetch ) {

View File

@ -75,7 +75,8 @@ class WC_Admin_REST_Reports_Customers_Stats_Controller extends WC_REST_Reports_C
$report_data = $customers_query->get_data();
$out_data = array(
'totals' => $report_data,
'intervals' => array(), // TODO: is this needed?
// TODO: is this needed? the single element array tricks the isReportDataEmpty() selector.
'intervals' => array( (object) array() ),
);
return rest_ensure_response( $out_data );