overleaf/services/web/frontend/js/shared/components/split-test-badge.tsx
Alexandre Bourdin e9e36737e6 Merge pull request #8957 from overleaf/ab-split-test-controls-badge
[web] SplitTestBadge based on split test phase and badge config

GitOrigin-RevId: e178ca864fd6619ff61a2a84fc1ccb5d54e0a814
2022-07-26 08:04:28 +00:00

53 lines
1.3 KiB
TypeScript

import { useSplitTestContext } from '../context/split-test-context'
import BetaBadge from './beta-badge'
import { OverlayTriggerProps } from 'react-bootstrap'
type TooltipProps = {
id?: string
placement?: OverlayTriggerProps['placement']
className?: string
}
type SplitTestBadgeProps = {
splitTestName: string
displayOnVariants: string[]
tooltip?: TooltipProps
}
export default function SplitTestBadge({
splitTestName,
displayOnVariants,
tooltip = {},
}: SplitTestBadgeProps) {
const { splitTestVariants, splitTestInfo } = useSplitTestContext()
const testInfo = splitTestInfo[splitTestName]
if (!testInfo) {
return null
}
const variant = splitTestVariants[splitTestName]
if (!variant || !displayOnVariants.includes(variant)) {
return null
}
return (
<BetaBadge
tooltip={{
id: tooltip.id || `${splitTestName}-badge-tooltip`,
className: `split-test-badge-tooltip ${tooltip.className}`,
text: testInfo.badgeInfo?.tooltipText || (
<>
We are testing this new feature.
<br />
Click to give feedback
</>
),
}}
phase={testInfo.phase}
url={
testInfo.badgeInfo?.url?.length ? testInfo.badgeInfo?.url : undefined
}
/>
)
}