2020-05-14 03:23:03 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-05-20 22:15:18 +00:00
|
|
|
import { useContext } from '@wordpress/element';
|
2020-05-14 03:23:03 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-05-20 22:15:18 +00:00
|
|
|
import classnames from 'classnames';
|
2020-05-14 03:23:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import {
|
|
|
|
SummaryNumber,
|
|
|
|
SummaryNumberPlaceholder,
|
|
|
|
} from '@woocommerce/components';
|
|
|
|
import { getPersistedQuery } from '@woocommerce/navigation';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import withSelect from 'wc-api/with-select';
|
|
|
|
import { recordEvent } from 'lib/tracks';
|
|
|
|
import { CurrencyContext } from 'lib/currency-context';
|
|
|
|
import {
|
|
|
|
getIndicatorData,
|
2020-06-04 23:14:55 +00:00
|
|
|
getIndicatorValues,
|
2020-05-14 03:23:03 +00:00
|
|
|
} from 'dashboard/store-performance/utils';
|
|
|
|
|
|
|
|
export const StatsList = ( {
|
|
|
|
stats,
|
|
|
|
primaryData,
|
|
|
|
secondaryData,
|
|
|
|
primaryRequesting,
|
|
|
|
secondaryRequesting,
|
|
|
|
primaryError,
|
|
|
|
secondaryError,
|
|
|
|
query,
|
|
|
|
} ) => {
|
2020-06-17 23:33:40 +00:00
|
|
|
const { formatAmount, getCurrencyConfig } = useContext( CurrencyContext );
|
2020-05-14 03:23:03 +00:00
|
|
|
if ( primaryError || secondaryError ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const persistedQuery = getPersistedQuery( query );
|
2020-06-17 23:33:40 +00:00
|
|
|
const currency = getCurrencyConfig();
|
2020-05-14 03:23:03 +00:00
|
|
|
|
|
|
|
return (
|
2020-05-20 22:15:18 +00:00
|
|
|
<ul
|
|
|
|
className={ classnames( 'woocommerce-stats-overview__stats', {
|
|
|
|
'is-even': stats.length % 2 === 0,
|
|
|
|
} ) }
|
|
|
|
>
|
2020-05-14 03:23:03 +00:00
|
|
|
{ stats.map( ( item ) => {
|
|
|
|
if ( primaryRequesting || secondaryRequesting ) {
|
2020-05-20 22:15:18 +00:00
|
|
|
return (
|
|
|
|
<SummaryNumberPlaceholder
|
2020-06-15 02:17:12 +00:00
|
|
|
className="is-homescreen"
|
2020-05-20 22:15:18 +00:00
|
|
|
key={ item.stat }
|
|
|
|
/>
|
|
|
|
);
|
2020-05-14 03:23:03 +00:00
|
|
|
}
|
|
|
|
const {
|
|
|
|
primaryValue,
|
|
|
|
secondaryValue,
|
|
|
|
delta,
|
|
|
|
reportUrl,
|
2020-06-04 23:14:55 +00:00
|
|
|
reportUrlType,
|
|
|
|
} = getIndicatorValues( {
|
2020-05-14 03:23:03 +00:00
|
|
|
indicator: item,
|
|
|
|
primaryData,
|
|
|
|
secondaryData,
|
|
|
|
currency,
|
2020-06-17 23:33:40 +00:00
|
|
|
formatAmount,
|
2020-05-14 03:23:03 +00:00
|
|
|
persistedQuery,
|
|
|
|
} );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SummaryNumber
|
2020-06-15 02:17:12 +00:00
|
|
|
isHomescreen
|
2020-05-14 03:23:03 +00:00
|
|
|
key={ item.stat }
|
|
|
|
href={ reportUrl }
|
2020-06-04 23:14:55 +00:00
|
|
|
hrefType={ reportUrlType }
|
2020-05-14 03:23:03 +00:00
|
|
|
label={ item.label }
|
|
|
|
value={ primaryValue }
|
|
|
|
prevLabel={ __(
|
|
|
|
'Previous Period:',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
prevValue={ secondaryValue }
|
|
|
|
delta={ delta }
|
|
|
|
onLinkClickCallback={ () => {
|
|
|
|
recordEvent( 'statsoverview_indicators_click', {
|
|
|
|
key: item.stat,
|
|
|
|
} );
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
2020-05-20 22:15:18 +00:00
|
|
|
</ul>
|
2020-05-14 03:23:03 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withSelect( ( select, { stats, query } ) => {
|
|
|
|
if ( stats.length === 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return getIndicatorData( select, stats, query );
|
|
|
|
} )( StatsList );
|