2018-11-14 21:04:59 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-02-14 04:03:00 +00:00
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
|
|
|
import { find } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { getIdsFromQuery, stringifyQuery } from '@woocommerce/navigation';
|
2018-12-06 22:18:46 +00:00
|
|
|
|
2018-11-14 21:04:59 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-12-06 22:18:46 +00:00
|
|
|
import { getTaxCode } from './utils';
|
2019-01-30 07:22:10 +00:00
|
|
|
import { NAMESPACE } from 'wc-api/constants';
|
2018-11-14 21:04:59 +00:00
|
|
|
|
|
|
|
export const charts = [
|
|
|
|
{
|
2019-01-22 15:49:17 +00:00
|
|
|
key: 'total_tax',
|
|
|
|
label: __( 'Total Tax', 'wc-admin' ),
|
2019-02-15 10:54:41 +00:00
|
|
|
order: 'desc',
|
|
|
|
orderby: 'total_tax',
|
2018-11-14 21:04:59 +00:00
|
|
|
type: 'currency',
|
|
|
|
},
|
|
|
|
{
|
2019-01-22 15:49:17 +00:00
|
|
|
key: 'order_tax',
|
|
|
|
label: __( 'Order Tax', 'wc-admin' ),
|
2019-02-15 10:54:41 +00:00
|
|
|
order: 'desc',
|
|
|
|
orderby: 'order_tax',
|
2018-11-14 21:04:59 +00:00
|
|
|
type: 'currency',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'shipping_tax',
|
|
|
|
label: __( 'Shipping Tax', 'wc-admin' ),
|
2019-02-15 10:54:41 +00:00
|
|
|
order: 'desc',
|
|
|
|
orderby: 'shipping_tax',
|
2018-11-14 21:04:59 +00:00
|
|
|
type: 'currency',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'orders_count',
|
|
|
|
label: __( 'Orders Count', 'wc-admin' ),
|
2019-02-15 10:54:41 +00:00
|
|
|
order: 'desc',
|
|
|
|
orderby: 'orders_count',
|
2018-11-14 21:04:59 +00:00
|
|
|
type: 'number',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export const filters = [
|
|
|
|
{
|
|
|
|
label: __( 'Show', 'wc-admin' ),
|
|
|
|
staticParams: [ 'chart' ],
|
|
|
|
param: 'filter',
|
|
|
|
showFilters: () => true,
|
2018-12-06 22:18:46 +00:00
|
|
|
filters: [
|
|
|
|
{ label: __( 'All Taxes', 'wc-admin' ), value: 'all' },
|
|
|
|
{
|
|
|
|
label: __( 'Comparison', 'wc-admin' ),
|
2019-02-14 04:03:00 +00:00
|
|
|
value: 'compare-taxes',
|
2018-12-06 22:18:46 +00:00
|
|
|
chartMode: 'item-comparison',
|
|
|
|
settings: {
|
|
|
|
type: 'taxes',
|
|
|
|
param: 'taxes',
|
2019-02-14 04:03:00 +00:00
|
|
|
// @TODO: Core /taxes endpoint should support a collection param 'include'.
|
|
|
|
getLabels: function( queryString = '' ) {
|
|
|
|
const idList = getIdsFromQuery( queryString );
|
|
|
|
if ( idList.length < 1 ) {
|
|
|
|
return Promise.resolve( [] );
|
|
|
|
}
|
|
|
|
const payload = stringifyQuery( {
|
|
|
|
per_page: -1,
|
|
|
|
} );
|
|
|
|
return apiFetch( { path: NAMESPACE + '/taxes' + payload } ).then( taxes => {
|
|
|
|
return idList.map( id => {
|
|
|
|
const tax = find( taxes, { id } );
|
|
|
|
return {
|
|
|
|
id: tax.id,
|
|
|
|
label: getTaxCode( tax ),
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
},
|
2018-12-06 22:18:46 +00:00
|
|
|
labels: {
|
|
|
|
helpText: __( 'Select at least two tax codes to compare', 'wc-admin' ),
|
|
|
|
placeholder: __( 'Search for tax codes to compare', 'wc-admin' ),
|
|
|
|
title: __( 'Compare Tax Codes', 'wc-admin' ),
|
|
|
|
update: __( 'Compare', 'wc-admin' ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2018-11-14 21:04:59 +00:00
|
|
|
},
|
|
|
|
];
|