// @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 (
{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 ? (
) : (
{__('No results for this test yet.')}
)}
{test.totalParticipants > 0 && (
{test.variants.map(variant => (
{__('Conversion Rate')}
{__('Conversions')}
{__('Participants')}
0 ? 'ABTestWinning' : 'ABTestLosing'}>
))}
{variant.name}
{variant.id === test.control && ' *'}
{`${variant.rate}%`}
{variant.uplift !== 0 && (
{[
' (',
variant.uplift > 0 ? '+' : '',
variant.uplift,
'%)',
].join('')}
)}
{variant.conversions}
{variant.participants}
| {__('Title')} | {__('Started at')} | {__('Page / Shortcode')} | {__('Conversion Goal')} | {__('Participants')} |
|---|
{__('Edit a page or post to add an A/B Test to the content.')}