TraceDetailsRouting.tsx 2.0 KB

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