Merge pull request woocommerce/woocommerce-admin#2258 from woocommerce/fix/dashboard-charts-data

Dashboard: Extend charts data
This commit is contained in:
Paul Sealock 2019-05-21 08:18:25 +12:00 committed by GitHub
commit 765fbc6799
19 changed files with 96 additions and 32 deletions

View File

@ -229,7 +229,28 @@ ReportChart.propTypes = {
/**
* Properties of the selected chart.
*/
selectedChart: PropTypes.object.isRequired,
selectedChart: PropTypes.shape( {
/**
* Key of the selected chart.
*/
key: PropTypes.string.isRequired,
/**
* Chart label.
*/
label: PropTypes.string.isRequired,
/**
* Order query argument.
*/
order: PropTypes.oneOf( [ 'asc', 'desc' ] ),
/**
* Order by query argument.
*/
orderby: PropTypes.string,
/**
* Number type for formatting.
*/
type: PropTypes.oneOf( [ 'average', 'number', 'currency' ] ).isRequired,
} ).isRequired,
};
ReportChart.defaultProps = {

View File

@ -129,6 +129,22 @@ ReportSummary.propTypes = {
* Key of the selected chart.
*/
key: PropTypes.string.isRequired,
/**
* Chart label.
*/
label: PropTypes.string.isRequired,
/**
* Order query argument.
*/
order: PropTypes.oneOf( [ 'asc', 'desc' ] ),
/**
* Order by query argument.
*/
orderby: PropTypes.string,
/**
* Number type for formatting.
*/
type: PropTypes.oneOf( [ 'average', 'number', 'currency' ] ).isRequired,
} ).isRequired,
/**
* Data to display in the SummaryNumbers.

View File

@ -3,13 +3,16 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import { getCategoryLabels } from 'lib/async-requests';
export const charts = [
const CATEGORY_REPORT_CHART_FILTER = 'woocommerce_admin_category_report_chart_filter';
export const charts = applyFilters( CATEGORY_REPORT_CHART_FILTER, [
{
key: 'items_sold',
label: __( 'Items Sold', 'woocommerce-admin' ),
@ -31,7 +34,7 @@ export const charts = [
orderby: 'orders_count',
type: 'number',
},
];
] );
export const filters = [
{

View File

@ -68,7 +68,6 @@ export default class CategoriesReport extends Component {
/>
<ReportChart
filters={ filters }
charts={ charts }
mode={ mode }
endpoint="products"
limitProperties={ isSingleCategoryView ? [ 'products', 'categories' ] : [ 'categories' ] }

View File

@ -3,13 +3,16 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import { getCouponLabels } from 'lib/async-requests';
export const charts = [
const COUPON_REPORT_CHART_FILTER = 'woocommerce_admin_coupon_report_chart_filter';
export const charts = applyFilters( COUPON_REPORT_CHART_FILTER, [
{
key: 'orders_count',
label: __( 'Discounted Orders', 'woocommerce-admin' ),
@ -24,7 +27,7 @@ export const charts = [
orderby: 'amount',
type: 'currency',
},
];
] );
export const filters = [
{

View File

@ -60,7 +60,6 @@ export default class CouponsReport extends Component {
/>
<ReportChart
filters={ filters }
charts={ charts }
mode={ mode }
endpoint="coupons"
path={ path }

View File

@ -3,19 +3,22 @@
* External dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import { getCustomerLabels, getProductLabels } from 'lib/async-requests';
export const charts = [
const DOWLOADS_REPORT_CHART_FILTER = 'woocommerce_admin_downloads_report_chart_filter';
export const charts = applyFilters( DOWLOADS_REPORT_CHART_FILTER, [
{
key: 'download_count',
label: __( 'Downloads', 'woocommerce-admin' ),
type: 'number',
},
];
] );
export const filters = [
{

View File

@ -40,7 +40,6 @@ export default class DownloadsReport extends Component {
advancedFilters={ advancedFilters }
/>
<ReportChart
charts={ charts }
endpoint="downloads"
path={ path }
query={ query }

View File

@ -3,6 +3,7 @@
* External dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
@ -11,7 +12,9 @@ import { getCouponLabels, getProductLabels } from 'lib/async-requests';
const { orderStatuses } = wcSettings;
export const charts = [
const ORDERS_REPORT_CHART_FILTER = 'woocommerce_admin_orders_report_chart_filter';
export const charts = applyFilters( ORDERS_REPORT_CHART_FILTER, [
{
key: 'orders_count',
label: __( 'Orders Count', 'woocommerce-admin' ),
@ -36,7 +39,7 @@ export const charts = [
orderby: 'num_items_sold',
type: 'average',
},
];
] );
export const filters = [
{

View File

@ -40,7 +40,6 @@ export default class OrdersReport extends Component {
advancedFilters={ advancedFilters }
/>
<ReportChart
charts={ charts }
endpoint="orders"
path={ path }
query={ query }

View File

@ -3,13 +3,16 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import { getProductLabels, getVariationLabels } from 'lib/async-requests';
export const charts = [
const PRODUCTS_REPORT_CHART_FILTER = 'woocommerce_admin_products_report_chart_filter';
export const charts = applyFilters( PRODUCTS_REPORT_CHART_FILTER, [
{
key: 'items_sold',
label: __( 'Items Sold', 'woocommerce-admin' ),
@ -31,7 +34,7 @@ export const charts = [
orderby: 'orders_count',
type: 'number',
},
];
] );
const filterConfig = {
label: __( 'Show', 'woocommerce-admin' ),

View File

@ -81,7 +81,6 @@ class ProductsReport extends Component {
<ReportChart
mode={ mode }
filters={ filters }
charts={ charts }
endpoint="products"
isRequesting={ isRequesting }
itemsLabel={ itemsLabel }

View File

@ -3,8 +3,11 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
export const charts = [
const REVENUE_REPORT_CHART_FILTER = 'woocommerce_admin_revenue_report_chart_filter';
export const charts = applyFilters( REVENUE_REPORT_CHART_FILTER, [
{
key: 'gross_revenue',
label: __( 'Gross Revenue', 'woocommerce-admin' ),
@ -45,4 +48,4 @@ export const charts = [
orderby: 'net_revenue',
type: 'currency',
},
];
] );

View File

@ -33,7 +33,6 @@ export default class RevenueReport extends Component {
selectedChart={ getSelectedChart( query.chart, charts ) }
/>
<ReportChart
charts={ charts }
endpoint="revenue"
path={ path }
query={ query }

View File

@ -3,6 +3,7 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
@ -11,7 +12,9 @@ import { getRequestByIdString } from 'lib/async-requests';
import { getTaxCode } from './utils';
import { NAMESPACE } from 'wc-api/constants';
export const charts = [
const TAXES_REPORT_CHART_FILTER = 'woocommerce_admin_taxes_report_chart_filter';
export const charts = applyFilters( TAXES_REPORT_CHART_FILTER, [
{
key: 'total_tax',
label: __( 'Total Tax', 'woocommerce-admin' ),
@ -40,7 +43,7 @@ export const charts = [
orderby: 'orders_count',
type: 'number',
},
];
] );
export const filters = [
{

View File

@ -57,7 +57,6 @@ export default class TaxesReport extends Component {
/>
<ReportChart
filters={ filters }
charts={ charts }
mode={ mode }
endpoint="taxes"
query={ chartQuery }

View File

@ -1,4 +1,9 @@
/** @format */
/**
* External dependencies
*/
import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
*/
@ -9,15 +14,22 @@ import { charts as revenueCharts } from 'analytics/report/revenue/config';
import { charts as categoriesCharts } from 'analytics/report/categories/config';
import { charts as couponsCharts } from 'analytics/report/coupons/config';
import { charts as taxesCharts } from 'analytics/report/taxes/config';
import { charts as downloadsCharts } from 'analytics/report/downloads/config';
const allCharts = ordersCharts
const DASHBOARD_CHARTS_FILTER = 'woocommerce_admin_dashboard_charts_filter';
const allCharts = applyFilters(
DASHBOARD_CHARTS_FILTER,
revenueCharts
.map( d => ( { ...d, endpoint: 'orders' } ) )
.concat(
ordersCharts.map( d => ( { ...d, endpoint: 'revenue' } ) ),
productsCharts.map( d => ( { ...d, endpoint: 'products' } ) ),
revenueCharts.map( d => ( { ...d, endpoint: 'revenue' } ) ),
categoriesCharts.map( d => ( { ...d, endpoint: 'categories' } ) ),
couponsCharts.map( d => ( { ...d, endpoint: 'orders' } ) ),
taxesCharts.map( d => ( { ...d, endpoint: 'taxes' } ) )
taxesCharts.map( d => ( { ...d, endpoint: 'taxes' } ) ),
downloadsCharts.map( d => ( { ...d, endpoint: 'downloads' } ) )
)
);
// Need to remove duplicate charts, by key, from the configs

View File

@ -50,6 +50,7 @@ export default applyFilters( DEFAULT_SECTIONS_FILTER, [
'total_tax',
'order_tax',
'shipping_tax',
'download_count',
],
},
{

View File

@ -44,7 +44,7 @@ class WC_Admin_Analytics_Dashboard {
}
/**
* Preload data from the performance indicators endpoint.
* Preload data from API endpoints.
*
* @param array $endpoints Array of preloaded endpoints.
* @return array