// @flow import React, { Fragment } from 'react'; import classNames from 'classnames'; import format from 'date-fns/format'; import distanceInWords from 'date-fns/distance_in_words'; import Table from '../../components/Table/Table'; import Significance from '../../../Significance/Significance'; import { decodeLink } from '../../../../helpers/wordpress'; import { i18n } from '../../../../wp'; import './Overview.css'; const { __ } = i18n; type OverviewData = { activeTests: TestData[]; }; function postLink(name: string, link?: string, testId?: string) { const decodedLink = decodeLink(link); const url = [ decodedLink, testId ? '&test=' : '', testId, ].join(''); return link ? ({name !== '' ? name : __('No Name')}) : name; } function removeLink(link?: string) { return postLink(__('Remove'), link); } const toTestVariantResult = variant => ({ id: variant.id, name: variant.name, participants: variant.participants, conversions: variant.conversions, }); function Test(test: TestData) { const isSingle = test.postType === 'abt4wp-test'; return (
{postLink(test.title, test.postLink, test.id)}
{postLink(__('Edit'), test.postLink, test.id)} {isSingle && ' | '} {isSingle && ( {removeLink(test.postDeleteLink)} )}
{test.startedAt > 0 ? ( {format(test.startedAt, 'YYYY/MM/DD')} {` (${distanceInWords(test.startedAt, new Date())})`} ) : ( — )} { isSingle ? {`[ab-test id=${test.postId}]`} : postLink(test.postName, test.postLink, test.id) } {postLink(test.goalName, test.goalLink)} {test.totalParticipants} {test.totalParticipants > 0 ? ( {test.variants.map(variant => ( 0 ? 'ABTestWinning' : 'ABTestLosing'}> ))}
{__('Conversion Rate')} {__('Conversions')} {__('Participants')}
{variant.name} {variant.id === test.control && ' *'} {`${variant.rate}%`} {variant.uplift !== 0 && ( {[ ' (', variant.uplift > 0 ? '+' : '', variant.uplift, '%)', ].join('')} )} {variant.conversions} {variant.participants}
) : ( {__('No results for this test yet.')} )} {test.totalParticipants > 0 && ( )} ); } function Overview({ data }: { data: OverviewData }) { const { activeTests } = data; return (

{__('A/B Tests')}

{__('Add New')}
{activeTests && activeTests.length > 0 ? ( {activeTests.map(Test)}
{__('Title')} {__('Started at')} {__('Page / Shortcode')} {__('Conversion Goal')} {__('Participants')}
) : (

{__('No active tests found in content.')}

{__('Edit a page or post to add an A/B Test to the content.')}

)}
); } export default Overview;