timeSpentCell.tsx 1.6 KB

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