TraceDetailsRouting.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import type {LocationDescriptorObject} from 'history';
  2. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  3. import {getEventTimestamp} from 'sentry/components/quickTrace/utils';
  4. import type {Event} from 'sentry/types/event';
  5. import {browserHistory} from 'sentry/utils/browserHistory';
  6. import {useLocation} from 'sentry/utils/useLocation';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import {getTraceDetailsUrl, shouldForceRouteToOldView} from './utils';
  9. type Props = {
  10. children: JSX.Element;
  11. event: Event;
  12. };
  13. function TraceDetailsRouting(props: Props) {
  14. const {event, children} = props;
  15. const organization = useOrganization();
  16. const location = useLocation();
  17. const datetimeSelection = normalizeDateTimeParams(location.query);
  18. const traceId = event.contexts?.trace?.trace_id ?? '';
  19. if (location.query?.legacy) {
  20. return children;
  21. }
  22. if (
  23. organization.features.includes('trace-view-v1') &&
  24. !shouldForceRouteToOldView(organization, getEventTimestamp(event))
  25. ) {
  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 {
  32. const traceDetailsLocation: LocationDescriptorObject = getTraceDetailsUrl({
  33. organization,
  34. traceSlug: traceId,
  35. dateSelection: datetimeSelection,
  36. timestamp: getEventTimestamp(event),
  37. eventId: event.eventID,
  38. location,
  39. });
  40. const query = {...traceDetailsLocation.query};
  41. if (location.hash.includes('span')) {
  42. const spanHashValue = location.hash
  43. .split('#')
  44. .filter(value => value.includes('span'))[0];
  45. const spanId = spanHashValue.split('-')[1];
  46. if (spanId) {
  47. query.node = [`span-${spanId}`, `txn-${event.eventID}`];
  48. }
  49. }
  50. browserHistory.replace({
  51. pathname: traceDetailsLocation.pathname,
  52. query,
  53. });
  54. }
  55. }
  56. return children;
  57. }
  58. export default TraceDetailsRouting;