Jetpack stats on home page (https://github.com/woocommerce/woocommerce-admin/pull/4481)
* Get Jetpack stats appearing on the home page * Update hidden stats in stats overview test * Make jetpack stats appear by default * Add reportUrlType to dashboard store performance area Co-authored-by: Rebecca Scott <me@becdetat.com>
This commit is contained in:
parent
479817cdad
commit
b4c735f0de
|
@ -30,7 +30,7 @@ import withSelect from 'wc-api/with-select';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
import { recordEvent } from 'lib/tracks';
|
import { recordEvent } from 'lib/tracks';
|
||||||
import { CurrencyContext } from 'lib/currency-context';
|
import { CurrencyContext } from 'lib/currency-context';
|
||||||
import { getIndicatorData, getIndictorValues } from './utils';
|
import { getIndicatorData, getIndicatorValues } from './utils';
|
||||||
|
|
||||||
const { performanceIndicators: indicators } = getSetting( 'dataEndpoints', {
|
const { performanceIndicators: indicators } = getSetting( 'dataEndpoints', {
|
||||||
performanceIndicators: [],
|
performanceIndicators: [],
|
||||||
|
@ -146,7 +146,8 @@ class StorePerformance extends Component {
|
||||||
secondaryValue,
|
secondaryValue,
|
||||||
delta,
|
delta,
|
||||||
reportUrl,
|
reportUrl,
|
||||||
} = getIndictorValues( {
|
reportUrlType,
|
||||||
|
} = getIndicatorValues( {
|
||||||
indicator,
|
indicator,
|
||||||
primaryData,
|
primaryData,
|
||||||
secondaryData,
|
secondaryData,
|
||||||
|
@ -159,6 +160,7 @@ class StorePerformance extends Component {
|
||||||
<SummaryNumber
|
<SummaryNumber
|
||||||
key={ i }
|
key={ i }
|
||||||
href={ reportUrl }
|
href={ reportUrl }
|
||||||
|
hrefType={ reportUrlType }
|
||||||
label={ indicator.label }
|
label={ indicator.label }
|
||||||
value={ primaryValue }
|
value={ primaryValue }
|
||||||
prevLabel={ prevLabel }
|
prevLabel={ prevLabel }
|
||||||
|
|
|
@ -11,8 +11,23 @@ import { getCurrentDates, appendTimestamp } from '@woocommerce/date';
|
||||||
import { SETTINGS_STORE_NAME } from '@woocommerce/data';
|
import { SETTINGS_STORE_NAME } from '@woocommerce/data';
|
||||||
import { getNewPath } from '@woocommerce/navigation';
|
import { getNewPath } from '@woocommerce/navigation';
|
||||||
import { calculateDelta, formatValue } from '@woocommerce/number';
|
import { calculateDelta, formatValue } from '@woocommerce/number';
|
||||||
|
import { getAdminLink } from '@woocommerce/wc-admin-settings';
|
||||||
|
|
||||||
export const getIndictorValues = ( {
|
function getReportUrl( href, persistedQuery, primaryItem ) {
|
||||||
|
if ( ! href ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( href === '/jetpack' ) {
|
||||||
|
return getAdminLink( 'admin.php?page=jetpack#/dashboard' );
|
||||||
|
}
|
||||||
|
|
||||||
|
return getNewPath( persistedQuery, href, {
|
||||||
|
chart: primaryItem.chart,
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getIndicatorValues = ( {
|
||||||
indicator,
|
indicator,
|
||||||
primaryData,
|
primaryData,
|
||||||
secondaryData,
|
secondaryData,
|
||||||
|
@ -38,12 +53,8 @@ export const getIndictorValues = ( {
|
||||||
primaryItem._links.report[ 0 ] &&
|
primaryItem._links.report[ 0 ] &&
|
||||||
primaryItem._links.report[ 0 ].href ) ||
|
primaryItem._links.report[ 0 ].href ) ||
|
||||||
'';
|
'';
|
||||||
const reportUrl =
|
const reportUrl = getReportUrl( href, persistedQuery, primaryItem );
|
||||||
( href &&
|
const reportUrlType = href === '/jetpack' ? 'wp-admin' : 'wc-admin';
|
||||||
getNewPath( persistedQuery, href, {
|
|
||||||
chart: primaryItem.chart,
|
|
||||||
} ) ) ||
|
|
||||||
'';
|
|
||||||
const isCurrency = primaryItem.format === 'currency';
|
const isCurrency = primaryItem.format === 'currency';
|
||||||
|
|
||||||
const delta = calculateDelta( primaryItem.value, secondaryItem.value );
|
const delta = calculateDelta( primaryItem.value, secondaryItem.value );
|
||||||
|
@ -58,6 +69,7 @@ export const getIndictorValues = ( {
|
||||||
secondaryValue,
|
secondaryValue,
|
||||||
delta,
|
delta,
|
||||||
reportUrl,
|
reportUrl,
|
||||||
|
reportUrlType,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,8 @@ export const DEFAULT_STATS = applyFilters(
|
||||||
'revenue/net_revenue',
|
'revenue/net_revenue',
|
||||||
'orders/orders_count',
|
'orders/orders_count',
|
||||||
'products/items_sold',
|
'products/items_sold',
|
||||||
|
'jetpack/stats/visitors',
|
||||||
|
'jetpack/stats/views',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import { recordEvent } from 'lib/tracks';
|
||||||
import { CurrencyContext } from 'lib/currency-context';
|
import { CurrencyContext } from 'lib/currency-context';
|
||||||
import {
|
import {
|
||||||
getIndicatorData,
|
getIndicatorData,
|
||||||
getIndictorValues,
|
getIndicatorValues,
|
||||||
} from 'dashboard/store-performance/utils';
|
} from 'dashboard/store-performance/utils';
|
||||||
|
|
||||||
export const StatsList = ( {
|
export const StatsList = ( {
|
||||||
|
@ -62,7 +62,8 @@ export const StatsList = ( {
|
||||||
secondaryValue,
|
secondaryValue,
|
||||||
delta,
|
delta,
|
||||||
reportUrl,
|
reportUrl,
|
||||||
} = getIndictorValues( {
|
reportUrlType,
|
||||||
|
} = getIndicatorValues( {
|
||||||
indicator: item,
|
indicator: item,
|
||||||
primaryData,
|
primaryData,
|
||||||
secondaryData,
|
secondaryData,
|
||||||
|
@ -76,6 +77,7 @@ export const StatsList = ( {
|
||||||
isHomepage
|
isHomepage
|
||||||
key={ item.stat }
|
key={ item.stat }
|
||||||
href={ reportUrl }
|
href={ reportUrl }
|
||||||
|
hrefType={ reportUrlType }
|
||||||
label={ item.label }
|
label={ item.label }
|
||||||
value={ primaryValue }
|
value={ primaryValue }
|
||||||
prevLabel={ __(
|
prevLabel={ __(
|
||||||
|
|
|
@ -21,6 +21,7 @@ import Link from '../link';
|
||||||
const SummaryNumber = ( {
|
const SummaryNumber = ( {
|
||||||
delta,
|
delta,
|
||||||
href,
|
href,
|
||||||
|
hrefType,
|
||||||
isOpen,
|
isOpen,
|
||||||
label,
|
label,
|
||||||
onToggle,
|
onToggle,
|
||||||
|
@ -81,6 +82,7 @@ const SummaryNumber = ( {
|
||||||
containerProps.href = href;
|
containerProps.href = href;
|
||||||
containerProps.role = 'menuitem';
|
containerProps.role = 'menuitem';
|
||||||
containerProps.onClick = onLinkClickCallback;
|
containerProps.onClick = onLinkClickCallback;
|
||||||
|
containerProps.type = hrefType;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Container = 'div';
|
Container = 'div';
|
||||||
|
@ -154,6 +156,11 @@ SummaryNumber.propTypes = {
|
||||||
* An internal link to the report focused on this number.
|
* An internal link to the report focused on this number.
|
||||||
*/
|
*/
|
||||||
href: PropTypes.string,
|
href: PropTypes.string,
|
||||||
|
/**
|
||||||
|
* The type of the link
|
||||||
|
*/
|
||||||
|
hrefType: PropTypes.oneOf( [ 'wp-admin', 'wc-admin', 'external' ] )
|
||||||
|
.isRequired,
|
||||||
/**
|
/**
|
||||||
* Boolean describing whether the menu list is open. Only applies in mobile view,
|
* Boolean describing whether the menu list is open. Only applies in mobile view,
|
||||||
* and only applies to the toggle-able item (first in the list).
|
* and only applies to the toggle-able item (first in the list).
|
||||||
|
@ -196,6 +203,7 @@ SummaryNumber.propTypes = {
|
||||||
|
|
||||||
SummaryNumber.defaultProps = {
|
SummaryNumber.defaultProps = {
|
||||||
href: '',
|
href: '',
|
||||||
|
hrefType: 'wc-admin',
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
prevLabel: __( 'Previous Period:', 'woocommerce-admin' ),
|
prevLabel: __( 'Previous Period:', 'woocommerce-admin' ),
|
||||||
reverseTrend: false,
|
reverseTrend: false,
|
||||||
|
|
|
@ -231,6 +231,8 @@ class Controller extends \WC_REST_Reports_Controller {
|
||||||
$this->endpoints[ $endpoint ] = '/jetpack/v4/module/' . $item['module'] . '/data';
|
$this->endpoints[ $endpoint ] = '/jetpack/v4/module/' . $item['module'] . '/data';
|
||||||
$this->formats[ $stat ] = $item['format'];
|
$this->formats[ $stat ] = $item['format'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->urls['jetpack/stats'] = '/jetpack';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue