timeSpentCell.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 formattedTotal = getDuration((total ?? 0) / 1000, 2, true);
  23. const tooltip = percentage ? getTimeSpentExplanation(percentage, op) : undefined;
  24. return (
  25. <NumberContainer {...containerProps}>
  26. <Tooltip isHoverable title={tooltip} showUnderline>
  27. {defined(total) ? formattedTotal : '--'}
  28. </Tooltip>
  29. </NumberContainer>
  30. );
  31. }
  32. export function getTimeSpentExplanation(percentage: number, op?: string) {
  33. const formattedPercentage = formatPercentage(clamp(percentage ?? 0, 0, 1));
  34. return tct(
  35. 'The application spent [percentage] of its total time on this [span]. Read more about Time Spent in our [documentation:documentation].',
  36. {
  37. percentage: formattedPercentage,
  38. span: formatSpanOperation(op, 'short'),
  39. documentation: (
  40. <ExternalLink href="https://docs.sentry.io/product/performance/queries/#what-is-time-spent" />
  41. ),
  42. }
  43. );
  44. }