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';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/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() {
|
2022-06-21 08:37:34 +00:00
|
|
|
const { charts, endpoint, path, query, selectedChart, filters } =
|
|
|
|
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
|
|
|
|
as="h3"
|
2021-08-13 19:06:32 +00:00
|
|
|
size={ 16 }
|
|
|
|
weight={ 600 }
|
|
|
|
color="#23282d"
|
2021-06-28 01:14:59 +00:00
|
|
|
>
|
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 )
|
|
|
|
) }
|
|
|
|
>
|
2023-11-16 11:15:11 +00:00
|
|
|
{ sprintf(
|
2020-12-21 19:06:41 +00:00
|
|
|
/* translators: %s is the chart type */
|
2023-11-16 11:15:11 +00:00
|
|
|
__( '%s Report', 'woocommerce' ),
|
|
|
|
selectedChart.label
|
|
|
|
) }
|
2020-12-21 19:06:41 +00:00
|
|
|
</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;
|