2019-01-11 15:11:10 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import { get, map } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { formatCurrency, getCurrencyFormatDecimal } from '@woocommerce/currency';
|
|
|
|
import { getNewPath, getPersistedQuery } from '@woocommerce/navigation';
|
|
|
|
import { Link } from '@woocommerce/components';
|
2019-01-29 16:48:46 +00:00
|
|
|
import { numberFormat } from '@woocommerce/number';
|
2019-01-11 15:11:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Leaderboard from 'analytics/components/leaderboard';
|
|
|
|
|
|
|
|
export class TopSellingCategories extends Component {
|
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
|
|
|
|
|
|
|
this.getRowsContent = this.getRowsContent.bind( this );
|
|
|
|
this.getHeadersContent = this.getHeadersContent.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
getHeadersContent() {
|
|
|
|
return [
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Category', 'woocommerce-admin' ),
|
2019-01-11 15:11:10 +00:00
|
|
|
key: 'category',
|
|
|
|
required: true,
|
|
|
|
isLeftAligned: true,
|
|
|
|
isSortable: false,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Items Sold', 'woocommerce-admin' ),
|
2019-01-11 15:11:10 +00:00
|
|
|
key: 'items_sold',
|
|
|
|
required: false,
|
|
|
|
isSortable: false,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Net Revenue', 'woocommerce-admin' ),
|
2019-01-11 15:11:10 +00:00
|
|
|
key: 'net_revenue',
|
|
|
|
required: true,
|
|
|
|
isSortable: false,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getRowsContent( data ) {
|
|
|
|
const { query } = this.props;
|
|
|
|
const persistedQuery = getPersistedQuery( query );
|
|
|
|
return map( data, row => {
|
2019-03-05 02:56:47 +00:00
|
|
|
const { category_id, items_sold, net_revenue } = row;
|
|
|
|
const extended_info = row.extended_info || {};
|
2019-01-11 15:11:10 +00:00
|
|
|
const name = get( extended_info, [ 'name' ] );
|
|
|
|
const categoryUrl = getNewPath( persistedQuery, 'analytics/categories', {
|
2019-01-18 07:46:12 +00:00
|
|
|
filter: 'single_category',
|
2019-01-11 15:11:10 +00:00
|
|
|
categories: category_id,
|
|
|
|
} );
|
|
|
|
const categoryLink = (
|
|
|
|
<Link href={ categoryUrl } type="wc-admin">
|
|
|
|
{ name }
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
display: categoryLink,
|
|
|
|
value: name,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: numberFormat( items_sold ),
|
|
|
|
value: items_sold,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatCurrency( net_revenue ),
|
|
|
|
value: getCurrencyFormatDecimal( net_revenue ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { query, totalRows } = this.props;
|
|
|
|
const tableQuery = {
|
|
|
|
orderby: 'items_sold',
|
|
|
|
order: 'desc',
|
|
|
|
per_page: totalRows,
|
|
|
|
extended_info: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Leaderboard
|
|
|
|
endpoint="categories"
|
|
|
|
getHeadersContent={ this.getHeadersContent }
|
|
|
|
getRowsContent={ this.getRowsContent }
|
|
|
|
query={ query }
|
|
|
|
tableQuery={ tableQuery }
|
2019-03-13 17:14:02 +00:00
|
|
|
title={ __( 'Top Categories - Items Sold', 'woocommerce-admin' ) }
|
2019-01-11 15:11:10 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TopSellingCategories;
|