2018-12-19 11:18:43 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, _n } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
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-11-26 19:39:40 +00:00
|
|
|
import { defaultTableDateFormat, getCurrentDates } from 'lib/date';
|
2019-01-14 09:54:44 +00:00
|
|
|
import { Date, Link } from '@woocommerce/components';
|
2018-12-19 11:18:43 +00:00
|
|
|
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
|
2019-11-21 21:51:52 +00:00
|
|
|
import { formatValue } from 'lib/number-format';
|
2019-11-22 17:07:26 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/wc-admin-settings';
|
2018-12-19 11:18:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ReportTable from 'analytics/components/report-table';
|
|
|
|
|
|
|
|
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 [
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Date', 'woocommerce-admin' ),
|
2018-12-19 11:18:43 +00:00
|
|
|
key: 'date',
|
|
|
|
defaultSort: true,
|
|
|
|
required: true,
|
|
|
|
isLeftAligned: true,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Product Title', 'woocommerce-admin' ),
|
2019-01-10 17:10:31 +00:00
|
|
|
key: 'product',
|
|
|
|
isSortable: true,
|
2018-12-19 11:18:43 +00:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'File Name', 'woocommerce-admin' ),
|
2018-12-19 11:18:43 +00:00
|
|
|
key: 'file_name',
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Order #', 'woocommerce-admin' ),
|
|
|
|
screenReaderLabel: __( 'Order Number', 'woocommerce-admin' ),
|
2019-02-28 14:14:21 +00:00
|
|
|
key: 'order_number',
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'User Name', 'woocommerce-admin' ),
|
2018-12-19 11:18:43 +00:00
|
|
|
key: 'user_id',
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'IP', 'woocommerce-admin' ),
|
2018-12-19 11:18:43 +00:00
|
|
|
key: 'ip_address',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getRowsContent( downloads ) {
|
|
|
|
const { query } = this.props;
|
|
|
|
const persistedQuery = getPersistedQuery( query );
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
return map( downloads, ( download ) => {
|
2019-02-19 19:35:29 +00:00
|
|
|
const {
|
|
|
|
_embedded,
|
|
|
|
date,
|
2020-02-14 02:23:21 +00:00
|
|
|
file_name: fileName,
|
|
|
|
file_path: filePath,
|
|
|
|
ip_address: ipAddress,
|
|
|
|
order_id: orderId,
|
|
|
|
order_number: orderNumber,
|
|
|
|
product_id: productId,
|
2019-02-19 19:35:29 +00:00
|
|
|
username,
|
|
|
|
} = download;
|
2019-01-07 11:54:42 +00:00
|
|
|
const { name: productName } = _embedded.product[ 0 ];
|
2018-12-19 11:18:43 +00:00
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const productLink = getNewPath(
|
|
|
|
persistedQuery,
|
|
|
|
'/analytics/products',
|
|
|
|
{
|
|
|
|
filter: 'single_product',
|
|
|
|
products: productId,
|
|
|
|
}
|
|
|
|
);
|
2018-12-19 11:18:43 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
display: (
|
|
|
|
<Date
|
|
|
|
date={ date }
|
|
|
|
visibleFormat={ defaultTableDateFormat }
|
|
|
|
/>
|
|
|
|
),
|
2018-12-19 11:18:43 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
{
|
2019-01-08 16:51:19 +00:00
|
|
|
display: (
|
2020-02-14 02:23:21 +00:00
|
|
|
<Link href={ filePath } type="external">
|
|
|
|
{ fileName }
|
2019-01-08 16:51:19 +00:00
|
|
|
</Link>
|
|
|
|
),
|
2020-02-14 02:23:21 +00:00
|
|
|
value: fileName,
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
display: (
|
2019-11-22 17:07:26 +00:00
|
|
|
<Link
|
2020-02-14 02:23:21 +00:00
|
|
|
href={ getAdminLink(
|
|
|
|
`post.php?post=${ orderId }&action=edit`
|
|
|
|
) }
|
2019-11-22 17:07:26 +00:00
|
|
|
type="wp-admin"
|
|
|
|
>
|
2020-02-14 02:23:21 +00:00
|
|
|
{ orderNumber }
|
2018-12-19 11:18:43 +00:00
|
|
|
</Link>
|
|
|
|
),
|
2020-02-14 02:23:21 +00:00
|
|
|
value: orderNumber,
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
{
|
2019-02-19 19:35:29 +00:00
|
|
|
display: username,
|
|
|
|
value: username,
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
display: ipAddress,
|
|
|
|
value: ipAddress,
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
getSummary( totals ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
const { download_count: downloadCount = 0 } = totals;
|
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-03-13 17:14:02 +00:00
|
|
|
label: _n( 'day', 'days', days, 'woocommerce-admin' ),
|
2019-11-21 21:51:52 +00:00
|
|
|
value: formatValue( 'number', days ),
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
label: _n(
|
|
|
|
'download',
|
|
|
|
'downloads',
|
|
|
|
downloadCount,
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
value: formatValue( 'number', downloadCount ),
|
2018-12-19 11:18:43 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-03-21 03:25:05 +00:00
|
|
|
const { query, filters, advancedFilters } = this.props;
|
2018-12-19 11:18:43 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
} }
|
2019-03-13 17:14:02 +00:00
|
|
|
title={ __( 'Downloads', 'woocommerce-admin' ) }
|
2018-12-19 11:18:43 +00:00
|
|
|
columnPrefsKey="downloads_report_columns"
|
2019-03-21 03:25:05 +00:00
|
|
|
filters={ filters }
|
|
|
|
advancedFilters={ advancedFilters }
|
2018-12-19 11:18:43 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|