From 34aa71cfbb1204d3d9d46d773f237f2de26fc870 Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Mon, 20 May 2019 13:57:06 +1200 Subject: [PATCH] Dashboard Charts: simplify data --- .../components/report-chart/index.js | 23 +++++++++++++- .../components/report-summary/index.js | 16 ++++++++++ .../analytics/report/categories/config.js | 7 +++-- .../analytics/report/categories/index.js | 1 - .../client/analytics/report/coupons/config.js | 7 +++-- .../client/analytics/report/coupons/index.js | 1 - .../analytics/report/downloads/config.js | 7 +++-- .../analytics/report/downloads/index.js | 1 - .../client/analytics/report/orders/config.js | 7 +++-- .../client/analytics/report/orders/index.js | 1 - .../analytics/report/products/config.js | 7 +++-- .../client/analytics/report/products/index.js | 1 - .../client/analytics/report/revenue/config.js | 7 +++-- .../client/analytics/report/revenue/index.js | 1 - .../client/analytics/report/taxes/config.js | 7 +++-- .../client/analytics/report/taxes/index.js | 1 - .../dashboard/dashboard-charts/config.js | 30 +++++++++++++------ .../client/dashboard/default-sections.js | 1 + .../class-wc-admin-analytics-dashboard.php | 2 +- 19 files changed, 96 insertions(+), 32 deletions(-) diff --git a/plugins/woocommerce-admin/client/analytics/components/report-chart/index.js b/plugins/woocommerce-admin/client/analytics/components/report-chart/index.js index e7e04033256..a148a2020f7 100644 --- a/plugins/woocommerce-admin/client/analytics/components/report-chart/index.js +++ b/plugins/woocommerce-admin/client/analytics/components/report-chart/index.js @@ -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 = { diff --git a/plugins/woocommerce-admin/client/analytics/components/report-summary/index.js b/plugins/woocommerce-admin/client/analytics/components/report-summary/index.js index 94a2440e172..c177aeae34a 100644 --- a/plugins/woocommerce-admin/client/analytics/components/report-summary/index.js +++ b/plugins/woocommerce-admin/client/analytics/components/report-summary/index.js @@ -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. diff --git a/plugins/woocommerce-admin/client/analytics/report/categories/config.js b/plugins/woocommerce-admin/client/analytics/report/categories/config.js index e975eb20392..c8528aadea4 100644 --- a/plugins/woocommerce-admin/client/analytics/report/categories/config.js +++ b/plugins/woocommerce-admin/client/analytics/report/categories/config.js @@ -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 = [ { diff --git a/plugins/woocommerce-admin/client/analytics/report/categories/index.js b/plugins/woocommerce-admin/client/analytics/report/categories/index.js index 82c8f93e390..2f853fa8b82 100644 --- a/plugins/woocommerce-admin/client/analytics/report/categories/index.js +++ b/plugins/woocommerce-admin/client/analytics/report/categories/index.js @@ -68,7 +68,6 @@ export default class CategoriesReport extends Component { /> ( { ...d, endpoint: 'orders' } ) ) - .concat( - 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' } ) ) - ); +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' } ) ), + categoriesCharts.map( d => ( { ...d, endpoint: 'categories' } ) ), + couponsCharts.map( d => ( { ...d, endpoint: 'orders' } ) ), + taxesCharts.map( d => ( { ...d, endpoint: 'taxes' } ) ), + downloadsCharts.map( d => ( { ...d, endpoint: 'downloads' } ) ) + ) +); // Need to remove duplicate charts, by key, from the configs export const uniqCharts = allCharts.reduce( ( a, b ) => { diff --git a/plugins/woocommerce-admin/client/dashboard/default-sections.js b/plugins/woocommerce-admin/client/dashboard/default-sections.js index 71346df6826..0856352dc30 100644 --- a/plugins/woocommerce-admin/client/dashboard/default-sections.js +++ b/plugins/woocommerce-admin/client/dashboard/default-sections.js @@ -50,6 +50,7 @@ export default applyFilters( DEFAULT_SECTIONS_FILTER, [ 'total_tax', 'order_tax', 'shipping_tax', + 'download_count', ], }, { diff --git a/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php b/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php index fcda49a22de..1296079bd36 100644 --- a/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php +++ b/plugins/woocommerce-admin/includes/features/analytics-dashboard/class-wc-admin-analytics-dashboard.php @@ -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