performanceDuration.tsx 853 B

123456789101112131415161718192021222324252627282930313233343536
  1. import Duration from 'sentry/components/duration';
  2. import {defined} from 'sentry/utils';
  3. interface DurationProps {
  4. abbreviation?: boolean;
  5. }
  6. interface SecondsProps extends DurationProps {
  7. seconds: number;
  8. }
  9. interface MillisecondsProps extends DurationProps {
  10. milliseconds: number;
  11. }
  12. type PerformanceDurationProps = SecondsProps | MillisecondsProps;
  13. function hasMilliseconds(props: PerformanceDurationProps): props is MillisecondsProps {
  14. return defined((props as MillisecondsProps).milliseconds);
  15. }
  16. function PerformanceDuration(props: PerformanceDurationProps) {
  17. const normalizedSeconds = hasMilliseconds(props)
  18. ? props.milliseconds / 1000
  19. : props.seconds;
  20. return (
  21. <Duration
  22. abbreviation={props.abbreviation}
  23. seconds={normalizedSeconds}
  24. fixedDigits={2}
  25. />
  26. );
  27. }
  28. export default PerformanceDuration;