2018-06-14 20:15:11 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2018-09-03 15:25:38 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2018-08-01 16:00:45 +00:00
|
|
|
import { format as formatDate } from '@wordpress/date';
|
2018-09-03 15:25:38 +00:00
|
|
|
import { map, find, orderBy } from 'lodash';
|
2018-06-14 20:15:11 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-09-03 15:25:38 +00:00
|
|
|
import { withSelect } from '@wordpress/data';
|
2018-06-14 20:15:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-08-20 21:18:13 +00:00
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
Chart,
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
ChartPlaceholder,
|
|
|
|
EmptyContent,
|
2018-08-20 21:18:13 +00:00
|
|
|
ReportFilters,
|
|
|
|
SummaryList,
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
SummaryListPlaceholder,
|
2018-08-20 21:18:13 +00:00
|
|
|
SummaryNumber,
|
|
|
|
TableCard,
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
TablePlaceholder,
|
2018-08-20 21:18:13 +00:00
|
|
|
} from '@woocommerce/components';
|
2018-09-03 07:54:45 +00:00
|
|
|
import { downloadCSVFile, generateCSVDataFromTable, generateCSVFileName } from 'lib/csv';
|
2018-08-01 16:00:45 +00:00
|
|
|
import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency';
|
2018-08-20 20:40:17 +00:00
|
|
|
import { getAdminLink, getNewPath, updateQueryString } from 'lib/nav-utils';
|
2018-09-03 15:25:38 +00:00
|
|
|
import { getAllReportData, isReportDataEmpty } from 'store/reports/utils';
|
2018-09-04 18:03:52 +00:00
|
|
|
import {
|
|
|
|
getCurrentDates,
|
|
|
|
isoDateFormat,
|
|
|
|
getPreviousDate,
|
|
|
|
getIntervalForQuery,
|
|
|
|
getAllowedIntervalsForQuery,
|
|
|
|
getDateFormatsForInterval,
|
|
|
|
} from 'lib/date';
|
2018-09-03 15:25:38 +00:00
|
|
|
import { MAX_PER_PAGE } from 'store/constants';
|
2018-06-20 15:09:37 +00:00
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
export class RevenueReport extends Component {
|
2018-06-26 14:59:35 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
2018-09-03 07:54:45 +00:00
|
|
|
this.onDownload = this.onDownload.bind( this );
|
2018-08-01 16:00:45 +00:00
|
|
|
this.onQueryChange = this.onQueryChange.bind( this );
|
2018-06-26 21:02:08 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 07:54:45 +00:00
|
|
|
onDownload( headers, rows, query ) {
|
|
|
|
// @TODO The current implementation only downloads the contents displayed in the table.
|
|
|
|
// Another solution is required when the data set is larger (see #311).
|
|
|
|
return () => {
|
|
|
|
downloadCSVFile(
|
|
|
|
generateCSVFileName( 'revenue', query ),
|
|
|
|
generateCSVDataFromTable( headers, rows )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
/**
|
|
|
|
* This function returns an event handler for the given `param`
|
2018-08-06 17:01:41 +00:00
|
|
|
* @todo Move handling of this to a library?
|
2018-08-01 16:00:45 +00:00
|
|
|
* @param {string} param The parameter in the querystring which should be updated (ex `page`, `per_page`)
|
|
|
|
* @return {function} A callback which will update `param` to the passed value when called.
|
|
|
|
*/
|
|
|
|
onQueryChange( param ) {
|
2018-08-06 17:01:41 +00:00
|
|
|
switch ( param ) {
|
|
|
|
case 'sort':
|
|
|
|
return ( key, dir ) => updateQueryString( { orderby: key, order: dir } );
|
|
|
|
default:
|
|
|
|
return value => updateQueryString( { [ param ]: value } );
|
|
|
|
}
|
2018-08-01 16:00:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getHeadersContent() {
|
|
|
|
return [
|
2018-08-06 17:01:41 +00:00
|
|
|
{
|
|
|
|
label: __( 'Date', 'wc-admin' ),
|
|
|
|
key: 'date_start',
|
|
|
|
required: true,
|
|
|
|
defaultSort: true,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Orders', 'wc-admin' ),
|
|
|
|
key: 'orders_count',
|
|
|
|
required: false,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Gross Revenue', 'wc-admin' ),
|
|
|
|
key: 'gross_revenue',
|
|
|
|
required: true,
|
|
|
|
isSortable: true,
|
2018-08-13 15:25:32 +00:00
|
|
|
isNumeric: true,
|
2018-08-06 17:01:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Refunds', 'wc-admin' ),
|
|
|
|
key: 'refunds',
|
|
|
|
required: false,
|
|
|
|
isSortable: true,
|
2018-08-13 15:25:32 +00:00
|
|
|
isNumeric: true,
|
2018-08-06 17:01:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Coupons', 'wc-admin' ),
|
|
|
|
key: 'coupons',
|
|
|
|
required: false,
|
|
|
|
isSortable: true,
|
2018-08-13 15:25:32 +00:00
|
|
|
isNumeric: true,
|
2018-08-06 17:01:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Taxes', 'wc-admin' ),
|
|
|
|
key: 'taxes',
|
|
|
|
required: false,
|
2018-09-03 15:25:38 +00:00
|
|
|
isSortable: true,
|
2018-08-13 15:25:32 +00:00
|
|
|
isNumeric: true,
|
2018-08-06 17:01:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Shipping', 'wc-admin' ),
|
|
|
|
key: 'shipping',
|
|
|
|
required: false,
|
|
|
|
isSortable: true,
|
2018-08-13 15:25:32 +00:00
|
|
|
isNumeric: true,
|
2018-08-06 17:01:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Net Revenue', 'wc-admin' ),
|
|
|
|
key: 'net_revenue',
|
|
|
|
required: false,
|
|
|
|
isSortable: true,
|
2018-08-13 15:25:32 +00:00
|
|
|
isNumeric: true,
|
2018-08-06 17:01:41 +00:00
|
|
|
},
|
2018-08-01 16:00:45 +00:00
|
|
|
];
|
2018-06-26 14:59:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
getRowsContent( data = [] ) {
|
2018-09-04 18:03:52 +00:00
|
|
|
const { query } = this.props;
|
|
|
|
const currentInterval = getIntervalForQuery( query );
|
|
|
|
const formats = getDateFormatsForInterval( currentInterval );
|
|
|
|
|
2018-06-26 22:17:05 +00:00
|
|
|
return map( data, row => {
|
|
|
|
const {
|
|
|
|
coupons,
|
|
|
|
gross_revenue,
|
|
|
|
net_revenue,
|
|
|
|
orders_count,
|
|
|
|
refunds,
|
|
|
|
shipping,
|
|
|
|
taxes,
|
|
|
|
} = row.subtotals;
|
|
|
|
|
2018-07-13 19:36:41 +00:00
|
|
|
// @TODO How to create this per-report? Can use `w`, `year`, `m` to build time-specific order links
|
|
|
|
// we need to know which kind of report this is, and parse the `label` to get this row's date
|
2018-06-20 15:09:37 +00:00
|
|
|
const orderLink = (
|
2018-09-03 15:25:38 +00:00
|
|
|
<a
|
|
|
|
href={ getAdminLink(
|
|
|
|
'edit.php?post_type=shop_order&m=' + formatDate( 'Ymd', row.date_start )
|
|
|
|
) }
|
|
|
|
>
|
2018-06-26 22:17:05 +00:00
|
|
|
{ orders_count }
|
2018-06-20 15:09:37 +00:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
return [
|
2018-08-01 16:00:45 +00:00
|
|
|
{
|
2018-09-04 18:03:52 +00:00
|
|
|
display: formatDate( formats.tableFormat, row.date_start ),
|
2018-08-01 16:00:45 +00:00
|
|
|
value: row.date_start,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: orderLink,
|
|
|
|
value: Number( orders_count ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatCurrency( gross_revenue ),
|
|
|
|
value: getCurrencyFormatDecimal( gross_revenue ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatCurrency( refunds ),
|
|
|
|
value: getCurrencyFormatDecimal( refunds ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatCurrency( coupons ),
|
|
|
|
value: getCurrencyFormatDecimal( coupons ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatCurrency( taxes ),
|
|
|
|
value: getCurrencyFormatDecimal( taxes ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatCurrency( shipping ),
|
|
|
|
value: getCurrencyFormatDecimal( shipping ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatCurrency( net_revenue ),
|
|
|
|
value: getCurrencyFormatDecimal( net_revenue ),
|
|
|
|
},
|
2018-06-20 15:09:37 +00:00
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
getCharts() {
|
2018-08-01 16:00:45 +00:00
|
|
|
return [
|
|
|
|
{
|
2018-09-03 15:25:38 +00:00
|
|
|
key: 'gross_revenue',
|
|
|
|
label: __( 'Gross Revenue', 'wc-admin' ),
|
|
|
|
type: 'currency',
|
2018-08-01 16:00:45 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-03 15:25:38 +00:00
|
|
|
key: 'refunds',
|
|
|
|
label: __( 'Refunds', 'wc-admin' ),
|
|
|
|
type: 'currency',
|
2018-08-01 16:00:45 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-03 15:25:38 +00:00
|
|
|
key: 'coupons',
|
|
|
|
label: __( 'Coupons', 'wc-admin' ),
|
|
|
|
type: 'currency',
|
2018-08-01 16:00:45 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-03 15:25:38 +00:00
|
|
|
key: 'taxes',
|
|
|
|
label: __( 'Taxes', 'wc-admin' ),
|
|
|
|
type: 'currency',
|
2018-08-01 16:00:45 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-03 15:25:38 +00:00
|
|
|
key: 'shipping',
|
|
|
|
label: __( 'Shipping', 'wc-admin' ),
|
|
|
|
type: 'currency',
|
2018-08-01 16:00:45 +00:00
|
|
|
},
|
|
|
|
{
|
2018-09-03 15:25:38 +00:00
|
|
|
key: 'net_revenue',
|
|
|
|
label: __( 'Net Revenue', 'wc-admin' ),
|
|
|
|
type: 'currency',
|
2018-08-01 16:00:45 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
getSelectedChart() {
|
|
|
|
const { query } = this.props;
|
|
|
|
const charts = this.getCharts();
|
|
|
|
|
|
|
|
const chart = find( charts, { key: query.chart } );
|
|
|
|
if ( chart ) {
|
|
|
|
return chart;
|
|
|
|
}
|
|
|
|
|
|
|
|
return charts[ 0 ];
|
|
|
|
}
|
|
|
|
|
2018-08-17 22:47:54 +00:00
|
|
|
// TODO since this pattern will exist on every report, this possibly should become a component
|
2018-09-03 15:25:38 +00:00
|
|
|
renderChartSummaryNumbers() {
|
2018-08-17 22:47:54 +00:00
|
|
|
const selectedChart = this.getSelectedChart();
|
2018-09-03 15:25:38 +00:00
|
|
|
const { primaryData, secondaryData } = this.props;
|
|
|
|
const { totals } = primaryData.data;
|
|
|
|
const secondaryTotals = secondaryData.data.totals || {};
|
|
|
|
|
|
|
|
const summaryNumbers = map( this.getCharts(), chart => {
|
|
|
|
const { key, label, type } = chart;
|
|
|
|
const isSelected = selectedChart.key === key;
|
2018-08-17 22:47:54 +00:00
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
let value = parseFloat( totals[ key ] );
|
|
|
|
let secondaryValue =
|
|
|
|
( secondaryTotals[ key ] && parseFloat( secondaryTotals[ key ] ) ) || undefined;
|
|
|
|
|
|
|
|
let delta = 0;
|
|
|
|
if ( secondaryValue && secondaryValue !== 0 ) {
|
|
|
|
delta = Math.round( ( value - secondaryValue ) / secondaryValue * 100 );
|
|
|
|
}
|
2018-08-17 22:47:54 +00:00
|
|
|
|
|
|
|
switch ( type ) {
|
|
|
|
// TODO: implement other format handlers
|
|
|
|
case 'currency':
|
|
|
|
value = formatCurrency( value );
|
2018-09-03 15:25:38 +00:00
|
|
|
secondaryValue = secondaryValue && formatCurrency( secondaryValue );
|
2018-08-17 22:47:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-20 20:40:17 +00:00
|
|
|
const href = getNewPath( { chart: key } );
|
2018-08-17 22:47:54 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<SummaryNumber
|
|
|
|
key={ key }
|
|
|
|
value={ value }
|
|
|
|
label={ label }
|
|
|
|
selected={ isSelected }
|
2018-09-03 15:25:38 +00:00
|
|
|
prevValue={ secondaryValue }
|
|
|
|
delta={ delta }
|
2018-08-20 20:40:17 +00:00
|
|
|
href={ href }
|
2018-08-17 22:47:54 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
return <SummaryList>{ summaryNumbers }</SummaryList>;
|
|
|
|
}
|
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
renderChart() {
|
|
|
|
const { primaryData, secondaryData, query } = this.props;
|
2018-09-04 18:03:52 +00:00
|
|
|
|
|
|
|
const currentInterval = getIntervalForQuery( query );
|
|
|
|
const allowedIntervals = getAllowedIntervalsForQuery( query );
|
|
|
|
const formats = getDateFormatsForInterval( currentInterval );
|
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
const { primary, secondary } = getCurrentDates( query );
|
|
|
|
const selectedChart = this.getSelectedChart();
|
|
|
|
|
|
|
|
const primaryKey = `${ primary.label } (${ primary.range })`;
|
|
|
|
const secondaryKey = `${ secondary.label } (${ secondary.range })`;
|
2018-08-17 22:47:54 +00:00
|
|
|
|
2018-09-04 18:03:52 +00:00
|
|
|
const chartData = primaryData.data.intervals.map( function( interval, index ) {
|
|
|
|
const secondaryDate = getPreviousDate(
|
|
|
|
formatDate( 'Y-m-d', interval.date_start ),
|
|
|
|
primary.after,
|
|
|
|
secondary.after,
|
|
|
|
query.compare,
|
|
|
|
currentInterval
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* When looking at weeks, getting the previous date doesn't always work
|
|
|
|
* because subtracting the correct number of weeks from `interval.date_start`
|
|
|
|
* yeilds the start of the week correct week, but not necessarily the of the
|
|
|
|
* period in question.
|
|
|
|
*
|
|
|
|
* When https://github.com/woocommerce/woocommerce/issues/21298 is resolved and
|
|
|
|
* data will be zero-filled, there is a strong argument for all this logic to be
|
|
|
|
* removed in favor of simply matching up the indices in each array of data.
|
|
|
|
*/
|
|
|
|
const secondaryInterval =
|
|
|
|
0 === index && 'week' === currentInterval
|
|
|
|
? secondaryData.data.intervals[ 0 ]
|
|
|
|
: find( secondaryData.data.intervals, {
|
|
|
|
date_start:
|
|
|
|
secondaryDate.format( isoDateFormat ) +
|
|
|
|
' ' +
|
|
|
|
formatDate( 'H:i:s', interval.date_start ),
|
|
|
|
} );
|
2018-09-03 15:25:38 +00:00
|
|
|
return {
|
2018-09-04 18:03:52 +00:00
|
|
|
date: formatDate( 'Y-m-d\\TH:i:s', interval.date_start ),
|
2018-09-03 15:25:38 +00:00
|
|
|
[ primaryKey ]: interval.subtotals[ selectedChart.key ] || 0,
|
|
|
|
[ secondaryKey ]:
|
|
|
|
( secondaryInterval && secondaryInterval.subtotals[ selectedChart.key ] ) || 0,
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
|
|
|
return (
|
2018-09-14 16:17:39 +00:00
|
|
|
<Chart
|
|
|
|
data={ chartData }
|
|
|
|
title={ selectedChart.label }
|
|
|
|
interval={ currentInterval }
|
|
|
|
allowedIntervals={ allowedIntervals }
|
|
|
|
tooltipFormat={ formats.tooltipFormat }
|
|
|
|
xFormat={ formats.xFormat }
|
|
|
|
x2Format={ formats.x2Format }
|
|
|
|
dateParser={ '%Y-%m-%dT%H:%M:%S' }
|
|
|
|
/>
|
2018-09-03 15:25:38 +00:00
|
|
|
);
|
2018-08-17 22:47:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
renderTable() {
|
|
|
|
const { primaryData, query } = this.props;
|
|
|
|
const intervals = primaryData.data.intervals;
|
|
|
|
|
|
|
|
const page = parseInt( query.page ) || 1;
|
|
|
|
const rowsPerPage = parseInt( query.per_page ) || 25;
|
|
|
|
|
|
|
|
const rows =
|
|
|
|
this.getRowsContent(
|
|
|
|
orderBy(
|
|
|
|
intervals,
|
|
|
|
function( interval ) {
|
|
|
|
return 'undefined' === typeof interval.subtotals[ query.orderby ]
|
|
|
|
? interval.date_start
|
|
|
|
: interval.subtotals[ query.orderby ];
|
|
|
|
},
|
|
|
|
query.order || 'asc'
|
|
|
|
).slice( ( page - 1 ) * rowsPerPage, page * rowsPerPage )
|
|
|
|
) || [];
|
|
|
|
|
2018-08-01 16:00:45 +00:00
|
|
|
const headers = this.getHeadersContent();
|
2018-09-03 15:25:38 +00:00
|
|
|
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
const tableQuery = {
|
|
|
|
...query,
|
|
|
|
orderby: query.orderby || 'date_start',
|
|
|
|
order: query.order || 'asc',
|
|
|
|
};
|
2018-09-03 15:25:38 +00:00
|
|
|
return (
|
|
|
|
<TableCard
|
|
|
|
title={ __( 'Revenue', 'wc-admin' ) }
|
|
|
|
rows={ rows }
|
|
|
|
totalRows={ intervals.length }
|
|
|
|
rowsPerPage={ rowsPerPage }
|
|
|
|
headers={ headers }
|
|
|
|
onClickDownload={ this.onDownload( headers, rows, tableQuery ) }
|
|
|
|
onQueryChange={ this.onQueryChange }
|
|
|
|
query={ tableQuery }
|
|
|
|
summary={ null }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
renderPlaceholder() {
|
|
|
|
const { path, query } = this.props;
|
|
|
|
const headers = this.getHeadersContent();
|
|
|
|
const charts = this.getCharts();
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ReportFilters query={ query } path={ path } />
|
2018-09-03 15:25:38 +00:00
|
|
|
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
<span className="screen-reader-text">
|
|
|
|
{ __( 'Your requested data is loading', 'wc-admin' ) }
|
|
|
|
</span>
|
2018-09-03 15:25:38 +00:00
|
|
|
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
<SummaryListPlaceholder numberOfItems={ charts.length } />
|
|
|
|
<ChartPlaceholder />
|
|
|
|
<Card
|
|
|
|
title={ __( 'Revenue', 'wc-admin' ) }
|
|
|
|
className="woocommerce-analytics__table-placeholder"
|
|
|
|
>
|
|
|
|
<TablePlaceholder caption={ __( 'Revenue', 'wc-admin' ) } headers={ headers } />
|
|
|
|
</Card>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { path, query, primaryData, secondaryData } = this.props;
|
2018-09-03 15:25:38 +00:00
|
|
|
|
|
|
|
if ( primaryData.isRequesting || secondaryData.isRequesting ) {
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
return this.renderPlaceholder();
|
2018-09-03 15:25:38 +00:00
|
|
|
}
|
|
|
|
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
if ( isReportDataEmpty( primaryData ) || primaryData.isError || secondaryData.isError ) {
|
|
|
|
let title, actionLabel, actionURL, actionCallback;
|
|
|
|
if ( primaryData.isError || secondaryData.isError ) {
|
|
|
|
title = __( 'There was an error getting your stats. Please try again.', 'wc-admin' );
|
|
|
|
actionLabel = __( 'Reload', 'wc-admin' );
|
|
|
|
actionCallback = () => {
|
|
|
|
// TODO Add tracking for how often an error is displayed, and the reload action is clicked.
|
|
|
|
window.location.reload();
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
title = __( 'No results could be found for this date range.', 'wc-admin' );
|
|
|
|
actionLabel = __( 'View Orders', 'wc-admin' );
|
|
|
|
actionURL = getAdminLink( 'edit.php?post_type=shop_order' );
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ReportFilters query={ query } path={ path } />
|
|
|
|
<EmptyContent
|
|
|
|
title={ title }
|
|
|
|
actionLabel={ actionLabel }
|
|
|
|
actionURL={ actionURL }
|
|
|
|
actionCallback={ actionCallback }
|
|
|
|
/>
|
|
|
|
</Fragment>
|
|
|
|
);
|
2018-09-03 15:25:38 +00:00
|
|
|
}
|
2018-06-20 15:09:37 +00:00
|
|
|
|
2018-06-14 20:15:11 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
2018-08-08 21:24:48 +00:00
|
|
|
<ReportFilters query={ query } path={ path } />
|
2018-06-14 20:15:11 +00:00
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
{ this.renderChartSummaryNumbers() }
|
|
|
|
{ this.renderChart() }
|
|
|
|
{ this.renderTable() }
|
2018-06-14 20:15:11 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RevenueReport.propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
path: PropTypes.string.isRequired,
|
|
|
|
query: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
2018-09-03 15:25:38 +00:00
|
|
|
export default compose(
|
|
|
|
withSelect( ( select, props ) => {
|
|
|
|
const { query } = props;
|
|
|
|
const datesFromQuery = getCurrentDates( query );
|
2018-09-04 18:03:52 +00:00
|
|
|
const interval = getIntervalForQuery( query );
|
2018-09-03 15:25:38 +00:00
|
|
|
const baseArgs = {
|
|
|
|
order: 'asc',
|
2018-09-04 18:03:52 +00:00
|
|
|
interval: interval,
|
2018-09-03 15:25:38 +00:00
|
|
|
per_page: MAX_PER_PAGE,
|
|
|
|
};
|
|
|
|
|
|
|
|
const primaryData = getAllReportData(
|
|
|
|
'revenue',
|
|
|
|
{
|
|
|
|
...baseArgs,
|
|
|
|
after: datesFromQuery.primary.after,
|
|
|
|
before: datesFromQuery.primary.before,
|
|
|
|
},
|
|
|
|
select
|
|
|
|
);
|
|
|
|
|
|
|
|
const secondaryData = getAllReportData(
|
|
|
|
'revenue',
|
|
|
|
{
|
|
|
|
...baseArgs,
|
|
|
|
after: datesFromQuery.secondary.after,
|
|
|
|
before: datesFromQuery.secondary.before,
|
|
|
|
},
|
|
|
|
select
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
primaryData,
|
|
|
|
secondaryData,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( RevenueReport );
|