From ffee7cc8413d03f839251e91feb3b2d2e197315f Mon Sep 17 00:00:00 2001 From: Jonathan Belcher Date: Wed, 7 Nov 2018 11:38:34 -0500 Subject: [PATCH] Moves charts to config to delete chart.js (https://github.com/woocommerce/woocommerce-admin/pull/793) --- .../client/analytics/report/orders/chart.js | 80 ------------------- .../client/analytics/report/orders/config.js | 23 ++++++ .../client/analytics/report/orders/index.js | 29 ++++++- 3 files changed, 49 insertions(+), 83 deletions(-) delete mode 100644 plugins/woocommerce-admin/client/analytics/report/orders/chart.js diff --git a/plugins/woocommerce-admin/client/analytics/report/orders/chart.js b/plugins/woocommerce-admin/client/analytics/report/orders/chart.js deleted file mode 100644 index 37c23409123..00000000000 --- a/plugins/woocommerce-admin/client/analytics/report/orders/chart.js +++ /dev/null @@ -1,80 +0,0 @@ -/** @format */ -/** - * External dependencies - */ -import { __ } from '@wordpress/i18n'; -import { Component, Fragment } from '@wordpress/element'; -import { find } from 'lodash'; -import PropTypes from 'prop-types'; - -/** - * Internal dependencies - */ -import ReportChart from 'analytics/components/report-chart'; -import ReportSummary from 'analytics/components/report-summary'; - -class OrdersReportChart extends Component { - getCharts() { - return [ - { - key: 'orders_count', - label: __( 'Orders Count', 'wc-admin' ), - type: 'number', - }, - { - key: 'net_revenue', - label: __( 'Net Revenue', 'wc-admin' ), - type: 'currency', - }, - { - key: 'avg_order_value', - label: __( 'Average Order Value', 'wc-admin' ), - type: 'currency', - }, - { - key: 'avg_items_per_order', - label: __( 'Average Items Per Order', 'wc-admin' ), - type: 'average', - }, - ]; - } - - getSelectedChart() { - const { query } = this.props; - const charts = this.getCharts(); - const chart = find( charts, { key: query.chart } ); - if ( chart ) { - return chart; - } - - return charts[ 0 ]; - } - - render() { - const { path, query } = this.props; - return ( - - - - - ); - } -} - -OrdersReportChart.propTypes = { - path: PropTypes.string.isRequired, - query: PropTypes.object.isRequired, -}; - -export default OrdersReportChart; diff --git a/plugins/woocommerce-admin/client/analytics/report/orders/config.js b/plugins/woocommerce-admin/client/analytics/report/orders/config.js index c70b86cbdb1..65f1ab01850 100644 --- a/plugins/woocommerce-admin/client/analytics/report/orders/config.js +++ b/plugins/woocommerce-admin/client/analytics/report/orders/config.js @@ -12,6 +12,29 @@ import { NAMESPACE } from 'store/constants'; const { orderStatuses } = wcSettings; +export const charts = [ + { + key: 'orders_count', + label: __( 'Orders Count', 'wc-admin' ), + type: 'number', + }, + { + key: 'net_revenue', + label: __( 'Net Revenue', 'wc-admin' ), + type: 'currency', + }, + { + key: 'avg_order_value', + label: __( 'Average Order Value', 'wc-admin' ), + type: 'currency', + }, + { + key: 'avg_items_per_order', + label: __( 'Average Items Per Order', 'wc-admin' ), + type: 'average', + }, +]; + export const filters = [ { label: __( 'Show', 'wc-admin' ), diff --git a/plugins/woocommerce-admin/client/analytics/report/orders/index.js b/plugins/woocommerce-admin/client/analytics/report/orders/index.js index 0091ac66cb9..c0c4eaae252 100644 --- a/plugins/woocommerce-admin/client/analytics/report/orders/index.js +++ b/plugins/woocommerce-admin/client/analytics/report/orders/index.js @@ -13,11 +13,22 @@ import { ReportFilters } from '@woocommerce/components'; /** * Internal dependencies */ -import { advancedFilters, filters } from './config'; -import OrdersReportChart from './chart'; +import { advancedFilters, charts, filters } from './config'; import OrdersReportTable from './table'; +import ReportChart from 'analytics/components/report-chart'; +import ReportSummary from 'analytics/components/report-summary'; export default class OrdersReport extends Component { + getSelectedChart() { + const { query } = this.props; + const chart = find( charts, { key: query.chart } ); + if ( chart ) { + return chart; + } + + return charts[ 0 ]; + } + render() { const { path, query } = this.props; @@ -29,7 +40,19 @@ export default class OrdersReport extends Component { filters={ filters } advancedFilters={ advancedFilters } /> - + + );