import React, { Fragment } from 'react'; import classNames from 'classnames'; import { __ } from '@wordpress/i18n'; import apiFetch from '@wordpress/api-fetch'; import format from 'date-fns/format'; import formatDistance from 'date-fns/formatDistance'; import Table from '../../components/Table/Table'; import Significance from '../../../Significance/Significance'; import { decodeLink } from '../../../../helpers/wordpress'; import './Overview.css'; type OverviewData = { activeTests: TestData[]; }; function postLink(name: string, link?: string, testId?: string): React.ReactNode | string { const decodedLink = decodeLink(link); const url = [ decodedLink, testId ? '&test=' : '', testId, ].join(''); return link ? ({name !== '' ? name : __('No Name', 'ab-testing-for-wp')}) : name; } function removeLink(link?: string): React.ReactNode | null { return postLink(__('Remove', 'ab-testing-for-wp'), link); } function startTest(id: string, isEnabled: boolean, cb: () => void): void { apiFetch({ path: 'ab-testing-for-wp/v1/update-test', method: 'POST', data: { id, isEnabled }, }) .then((data) => { if (!ABTestingForWP_Data) return; ABTestingForWP_Data.activeTests = ABTestingForWP_Data.activeTests.map((t) => { if (t.id === data.id) return data; return t; }); cb(); }); } const toTestVariantResult = (variant: TestVariant): { id: TestVariant['id']; name: TestVariant['name']; participants: TestVariant['participants']; conversions: TestVariant['conversions']; } => ({ id: variant.id, name: variant.name, participants: variant.participants, conversions: variant.conversions, }); interface TestProps { test: TestData; reload: () => void; } const Test: React.FC = ({ test, reload }) => { const isSingle = test.postType === 'abt4wp-test'; return ( {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}