TraceDetailsRouting.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {useEffect} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import {LocationDescriptorObject} from 'history';
  4. import {transactionTargetHash} from 'sentry/components/events/interfaces/spans/utils';
  5. import LoadingIndicator from 'sentry/components/loadingIndicator';
  6. import {Event} from 'sentry/types';
  7. import {TraceMetaQueryChildrenProps} from 'sentry/utils/performance/quickTrace/traceMetaQuery';
  8. import {useLocation} from 'sentry/utils/useLocation';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. import {DEFAULT_TRACE_ROWS_LIMIT} from './limitExceededMessage';
  11. import {getTraceDetailsUrl} from './utils';
  12. type Props = {
  13. children: JSX.Element;
  14. event: Event;
  15. metaResults: TraceMetaQueryChildrenProps | undefined;
  16. }
  17. function TraceDetailsRouting(props: Props) {
  18. const {metaResults, event, children} = props;
  19. const organization = useOrganization();
  20. const location = useLocation();
  21. useEffect(() => {
  22. const traceId = event.contexts?.trace?.trace_id ?? '';
  23. if (
  24. organization.features.includes('performance-trace-details') &&
  25. metaResults?.meta &&
  26. metaResults?.meta.transactions <= DEFAULT_TRACE_ROWS_LIMIT
  27. ) {
  28. const traceDetailsLocation: LocationDescriptorObject = getTraceDetailsUrl(
  29. organization,
  30. traceId,
  31. event.title,
  32. location.query
  33. );
  34. browserHistory.replace({
  35. pathname: traceDetailsLocation.pathname,
  36. query: {
  37. transaction: traceDetailsLocation.query?.transaction,
  38. },
  39. hash: transactionTargetHash(event.eventID) + location.hash,
  40. });
  41. }
  42. }, [event, metaResults, location , organization]);
  43. if (metaResults?.isLoading &&
  44. organization.features.includes('performance-trace-details')
  45. ) {
  46. return <LoadingIndicator />;
  47. }
  48. return children;
  49. }
  50. export default TraceDetailsRouting;