timeSpentCell.tsx 1.6 KB

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