/** * WordPress dependencies */ import { SelectControl, Spinner } from '@wordpress/components'; import { useState } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies */ import { getMetricDescription, isInEnum, Metric } from '../../common/utils/constants'; import { PerformanceStatPanel } from './component-panel'; import { PerformanceData } from './model'; /** * PerformanceReferrersPanel component props. * * @since 3.14.0 */ type PerformanceReferrersPanelProps = { data: PerformanceData; isLoading: boolean; } /** * The Referrers panel for the Performance Stats Sidebar. * * @since 3.14.0 * * @param {PerformanceReferrersPanelProps} props The component's props. * * @return {import('react').JSX.Element} The PerformanceReferrersPanel JSX Element. */ export const PerformanceReferrersPanel = ( { data, isLoading, }: Readonly ): React.JSX.Element => { const [ metric, setMetric ] = useState( Metric.Views ); const [ isOpen, setIsOpen ] = useState( false ); /* translators: %s: metric description */ const subtitle = sprintf( __( 'By %s', 'wp-parsely' ), getMetricDescription( metric ) ); return ( setIsOpen( ! isOpen ) } > { isOpen && (
{ if ( isInEnum( selection, Metric ) ) { setMetric( selection as Metric ); } } } > { Object.values( Metric ).map( ( value ) => ( ) ) }
) } { isLoading ? (
) : (
{ Object.entries( data.referrers.top ).map( ( [ key, value ] ) => { if ( key === 'totals' ) { return null; } let referrerUrl = key; if ( key === 'direct' ) { referrerUrl = __( 'Direct', 'wp-parsely' ); } /* translators: %s: Percentage value, %%: Escaped percent sign */ const ariaLabel = sprintf( __( '%s%%', 'wp-parsely' ), value.viewsPercentage ); // eslint-disable-line @wordpress/valid-sprintf return (
{ referrerUrl }
{ value.views }
); } ) }
) }
); };