2018-09-17 02:26:34 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-07-13 22:17:51 +00:00
|
|
|
import { __, _x } from '@wordpress/i18n';
|
2019-05-20 01:57:06 +00:00
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2021-04-22 20:06:46 +00:00
|
|
|
import { dispatch } from '@wordpress/data';
|
2023-03-16 14:22:33 +00:00
|
|
|
import { STORE_KEY as CES_STORE_KEY } from '@woocommerce/customer-effort-score';
|
2018-09-17 02:26:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-08-13 02:05:22 +00:00
|
|
|
import { getCouponLabels } from '../../../lib/async-requests';
|
2018-09-17 02:26:34 +00:00
|
|
|
|
2019-12-05 22:38:26 +00:00
|
|
|
const COUPON_REPORT_CHARTS_FILTER = 'woocommerce_admin_coupons_report_charts';
|
|
|
|
const COUPON_REPORT_FILTERS_FILTER = 'woocommerce_admin_coupons_report_filters';
|
2020-02-14 02:23:21 +00:00
|
|
|
const COUPON_REPORT_ADVANCED_FILTERS_FILTER =
|
|
|
|
'woocommerce_admin_coupon_report_advanced_filters';
|
2019-05-20 01:57:06 +00:00
|
|
|
|
2021-04-22 20:06:46 +00:00
|
|
|
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
|
|
|
|
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* @typedef {import('../index.js').chart} chart
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Coupons Report charts filter.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_coupons_report_charts
|
|
|
|
* @param {Array.<chart>} charts Report charts.
|
|
|
|
*/
|
2019-08-28 14:55:55 +00:00
|
|
|
export const charts = applyFilters( COUPON_REPORT_CHARTS_FILTER, [
|
2018-11-16 13:39:29 +00:00
|
|
|
{
|
2018-12-21 02:13:57 +00:00
|
|
|
key: 'orders_count',
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Discounted orders', 'woocommerce' ),
|
2019-02-15 10:54:41 +00:00
|
|
|
order: 'desc',
|
|
|
|
orderby: 'orders_count',
|
2018-11-16 13:39:29 +00:00
|
|
|
type: 'number',
|
|
|
|
},
|
|
|
|
{
|
2018-12-21 02:13:57 +00:00
|
|
|
key: 'amount',
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Amount', 'woocommerce' ),
|
2019-02-15 10:54:41 +00:00
|
|
|
order: 'desc',
|
|
|
|
orderby: 'amount',
|
2018-11-16 13:39:29 +00:00
|
|
|
type: 'currency',
|
|
|
|
},
|
2019-05-20 01:57:06 +00:00
|
|
|
] );
|
2018-11-16 13:39:29 +00:00
|
|
|
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* Coupons Report Advanced Filters.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_coupon_report_advanced_filters
|
2022-03-18 11:45:14 +00:00
|
|
|
* @param {Object} advancedFilters Report Advanced Filters.
|
|
|
|
* @param {string} advancedFilters.title Interpolated component string for Advanced Filters title.
|
2022-02-11 14:38:38 +00:00
|
|
|
* @param {Object} advancedFilters.filters An object specifying a report's Advanced Filters.
|
|
|
|
*/
|
2021-07-13 22:17:51 +00:00
|
|
|
export const advancedFilters = applyFilters(
|
|
|
|
COUPON_REPORT_ADVANCED_FILTERS_FILTER,
|
2018-09-17 02:26:34 +00:00
|
|
|
{
|
2021-07-13 22:17:51 +00:00
|
|
|
filters: {},
|
|
|
|
title: _x(
|
2023-04-26 10:58:14 +00:00
|
|
|
'Coupons match <select/> filters',
|
2021-07-13 22:17:51 +00:00
|
|
|
'A sentence describing filters for Coupons. See screen shot for context: https://cloudup.com/cSsUY9VeCVJ',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-07-13 22:17:51 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const filterValues = [
|
2022-03-30 09:00:04 +00:00
|
|
|
{ label: __( 'All coupons', 'woocommerce' ), value: 'all' },
|
2021-07-13 22:17:51 +00:00
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Single coupon', 'woocommerce' ),
|
2021-07-13 22:17:51 +00:00
|
|
|
value: 'select_coupon',
|
|
|
|
chartMode: 'item-comparison',
|
|
|
|
subFilters: [
|
2019-01-20 22:31:03 +00:00
|
|
|
{
|
2021-07-13 22:17:51 +00:00
|
|
|
component: 'Search',
|
|
|
|
value: 'single_coupon',
|
2019-01-20 22:31:03 +00:00
|
|
|
chartMode: 'item-comparison',
|
2021-07-13 22:17:51 +00:00
|
|
|
path: [ 'select_coupon' ],
|
2018-10-29 01:30:24 +00:00
|
|
|
settings: {
|
|
|
|
type: 'coupons',
|
2018-11-16 13:39:29 +00:00
|
|
|
param: 'coupons',
|
2019-01-24 09:35:27 +00:00
|
|
|
getLabels: getCouponLabels,
|
2018-10-29 01:30:24 +00:00
|
|
|
labels: {
|
2021-07-13 22:17:51 +00:00
|
|
|
placeholder: __(
|
|
|
|
'Type to search for a coupon',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2020-02-14 02:23:21 +00:00
|
|
|
),
|
2022-03-30 09:00:04 +00:00
|
|
|
button: __( 'Single Coupon', 'woocommerce' ),
|
2018-10-29 01:30:24 +00:00
|
|
|
},
|
|
|
|
},
|
2018-09-17 02:26:34 +00:00
|
|
|
},
|
2018-10-29 01:30:24 +00:00
|
|
|
],
|
2018-09-17 02:26:34 +00:00
|
|
|
},
|
2021-07-13 22:17:51 +00:00
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Comparison', 'woocommerce' ),
|
2021-07-13 22:17:51 +00:00
|
|
|
value: 'compare-coupons',
|
|
|
|
settings: {
|
|
|
|
type: 'coupons',
|
|
|
|
param: 'coupons',
|
|
|
|
getLabels: getCouponLabels,
|
|
|
|
labels: {
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Compare Coupon Codes', 'woocommerce' ),
|
|
|
|
update: __( 'Compare', 'woocommerce' ),
|
2021-07-13 22:17:51 +00:00
|
|
|
helpText: __(
|
|
|
|
'Check at least two coupon codes below to compare',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-07-13 22:17:51 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
onClick: addCesSurveyForAnalytics,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
2019-08-27 19:33:31 +00:00
|
|
|
|
2021-07-13 22:17:51 +00:00
|
|
|
if ( Object.keys( advancedFilters.filters ).length ) {
|
|
|
|
filterValues.push( {
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Advanced filters', 'woocommerce' ),
|
2021-07-13 22:17:51 +00:00
|
|
|
value: 'advanced',
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* @typedef {import('../index.js').filter} filter
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Coupons Report Filters.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_coupons_report_filters
|
|
|
|
* @param {Array.<filter>} filters Report filters.
|
|
|
|
*/
|
2021-07-13 22:17:51 +00:00
|
|
|
export const filters = applyFilters( COUPON_REPORT_FILTERS_FILTER, [
|
|
|
|
{
|
2022-03-30 09:00:04 +00:00
|
|
|
label: __( 'Show', 'woocommerce' ),
|
2021-07-13 22:17:51 +00:00
|
|
|
staticParams: [ 'chartType', 'paged', 'per_page' ],
|
|
|
|
param: 'filter',
|
|
|
|
showFilters: () => true,
|
|
|
|
filters: filterValues,
|
|
|
|
},
|
|
|
|
] );
|