TraceDetailsRouting.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {useEffect} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import type {LocationDescriptorObject} from 'history';
  4. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  5. import {getEventTimestamp} from 'sentry/components/quickTrace/utils';
  6. import type {Event} from 'sentry/types';
  7. import {useLocation} from 'sentry/utils/useLocation';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {getTraceDetailsUrl} from './utils';
  10. type Props = {
  11. children: JSX.Element;
  12. event: Event;
  13. };
  14. function TraceDetailsRouting(props: Props) {
  15. const {event, children} = props;
  16. const organization = useOrganization();
  17. const location = useLocation();
  18. const datetimeSelection = normalizeDateTimeParams(location.query);
  19. useEffect(() => {
  20. const traceId = event.contexts?.trace?.trace_id ?? '';
  21. if (organization.features.includes('trace-view-v1')) {
  22. if (event?.groupID && event?.eventID) {
  23. const issuesLocation = `/organizations/${organization.slug}/issues/${event.groupID}/events/${event.eventID}`;
  24. browserHistory.replace({
  25. pathname: issuesLocation,
  26. });
  27. } else {
  28. const traceDetailsLocation: LocationDescriptorObject = getTraceDetailsUrl(
  29. organization,
  30. traceId,
  31. datetimeSelection,
  32. location.query,
  33. getEventTimestamp(event),
  34. event.eventID
  35. );
  36. browserHistory.replace({
  37. pathname: traceDetailsLocation.pathname,
  38. query: traceDetailsLocation.query,
  39. });
  40. }
  41. }
  42. }, [event, location, organization, datetimeSelection]);
  43. return children;
  44. }
  45. export default TraceDetailsRouting;