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
|
|
|
|
*/
|
2018-06-14 20:15:11 +00:00
|
|
|
import ExampleReport from './example';
|
2018-08-20 21:24:17 +00:00
|
|
|
import Header from 'layout/header';
|
|
|
|
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';
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
report: 'test',
|
|
|
|
title: __( 'Example', 'wc-admin' ),
|
|
|
|
component: ExampleReport,
|
|
|
|
},
|
|
|
|
] );
|
|
|
|
|
|
|
|
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>
|
|
|
|
<Header sections={ [ [ '/analytics', __( 'Analytics', 'wc-admin' ) ], report.title ] } />
|
|
|
|
<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 );
|