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