timeSpentCell.tsx 1.1 KB

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