2018-12-19 11:18:43 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, _n } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import { format as formatDate } from '@wordpress/date';
|
|
|
|
import { map } from 'lodash';
|
2019-01-07 11:54:42 +00:00
|
|
|
import moment from 'moment';
|
2018-12-19 11:18:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2019-01-07 11:54:42 +00:00
|
|
|
import { getIntervalForQuery, getCurrentDates, getDateFormatsForInterval } from '@woocommerce/date';
|
2018-12-19 11:18:43 +00:00
|
|
|
import { Link } from '@woocommerce/components';
|
|
|
|
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ReportTable from 'analytics/components/report-table';
|
|
|
|
import { numberFormat } from 'lib/number';
|
|
|
|
|
|
|
|
export default class CouponsReportTable extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.getHeadersContent = this.getHeadersContent.bind( this );
|
|
|
|
this.getRowsContent = this.getRowsContent.bind( this );
|
|
|
|
this.getSummary = this.getSummary.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
getHeadersContent() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: __( 'Date', 'wc-admin' ),
|
|
|
|
key: 'date',
|
|
|
|
defaultSort: true,
|
|
|
|
required: true,
|
|
|
|
isLeftAligned: true,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Product Title', 'wc-admin' ),
|
|
|
|
key: 'product_id',
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'File Name', 'wc-admin' ),
|
|
|
|
key: 'file_name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Order #', 'wc-admin' ),
|
|
|
|
screenReaderLabel: __( 'Order ID', 'wc-admin' ),
|
|
|
|
key: 'order_id',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'User Name', 'wc-admin' ),
|
|
|
|
key: 'user_id',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'IP', 'wc-admin' ),
|
|
|
|
key: 'ip_address',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getRowsContent( downloads ) {
|
|
|
|
const { query } = this.props;
|
|
|
|
const currentInterval = getIntervalForQuery( query );
|
|
|
|
const { tableFormat } = getDateFormatsForInterval( currentInterval );
|
|
|
|
const persistedQuery = getPersistedQuery( query );
|
|
|
|
|
|
|
|
return map( downloads, download => {
|
2019-01-07 11:54:42 +00:00
|
|
|
const { _embedded, date, file_name, ip_address, order_id, product_id } = download;
|
|
|
|
const { name: productName } = _embedded.product[ 0 ];
|
|
|
|
const { name: userName } = _embedded.user[ 0 ];
|
2018-12-19 11:18:43 +00:00
|
|
|
|
|
|
|
const productLink = getNewPath( persistedQuery, 'products', {
|
|
|
|
filter: 'single_product',
|
|
|
|
products: product_id,
|
|
|
|
} );
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
display: formatDate( tableFormat, date ),
|
|
|
|
value: date,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: (
|
|
|
|
<Link href={ productLink } type="wc-admin">
|
2019-01-07 11:54:42 +00:00
|
|
|
{ productName }
|
2018-12-19 11:18:43 +00:00
|
|
|
</Link>
|
|
|
|
),
|
2019-01-07 11:54:42 +00:00
|
|
|
value: productName,
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
display: file_name,
|
|
|
|
value: file_name,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: (
|
|
|
|
<Link href={ `post.php?post=${ order_id }&action=edit` } type="wp-admin">
|
|
|
|
{ order_id }
|
|
|
|
</Link>
|
|
|
|
),
|
|
|
|
value: order_id,
|
|
|
|
},
|
|
|
|
{
|
2019-01-07 11:54:42 +00:00
|
|
|
display: userName,
|
|
|
|
value: userName,
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
display: ip_address,
|
|
|
|
value: ip_address,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
getSummary( totals ) {
|
|
|
|
if ( ! totals ) {
|
|
|
|
return [];
|
|
|
|
}
|
2019-01-07 11:54:42 +00:00
|
|
|
const { query } = this.props;
|
|
|
|
const dates = getCurrentDates( query );
|
|
|
|
const after = moment( dates.primary.after );
|
|
|
|
const before = moment( dates.primary.before );
|
|
|
|
const days = before.diff( after, 'days' ) + 1;
|
|
|
|
|
2018-12-19 11:18:43 +00:00
|
|
|
return [
|
|
|
|
{
|
2019-01-07 11:54:42 +00:00
|
|
|
label: _n( 'day', 'days', days, 'wc-admin' ),
|
|
|
|
value: numberFormat( days ),
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
{
|
2019-01-07 11:54:42 +00:00
|
|
|
label: _n( 'download', 'downloads', totals.download_count, 'wc-admin' ),
|
|
|
|
value: numberFormat( totals.download_count ),
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { query } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ReportTable
|
|
|
|
endpoint="downloads"
|
|
|
|
getHeadersContent={ this.getHeadersContent }
|
|
|
|
getRowsContent={ this.getRowsContent }
|
|
|
|
getSummary={ this.getSummary }
|
|
|
|
query={ query }
|
2019-01-07 11:54:42 +00:00
|
|
|
tableQuery={ {
|
|
|
|
_embed: true,
|
|
|
|
} }
|
2018-12-19 11:18:43 +00:00
|
|
|
title={ __( 'Downloads', 'wc-admin' ) }
|
|
|
|
columnPrefsKey="downloads_report_columns"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|