2018-12-06 22:21:46 +00:00
/** @format */
/ * *
* External dependencies
* /
2018-12-10 20:01:22 +00:00
import { _ _ , _x } from '@wordpress/i18n' ;
2018-12-14 15:13:34 +00:00
import { decodeEntities } from '@wordpress/html-entities' ;
2019-08-23 16:41:42 +00:00
import { applyFilters } from '@wordpress/hooks' ;
2018-12-17 20:50:45 +00:00
/ * *
* Internal dependencies
* /
2019-01-24 09:35:27 +00:00
import { getCustomerLabels , getRequestByIdString } from 'lib/async-requests' ;
2019-01-30 07:22:10 +00:00
import { NAMESPACE } from 'wc-api/constants' ;
2018-12-06 22:21:46 +00:00
2019-08-23 16:41:42 +00:00
const CUSTOMERS _REPORT _FILTERS _FILTER = 'woocommerce_admin_customers_report_filters' ;
const CUSTOMERS _REPORT _ADVANCED _FILTERS _FILTER =
'woocommerce_admin_customers_report_advanced_filters' ;
export const filters = applyFilters ( CUSTOMERS _REPORT _FILTERS _FILTER , [
2018-12-06 22:21:46 +00:00
{
2019-03-13 17:14:02 +00:00
label : _ _ ( 'Show' , 'woocommerce-admin' ) ,
2018-12-06 22:21:46 +00:00
staticParams : [ ] ,
param : 'filter' ,
showFilters : ( ) => true ,
2018-12-10 20:01:22 +00:00
filters : [
2019-03-13 17:14:02 +00:00
{ label : _ _ ( 'All Customers' , 'woocommerce-admin' ) , value : 'all' } ,
2019-03-18 02:39:54 +00:00
{
label : _ _ ( 'Single Customer' , 'woocommerce-admin' ) ,
value : 'select_customer' ,
chartMode : 'item-comparison' ,
subFilters : [
{
component : 'Search' ,
value : 'single_customer' ,
chartMode : 'item-comparison' ,
path : [ 'select_customer' ] ,
settings : {
type : 'customers' ,
param : 'customers' ,
getLabels : getCustomerLabels ,
labels : {
placeholder : _ _ ( 'Type to search for a customer' , 'woocommerce-admin' ) ,
button : _ _ ( 'Single Customer' , 'woocommerce-admin' ) ,
} ,
} ,
} ,
] ,
} ,
2019-03-13 17:14:02 +00:00
{ label : _ _ ( 'Advanced Filters' , 'woocommerce-admin' ) , value : 'advanced' } ,
2018-12-10 20:01:22 +00:00
] ,
2018-12-06 22:21:46 +00:00
} ,
2019-08-23 16:41:42 +00:00
] ) ;
2018-12-10 20:01:22 +00:00
/*eslint-disable max-len*/
2019-08-23 16:41:42 +00:00
export const advancedFilters = applyFilters ( CUSTOMERS _REPORT _ADVANCED _FILTERS _FILTER , {
2018-12-10 20:01:22 +00:00
title : _x (
'Customers Match {{select /}} Filters' ,
'A sentence describing filters for Customers. See screen shot for context: https://cloudup.com/cCsm3GeXJbE' ,
2019-03-13 17:14:02 +00:00
'woocommerce-admin'
2018-12-10 20:01:22 +00:00
) ,
filters : {
name : {
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'Name' , 'woocommerce-admin' ) ,
placeholder : _ _ ( 'Search' , 'woocommerce-admin' ) ,
remove : _ _ ( 'Remove customer name filter' , 'woocommerce-admin' ) ,
rule : _ _ ( 'Select a customer name filter match' , 'woocommerce-admin' ) ,
2018-12-10 22:18:45 +00:00
/* translators: A sentence describing a Product filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
title : _ _ ( '{{title}}Name{{/title}} {{rule /}} {{filter /}}' , 'woocommerce-admin' ) ,
filter : _ _ ( 'Select customer name' , 'woocommerce-admin' ) ,
2018-12-10 20:01:22 +00:00
} ,
rules : [
{
value : 'includes' ,
2018-12-10 22:18:45 +00:00
/* translators: Sentence fragment, logical, "Includes" refers to customer names including a given name(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Includes' , 'customer names' , 'woocommerce-admin' ) ,
2018-12-10 20:01:22 +00:00
} ,
{
value : 'excludes' ,
2018-12-10 22:18:45 +00:00
/* translators: Sentence fragment, logical, "Excludes" refers to customer names excluding a given name(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Excludes' , 'customer names' , 'woocommerce-admin' ) ,
2018-12-10 20:01:22 +00:00
} ,
] ,
input : {
component : 'Search' ,
2018-12-13 15:21:11 +00:00
type : 'customers' ,
2019-02-04 08:51:29 +00:00
getLabels : getRequestByIdString ( NAMESPACE + '/customers' , customer => ( {
2018-12-13 15:21:11 +00:00
id : customer . id ,
2019-02-13 16:48:14 +00:00
label : customer . name ,
2018-12-10 20:01:22 +00:00
} ) ) ,
} ,
} ,
2018-12-14 15:13:34 +00:00
country : {
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'Country' , 'woocommerce-admin' ) ,
placeholder : _ _ ( 'Search' , 'woocommerce-admin' ) ,
remove : _ _ ( 'Remove country filter' , 'woocommerce-admin' ) ,
rule : _ _ ( 'Select a country filter match' , 'woocommerce-admin' ) ,
2018-12-14 15:13:34 +00:00
/* translators: A sentence describing a Product filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
title : _ _ ( '{{title}}Country{{/title}} {{rule /}} {{filter /}}' , 'woocommerce-admin' ) ,
filter : _ _ ( 'Select country' , 'woocommerce-admin' ) ,
2018-12-14 15:13:34 +00:00
} ,
rules : [
{
value : 'includes' ,
/* translators: Sentence fragment, logical, "Includes" refers to countries including a given country or countries. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Includes' , 'countries' , 'woocommerce-admin' ) ,
2018-12-14 15:13:34 +00:00
} ,
{
value : 'excludes' ,
/* translators: Sentence fragment, logical, "Excludes" refers to countries excluding a given country or countries. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Excludes' , 'countries' , 'woocommerce-admin' ) ,
2018-12-14 15:13:34 +00:00
} ,
] ,
input : {
component : 'Search' ,
type : 'countries' ,
getLabels : async value => {
const countries =
( wcSettings . dataEndpoints && wcSettings . dataEndpoints . countries ) || [ ] ;
const allLabels = countries . map ( country => ( {
id : country . code ,
label : decodeEntities ( country . name ) ,
} ) ) ;
const labels = value . split ( ',' ) ;
return await allLabels . filter ( label => {
return labels . includes ( label . id ) ;
} ) ;
} ,
} ,
} ,
2018-12-17 15:49:03 +00:00
username : {
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'Username' , 'woocommerce-admin' ) ,
placeholder : _ _ ( 'Search customer username' , 'woocommerce-admin' ) ,
remove : _ _ ( 'Remove customer username filter' , 'woocommerce-admin' ) ,
rule : _ _ ( 'Select a customer username filter match' , 'woocommerce-admin' ) ,
2018-12-17 15:49:03 +00:00
/* translators: A sentence describing a customer username filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
title : _ _ ( '{{title}}Username{{/title}} {{rule /}} {{filter /}}' , 'woocommerce-admin' ) ,
filter : _ _ ( 'Select customer username' , 'woocommerce-admin' ) ,
2018-12-17 15:49:03 +00:00
} ,
rules : [
{
value : 'includes' ,
/* translators: Sentence fragment, logical, "Includes" refers to customer usernames including a given username(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Includes' , 'customer usernames' , 'woocommerce-admin' ) ,
2018-12-17 15:49:03 +00:00
} ,
{
value : 'excludes' ,
/* translators: Sentence fragment, logical, "Excludes" refers to customer usernames excluding a given username(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Excludes' , 'customer usernames' , 'woocommerce-admin' ) ,
2018-12-17 15:49:03 +00:00
} ,
] ,
input : {
component : 'Search' ,
type : 'usernames' ,
2019-01-24 09:35:27 +00:00
getLabels : getCustomerLabels ,
2018-12-17 15:49:03 +00:00
} ,
} ,
2018-12-17 16:20:11 +00:00
email : {
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'Email' , 'woocommerce-admin' ) ,
placeholder : _ _ ( 'Search customer email' , 'woocommerce-admin' ) ,
remove : _ _ ( 'Remove customer email filter' , 'woocommerce-admin' ) ,
rule : _ _ ( 'Select a customer email filter match' , 'woocommerce-admin' ) ,
2018-12-17 16:20:11 +00:00
/* translators: A sentence describing a customer email filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
title : _ _ ( '{{title}}Email{{/title}} {{rule /}} {{filter /}}' , 'woocommerce-admin' ) ,
filter : _ _ ( 'Select customer email' , 'woocommerce-admin' ) ,
2018-12-17 16:20:11 +00:00
} ,
rules : [
{
value : 'includes' ,
/* translators: Sentence fragment, logical, "Includes" refers to customer emails including a given email(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Includes' , 'customer emails' , 'woocommerce-admin' ) ,
2018-12-17 16:20:11 +00:00
} ,
{
value : 'excludes' ,
/* translators: Sentence fragment, logical, "Excludes" refers to customer emails excluding a given email(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Excludes' , 'customer emails' , 'woocommerce-admin' ) ,
2018-12-17 16:20:11 +00:00
} ,
] ,
input : {
component : 'Search' ,
type : 'emails' ,
2019-02-04 08:51:29 +00:00
getLabels : getRequestByIdString ( NAMESPACE + '/customers' , customer => ( {
2018-12-17 16:20:11 +00:00
id : customer . id ,
label : customer . email ,
} ) ) ,
} ,
} ,
2019-01-29 00:35:27 +00:00
orders _count : {
2018-12-21 04:07:54 +00:00
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'No. of Orders' , 'woocommerce-admin' ) ,
2019-06-06 06:18:33 +00:00
remove : _ _ ( 'Remove order filter' , 'woocommerce-admin' ) ,
2019-03-13 17:14:02 +00:00
rule : _ _ ( 'Select an order count filter match' , 'woocommerce-admin' ) ,
title : _ _ (
'{{title}}No. of Orders{{/title}} {{rule /}} {{filter /}}' ,
'woocommerce-admin'
) ,
2018-12-21 04:07:54 +00:00
} ,
rules : [
{
value : 'max' ,
/* translators: Sentence fragment, logical, "Less Than" refers to number of orders a customer has placed, less than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Less Than' , 'number of orders' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
{
value : 'min' ,
/* translators: Sentence fragment, logical, "More Than" refers to number of orders a customer has placed, more than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'More Than' , 'number of orders' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
{
value : 'between' ,
/* translators: Sentence fragment, logical, "Between" refers to number of orders a customer has placed, between two given integers. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Between' , 'number of orders' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
] ,
input : {
component : 'Number' ,
} ,
} ,
total _spend : {
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'Total Spend' , 'woocommerce-admin' ) ,
remove : _ _ ( 'Remove total spend filter' , 'woocommerce-admin' ) ,
rule : _ _ ( 'Select a total spend filter match' , 'woocommerce-admin' ) ,
title : _ _ ( '{{title}}Total Spend{{/title}} {{rule /}} {{filter /}}' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
rules : [
{
value : 'max' ,
/* translators: Sentence fragment, logical, "Less Than" refers to total spending by a customer, less than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Less Than' , 'total spend by customer' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
{
value : 'min' ,
/* translators: Sentence fragment, logical, "Less Than" refers to total spending by a customer, more than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'More Than' , 'total spend by customer' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
{
value : 'between' ,
/* translators: Sentence fragment, logical, "Between" refers to total spending by a customer, between two given amounts. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Between' , 'total spend by customer' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
] ,
input : {
component : 'Currency' ,
} ,
} ,
avg _order _value : {
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'AOV' , 'woocommerce-admin' ) ,
2019-06-06 05:54:28 +00:00
remove : _ _ ( 'Remove average order value filter' , 'woocommerce-admin' ) ,
2019-03-13 17:14:02 +00:00
rule : _ _ ( 'Select an average order value filter match' , 'woocommerce-admin' ) ,
title : _ _ ( '{{title}}AOV{{/title}} {{rule /}} {{filter /}}' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
rules : [
{
value : 'max' ,
/* translators: Sentence fragment, logical, "Less Than" refers to average order value of a customer, more than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Less Than' , 'average order value of customer' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
{
value : 'min' ,
/* translators: Sentence fragment, logical, "Less Than" refers to average order value of a customer, less than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'More Than' , 'average order value of customer' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
{
value : 'between' ,
/* translators: Sentence fragment, logical, "Between" refers to average order value of a customer, between two given amounts. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Between' , 'average order value of customer' , 'woocommerce-admin' ) ,
2018-12-21 04:07:54 +00:00
} ,
] ,
input : {
component : 'Currency' ,
} ,
} ,
2018-12-10 22:06:21 +00:00
registered : {
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'Registered' , 'woocommerce-admin' ) ,
remove : _ _ ( 'Remove registered filter' , 'woocommerce-admin' ) ,
rule : _ _ ( 'Select a registered filter match' , 'woocommerce-admin' ) ,
2018-12-10 22:06:21 +00:00
/* translators: A sentence describing a Product filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
title : _ _ ( '{{title}}Registered{{/title}} {{rule /}} {{filter /}}' , 'woocommerce-admin' ) ,
filter : _ _ ( 'Select registered date' , 'woocommerce-admin' ) ,
2018-12-10 22:06:21 +00:00
} ,
rules : [
{
value : 'before' ,
/* translators: Sentence fragment, logical, "Before" refers to customers registered before a given date. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Before' , 'date' , 'woocommerce-admin' ) ,
2018-12-10 22:06:21 +00:00
} ,
{
value : 'after' ,
/* translators: Sentence fragment, logical, "after" refers to customers registered after a given date. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'After' , 'date' , 'woocommerce-admin' ) ,
2018-12-10 22:06:21 +00:00
} ,
{
value : 'between' ,
/* translators: Sentence fragment, logical, "Between" refers to average order value of a customer, between two given amounts. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Between' , 'date' , 'woocommerce-admin' ) ,
2018-12-10 22:06:21 +00:00
} ,
] ,
input : {
component : 'Date' ,
} ,
} ,
2019-01-15 00:02:24 +00:00
last _active : {
labels : {
2019-03-13 17:14:02 +00:00
add : _ _ ( 'Last active' , 'woocommerce-admin' ) ,
remove : _ _ ( 'Remove last active filter' , 'woocommerce-admin' ) ,
rule : _ _ ( 'Select a last active filter match' , 'woocommerce-admin' ) ,
2019-01-15 00:02:24 +00:00
/* translators: A sentence describing a Product filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
title : _ _ ( '{{title}}Last active{{/title}} {{rule /}} {{filter /}}' , 'woocommerce-admin' ) ,
filter : _ _ ( 'Select registered date' , 'woocommerce-admin' ) ,
2019-01-15 00:02:24 +00:00
} ,
rules : [
{
value : 'before' ,
/* translators: Sentence fragment, logical, "Before" refers to customers registered before a given date. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Before' , 'date' , 'woocommerce-admin' ) ,
2019-01-15 00:02:24 +00:00
} ,
{
value : 'after' ,
/* translators: Sentence fragment, logical, "after" refers to customers registered after a given date. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'After' , 'date' , 'woocommerce-admin' ) ,
2019-01-15 00:02:24 +00:00
} ,
{
value : 'between' ,
/* translators: Sentence fragment, logical, "Between" refers to average order value of a customer, between two given amounts. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
2019-03-13 17:14:02 +00:00
label : _x ( 'Between' , 'date' , 'woocommerce-admin' ) ,
2019-01-15 00:02:24 +00:00
} ,
] ,
input : {
component : 'Date' ,
} ,
} ,
2018-12-10 20:01:22 +00:00
} ,
2019-08-23 16:41:42 +00:00
} ) ;
2018-12-10 20:01:22 +00:00
/*eslint-enable max-len*/