2018-09-17 02:26:34 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
2020-11-24 23:18:50 +00:00
|
|
|
import { withDispatch } from '@wordpress/data';
|
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';
|
2020-08-13 02:05:22 +00:00
|
|
|
import getSelectedChart from '../../../lib/get-selected-chart';
|
|
|
|
import ReportChart from '../../components/report-chart';
|
|
|
|
import ReportSummary from '../../components/report-summary';
|
|
|
|
import ReportFilters from '../../components/report-filters';
|
2020-11-24 23:18:50 +00:00
|
|
|
import { STORE_KEY as CES_STORE_KEY } from '../../../customer-effort-score-tracks/data/constants';
|
2018-09-17 02:26:34 +00:00
|
|
|
|
2020-11-24 23:18:50 +00:00
|
|
|
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 =
|
2020-02-14 02:23:21 +00:00
|
|
|
query.filter === 'compare-coupons' &&
|
|
|
|
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() {
|
2020-11-24 23:18:50 +00:00
|
|
|
const {
|
|
|
|
isRequesting,
|
|
|
|
query,
|
|
|
|
path,
|
|
|
|
addCesSurveyForAnalytics,
|
|
|
|
} = this.props;
|
2019-02-21 15:16:44 +00:00
|
|
|
const { mode, itemsLabel } = this.getChartMeta();
|
|
|
|
|
2020-11-24 23:18:50 +00:00
|
|
|
filters[ 0 ].filters.find(
|
|
|
|
( item ) => item.value === 'compare-coupons'
|
|
|
|
).settings.onClick = addCesSurveyForAnalytics;
|
|
|
|
|
2019-02-21 15:16:44 +00:00
|
|
|
const chartQuery = {
|
|
|
|
...query,
|
|
|
|
};
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
if ( mode === 'item-comparison' ) {
|
2019-02-21 15:16:44 +00:00
|
|
|
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
|
2020-03-31 15:08:40 +00:00
|
|
|
charts={ charts }
|
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,
|
|
|
|
};
|
2020-11-24 23:18:50 +00:00
|
|
|
|
|
|
|
export default withDispatch( ( dispatch ) => {
|
|
|
|
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
|
|
|
|
return { addCesSurveyForAnalytics };
|
|
|
|
} )( CouponsReport );
|