import React from 'react'; import withTestData from '../../experiments/data/with-test-data'; import { getLetter, getDateString, getDurationString, } from '../../utils'; import { Button } from '@/components/ui/button'; import { Caption } from '@/components/ui/typography'; import { cn } from '@/lib/utils'; const { __ } = wp.i18n; const TrayResults = ( props: any ) => { const { abTest, test = {}, values = [], resetTest, revertValue, } = props; const { results, end_time: endTime, start_time: startTime, traffic_percentage: trafficPercentage, } = test; const { winner = null, variants = [], } = results; const hasEnded = endTime < Date.now(); return ( <> { /* Results table */ } { values.map( ( value: any, index: number ) => { const variant = variants[ index ] || { rate: 0.0 }; const isWinner = index === winner; return ( 0 && 'border-t' ) } style={ index > 0 ? { borderTopColor: '#ddd' } : {} } > ); } ) }
{ __( 'Variant', 'altis' ) } { abTest.singleTitle } { __( 'Conversion', 'altis' ) } { __( 'Status', 'altis' ) }
{ `${ __( 'Variant', 'altis' ) } ${ getLetter( index ) }` } { index === 0 ? ` ${ __( '(original)', 'altis' ) }` : '' } { abTest.displayValue( value ) } { ( variant.rate * 100 ).toFixed( 2 ) }% { isWinner && ( { __( 'Winner', 'altis' ) } ) }
{ /* Metadata + actions bar */ }
{ /* Result notice */ } { winner !== null ? __( 'Test complete — we have a winner!', 'altis' ) : hasEnded ? __( 'Test ended without a clear winner.', 'altis' ) : '' }
{ /* Metadata */ }
{ __( 'Traffic', 'altis' ) }: { trafficPercentage }% { __( 'Started', 'altis' ) }: { getDateString( startTime ) } { __( 'Ended', 'altis' ) }: { getDateString( endTime ) } { __( 'Duration', 'altis' ) }: { getDurationString( endTime - startTime ) }
{ /* Actions */ }
{ winner !== null && winner !== 0 && ( ) } { winner === 0 && ( { __( 'The original performed best — no changes needed.', 'altis' ) } ) }
); }; export const ExperimentTrayResults = withTestData( TrayResults );