/** * Active A/B tests for a prompt (#150) — shows the traffic split per variant. * Per-variant metrics are comparable via the existing per-version analytics. */ import React from 'react'; import { useApi } from '../hooks/useApi'; import { listAbTests } from '../api/prompt-ab'; export function PromptAbTests({ templateId }: { templateId: string }): React.ReactElement | null { const { data } = useApi(() => listAbTests(templateId), [templateId]); const active = (data?.abTests ?? []).filter((t) => t.status === 'active'); if (active.length === 0) return null; return (

A/B tests

{active.map((t) => { const total = t.variants.reduce((s, v) => s + v.weight, 0) || 1; return (
{t.environment} · traffic split
{t.variants.map((v) => ( {v.label}: {Math.round((v.weight / total) * 100)}%{' '} ({v.versionId.slice(0, 8)}) ))}
); })}
); } export default PromptAbTests;