2018-09-17 02:26:34 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2018-11-16 13:39:29 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-02-21 15:16:44 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2018-11-16 13:39:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { ReportFilters } from '@woocommerce/components';
|
2018-09-17 02:26:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-11-16 13:39:29 +00:00
|
|
|
import { charts, filters } from './config';
|
2018-11-16 03:35:10 +00:00
|
|
|
import CouponsReportTable from './table';
|
2018-11-16 13:39:29 +00:00
|
|
|
import getSelectedChart from 'lib/get-selected-chart';
|
|
|
|
import ReportChart from 'analytics/components/report-chart';
|
|
|
|
import ReportSummary from 'analytics/components/report-summary';
|
2018-09-17 02:26:34 +00:00
|
|
|
|
2018-11-16 13:39:29 +00:00
|
|
|
export default class CouponsReport extends Component {
|
2019-02-21 15:16:44 +00:00
|
|
|
getChartMeta() {
|
|
|
|
const { query } = this.props;
|
|
|
|
const isCompareView = [ 'top_orders', 'top_discount', 'compare-coupons' ].includes(
|
|
|
|
query.filter
|
|
|
|
);
|
|
|
|
|
|
|
|
const mode = isCompareView ? 'item-comparison' : 'time-comparison';
|
|
|
|
const itemsLabel = __( '%d coupons', 'wc-admin' );
|
|
|
|
|
|
|
|
return {
|
|
|
|
itemsLabel,
|
|
|
|
mode,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-09-17 02:26:34 +00:00
|
|
|
render() {
|
2019-02-26 09:28:50 +00:00
|
|
|
const { isRequesting, query, path } = this.props;
|
2019-02-21 15:16:44 +00:00
|
|
|
const { mode, itemsLabel } = this.getChartMeta();
|
|
|
|
|
|
|
|
const chartQuery = {
|
|
|
|
...query,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( 'item-comparison' === mode ) {
|
|
|
|
chartQuery.segmentby = 'coupon';
|
|
|
|
}
|
2018-09-17 02:26:34 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ReportFilters query={ query } path={ path } filters={ filters } />
|
2018-11-16 13:39:29 +00:00
|
|
|
<ReportSummary
|
|
|
|
charts={ charts }
|
2018-12-21 02:13:57 +00:00
|
|
|
endpoint="coupons"
|
2019-02-21 15:16:44 +00:00
|
|
|
query={ chartQuery }
|
2018-11-16 13:39:29 +00:00
|
|
|
selectedChart={ getSelectedChart( query.chart, charts ) }
|
|
|
|
/>
|
|
|
|
<ReportChart
|
2019-02-21 15:16:44 +00:00
|
|
|
filters={ filters }
|
2018-11-16 13:39:29 +00:00
|
|
|
charts={ charts }
|
2019-02-21 15:16:44 +00:00
|
|
|
mode={ mode }
|
2018-12-21 02:13:57 +00:00
|
|
|
endpoint="coupons"
|
2018-11-16 13:39:29 +00:00
|
|
|
path={ path }
|
2019-02-21 15:16:44 +00:00
|
|
|
query={ chartQuery }
|
|
|
|
itemsLabel={ itemsLabel }
|
2018-11-16 13:39:29 +00:00
|
|
|
selectedChart={ getSelectedChart( query.chart, charts ) }
|
|
|
|
/>
|
2019-02-26 09:28:50 +00:00
|
|
|
<CouponsReportTable isRequesting={ isRequesting } query={ query } />
|
2018-09-17 02:26:34 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 13:39:29 +00:00
|
|
|
|
|
|
|
CouponsReport.propTypes = {
|
|
|
|
query: PropTypes.object.isRequired,
|
|
|
|
};
|