timeSpentCell.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import clamp from 'lodash/clamp';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {Tooltip} from 'sentry/components/tooltip';
  4. import {tct} from 'sentry/locale';
  5. import {defined} from 'sentry/utils';
  6. import {NumberContainer} from 'sentry/utils/discover/styles';
  7. import {
  8. formatPercentage,
  9. formatSpanOperation,
  10. getDuration,
  11. } from 'sentry/utils/formatters';
  12. interface Props {
  13. containerProps?: React.DetailedHTMLProps<
  14. React.HTMLAttributes<HTMLDivElement>,
  15. HTMLDivElement
  16. >;
  17. op?: string;
  18. percentage?: number;
  19. total?: number;
  20. }
  21. export function TimeSpentCell({percentage, total, op, containerProps}: Props) {
  22. const formattedPercentage = formatPercentage(clamp(percentage ?? 0, 0, 1));
  23. const formattedTotal = getDuration((total ?? 0) / 1000, 2, true);
  24. const tooltip = tct(
  25. 'The application spent [percentage] of its total time on this [span]. Read more about Time Spent in our [documentation:documentation].',
  26. {
  27. percentage: formattedPercentage,
  28. span: formatSpanOperation(op, 'short'),
  29. documentation: (
  30. <ExternalLink href="https://docs.sentry.io/product/performance/queries/#what-is-time-spent" />
  31. ),
  32. }
  33. );
  34. return (
  35. <NumberContainer {...containerProps}>
  36. <Tooltip isHoverable title={tooltip} showUnderline>
  37. {defined(total) ? formattedTotal : '--'}
  38. </Tooltip>
  39. </NumberContainer>
  40. );
  41. }