Hook customers report table summary up to stats endpoint.
This commit is contained in:
parent
07cbaae2a5
commit
4a6f2652b6
|
@ -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' ) } }
|
||||
|
|
|
@ -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 ) {
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in New Issue