import styled from '@emotion/styled'; import {t} from 'sentry/locale'; import getDuration from 'sentry/utils/duration/getDuration'; import {TextAlignRight} from 'sentry/views/insights/common/components/textAlign'; type Props = { compareToDuration: number; duration: number; containerProps?: React.DetailedHTMLProps< React.HTMLAttributes, HTMLSpanElement >; }; export function DurationComparisonCell({ duration, compareToDuration, containerProps, }: Props) { const diff = duration - compareToDuration; if (isNearAverage(duration, compareToDuration)) { return {t('Near Average')}; } const readableDiff = getDuration(diff / 1000, 2, true, true); const labelString = diff > 0 ? `+${readableDiff} above` : `${readableDiff} below`; return ( {labelString} ); } export const isNearAverage = (duration: number, compareToDuration: number) => { const maxDiff = 0.03 * compareToDuration; const diff = Math.abs(duration - compareToDuration); return diff < maxDiff; }; const ComparisonLabel = styled('span')<{value: number}>` color: ${p => p.value === 0 ? p.theme.subText : p.value < 0 ? p.theme.green400 : p.theme.red400}; text-align: right; `;