* Add Categories report filters

* Remove the option to sort categories by name, given that it's not supported by the endpoint
This commit is contained in:
Albert Juhé Lluveras 2018-12-25 10:28:20 +01:00 committed by GitHub
parent 024d267ae6
commit 1ca1dba3e7
6 changed files with 52 additions and 12 deletions

View File

@ -4,6 +4,12 @@
*/ */
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { getRequestByIdString } from 'lib/async-requests';
import { NAMESPACE } from 'store/constants';
export const charts = [ export const charts = [
{ {
key: 'items_sold', key: 'items_sold',
@ -30,7 +36,37 @@ export const filters = [
showFilters: () => true, showFilters: () => true,
filters: [ filters: [
{ label: __( 'All Categories', 'wc-admin' ), value: 'all' }, { label: __( 'All Categories', 'wc-admin' ), value: 'all' },
{ label: __( 'Advanced Filters', 'wc-admin' ), value: 'advanced' }, {
label: __( 'Comparison', 'wc-admin' ),
value: 'compare-categories',
chartMode: 'item-comparison',
settings: {
type: 'categories',
param: 'categories',
getLabels: getRequestByIdString( NAMESPACE + 'products/categories', cat => ( {
id: cat.id,
label: cat.name,
} ) ),
labels: {
helpText: __( 'Select at least two categories to compare', 'wc-admin' ),
placeholder: __( 'Search for categories to compare', 'wc-admin' ),
title: __( 'Compare Categories', 'wc-admin' ),
update: __( 'Compare', 'wc-admin' ),
},
},
},
{
label: __( 'Top Categories by Items Sold', 'wc-admin' ),
value: 'top_items',
chartMode: 'item-comparison',
query: { orderby: 'items_sold', order: 'desc' },
},
{
label: __( 'Top Categories by Net Revenue', 'wc-admin' ),
value: 'top_revenue',
chartMode: 'item-comparison',
query: { orderby: 'net_revenue', order: 'desc' },
},
], ],
}, },
]; ];

View File

@ -34,7 +34,6 @@ class CategoriesReportTable extends Component {
key: 'category', key: 'category',
required: true, required: true,
isLeftAligned: true, isLeftAligned: true,
isSortable: true,
}, },
{ {
label: __( 'Items sold', 'wc-admin' ), label: __( 'Items sold', 'wc-admin' ),
@ -45,8 +44,7 @@ class CategoriesReportTable extends Component {
isNumeric: true, isNumeric: true,
}, },
{ {
label: __( 'G. Revenue', 'wc-admin' ), label: __( 'Net Revenue', 'wc-admin' ),
screenReaderLabel: __( 'Gross Revenue', 'wc-admin' ),
key: 'net_revenue', key: 'net_revenue',
isSortable: true, isSortable: true,
isNumeric: true, isNumeric: true,
@ -125,15 +123,21 @@ class CategoriesReportTable extends Component {
render() { render() {
const { query } = this.props; const { query } = this.props;
const labels = {
helpText: __( 'Select at least two categories to compare', 'wc-admin' ),
placeholder: __( 'Search by category name', 'wc-admin' ),
};
return ( return (
<ReportTable <ReportTable
compareBy="product_cats" compareBy="categories"
endpoint="categories" endpoint="categories"
getHeadersContent={ this.getHeadersContent } getHeadersContent={ this.getHeadersContent }
getRowsContent={ this.getRowsContent } getRowsContent={ this.getRowsContent }
getSummary={ this.getSummary } getSummary={ this.getSummary }
itemIdField="category_id" itemIdField="category_id"
query={ query } query={ query }
labels={ labels }
tableQuery={ { tableQuery={ {
orderby: query.orderby || 'items_sold', orderby: query.orderby || 'items_sold',
order: query.order || 'desc', order: query.order || 'desc',

View File

@ -81,10 +81,10 @@ const filterConfig = {
}, },
{ {
label: __( 'Product Category Comparison', 'wc-admin' ), label: __( 'Product Category Comparison', 'wc-admin' ),
value: 'compare-product_cats', value: 'compare-categories',
chartMode: 'item-comparison', chartMode: 'item-comparison',
settings: { settings: {
type: 'product_cats', type: 'categories',
param: 'categories', param: 'categories',
getLabels: getRequestByIdString( NAMESPACE + 'products/categories', category => ( { getLabels: getRequestByIdString( NAMESPACE + 'products/categories', category => ( {
id: category.id, id: category.id,

View File

@ -21,7 +21,7 @@ import { computeSuggestionMatch } from './utils';
* @type {Completer} * @type {Completer}
*/ */
export default { export default {
name: 'product_cats', name: 'categories',
className: 'woocommerce-search__product-result', className: 'woocommerce-search__product-result',
options( search ) { options( search ) {
let payload = ''; let payload = '';

View File

@ -2,6 +2,7 @@
/** /**
* Export all autocompleters * Export all autocompleters
*/ */
export { default as productCategory } from './categories';
export { default as countries } from './countries'; export { default as countries } from './countries';
export { default as coupons } from './coupons'; export { default as coupons } from './coupons';
export { default as customers } from './customers'; export { default as customers } from './customers';
@ -9,7 +10,6 @@ export { default as downloadIps } from './download-ips';
export { default as emails } from './emails'; export { default as emails } from './emails';
export { default as orders } from './orders'; export { default as orders } from './orders';
export { default as product } from './product'; export { default as product } from './product';
export { default as productCategory } from './product-cat';
export { default as taxes } from './taxes'; export { default as taxes } from './taxes';
export { default as usernames } from './usernames'; export { default as usernames } from './usernames';
export { default as variations } from './variations'; export { default as variations } from './variations';

View File

@ -78,6 +78,8 @@ class Search extends Component {
getAutocompleter() { getAutocompleter() {
switch ( this.props.type ) { switch ( this.props.type ) {
case 'categories':
return productCategory;
case 'countries': case 'countries':
return countries; return countries;
case 'coupons': case 'coupons':
@ -92,8 +94,6 @@ class Search extends Component {
return orders; return orders;
case 'products': case 'products':
return product; return product;
case 'product_cats':
return productCategory;
case 'taxes': case 'taxes':
return taxes; return taxes;
case 'usernames': case 'usernames':
@ -241,6 +241,7 @@ Search.propTypes = {
* The object type to be used in searching. * The object type to be used in searching.
*/ */
type: PropTypes.oneOf( [ type: PropTypes.oneOf( [
'categories',
'countries', 'countries',
'coupons', 'coupons',
'customers', 'customers',
@ -248,7 +249,6 @@ Search.propTypes = {
'emails', 'emails',
'orders', 'orders',
'products', 'products',
'product_cats',
'taxes', 'taxes',
'usernames', 'usernames',
'variations', 'variations',