2018-12-22 00:24:26 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-01-08 06:48:39 +00:00
|
|
|
import { Component } from '@wordpress/element';
|
2018-12-22 00:24:26 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-08 06:48:39 +00:00
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2018-12-22 00:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { Card } from '@woocommerce/components';
|
2019-02-06 19:28:29 +00:00
|
|
|
import { getAdminLink, getHistory } from '@woocommerce/navigation';
|
2018-12-22 00:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ReportChart from 'analytics/components/report-chart';
|
|
|
|
import './block.scss';
|
|
|
|
|
|
|
|
class ChartBlock extends Component {
|
2019-01-08 06:48:39 +00:00
|
|
|
handleChartClick = () => {
|
|
|
|
const { charts } = this.props;
|
|
|
|
|
|
|
|
if ( ! charts || ! charts.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-02-06 19:28:29 +00:00
|
|
|
getHistory().push( 'analytics/' + charts[ 0 ].endpoint + '?chart=' + charts[ 0 ].key );
|
2019-01-08 06:48:39 +00:00
|
|
|
};
|
|
|
|
|
2018-12-22 00:24:26 +00:00
|
|
|
render() {
|
|
|
|
const { charts, endpoint, path, query } = this.props;
|
|
|
|
|
|
|
|
if ( ! charts || ! charts.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-01-08 06:48:39 +00:00
|
|
|
<div
|
|
|
|
role="presentation"
|
|
|
|
className="woocommerce-dashboard__chart-block-wrapper"
|
|
|
|
onClick={ this.handleChartClick }
|
|
|
|
>
|
2018-12-22 00:24:26 +00:00
|
|
|
<Card className="woocommerce-dashboard__chart-block" title={ charts[ 0 ].label }>
|
2019-01-08 06:48:39 +00:00
|
|
|
<a
|
|
|
|
className="screen-reader-text"
|
|
|
|
href={ getAdminLink(
|
|
|
|
'admin.php?page=wc-admin#/analytics/' +
|
|
|
|
charts[ 0 ].endpoint +
|
|
|
|
'?chart=' +
|
|
|
|
charts[ 0 ].key
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
{ /* translators: %s is the chart type */
|
2019-03-13 17:14:02 +00:00
|
|
|
sprintf( __( '%s Report', 'woocommerce-admin' ), charts[ 0 ].label ) }
|
2019-01-08 06:48:39 +00:00
|
|
|
</a>
|
2018-12-22 00:24:26 +00:00
|
|
|
<ReportChart
|
|
|
|
charts={ charts }
|
|
|
|
endpoint={ endpoint }
|
|
|
|
query={ query }
|
2019-01-08 09:21:47 +00:00
|
|
|
interactiveLegend={ false }
|
|
|
|
legendPosition="bottom"
|
|
|
|
path={ path }
|
2018-12-22 00:24:26 +00:00
|
|
|
selectedChart={ charts[ 0 ] }
|
2019-01-08 09:21:47 +00:00
|
|
|
showHeaderControls={ false }
|
2018-12-22 00:24:26 +00:00
|
|
|
/>
|
|
|
|
</Card>
|
2019-01-08 06:48:39 +00:00
|
|
|
</div>
|
2018-12-22 00:24:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ChartBlock.propTypes = {
|
|
|
|
charts: PropTypes.array,
|
|
|
|
endpoint: PropTypes.string.isRequired,
|
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
query: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ChartBlock;
|