-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
config.js
140 lines (130 loc) · 3.44 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* External dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { applyFilters } from '@wordpress/hooks';
import { dispatch } from '@wordpress/data';
import { STORE_KEY as CES_STORE_KEY } from '@woocommerce/customer-effort-score';
/**
* Internal dependencies
*/
import { getCouponLabels } from '../../../lib/async-requests';
const COUPON_REPORT_CHARTS_FILTER = 'woocommerce_admin_coupons_report_charts';
const COUPON_REPORT_FILTERS_FILTER = 'woocommerce_admin_coupons_report_filters';
const COUPON_REPORT_ADVANCED_FILTERS_FILTER =
'woocommerce_admin_coupon_report_advanced_filters';
const { addCesSurveyForAnalytics } = dispatch( CES_STORE_KEY );
/**
* @typedef {import('../index.js').chart} chart
*/
/**
* Coupons Report charts filter.
*
* @filter woocommerce_admin_coupons_report_charts
* @param {Array.<chart>} charts Report charts.
*/
export const charts = applyFilters( COUPON_REPORT_CHARTS_FILTER, [
{
key: 'orders_count',
label: __( 'Discounted orders', 'woocommerce' ),
order: 'desc',
orderby: 'orders_count',
type: 'number',
},
{
key: 'amount',
label: __( 'Amount', 'woocommerce' ),
order: 'desc',
orderby: 'amount',
type: 'currency',
},
] );
/**
* Coupons Report Advanced Filters.
*
* @filter woocommerce_admin_coupon_report_advanced_filters
* @param {Object} advancedFilters Report Advanced Filters.
* @param {string} advancedFilters.title Interpolated component string for Advanced Filters title.
* @param {Object} advancedFilters.filters An object specifying a report's Advanced Filters.
*/
export const advancedFilters = applyFilters(
COUPON_REPORT_ADVANCED_FILTERS_FILTER,
{
filters: {},
title: _x(
'Coupons match {{select /}} filters',
'A sentence describing filters for Coupons. See screen shot for context: https://cloudup.com/cSsUY9VeCVJ',
'woocommerce'
),
}
);
const filterValues = [
{ label: __( 'All coupons', 'woocommerce' ), value: 'all' },
{
label: __( 'Single coupon', 'woocommerce' ),
value: 'select_coupon',
chartMode: 'item-comparison',
subFilters: [
{
component: 'Search',
value: 'single_coupon',
chartMode: 'item-comparison',
path: [ 'select_coupon' ],
settings: {
type: 'coupons',
param: 'coupons',
getLabels: getCouponLabels,
labels: {
placeholder: __(
'Type to search for a coupon',
'woocommerce'
),
button: __( 'Single Coupon', 'woocommerce' ),
},
},
},
],
},
{
label: __( 'Comparison', 'woocommerce' ),
value: 'compare-coupons',
settings: {
type: 'coupons',
param: 'coupons',
getLabels: getCouponLabels,
labels: {
title: __( 'Compare Coupon Codes', 'woocommerce' ),
update: __( 'Compare', 'woocommerce' ),
helpText: __(
'Check at least two coupon codes below to compare',
'woocommerce'
),
},
onClick: addCesSurveyForAnalytics,
},
},
];
if ( Object.keys( advancedFilters.filters ).length ) {
filterValues.push( {
label: __( 'Advanced filters', 'woocommerce' ),
value: 'advanced',
} );
}
/**
* @typedef {import('../index.js').filter} filter
*/
/**
* Coupons Report Filters.
*
* @filter woocommerce_admin_coupons_report_filters
* @param {Array.<filter>} filters Report filters.
*/
export const filters = applyFilters( COUPON_REPORT_FILTERS_FILTER, [
{
label: __( 'Show', 'woocommerce' ),
staticParams: [ 'chartType', 'paged', 'per_page' ],
param: 'filter',
showFilters: () => true,
filters: filterValues,
},
] );