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-09-03 21:45:40 +00:00
|
|
|
import { withSelect } from '@wordpress/data';
|
2020-05-20 22:15:18 +00:00
|
|
|
import classnames from 'classnames';
|
2020-05-14 03:23:03 +00:00
|
|
|
import {
|
|
|
|
SummaryNumber,
|
|
|
|
SummaryNumberPlaceholder,
|
|
|
|
} from '@woocommerce/components';
|
|
|
|
import { getPersistedQuery } from '@woocommerce/navigation';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2020-05-14 03:23:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-08-13 02:05:22 +00:00
|
|
|
import { CurrencyContext } from '../../lib/currency-context';
|
2020-05-14 03:23:03 +00:00
|
|
|
import {
|
|
|
|
getIndicatorData,
|
2020-06-04 23:14:55 +00:00
|
|
|
getIndicatorValues,
|
2020-08-13 02:05:22 +00:00
|
|
|
} from '../../dashboard/store-performance/utils';
|
2020-05-14 03:23:03 +00:00
|
|
|
|
|
|
|
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-09-14 23:44:46 +00:00
|
|
|
return <SummaryNumberPlaceholder key={ item.stat } />;
|
2020-05-14 03:23:03 +00:00
|
|
|
}
|
2020-09-14 23:44:46 +00:00
|
|
|
|
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={ __(
|
2021-08-13 18:54:24 +00:00
|
|
|
'Previous period:',
|
2020-05-14 03:23:03 +00:00
|
|
|
'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 );
|