breadcrumb.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {Location, LocationDescriptor} from 'history';
  2. import Breadcrumbs, {Crumb} from 'sentry/components/breadcrumbs';
  3. import {t} from 'sentry/locale';
  4. import {Organization} from 'sentry/types';
  5. import {SpanSlug} from 'sentry/utils/performance/suspectSpans/types';
  6. import {decodeScalar} from 'sentry/utils/queryString';
  7. import Tab from './transactionSummary/tabs';
  8. import {eventsRouteWithQuery} from './transactionSummary/transactionEvents/utils';
  9. import {spansRouteWithQuery} from './transactionSummary/transactionSpans/utils';
  10. import {tagsRouteWithQuery} from './transactionSummary/transactionTags/utils';
  11. import {vitalsRouteWithQuery} from './transactionSummary/transactionVitals/utils';
  12. import {transactionSummaryRouteWithQuery} from './transactionSummary/utils';
  13. import {vitalDetailRouteWithQuery} from './vitalDetail/utils';
  14. import {getPerformanceLandingUrl} from './utils';
  15. type Props = {
  16. location: Location;
  17. organization: Organization;
  18. eventSlug?: string;
  19. spanSlug?: SpanSlug;
  20. tab?: Tab;
  21. traceSlug?: string;
  22. transaction?: {
  23. name: string;
  24. project: string;
  25. };
  26. vitalName?: string;
  27. };
  28. function Breadcrumb(props: Props) {
  29. function getCrumbs() {
  30. const crumbs: Crumb[] = [];
  31. const {
  32. organization,
  33. location,
  34. transaction,
  35. vitalName,
  36. spanSlug,
  37. eventSlug,
  38. traceSlug,
  39. tab,
  40. } = props;
  41. const performanceTarget: LocationDescriptor = {
  42. pathname: getPerformanceLandingUrl(organization),
  43. query: {
  44. ...location.query,
  45. // clear out the transaction name
  46. transaction: undefined,
  47. },
  48. };
  49. crumbs.push({
  50. to: performanceTarget,
  51. label: t('Performance'),
  52. preservePageFilters: true,
  53. });
  54. if (vitalName) {
  55. const webVitalsTarget = vitalDetailRouteWithQuery({
  56. orgSlug: organization.slug,
  57. vitalName: 'fcp',
  58. projectID: decodeScalar(location.query.project),
  59. query: location.query,
  60. });
  61. crumbs.push({
  62. to: webVitalsTarget,
  63. label: t('Vital Detail'),
  64. preservePageFilters: true,
  65. });
  66. } else if (transaction) {
  67. const routeQuery = {
  68. orgSlug: organization.slug,
  69. transaction: transaction.name,
  70. projectID: transaction.project,
  71. query: location.query,
  72. };
  73. switch (tab) {
  74. case Tab.Tags: {
  75. const tagsTarget = tagsRouteWithQuery(routeQuery);
  76. crumbs.push({
  77. to: tagsTarget,
  78. label: t('Tags'),
  79. preservePageFilters: true,
  80. });
  81. break;
  82. }
  83. case Tab.Events: {
  84. const eventsTarget = eventsRouteWithQuery(routeQuery);
  85. crumbs.push({
  86. to: eventsTarget,
  87. label: t('All Events'),
  88. preservePageFilters: true,
  89. });
  90. break;
  91. }
  92. case Tab.WebVitals: {
  93. const webVitalsTarget = vitalsRouteWithQuery(routeQuery);
  94. crumbs.push({
  95. to: webVitalsTarget,
  96. label: t('Web Vitals'),
  97. preservePageFilters: true,
  98. });
  99. break;
  100. }
  101. case Tab.Spans: {
  102. const spansTarget = spansRouteWithQuery(routeQuery);
  103. crumbs.push({
  104. to: spansTarget,
  105. label: t('Spans'),
  106. preservePageFilters: true,
  107. });
  108. break;
  109. }
  110. case Tab.TransactionSummary:
  111. default: {
  112. const summaryTarget = transactionSummaryRouteWithQuery(routeQuery);
  113. crumbs.push({
  114. to: summaryTarget,
  115. label: t('Transaction Summary'),
  116. preservePageFilters: true,
  117. });
  118. }
  119. }
  120. }
  121. if (transaction && spanSlug) {
  122. crumbs.push({
  123. to: '',
  124. label: t('Span Summary'),
  125. });
  126. } else if (transaction && eventSlug) {
  127. crumbs.push({
  128. to: '',
  129. label: t('Event Details'),
  130. });
  131. } else if (traceSlug) {
  132. crumbs.push({
  133. to: '',
  134. label: t('Trace View'),
  135. });
  136. }
  137. return crumbs;
  138. }
  139. return <Breadcrumbs crumbs={getCrumbs()} />;
  140. }
  141. export default Breadcrumb;