woocommerce/plugins/woocommerce-admin/client/analytics/report/variations/index.js

95 lines
2.3 KiB
JavaScript
Raw Normal View History

Add Variations Report (https://github.com/woocommerce/woocommerce-admin/pull/5167) * Add initial Variations Report to analytics feature. * Restrict query to variations when not specifying any product IDs. * Add route to get variations without specifying a parent. * Move variations table component to variations report directory. * Add missing LIMIT clause to variations report query. * Remove broken features from Variations table. * Add Variations report controller to CSV emailer. * Add initial Variation Stats endpoint, based on Product Stats. * Hook Variations Report components up to new stats endpoint. * Hook attribute filter up to variations report queries. * Remove variation title filter usage. See: https://github.com/woocommerce/woocommerce-admin/pull/5100 * Use filtered separator in variation name formatting. * Add "single variation" to variations report, fix autocompleter API request. * Fix segmentation by variation. * Add comparison to variations report. * Always include manually specified variations in report results. * Fix variations report table comparison mode. The ReportTable component expects the `filter` query param. * Fixing styling of compare button without table search component. * Add variation filter to Orders report. * Link orders count to orders report filtered by variation. * Orders report: include variation attributes in product names. * Further style tweaks for variations report download button. * Add variations filter to order stats query. * Clean up "category includes" login in REST controllers. Prep for "category excludes" in the Variations report. * Support category exclusion in report filters. * Fix filter param used by the variation report table component. * Add category filter to variations report. * Fix initial selected ReportTable rows when using non-default compareParam. * Add a new autocompleter for variable products. * Add products filter to variations report. * Fix tests. * Handle variation IDs that are no longer found. * Add documentation. * Use getSetting() instead of directly accessing window properties in client code. * Fix ordering Variations by SKU.
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',
itemsLabel: __( '%d variations', 'woocommerce-admin' ),
mode: isCompareView ? 'item-comparison' : 'time-comparison',
};
};
const VariationsReport = ( props ) => {
const { itemsLabel, mode } = getChartMeta( props );
const { path, query, isError, isRequesting } = props;
if ( isError ) {
return <ReportError isError />;
}
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,
};
export default VariationsReport;