2019-01-31 01:04:11 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2019-03-06 05:32:05 +00:00
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
2019-01-31 01:04:11 +00:00
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
|
|
|
import interpolateComponents from 'interpolate-components';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { Link } from '@woocommerce/components';
|
|
|
|
|
|
|
|
const SETTINGS_FILTER = 'woocommerce_admin_analytics_settings';
|
|
|
|
|
|
|
|
const defaultOrderStatuses = [
|
|
|
|
'completed',
|
|
|
|
'processing',
|
|
|
|
'refunded',
|
|
|
|
'cancelled',
|
|
|
|
'failed',
|
|
|
|
'pending',
|
|
|
|
'on-hold',
|
|
|
|
];
|
|
|
|
const orderStatuses = Object.keys( wcSettings.orderStatuses )
|
|
|
|
.filter( status => status !== 'refunded' )
|
|
|
|
.map( key => {
|
|
|
|
return {
|
|
|
|
value: key,
|
|
|
|
label: wcSettings.orderStatuses[ key ],
|
|
|
|
description: sprintf(
|
2019-03-13 17:14:02 +00:00
|
|
|
__( 'Exclude the %s status from reports', 'woocommerce-admin' ),
|
2019-01-31 01:04:11 +00:00
|
|
|
wcSettings.orderStatuses[ key ]
|
|
|
|
),
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
export const analyticsSettings = applyFilters( SETTINGS_FILTER, [
|
2019-03-12 13:13:20 +00:00
|
|
|
{
|
|
|
|
name: 'woocommerce_rebuild_reports_data',
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Rebuild reports data:', 'woocommerce-admin' ),
|
2019-03-12 13:13:20 +00:00
|
|
|
inputType: 'button',
|
2019-03-13 17:14:02 +00:00
|
|
|
inputText: __( 'Rebuild reports', 'woocommerce-admin' ),
|
2019-03-12 13:13:20 +00:00
|
|
|
helpText: __(
|
|
|
|
'This tool will rebuild all of the information used by the reports. ' +
|
|
|
|
'Data will be processed in the background and may take some time depending on the size of your store.',
|
2019-03-13 17:14:02 +00:00
|
|
|
'woocommerce-admin'
|
2019-03-12 13:13:20 +00:00
|
|
|
),
|
|
|
|
callback: ( resolve, reject, addNotice ) => {
|
2019-03-13 17:14:02 +00:00
|
|
|
const errorMessage = __(
|
|
|
|
'There was a problem rebuilding your report data.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
);
|
2019-03-12 13:13:20 +00:00
|
|
|
|
|
|
|
apiFetch( { path: '/wc/v3/system_status/tools/rebuild_stats', method: 'PUT' } )
|
|
|
|
.then( response => {
|
|
|
|
if ( response.success ) {
|
|
|
|
addNotice( { status: 'success', message: response.message } );
|
|
|
|
// @todo This should be changed to detect when the lookup table population is complete.
|
|
|
|
setTimeout( () => resolve(), 300000 );
|
|
|
|
} else {
|
|
|
|
addNotice( { status: 'error', message: errorMessage } );
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.catch( error => {
|
|
|
|
if ( error && error.message ) {
|
|
|
|
addNotice( { status: 'error', message: error.message } );
|
|
|
|
}
|
|
|
|
reject();
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
},
|
2019-01-31 01:04:11 +00:00
|
|
|
{
|
|
|
|
name: 'woocommerce_excluded_report_order_statuses',
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Excluded Statuses:', 'woocommerce-admin' ),
|
2019-01-31 01:04:11 +00:00
|
|
|
inputType: 'checkboxGroup',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
key: 'defaultStatuses',
|
|
|
|
options: orderStatuses.filter( status => defaultOrderStatuses.includes( status.value ) ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'customStatuses',
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Custom Statuses', 'woocommerce-admin' ),
|
2019-01-31 01:04:11 +00:00
|
|
|
options: orderStatuses.filter( status => ! defaultOrderStatuses.includes( status.value ) ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
helpText: interpolateComponents( {
|
|
|
|
mixedString: __(
|
|
|
|
'Orders with these statuses are excluded from the totals in your reports. ' +
|
|
|
|
'The {{strong}}Refunded{{/strong}} status can not be excluded. {{moreLink}}Learn more{{/moreLink}}',
|
2019-03-13 17:14:02 +00:00
|
|
|
'woocommerce-admin'
|
2019-01-31 01:04:11 +00:00
|
|
|
),
|
|
|
|
components: {
|
|
|
|
strong: <strong />,
|
2019-02-06 06:41:53 +00:00
|
|
|
moreLink: <Link href="#" type="external" />, // @todo This needs to be replaced with a real link.
|
2019-01-31 01:04:11 +00:00
|
|
|
},
|
|
|
|
} ),
|
|
|
|
initialValue: wcSettings.wcAdminSettings.woocommerce_excluded_report_order_statuses || [],
|
|
|
|
defaultValue: [ 'pending', 'cancelled', 'failed' ],
|
|
|
|
},
|
2019-03-06 05:14:38 +00:00
|
|
|
{
|
|
|
|
name: 'woocommerce_actionable_order_statuses',
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Actionable Statuses:', 'woocommerce-admin' ),
|
2019-03-06 05:14:38 +00:00
|
|
|
inputType: 'checkboxGroup',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
key: 'defaultStatuses',
|
|
|
|
options: orderStatuses.filter( status => defaultOrderStatuses.includes( status.value ) ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'customStatuses',
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Custom Statuses', 'woocommerce-admin' ),
|
2019-03-06 05:14:38 +00:00
|
|
|
options: orderStatuses.filter( status => ! defaultOrderStatuses.includes( status.value ) ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
helpText: __(
|
|
|
|
'Orders with these statuses require action on behalf of the store admin.' +
|
|
|
|
'These orders will show up in the Orders tab under the activity panel.',
|
2019-03-13 17:14:02 +00:00
|
|
|
'woocommerce-admin'
|
2019-03-06 05:14:38 +00:00
|
|
|
),
|
|
|
|
initialValue: wcSettings.wcAdminSettings.woocommerce_actionable_order_statuses || [],
|
|
|
|
defaultValue: [ 'processing', 'on-hold' ],
|
|
|
|
},
|
2019-01-31 01:04:11 +00:00
|
|
|
] );
|