2018-12-22 00:24:26 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
2020-02-14 02:23:21 +00:00
|
|
|
import {
|
|
|
|
getHistory,
|
|
|
|
getNewPath,
|
|
|
|
getPersistedQuery,
|
|
|
|
} from '@woocommerce/navigation';
|
2019-11-22 17:07:26 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/wc-admin-settings';
|
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 = () => {
|
2020-03-31 15:08:40 +00:00
|
|
|
const { selectedChart } = this.props;
|
2019-01-08 06:48:39 +00:00
|
|
|
|
2020-03-31 15:08:40 +00:00
|
|
|
getHistory().push( this.getChartPath( selectedChart ) );
|
2019-01-08 06:48:39 +00:00
|
|
|
};
|
|
|
|
|
2019-07-02 00:19:55 +00:00
|
|
|
getChartPath( chart ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
return getNewPath(
|
|
|
|
{ chart: chart.key },
|
|
|
|
'/analytics/' + chart.endpoint,
|
|
|
|
getPersistedQuery()
|
|
|
|
);
|
2019-07-02 00:19:55 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 00:24:26 +00:00
|
|
|
render() {
|
2020-03-31 15:08:40 +00:00
|
|
|
const {
|
|
|
|
charts,
|
|
|
|
endpoint,
|
|
|
|
path,
|
|
|
|
query,
|
|
|
|
selectedChart,
|
2020-07-20 22:17:28 +00:00
|
|
|
filters,
|
2020-03-31 15:08:40 +00:00
|
|
|
} = this.props;
|
2018-12-22 00:24:26 +00:00
|
|
|
|
2020-03-31 15:08:40 +00:00
|
|
|
if ( ! selectedChart ) {
|
2018-12-22 00:24:26 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-01-08 06:48:39 +00:00
|
|
|
<div
|
|
|
|
role="presentation"
|
|
|
|
className="woocommerce-dashboard__chart-block-wrapper"
|
|
|
|
onClick={ this.handleChartClick }
|
|
|
|
>
|
2019-05-22 08:38:25 +00:00
|
|
|
<Card
|
|
|
|
className="woocommerce-dashboard__chart-block woocommerce-analytics__card"
|
2020-03-31 15:08:40 +00:00
|
|
|
title={ selectedChart.label }
|
2019-05-22 08:38:25 +00:00
|
|
|
>
|
2019-01-08 06:48:39 +00:00
|
|
|
<a
|
|
|
|
className="screen-reader-text"
|
2020-02-14 02:23:21 +00:00
|
|
|
href={ getAdminLink(
|
2020-03-31 15:08:40 +00:00
|
|
|
this.getChartPath( selectedChart )
|
2020-02-14 02:23:21 +00:00
|
|
|
) }
|
2019-01-08 06:48:39 +00:00
|
|
|
>
|
2020-07-28 02:32:58 +00:00
|
|
|
{
|
|
|
|
/* translators: %s is the chart type */
|
|
|
|
sprintf(
|
|
|
|
__( '%s Report', 'woocommerce-admin' ),
|
|
|
|
selectedChart.label
|
|
|
|
)
|
|
|
|
}
|
2019-01-08 06:48:39 +00:00
|
|
|
</a>
|
2018-12-22 00:24:26 +00:00
|
|
|
<ReportChart
|
2020-03-31 15:08:40 +00:00
|
|
|
charts={ charts }
|
2018-12-22 00:24:26 +00:00
|
|
|
endpoint={ endpoint }
|
|
|
|
query={ query }
|
2019-01-08 09:21:47 +00:00
|
|
|
interactiveLegend={ false }
|
|
|
|
legendPosition="bottom"
|
|
|
|
path={ path }
|
2020-03-31 15:08:40 +00:00
|
|
|
selectedChart={ selectedChart }
|
2019-01-08 09:21:47 +00:00
|
|
|
showHeaderControls={ false }
|
2020-07-20 22:17:28 +00:00
|
|
|
filters={ filters }
|
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,
|
2020-03-31 15:08:40 +00:00
|
|
|
selectedChart: PropTypes.object.isRequired,
|
2018-12-22 00:24:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ChartBlock;
|