2018-05-15 15:06:15 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2018-08-20 21:24:17 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2019-02-01 09:55:19 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2018-06-14 20:15:11 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-08-20 21:24:17 +00:00
|
|
|
import { find } from 'lodash';
|
2018-05-15 15:06:15 +00:00
|
|
|
|
2018-11-15 18:16:23 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { useFilters } from '@woocommerce/components';
|
2019-02-01 09:55:19 +00:00
|
|
|
import { getQuery } from '@woocommerce/navigation';
|
2018-11-15 18:16:23 +00:00
|
|
|
|
2018-05-15 15:06:15 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
import './style.scss';
|
2018-09-21 15:19:05 +00:00
|
|
|
import Header from 'header';
|
2018-08-20 21:24:17 +00:00
|
|
|
import OrdersReport from './orders';
|
2018-07-12 01:43:33 +00:00
|
|
|
import ProductsReport from './products';
|
2018-08-20 21:24:17 +00:00
|
|
|
import RevenueReport from './revenue';
|
2018-11-16 13:33:58 +00:00
|
|
|
import CategoriesReport from './categories';
|
2018-09-17 02:26:34 +00:00
|
|
|
import CouponsReport from './coupons';
|
2018-11-14 21:04:59 +00:00
|
|
|
import TaxesReport from './taxes';
|
2018-12-17 20:50:45 +00:00
|
|
|
import DownloadsReport from './downloads';
|
2018-12-14 23:58:08 +00:00
|
|
|
import StockReport from './stock';
|
2018-12-06 22:21:46 +00:00
|
|
|
import CustomersReport from './customers';
|
2019-02-01 09:55:19 +00:00
|
|
|
import { searchItemsByString } from 'wc-api/items/utils';
|
|
|
|
import withSelect from 'wc-api/with-select';
|
2018-08-20 21:24:17 +00:00
|
|
|
|
|
|
|
const REPORTS_FILTER = 'woocommerce-reports-list';
|
|
|
|
|
|
|
|
const getReports = () => {
|
|
|
|
const reports = applyFilters( REPORTS_FILTER, [
|
|
|
|
{
|
|
|
|
report: 'revenue',
|
|
|
|
title: __( 'Revenue', 'wc-admin' ),
|
|
|
|
component: RevenueReport,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
report: 'products',
|
|
|
|
title: __( 'Products', 'wc-admin' ),
|
|
|
|
component: ProductsReport,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
report: 'orders',
|
|
|
|
title: __( 'Orders', 'wc-admin' ),
|
|
|
|
component: OrdersReport,
|
|
|
|
},
|
2018-11-16 13:33:58 +00:00
|
|
|
{
|
|
|
|
report: 'categories',
|
|
|
|
title: __( 'Categories', 'wc-admin' ),
|
|
|
|
component: CategoriesReport,
|
|
|
|
},
|
2018-09-17 02:26:34 +00:00
|
|
|
{
|
|
|
|
report: 'coupons',
|
|
|
|
title: __( 'Coupons', 'wc-admin' ),
|
|
|
|
component: CouponsReport,
|
|
|
|
},
|
2018-11-14 21:04:59 +00:00
|
|
|
{
|
|
|
|
report: 'taxes',
|
|
|
|
title: __( 'Taxes', 'wc-admin' ),
|
|
|
|
component: TaxesReport,
|
|
|
|
},
|
2018-12-17 20:50:45 +00:00
|
|
|
{
|
|
|
|
report: 'downloads',
|
|
|
|
title: __( 'Downloads', 'wc-admin' ),
|
|
|
|
component: DownloadsReport,
|
|
|
|
},
|
2018-12-14 23:58:08 +00:00
|
|
|
{
|
|
|
|
report: 'stock',
|
|
|
|
title: __( 'Stock', 'wc-admin' ),
|
|
|
|
component: StockReport,
|
|
|
|
},
|
2018-12-06 22:21:46 +00:00
|
|
|
{
|
|
|
|
report: 'customers',
|
|
|
|
title: __( 'Customers', 'wc-admin' ),
|
|
|
|
component: CustomersReport,
|
|
|
|
},
|
2018-12-19 11:18:43 +00:00
|
|
|
{
|
|
|
|
report: 'downloads',
|
|
|
|
title: __( 'Downloads', 'wc-admin' ),
|
|
|
|
component: DownloadsReport,
|
|
|
|
},
|
2018-08-20 21:24:17 +00:00
|
|
|
] );
|
|
|
|
|
|
|
|
return reports;
|
|
|
|
};
|
2018-05-15 15:06:15 +00:00
|
|
|
|
2018-06-14 20:15:11 +00:00
|
|
|
class Report extends Component {
|
2018-08-20 21:24:17 +00:00
|
|
|
constructor() {
|
|
|
|
super( ...arguments );
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
hasError: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidCatch( error ) {
|
|
|
|
this.setState( {
|
|
|
|
hasError: true,
|
|
|
|
} );
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
console.warn( error );
|
|
|
|
/* eslint-enable no-console */
|
|
|
|
}
|
|
|
|
|
2018-05-15 15:06:15 +00:00
|
|
|
render() {
|
2018-08-20 21:24:17 +00:00
|
|
|
if ( this.state.hasError ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-06-14 20:15:11 +00:00
|
|
|
const { params } = this.props;
|
2018-08-20 21:24:17 +00:00
|
|
|
const report = find( getReports(), { report: params.report } );
|
|
|
|
if ( ! report ) {
|
|
|
|
return null;
|
2018-06-14 20:15:11 +00:00
|
|
|
}
|
2018-08-20 21:24:17 +00:00
|
|
|
const Container = report.component;
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2018-10-27 17:38:35 +00:00
|
|
|
<Header
|
|
|
|
sections={ [ [ '/analytics/revenue', __( 'Analytics', 'wc-admin' ) ], report.title ] }
|
|
|
|
/>
|
2018-08-20 21:24:17 +00:00
|
|
|
<Container { ...this.props } />
|
|
|
|
</Fragment>
|
|
|
|
);
|
2018-05-15 15:06:15 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-14 20:15:11 +00:00
|
|
|
|
|
|
|
Report.propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
2019-02-01 09:55:19 +00:00
|
|
|
export default compose(
|
|
|
|
useFilters( REPORTS_FILTER ),
|
|
|
|
withSelect( ( select, props ) => {
|
|
|
|
const { search } = getQuery();
|
|
|
|
|
|
|
|
if ( ! search ) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
const { report } = props.params;
|
|
|
|
const items = searchItemsByString( select, report, search );
|
|
|
|
const ids = Object.keys( items );
|
|
|
|
if ( ! ids.length ) {
|
2019-02-05 12:00:37 +00:00
|
|
|
return {};
|
2019-02-01 09:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
query: {
|
|
|
|
...props.query,
|
|
|
|
[ report ]: ids.join( ',' ),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( Report );
|