/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Component, Fragment } from '@wordpress/element'; import { compose } from '@wordpress/compose'; /** * WooCommerce dependencies */ import { getDateParamsFromQuery } from 'lib/date'; import { getPersistedQuery } from '@woocommerce/navigation'; import { getSetting } from '@woocommerce/wc-admin-settings'; import { SETTINGS_STORE_NAME } from '@woocommerce/data'; /** * Internal dependencies */ import { EllipsisMenu, MenuItem, MenuTitle, SectionHeader, SummaryList, SummaryListPlaceholder, SummaryNumber, } from '@woocommerce/components'; import withSelect from 'wc-api/with-select'; import './style.scss'; import { recordEvent } from 'lib/tracks'; import { CurrencyContext } from 'lib/currency-context'; import { getIndicatorData, getIndicatorValues } from './utils'; const { performanceIndicators: indicators } = getSetting( 'dataEndpoints', { performanceIndicators: [], } ); class StorePerformance extends Component { renderMenu() { const { hiddenBlocks, isFirst, isLast, onMove, onRemove, onTitleBlur, onTitleChange, onToggleHiddenBlock, titleInput, controls: Controls, } = this.props; return ( ( { __( 'Display Stats:', 'woocommerce-admin' ) } { indicators.map( ( indicator, i ) => { const checked = ! hiddenBlocks.includes( indicator.stat ); return ( { onToggleHiddenBlock( indicator.stat )(); recordEvent( 'dash_indicators_toggle', { status: checked ? 'off' : 'on', key: indicator.stat, } ); } } > { indicator.label } ); } ) } { window.wcAdminFeatures[ 'analytics-dashboard/customizable' ] && ( ) } ) } /> ); } renderList() { const { query, primaryRequesting, secondaryRequesting, primaryError, secondaryError, primaryData, secondaryData, userIndicators, defaultDateRange, } = this.props; if ( primaryRequesting || secondaryRequesting ) { return ( ); } if ( primaryError || secondaryError ) { return null; } const persistedQuery = getPersistedQuery( query ); const { compare } = getDateParamsFromQuery( query, defaultDateRange ); const prevLabel = compare === 'previous_period' ? __( 'Previous Period:', 'woocommerce-admin' ) : __( 'Previous Year:', 'woocommerce-admin' ); const { formatCurrency, getCurrency } = this.context; const currency = getCurrency(); return ( { () => userIndicators.map( ( indicator, i ) => { const { primaryValue, secondaryValue, delta, reportUrl, reportUrlType, } = getIndicatorValues( { indicator, primaryData, secondaryData, currency, formatCurrency, persistedQuery, } ); return ( { recordEvent( 'dash_indicators_click', { key: indicator.stat, } ); } } /> ); } ) } ); } render() { const { userIndicators, title } = this.props; return ( { userIndicators.length > 0 && (
{ this.renderList() }
) }
); } } StorePerformance.contextType = CurrencyContext; export default compose( withSelect( ( select, props ) => { const { hiddenBlocks, query } = props; const userIndicators = indicators.filter( ( indicator ) => ! hiddenBlocks.includes( indicator.stat ) ); const { woocommerce_default_date_range: defaultDateRange } = select( SETTINGS_STORE_NAME ).getSetting( 'wc_admin', 'wcAdminSettings' ); const data = { hiddenBlocks, userIndicators, indicators, defaultDateRange, }; if ( userIndicators.length === 0 ) { return data; } const indicatorData = getIndicatorData( select, userIndicators, query ); return { ...data, ...indicatorData, }; } ) )( StorePerformance );