Replace Rebuild reports settings with Import Historical Data (https://github.com/woocommerce/woocommerce-admin/pull/2198)

* Hide progress bars and status from Import Historical Data screen

* Remove Rebuild Reports Sections from Settings

* Add Delete Imported Data button to the default actions

* Unify @todo comments
This commit is contained in:
Albert Juhé Lluveras 2019-05-10 11:34:03 +02:00 committed by GitHub
parent c6a6e737c4
commit 54a09ab232
3 changed files with 41 additions and 60 deletions

View File

@ -3,7 +3,6 @@
* External dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';
import { applyFilters } from '@wordpress/hooks';
import interpolateComponents from 'interpolate-components';
@ -42,41 +41,6 @@ const orderStatuses = Object.keys( wcSettings.orderStatuses )
} );
export const analyticsSettings = applyFilters( SETTINGS_FILTER, [
{
name: 'woocommerce_rebuild_reports_data',
label: __( 'Rebuild reports data:', 'woocommerce-admin' ),
inputType: 'button',
inputText: __( 'Rebuild reports', 'woocommerce-admin' ),
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.',
'woocommerce-admin'
),
callback: ( resolve, reject, addNotice ) => {
const errorMessage = __(
'There was a problem rebuilding your report data.',
'woocommerce-admin'
);
apiFetch( { path: '/wc/v4/reports/import', method: 'PUT' } )
.then( response => {
if ( 'success' === response.status ) {
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();
} );
},
},
{
name: 'woocommerce_excluded_report_order_statuses',
label: __( 'Excluded Statuses:', 'woocommerce-admin' ),

View File

@ -46,10 +46,18 @@ function HistoricalDataActions( {
// Has no imported data
if ( ! hasImportedData ) {
// @todo When the import status endpoint is hooked up,
// the 'Delete Previously Imported Data' button should be
// removed from this section.
return (
<Button isPrimary onClick={ onStartImport }>
{ __( 'Start', 'woocommerce-admin' ) }
</Button>
<Fragment>
<Button isPrimary onClick={ onStartImport }>
{ __( 'Start', 'woocommerce-admin' ) }
</Button>
<Button isDefault onClick={ onDeletePreviousData }>
{ __( 'Delete Previously Imported Data', 'woocommerce-admin' ) }
</Button>
</Fragment>
);
}

View File

@ -30,6 +30,7 @@ class HistoricalData extends Component {
this.dateFormat = __( 'MM/DD/YYYY', 'woocommerce-admin' );
this.state = {
inProgress: false,
period: {
date: moment().format( this.dateFormat ),
label: 'all',
@ -74,6 +75,9 @@ class HistoricalData extends Component {
onStartImport() {
const { period, skipChecked } = this.state;
this.setState( {
inProgress: true,
} );
const params = {};
if ( skipChecked ) {
params.skip_existing = true;
@ -99,6 +103,9 @@ class HistoricalData extends Component {
}
onStopImport() {
this.setState( {
inProgress: false,
} );
const path = '/wc/v4/reports/import/cancel';
const errorMessage = __(
'There was a problem stopping your current import.',
@ -132,13 +139,8 @@ class HistoricalData extends Component {
}
getStatus() {
const {
customersProgress,
customersTotal,
inProgress,
ordersProgress,
ordersTotal,
} = this.props;
const { customersProgress, customersTotal, ordersProgress, ordersTotal } = this.props;
const { inProgress } = this.state;
if ( inProgress ) {
if ( customersProgress < customersTotal ) {
@ -165,16 +167,18 @@ class HistoricalData extends Component {
customersTotal,
hasImportedData,
importDate,
inProgress,
ordersProgress,
ordersTotal,
} = this.props;
const { period, skipChecked } = this.state;
const { inProgress, period, skipChecked } = this.state;
const hasImportedAllData =
! inProgress &&
hasImportedData &&
customersProgress === customersTotal &&
ordersProgress === ordersTotal;
// @todo When the import status endpoint is hooked up,
// this bool should be removed and assume it's true.
const showImportStatus = false;
return (
<Fragment>
@ -204,19 +208,25 @@ class HistoricalData extends Component {
checked={ skipChecked }
onChange={ this.onSkipChange }
/>
<HistoricalDataProgress
label={ __( 'Registered Customers', 'woocommerce-admin' ) }
progress={ customersProgress }
total={ customersTotal }
/>
<HistoricalDataProgress
label={ __( 'Orders', 'woocommerce-admin' ) }
progress={ ordersProgress }
total={ ordersTotal }
/>
{ showImportStatus && (
<Fragment>
<HistoricalDataProgress
label={ __( 'Registered Customers', 'woocommerce-admin' ) }
progress={ customersProgress }
total={ customersTotal }
/>
<HistoricalDataProgress
label={ __( 'Orders', 'woocommerce-admin' ) }
progress={ ordersProgress }
total={ ordersTotal }
/>
</Fragment>
) }
</Fragment>
) }
<HistoricalDataStatus importDate={ importDate } status={ this.getStatus() } />
{ showImportStatus && (
<HistoricalDataStatus importDate={ importDate } status={ this.getStatus() } />
) }
</div>
</div>
<HistoricalDataActions
@ -241,7 +251,6 @@ export default withSelect( () => {
customersTotal: 0,
hasImportedData: false,
importDate: '2019-04-01',
inProgress: false,
ordersProgress: 0,
ordersTotal: 0,
};