2020-09-25 13:57:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Fragment } from '@wordpress/element';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { advancedFilters, charts, filters } from './config';
|
|
|
|
import getSelectedChart from '../../../lib/get-selected-chart';
|
|
|
|
import ReportChart from '../../components/report-chart';
|
|
|
|
import ReportError from '../../components/report-error';
|
|
|
|
import ReportSummary from '../../components/report-summary';
|
|
|
|
import VariationsReportTable from './table';
|
|
|
|
import ReportFilters from '../../components/report-filters';
|
|
|
|
|
|
|
|
const getChartMeta = ( { query } ) => {
|
|
|
|
const isCompareView =
|
|
|
|
query[ 'filter-variations' ] === 'compare-variations' &&
|
|
|
|
query.variations &&
|
|
|
|
query.variations.split( ',' ).length > 1;
|
|
|
|
|
|
|
|
return {
|
|
|
|
compareObject: 'variations',
|
2023-11-16 11:15:11 +00:00
|
|
|
/* translators: %d: number of variations */
|
2022-03-30 09:00:04 +00:00
|
|
|
itemsLabel: __( '%d variations', 'woocommerce' ),
|
2020-09-25 13:57:48 +00:00
|
|
|
mode: isCompareView ? 'item-comparison' : 'time-comparison',
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const VariationsReport = ( props ) => {
|
|
|
|
const { itemsLabel, mode } = getChartMeta( props );
|
2021-04-22 20:06:46 +00:00
|
|
|
const { path, query, isError, isRequesting } = props;
|
2020-09-25 13:57:48 +00:00
|
|
|
|
|
|
|
if ( isError ) {
|
2021-06-01 10:07:35 +00:00
|
|
|
return <ReportError />;
|
2020-09-25 13:57:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const chartQuery = {
|
|
|
|
...query,
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( mode === 'item-comparison' ) {
|
|
|
|
chartQuery.segmentby = 'variation';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ReportFilters
|
|
|
|
query={ query }
|
|
|
|
path={ path }
|
|
|
|
filters={ filters }
|
|
|
|
advancedFilters={ advancedFilters }
|
|
|
|
report="variations"
|
|
|
|
/>
|
|
|
|
<ReportSummary
|
|
|
|
mode={ mode }
|
|
|
|
charts={ charts }
|
|
|
|
endpoint="variations"
|
|
|
|
isRequesting={ isRequesting }
|
|
|
|
query={ chartQuery }
|
|
|
|
selectedChart={ getSelectedChart( query.chart, charts ) }
|
|
|
|
filters={ filters }
|
|
|
|
advancedFilters={ advancedFilters }
|
|
|
|
/>
|
|
|
|
<ReportChart
|
|
|
|
charts={ charts }
|
|
|
|
mode={ mode }
|
|
|
|
filters={ filters }
|
|
|
|
advancedFilters={ advancedFilters }
|
|
|
|
endpoint="variations"
|
|
|
|
isRequesting={ isRequesting }
|
|
|
|
itemsLabel={ itemsLabel }
|
|
|
|
path={ path }
|
|
|
|
query={ chartQuery }
|
|
|
|
selectedChart={ getSelectedChart( chartQuery.chart, charts ) }
|
|
|
|
/>
|
|
|
|
<VariationsReportTable
|
|
|
|
isRequesting={ isRequesting }
|
|
|
|
query={ query }
|
|
|
|
filters={ filters }
|
|
|
|
advancedFilters={ advancedFilters }
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
VariationsReport.propTypes = {
|
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
query: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
2021-04-22 20:06:46 +00:00
|
|
|
export default VariationsReport;
|