2019-01-31 01:04:11 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
|
|
|
import interpolateComponents from 'interpolate-components';
|
|
|
|
|
2019-03-22 08:48:20 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-05-22 21:43:04 +00:00
|
|
|
import DefaultDate from './default-date';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminSetting, ORDER_STATUSES } from '~/utils/admin-settings';
|
2019-03-22 08:48:20 +00:00
|
|
|
|
2019-01-31 01:04:11 +00:00
|
|
|
const SETTINGS_FILTER = 'woocommerce_admin_analytics_settings';
|
2020-03-25 03:20:17 +00:00
|
|
|
export const DEFAULT_ACTIONABLE_STATUSES = [ 'processing', 'on-hold' ];
|
|
|
|
export const DEFAULT_ORDER_STATUSES = [
|
2019-01-31 01:04:11 +00:00
|
|
|
'completed',
|
|
|
|
'processing',
|
|
|
|
'refunded',
|
|
|
|
'cancelled',
|
|
|
|
'failed',
|
|
|
|
'pending',
|
|
|
|
'on-hold',
|
|
|
|
];
|
2020-03-25 03:20:17 +00:00
|
|
|
export const DEFAULT_DATE_RANGE = 'period=month&compare=previous_year';
|
2019-07-05 14:12:03 +00:00
|
|
|
|
2020-03-25 03:20:17 +00:00
|
|
|
const filteredOrderStatuses = Object.keys( ORDER_STATUSES )
|
2020-04-10 14:42:03 +00:00
|
|
|
.filter( ( status ) => status !== 'refunded' )
|
|
|
|
.map( ( key ) => {
|
2019-01-31 01:04:11 +00:00
|
|
|
return {
|
|
|
|
value: key,
|
2019-09-23 21:47:08 +00:00
|
|
|
label: ORDER_STATUSES[ key ],
|
2019-01-31 01:04:11 +00:00
|
|
|
description: sprintf(
|
2019-03-13 17:14:02 +00:00
|
|
|
__( 'Exclude the %s status from reports', 'woocommerce-admin' ),
|
2019-09-23 21:47:08 +00:00
|
|
|
ORDER_STATUSES[ key ]
|
2019-01-31 01:04:11 +00:00
|
|
|
),
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
2022-01-06 12:53:30 +00:00
|
|
|
const unregisteredOrderStatuses = getAdminSetting(
|
|
|
|
'unregisteredOrderStatuses',
|
|
|
|
{}
|
|
|
|
);
|
2020-04-10 14:42:03 +00:00
|
|
|
|
|
|
|
const orderStatusOptions = [
|
|
|
|
{
|
|
|
|
key: 'defaultStatuses',
|
|
|
|
options: filteredOrderStatuses.filter( ( status ) =>
|
|
|
|
DEFAULT_ORDER_STATUSES.includes( status.value )
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'customStatuses',
|
|
|
|
label: __( 'Custom Statuses', 'woocommerce-admin' ),
|
|
|
|
options: filteredOrderStatuses.filter(
|
|
|
|
( status ) => ! DEFAULT_ORDER_STATUSES.includes( status.value )
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'unregisteredStatuses',
|
|
|
|
label: __( 'Unregistered Statuses', 'woocommerce-admin' ),
|
|
|
|
options: Object.keys( unregisteredOrderStatuses ).map( ( key ) => {
|
|
|
|
return {
|
|
|
|
value: key,
|
|
|
|
label: key,
|
|
|
|
description: sprintf(
|
|
|
|
__(
|
|
|
|
'Exclude the %s status from reports',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
key
|
|
|
|
),
|
|
|
|
};
|
|
|
|
} ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* Filter Analytics Report settings. Add a UI element to the Analytics Settings page.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_analytics_settings
|
|
|
|
* @param {Object} reportSettings Report settings.
|
|
|
|
*/
|
2020-03-25 03:20:17 +00:00
|
|
|
export const config = applyFilters( SETTINGS_FILTER, {
|
|
|
|
woocommerce_excluded_report_order_statuses: {
|
2021-08-13 18:54:24 +00:00
|
|
|
label: __( 'Excluded statuses:', 'woocommerce-admin' ),
|
2019-01-31 01:04:11 +00:00
|
|
|
inputType: 'checkboxGroup',
|
2020-04-10 14:42:03 +00:00
|
|
|
options: orderStatusOptions,
|
2019-01-31 01:04:11 +00:00
|
|
|
helpText: interpolateComponents( {
|
|
|
|
mixedString: __(
|
|
|
|
'Orders with these statuses are excluded from the totals in your reports. ' +
|
2019-07-02 19:42:29 +00:00
|
|
|
'The {{strong}}Refunded{{/strong}} status can not be excluded.',
|
2019-03-13 17:14:02 +00:00
|
|
|
'woocommerce-admin'
|
2019-01-31 01:04:11 +00:00
|
|
|
),
|
|
|
|
components: {
|
|
|
|
strong: <strong />,
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
defaultValue: [ 'pending', 'cancelled', 'failed' ],
|
|
|
|
},
|
2020-03-25 03:20:17 +00:00
|
|
|
woocommerce_actionable_order_statuses: {
|
2021-08-13 18:54:24 +00:00
|
|
|
label: __( 'Actionable statuses:', 'woocommerce-admin' ),
|
2019-03-06 05:14:38 +00:00
|
|
|
inputType: 'checkboxGroup',
|
2020-04-10 14:42:03 +00:00
|
|
|
options: orderStatusOptions,
|
2019-03-06 05:14:38 +00:00
|
|
|
helpText: __(
|
2020-11-06 01:21:05 +00:00
|
|
|
'Orders with these statuses require action on behalf of the store admin. ' +
|
|
|
|
'These orders will show up in the Home Screen - Orders task.',
|
2019-03-13 17:14:02 +00:00
|
|
|
'woocommerce-admin'
|
2019-03-06 05:14:38 +00:00
|
|
|
),
|
2019-03-22 08:48:20 +00:00
|
|
|
defaultValue: DEFAULT_ACTIONABLE_STATUSES,
|
2019-03-06 05:14:38 +00:00
|
|
|
},
|
2020-03-25 03:20:17 +00:00
|
|
|
woocommerce_default_date_range: {
|
2019-05-22 21:43:04 +00:00
|
|
|
name: 'woocommerce_default_date_range',
|
2021-08-13 18:54:24 +00:00
|
|
|
label: __( 'Default date range:', 'woocommerce-admin' ),
|
2019-05-22 21:43:04 +00:00
|
|
|
inputType: 'component',
|
|
|
|
component: DefaultDate,
|
|
|
|
helpText: __(
|
|
|
|
'Select a default date range. When no range is selected, reports will be viewed by ' +
|
|
|
|
'the default date range.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2019-09-23 21:47:08 +00:00
|
|
|
defaultValue: DEFAULT_DATE_RANGE,
|
2019-05-22 21:43:04 +00:00
|
|
|
},
|
2020-03-25 03:20:17 +00:00
|
|
|
} );
|