timeSpentCell.tsx 987 B

123456789101112131415161718192021222324252627282930313233
  1. import clamp from 'lodash/clamp';
  2. import {Tooltip} from 'sentry/components/tooltip';
  3. import {tct} from 'sentry/locale';
  4. import {defined} from 'sentry/utils';
  5. import {formatPercentage, getDuration} from 'sentry/utils/formatters';
  6. import {TextAlignRight} from 'sentry/views/starfish/components/textAlign';
  7. interface Props {
  8. percentage?: number;
  9. total?: number;
  10. }
  11. export function TimeSpentCell({percentage, total}: Props) {
  12. const formattedPercentage = formatPercentage(clamp(percentage ?? 0, 0, 1));
  13. const formattedTotal = getDuration((total ?? 0) / 1000, 1);
  14. const tooltip = tct(
  15. 'The application spent [percentage] of its total time on this span.',
  16. {
  17. percentage: formattedPercentage,
  18. }
  19. );
  20. return (
  21. <TextAlignRight>
  22. <Tooltip isHoverable title={tooltip} showUnderline>
  23. {defined(total) ? formattedTotal : '--'} {'('}
  24. {defined(percentage) ? formattedPercentage : '--%'}
  25. {')'}
  26. </Tooltip>
  27. </TextAlignRight>
  28. );
  29. }