TraceDetailsRouting.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {useEffect} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import type {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 type {Event} from 'sentry/types';
  8. import type {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 (organization.features.includes('performance-trace-details')) {
  26. if (event?.groupID && event?.eventID) {
  27. const issuesLocation = `/organizations/${organization.slug}/issues/${event.groupID}/events/${event.eventID}`;
  28. browserHistory.replace({
  29. pathname: issuesLocation,
  30. });
  31. } else if (
  32. metaResults?.meta &&
  33. metaResults?.meta.transactions <= DEFAULT_TRACE_ROWS_LIMIT
  34. ) {
  35. const traceDetailsLocation: LocationDescriptorObject = getTraceDetailsUrl(
  36. organization,
  37. traceId,
  38. datetimeSelection,
  39. location.query
  40. );
  41. browserHistory.replace({
  42. pathname: traceDetailsLocation.pathname,
  43. query: traceDetailsLocation.query,
  44. hash: transactionTargetHash(event.eventID) + location.hash,
  45. });
  46. }
  47. }
  48. }, [event, metaResults, location, organization, datetimeSelection]);
  49. if (
  50. metaResults?.isLoading &&
  51. organization.features.includes('performance-trace-details')
  52. ) {
  53. return <LoadingIndicator />;
  54. }
  55. return children;
  56. }
  57. export default TraceDetailsRouting;