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';
|
2021-01-07 23:57:09 +00:00
|
|
|
import { Card, CardBody, CardHeader } from '@wordpress/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';
|
2021-01-07 23:57:09 +00:00
|
|
|
import { Text } from '@woocommerce/experimental';
|
2018-12-22 00:24:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-08-13 02:05:22 +00:00
|
|
|
import ReportChart from '../../analytics/components/report-chart';
|
2018-12-22 00:24:26 +00:00
|
|
|
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 }
|
|
|
|
>
|
2020-12-21 19:06:41 +00:00
|
|
|
<Card className="woocommerce-dashboard__chart-block">
|
|
|
|
<CardHeader>
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text
|
|
|
|
variant="title.small"
|
|
|
|
as="h3"
|
|
|
|
size="20"
|
|
|
|
lineHeight="28px"
|
|
|
|
>
|
2020-12-21 19:06:41 +00:00
|
|
|
{ selectedChart.label }
|
|
|
|
</Text>
|
|
|
|
</CardHeader>
|
|
|
|
<CardBody size={ null }>
|
|
|
|
<a
|
|
|
|
className="screen-reader-text"
|
|
|
|
href={ getAdminLink(
|
|
|
|
this.getChartPath( selectedChart )
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
{
|
|
|
|
/* translators: %s is the chart type */
|
|
|
|
sprintf(
|
|
|
|
__( '%s Report', 'woocommerce-admin' ),
|
|
|
|
selectedChart.label
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</a>
|
|
|
|
<ReportChart
|
|
|
|
charts={ charts }
|
|
|
|
endpoint={ endpoint }
|
|
|
|
query={ query }
|
|
|
|
interactiveLegend={ false }
|
|
|
|
legendPosition="bottom"
|
|
|
|
path={ path }
|
|
|
|
selectedChart={ selectedChart }
|
|
|
|
showHeaderControls={ false }
|
|
|
|
filters={ filters }
|
|
|
|
/>
|
|
|
|
</CardBody>
|
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;
|