common.tsx 743 B

123456789101112131415161718192021222324252627282930
  1. import styled from '@emotion/styled';
  2. import {t} from 'sentry/locale';
  3. type Props = {
  4. duration: number;
  5. p95: number;
  6. };
  7. export function DurationComparisonCell({duration, p95}: Props) {
  8. const diff = duration - p95;
  9. if (Math.floor(duration) === Math.floor(p95)) {
  10. return <PlaintextLabel>{t('At baseline')}</PlaintextLabel>;
  11. }
  12. const labelString =
  13. diff > 0 ? `+${diff.toFixed(2)}ms above` : `${diff.toFixed(2)}ms below`;
  14. return <ComparisonLabel value={diff}>{labelString}</ComparisonLabel>;
  15. }
  16. export const PlaintextLabel = styled('div')`
  17. text-align: right;
  18. `;
  19. export const ComparisonLabel = styled('div')<{value: number}>`
  20. text-align: right;
  21. color: ${p => (p.value < 0 ? p.theme.green400 : p.theme.red400)};
  22. `;