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
|
|
|
|
2018-09-17 02:26:34 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-08-27 19:33:31 +00:00
|
|
|
import { advancedFilters, 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';
|
2019-06-27 02:44:39 +00:00
|
|
|
import ReportFilters from 'analytics/components/report-filters';
|
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;
|
2019-03-07 02:57:22 +00:00
|
|
|
const isCompareView =
|
|
|
|
'compare-coupons' === query.filter && query.coupons && query.coupons.split( ',' ).length > 1;
|
2019-02-21 15:16:44 +00:00
|
|
|
|
|
|
|
const mode = isCompareView ? 'item-comparison' : 'time-comparison';
|
2019-03-13 17:14:02 +00:00
|
|
|
const itemsLabel = __( '%d coupons', 'woocommerce-admin' );
|
2019-02-21 15:16:44 +00:00
|
|
|
|
|
|
|
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>
|
2019-08-27 19:33:31 +00:00
|
|
|
<ReportFilters
|
|
|
|
query={ query }
|
|
|
|
path={ path }
|
|
|
|
filters={ filters }
|
|
|
|
advancedFilters={ advancedFilters }
|
|
|
|
report="coupons"
|
|
|
|
/>
|
2018-11-16 13:39:29 +00:00
|
|
|
<ReportSummary
|
|
|
|
charts={ charts }
|
2018-12-21 02:13:57 +00:00
|
|
|
endpoint="coupons"
|
2019-02-27 14:43:34 +00:00
|
|
|
isRequesting={ isRequesting }
|
2019-02-21 15:16:44 +00:00
|
|
|
query={ chartQuery }
|
2018-11-16 13:39:29 +00:00
|
|
|
selectedChart={ getSelectedChart( query.chart, charts ) }
|
2019-03-21 03:25:05 +00:00
|
|
|
filters={ filters }
|
2019-08-27 19:33:31 +00:00
|
|
|
advancedFilters={ advancedFilters }
|
2018-11-16 13:39:29 +00:00
|
|
|
/>
|
|
|
|
<ReportChart
|
2019-02-21 15:16:44 +00:00
|
|
|
filters={ filters }
|
2019-08-27 19:33:31 +00:00
|
|
|
advancedFilters={ advancedFilters }
|
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 }
|
2019-02-27 14:43:34 +00:00
|
|
|
isRequesting={ isRequesting }
|
2019-02-21 15:16:44 +00:00
|
|
|
itemsLabel={ itemsLabel }
|
2018-11-16 13:39:29 +00:00
|
|
|
selectedChart={ getSelectedChart( query.chart, charts ) }
|
|
|
|
/>
|
2019-08-27 19:33:31 +00:00
|
|
|
<CouponsReportTable
|
|
|
|
isRequesting={ isRequesting }
|
|
|
|
query={ query }
|
|
|
|
filters={ filters }
|
|
|
|
advancedFilters={ advancedFilters }
|
|
|
|
/>
|
2018-09-17 02:26:34 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 13:39:29 +00:00
|
|
|
|
|
|
|
CouponsReport.propTypes = {
|
|
|
|
query: PropTypes.object.isRequired,
|
|
|
|
};
|