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';
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-09-17 02:26:34 +00:00
|
|
|
import CouponsReport from './coupons';
|
2018-08-20 21:24:17 +00:00
|
|
|
import useFilters from 'components/higher-order/use-filters';
|
|
|
|
|
|
|
|
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-09-17 02:26:34 +00:00
|
|
|
{
|
|
|
|
report: 'coupons',
|
|
|
|
title: __( 'Coupons', 'wc-admin' ),
|
|
|
|
component: CouponsReport,
|
|
|
|
},
|
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,
|
|
|
|
};
|
|
|
|
|
2018-08-20 21:24:17 +00:00
|
|
|
export default useFilters( REPORTS_FILTER )( Report );
|