2019-05-20 20:50:25 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2019-06-11 12:47:53 +00:00
|
|
|
import { isNil } from 'lodash';
|
2019-07-02 20:50:59 +00:00
|
|
|
import { SectionHeader } from '@woocommerce/components';
|
2020-09-01 13:21:31 +00:00
|
|
|
import { IMPORT_STORE_NAME } from '@woocommerce/data';
|
|
|
|
import { withSelect } from '@wordpress/data';
|
2019-07-02 20:50:59 +00:00
|
|
|
|
2019-05-20 20:50:25 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-06-11 12:47:53 +00:00
|
|
|
import { formatParams, getStatus } from './utils';
|
2019-05-20 20:50:25 +00:00
|
|
|
import HistoricalDataActions from './actions';
|
|
|
|
import HistoricalDataPeriodSelector from './period-selector';
|
|
|
|
import HistoricalDataProgress from './progress';
|
|
|
|
import HistoricalDataStatus from './status';
|
|
|
|
import HistoricalDataSkipCheckbox from './skip-checkbox';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
class HistoricalDataLayout extends Component {
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
customersProgress,
|
|
|
|
customersTotal,
|
|
|
|
dateFormat,
|
|
|
|
importDate,
|
|
|
|
inProgress,
|
2020-09-01 13:21:31 +00:00
|
|
|
lastImportStartTimestamp,
|
|
|
|
clearStatusAndTotalsCache,
|
2019-05-20 20:50:25 +00:00
|
|
|
ordersProgress,
|
|
|
|
ordersTotal,
|
2020-09-01 13:21:31 +00:00
|
|
|
onImportStarted,
|
2019-05-20 20:50:25 +00:00
|
|
|
period,
|
2020-09-01 13:21:31 +00:00
|
|
|
stopImport,
|
2019-05-20 20:50:25 +00:00
|
|
|
skipChecked,
|
2020-09-01 13:21:31 +00:00
|
|
|
status,
|
2019-05-20 20:50:25 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2020-02-14 02:23:21 +00:00
|
|
|
<SectionHeader
|
2022-03-30 09:00:04 +00:00
|
|
|
title={ __( 'Import historical data', 'woocommerce' ) }
|
2020-02-14 02:23:21 +00:00
|
|
|
/>
|
2019-07-02 20:50:59 +00:00
|
|
|
<div className="woocommerce-settings__wrapper">
|
|
|
|
<div className="woocommerce-setting">
|
|
|
|
<div className="woocommerce-setting__input">
|
|
|
|
<span className="woocommerce-setting__help">
|
|
|
|
{ __(
|
|
|
|
'This tool populates historical analytics data by processing customers ' +
|
|
|
|
'and orders created prior to activating WooCommerce Admin.',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2019-07-02 20:50:59 +00:00
|
|
|
) }
|
|
|
|
</span>
|
|
|
|
{ status !== 'finished' && (
|
|
|
|
<Fragment>
|
|
|
|
<HistoricalDataPeriodSelector
|
|
|
|
dateFormat={ dateFormat }
|
|
|
|
disabled={ inProgress }
|
|
|
|
value={ period }
|
|
|
|
/>
|
|
|
|
<HistoricalDataSkipCheckbox
|
|
|
|
disabled={ inProgress }
|
|
|
|
checked={ skipChecked }
|
|
|
|
/>
|
|
|
|
<HistoricalDataProgress
|
2020-02-14 02:23:21 +00:00
|
|
|
label={ __(
|
|
|
|
'Registered Customers',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2020-02-14 02:23:21 +00:00
|
|
|
) }
|
2019-07-02 20:50:59 +00:00
|
|
|
progress={ customersProgress }
|
|
|
|
total={ customersTotal }
|
|
|
|
/>
|
|
|
|
<HistoricalDataProgress
|
2020-02-14 02:23:21 +00:00
|
|
|
label={ __(
|
|
|
|
'Orders and Refunds',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2020-02-14 02:23:21 +00:00
|
|
|
) }
|
2019-07-02 20:50:59 +00:00
|
|
|
progress={ ordersProgress }
|
|
|
|
total={ ordersTotal }
|
|
|
|
/>
|
|
|
|
</Fragment>
|
2019-05-20 20:50:25 +00:00
|
|
|
) }
|
2020-02-14 02:23:21 +00:00
|
|
|
<HistoricalDataStatus
|
|
|
|
importDate={ importDate }
|
|
|
|
status={ status }
|
|
|
|
/>
|
2019-07-02 20:50:59 +00:00
|
|
|
</div>
|
2019-05-20 20:50:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<HistoricalDataActions
|
2020-09-01 13:21:31 +00:00
|
|
|
clearStatusAndTotalsCache={ clearStatusAndTotalsCache }
|
|
|
|
dateFormat={ dateFormat }
|
2019-06-11 12:47:53 +00:00
|
|
|
importDate={ importDate }
|
2020-09-01 13:21:31 +00:00
|
|
|
lastImportStartTimestamp={ lastImportStartTimestamp }
|
|
|
|
onImportStarted={ onImportStarted }
|
|
|
|
stopImport={ stopImport }
|
2019-06-11 12:47:53 +00:00
|
|
|
status={ status }
|
2019-05-20 20:50:25 +00:00
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withSelect( ( select, props ) => {
|
2020-09-01 13:21:31 +00:00
|
|
|
const { getImportError, getImportStatus, getImportTotals } = select(
|
|
|
|
IMPORT_STORE_NAME
|
|
|
|
);
|
2019-06-11 12:47:53 +00:00
|
|
|
const {
|
|
|
|
activeImport,
|
2020-09-01 13:21:31 +00:00
|
|
|
cacheNeedsClearing,
|
2019-06-11 12:47:53 +00:00
|
|
|
dateFormat,
|
2020-09-01 13:21:31 +00:00
|
|
|
inProgress,
|
2019-06-11 12:47:53 +00:00
|
|
|
onImportStarted,
|
|
|
|
onImportFinished,
|
|
|
|
period,
|
2020-09-01 13:21:31 +00:00
|
|
|
startStatusCheckInterval,
|
2019-06-11 12:47:53 +00:00
|
|
|
skipChecked,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const params = formatParams( dateFormat, period, skipChecked );
|
2020-09-01 13:21:31 +00:00
|
|
|
const { customers, orders, lastImportStartTimestamp } = getImportTotals(
|
|
|
|
params
|
2020-02-14 02:23:21 +00:00
|
|
|
);
|
2019-05-20 20:50:25 +00:00
|
|
|
|
2019-06-11 12:47:53 +00:00
|
|
|
const {
|
2020-01-02 16:00:37 +00:00
|
|
|
customers: customersStatus,
|
2019-06-11 12:47:53 +00:00
|
|
|
imported_from: importDate,
|
|
|
|
is_importing: isImporting,
|
2020-01-02 16:00:37 +00:00
|
|
|
orders: ordersStatus,
|
2020-09-01 13:21:31 +00:00
|
|
|
} = getImportStatus( lastImportStartTimestamp );
|
2020-02-14 02:23:21 +00:00
|
|
|
const { imported: customersProgress, total: customersTotal } =
|
|
|
|
customersStatus || {};
|
2020-01-02 16:00:37 +00:00
|
|
|
const { imported: ordersProgress, total: ordersTotal } = ordersStatus || {};
|
2020-09-01 13:21:31 +00:00
|
|
|
|
|
|
|
const isError = Boolean(
|
|
|
|
getImportError( lastImportStartTimestamp ) || getImportError( params )
|
2020-02-14 02:23:21 +00:00
|
|
|
);
|
2019-06-11 12:47:53 +00:00
|
|
|
|
|
|
|
const hasImportStarted = Boolean(
|
2020-09-01 13:21:31 +00:00
|
|
|
! lastImportStartTimestamp && ! inProgress && isImporting === true
|
2019-06-11 12:47:53 +00:00
|
|
|
);
|
|
|
|
if ( hasImportStarted ) {
|
|
|
|
onImportStarted();
|
|
|
|
}
|
2020-09-01 13:21:31 +00:00
|
|
|
|
2019-06-11 12:47:53 +00:00
|
|
|
const hasImportFinished = Boolean(
|
2020-09-01 13:21:31 +00:00
|
|
|
inProgress &&
|
|
|
|
! cacheNeedsClearing &&
|
2019-06-11 12:47:53 +00:00
|
|
|
isImporting === false &&
|
2020-09-01 13:21:31 +00:00
|
|
|
( customersTotal > 0 || ordersTotal > 0 ) &&
|
|
|
|
customersProgress === customersTotal &&
|
|
|
|
ordersProgress === ordersTotal
|
2019-05-20 20:50:25 +00:00
|
|
|
);
|
2019-06-11 12:47:53 +00:00
|
|
|
|
2020-09-01 13:21:31 +00:00
|
|
|
let response = {
|
|
|
|
customersTotal: customers,
|
|
|
|
isError,
|
|
|
|
ordersTotal: orders,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( activeImport ) {
|
|
|
|
response = {
|
|
|
|
cacheNeedsClearing,
|
|
|
|
customersProgress,
|
|
|
|
customersTotal: isNil( customersTotal )
|
|
|
|
? customers
|
|
|
|
: customersTotal,
|
|
|
|
inProgress,
|
|
|
|
isError,
|
|
|
|
ordersProgress,
|
|
|
|
ordersTotal: isNil( ordersTotal ) ? orders : ordersTotal,
|
2019-06-11 12:47:53 +00:00
|
|
|
};
|
|
|
|
}
|
2019-05-20 20:50:25 +00:00
|
|
|
|
2020-09-01 13:21:31 +00:00
|
|
|
const status = getStatus( response );
|
|
|
|
|
|
|
|
if ( status === 'initializing' ) {
|
|
|
|
startStatusCheckInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( hasImportFinished ) {
|
|
|
|
onImportFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
return { ...response, importDate, status };
|
2019-05-20 20:50:25 +00:00
|
|
|
} )( HistoricalDataLayout );
|