2018-05-03 18:23:17 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-09-04 15:39:22 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2018-10-31 02:07:16 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2019-01-17 14:08:59 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2020-05-14 03:23:03 +00:00
|
|
|
import { getPersistedQuery } from '@woocommerce/navigation';
|
2019-09-23 21:47:08 +00:00
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
2020-03-25 03:20:17 +00:00
|
|
|
import { SETTINGS_STORE_NAME } from '@woocommerce/data';
|
2018-08-20 21:18:13 +00:00
|
|
|
import {
|
|
|
|
EllipsisMenu,
|
|
|
|
MenuItem,
|
|
|
|
MenuTitle,
|
2018-10-31 02:07:16 +00:00
|
|
|
SectionHeader,
|
2018-08-20 21:18:13 +00:00
|
|
|
SummaryList,
|
2019-01-17 14:08:59 +00:00
|
|
|
SummaryListPlaceholder,
|
2018-08-20 21:18:13 +00:00
|
|
|
SummaryNumber,
|
|
|
|
} from '@woocommerce/components';
|
2020-08-17 21:53:13 +00:00
|
|
|
import { getDateParamsFromQuery } from '@woocommerce/date';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2020-08-13 02:05:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import withSelect from '../../wc-api/with-select';
|
2018-06-29 18:27:18 +00:00
|
|
|
import './style.scss';
|
2020-08-13 02:05:22 +00:00
|
|
|
import { CurrencyContext } from '../../lib/currency-context';
|
2020-06-04 23:14:55 +00:00
|
|
|
import { getIndicatorData, getIndicatorValues } from './utils';
|
2018-05-10 19:23:41 +00:00
|
|
|
|
2019-09-23 21:47:08 +00:00
|
|
|
const { performanceIndicators: indicators } = getSetting( 'dataEndpoints', {
|
2020-05-04 22:58:39 +00:00
|
|
|
performanceIndicators: [],
|
2019-09-23 21:47:08 +00:00
|
|
|
} );
|
|
|
|
|
2018-07-02 18:08:50 +00:00
|
|
|
class StorePerformance extends Component {
|
2018-05-14 15:47:42 +00:00
|
|
|
renderMenu() {
|
2019-04-30 00:35:37 +00:00
|
|
|
const {
|
2019-05-07 07:21:34 +00:00
|
|
|
hiddenBlocks,
|
|
|
|
isFirst,
|
|
|
|
isLast,
|
|
|
|
onMove,
|
|
|
|
onRemove,
|
2019-04-30 00:35:37 +00:00
|
|
|
onTitleBlur,
|
|
|
|
onTitleChange,
|
2019-05-07 07:21:34 +00:00
|
|
|
onToggleHiddenBlock,
|
2019-04-30 00:35:37 +00:00
|
|
|
titleInput,
|
2019-05-09 01:13:14 +00:00
|
|
|
controls: Controls,
|
2019-04-30 00:35:37 +00:00
|
|
|
} = this.props;
|
2019-05-02 10:22:34 +00:00
|
|
|
|
2018-05-14 15:47:42 +00:00
|
|
|
return (
|
2019-05-02 10:22:34 +00:00
|
|
|
<EllipsisMenu
|
|
|
|
label={ __(
|
|
|
|
'Choose which analytics to display and the section name',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
2019-05-03 01:37:16 +00:00
|
|
|
renderContent={ ( { onToggle } ) => (
|
2019-04-30 00:35:37 +00:00
|
|
|
<Fragment>
|
2020-02-14 02:23:21 +00:00
|
|
|
<MenuTitle>
|
|
|
|
{ __( 'Display Stats:', 'woocommerce-admin' ) }
|
|
|
|
</MenuTitle>
|
2019-04-30 00:35:37 +00:00
|
|
|
{ indicators.map( ( indicator, i ) => {
|
2020-02-14 02:23:21 +00:00
|
|
|
const checked = ! hiddenBlocks.includes(
|
|
|
|
indicator.stat
|
|
|
|
);
|
2019-04-30 00:35:37 +00:00
|
|
|
return (
|
|
|
|
<MenuItem
|
|
|
|
checked={ checked }
|
|
|
|
isCheckbox
|
|
|
|
isClickable
|
|
|
|
key={ i }
|
2019-07-01 10:16:12 +00:00
|
|
|
onInvoke={ () => {
|
|
|
|
onToggleHiddenBlock( indicator.stat )();
|
|
|
|
recordEvent( 'dash_indicators_toggle', {
|
|
|
|
status: checked ? 'off' : 'on',
|
|
|
|
key: indicator.stat,
|
|
|
|
} );
|
|
|
|
} }
|
2019-04-30 00:35:37 +00:00
|
|
|
>
|
2019-09-04 15:39:22 +00:00
|
|
|
{ indicator.label }
|
2019-04-30 00:35:37 +00:00
|
|
|
</MenuItem>
|
|
|
|
);
|
|
|
|
} ) }
|
2020-02-14 02:23:21 +00:00
|
|
|
{ window.wcAdminFeatures[
|
|
|
|
'analytics-dashboard/customizable'
|
|
|
|
] && (
|
2019-05-22 20:43:45 +00:00
|
|
|
<Controls
|
|
|
|
onToggle={ onToggle }
|
|
|
|
onMove={ onMove }
|
|
|
|
onRemove={ onRemove }
|
|
|
|
isFirst={ isFirst }
|
|
|
|
isLast={ isLast }
|
|
|
|
onTitleBlur={ onTitleBlur }
|
|
|
|
onTitleChange={ onTitleChange }
|
|
|
|
titleInput={ titleInput }
|
|
|
|
/>
|
2019-05-09 01:13:14 +00:00
|
|
|
) }
|
2019-04-30 00:35:37 +00:00
|
|
|
</Fragment>
|
2019-05-02 10:22:34 +00:00
|
|
|
) }
|
2019-04-30 00:35:37 +00:00
|
|
|
/>
|
2018-05-14 15:47:42 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-17 14:08:59 +00:00
|
|
|
renderList() {
|
|
|
|
const {
|
|
|
|
query,
|
|
|
|
primaryRequesting,
|
|
|
|
secondaryRequesting,
|
|
|
|
primaryError,
|
|
|
|
secondaryError,
|
|
|
|
primaryData,
|
|
|
|
secondaryData,
|
|
|
|
userIndicators,
|
2020-03-25 03:20:17 +00:00
|
|
|
defaultDateRange,
|
2019-01-17 14:08:59 +00:00
|
|
|
} = this.props;
|
|
|
|
if ( primaryRequesting || secondaryRequesting ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
return (
|
|
|
|
<SummaryListPlaceholder
|
|
|
|
numberOfItems={ userIndicators.length }
|
|
|
|
/>
|
|
|
|
);
|
2019-01-17 14:08:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( primaryError || secondaryError ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const persistedQuery = getPersistedQuery( query );
|
|
|
|
|
2020-03-25 03:20:17 +00:00
|
|
|
const { compare } = getDateParamsFromQuery( query, defaultDateRange );
|
2019-01-17 14:08:59 +00:00
|
|
|
const prevLabel =
|
2020-02-14 02:23:21 +00:00
|
|
|
compare === 'previous_period'
|
2019-03-13 17:14:02 +00:00
|
|
|
? __( 'Previous Period:', 'woocommerce-admin' )
|
|
|
|
: __( 'Previous Year:', 'woocommerce-admin' );
|
2020-06-17 23:33:40 +00:00
|
|
|
const { formatAmount, getCurrencyConfig } = this.context;
|
|
|
|
const currency = getCurrencyConfig();
|
2019-01-17 14:08:59 +00:00
|
|
|
return (
|
|
|
|
<SummaryList>
|
2019-01-17 03:28:41 +00:00
|
|
|
{ () =>
|
|
|
|
userIndicators.map( ( indicator, i ) => {
|
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,
|
|
|
|
primaryData,
|
|
|
|
secondaryData,
|
|
|
|
currency,
|
2020-06-17 23:33:40 +00:00
|
|
|
formatAmount,
|
2020-05-14 03:23:03 +00:00
|
|
|
persistedQuery,
|
|
|
|
} );
|
2019-01-17 14:08:59 +00:00
|
|
|
|
2019-01-17 03:28:41 +00:00
|
|
|
return (
|
|
|
|
<SummaryNumber
|
|
|
|
key={ i }
|
|
|
|
href={ reportUrl }
|
2020-06-04 23:14:55 +00:00
|
|
|
hrefType={ reportUrlType }
|
2019-01-17 03:28:41 +00:00
|
|
|
label={ indicator.label }
|
|
|
|
value={ primaryValue }
|
|
|
|
prevLabel={ prevLabel }
|
|
|
|
prevValue={ secondaryValue }
|
|
|
|
delta={ delta }
|
2019-07-01 10:16:12 +00:00
|
|
|
onLinkClickCallback={ () => {
|
2020-02-14 02:23:21 +00:00
|
|
|
recordEvent( 'dash_indicators_click', {
|
|
|
|
key: indicator.stat,
|
|
|
|
} );
|
2019-07-01 10:16:12 +00:00
|
|
|
} }
|
2019-01-17 03:28:41 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
} )
|
|
|
|
}
|
2019-01-17 14:08:59 +00:00
|
|
|
</SummaryList>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-05-07 07:20:48 +00:00
|
|
|
const { userIndicators, title } = this.props;
|
2018-05-03 18:23:17 +00:00
|
|
|
return (
|
2018-10-31 02:07:16 +00:00
|
|
|
<Fragment>
|
2019-03-13 17:14:02 +00:00
|
|
|
<SectionHeader
|
2020-02-14 02:23:21 +00:00
|
|
|
title={
|
|
|
|
title || __( 'Store Performance', 'woocommerce-admin' )
|
|
|
|
}
|
2019-03-13 17:14:02 +00:00
|
|
|
menu={ this.renderMenu() }
|
|
|
|
/>
|
2019-05-07 07:20:48 +00:00
|
|
|
{ userIndicators.length > 0 && (
|
2020-02-14 02:23:21 +00:00
|
|
|
<div className="woocommerce-dashboard__store-performance">
|
|
|
|
{ this.renderList() }
|
|
|
|
</div>
|
2019-05-07 07:20:48 +00:00
|
|
|
) }
|
2018-10-31 02:07:16 +00:00
|
|
|
</Fragment>
|
2018-05-03 18:23:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-04-02 21:54:38 +00:00
|
|
|
|
|
|
|
StorePerformance.contextType = CurrencyContext;
|
|
|
|
|
2019-01-17 14:08:59 +00:00
|
|
|
export default compose(
|
|
|
|
withSelect( ( select, props ) => {
|
2020-07-20 22:17:28 +00:00
|
|
|
const { hiddenBlocks, query, filters } = props;
|
2019-04-03 01:36:20 +00:00
|
|
|
const userIndicators = indicators.filter(
|
2020-02-14 02:23:21 +00:00
|
|
|
( indicator ) => ! hiddenBlocks.includes( indicator.stat )
|
2019-04-03 01:36:20 +00:00
|
|
|
);
|
2020-05-14 03:23:03 +00:00
|
|
|
const { woocommerce_default_date_range: defaultDateRange } = select(
|
|
|
|
SETTINGS_STORE_NAME
|
|
|
|
).getSetting( 'wc_admin', 'wcAdminSettings' );
|
2019-01-17 14:08:59 +00:00
|
|
|
|
2020-05-14 03:23:03 +00:00
|
|
|
const data = {
|
2019-05-07 07:21:34 +00:00
|
|
|
hiddenBlocks,
|
2019-01-17 14:08:59 +00:00
|
|
|
userIndicators,
|
|
|
|
indicators,
|
2020-03-25 03:20:17 +00:00
|
|
|
defaultDateRange,
|
2019-01-17 14:08:59 +00:00
|
|
|
};
|
2020-05-14 03:23:03 +00:00
|
|
|
if ( userIndicators.length === 0 ) {
|
|
|
|
return data;
|
|
|
|
}
|
2020-07-20 22:17:28 +00:00
|
|
|
const indicatorData = getIndicatorData(
|
|
|
|
select,
|
|
|
|
userIndicators,
|
|
|
|
query,
|
|
|
|
filters
|
|
|
|
);
|
2020-05-14 03:23:03 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...data,
|
|
|
|
...indicatorData,
|
|
|
|
};
|
2019-01-17 14:08:59 +00:00
|
|
|
} )
|
|
|
|
)( StorePerformance );
|