breadcrumb.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import {useMemo} from 'react';
  2. import {Location} from 'history';
  3. import omit from 'lodash/omit';
  4. import _Breadcrumbs, {Crumb} from 'sentry/components/breadcrumbs';
  5. import {t} from 'sentry/locale';
  6. import {Organization, Project} from 'sentry/types';
  7. import {
  8. generateProfileDetailsRouteWithQuery,
  9. generateProfileFlamechartRouteWithQuery,
  10. generateProfileSummaryRouteWithQuery,
  11. generateProfilingRouteWithQuery,
  12. } from 'sentry/utils/profiling/routes';
  13. interface BreadcrumbsProps {
  14. organization: Organization;
  15. trails: Trail[];
  16. }
  17. function Breadcrumb({organization, trails}: BreadcrumbsProps) {
  18. const crumbs = useMemo(
  19. () => trails.map(trail => trailToCrumb(trail, {organization})),
  20. [organization, trails]
  21. );
  22. return <_Breadcrumbs crumbs={crumbs} />;
  23. }
  24. function trailToCrumb(
  25. trail: Trail,
  26. {
  27. organization,
  28. }: {
  29. organization: Organization;
  30. }
  31. ): Crumb {
  32. switch (trail.type) {
  33. case 'landing': {
  34. return {
  35. to: generateProfilingRouteWithQuery({
  36. // cursor and query are not used in the landing page
  37. // and break the API call as the qs gets forwarded to the API
  38. query: omit(trail.payload.query, ['cursor', 'query']),
  39. orgSlug: organization.slug,
  40. }),
  41. label: t('Profiling'),
  42. preservePageFilters: true,
  43. };
  44. }
  45. case 'profile summary': {
  46. return {
  47. to: generateProfileSummaryRouteWithQuery({
  48. // cursor and query are not used in the summary page
  49. // and break the API call as the qs gets forwarded to the API
  50. query: omit(trail.payload.query, ['cursor', 'query']),
  51. orgSlug: organization.slug,
  52. projectSlug: trail.payload.projectSlug,
  53. transaction: trail.payload.transaction,
  54. }),
  55. label: t('Profile Summary'),
  56. preservePageFilters: true,
  57. };
  58. }
  59. case 'flamechart': {
  60. const generateRouteWithQuery =
  61. trail.payload.tab === 'flamechart'
  62. ? generateProfileFlamechartRouteWithQuery
  63. : generateProfileDetailsRouteWithQuery;
  64. return {
  65. to: generateRouteWithQuery({
  66. query: trail.payload.query,
  67. orgSlug: organization.slug,
  68. projectSlug: trail.payload.projectSlug,
  69. profileId: trail.payload.profileId,
  70. }),
  71. label: trail.payload.transaction,
  72. preservePageFilters: true,
  73. };
  74. }
  75. default:
  76. throw new Error(`Unknown breadcrumb type: ${JSON.stringify(trail)}`);
  77. }
  78. }
  79. type ProfilingTrail = {
  80. payload: {
  81. query: Location['query'];
  82. };
  83. type: 'landing';
  84. };
  85. type ProfileSummaryTrail = {
  86. payload: {
  87. projectSlug: Project['slug'];
  88. query: Location['query'];
  89. transaction: string;
  90. };
  91. type: 'profile summary';
  92. };
  93. type FlamegraphTrail = {
  94. payload: {
  95. profileId: string;
  96. projectSlug: string;
  97. query: Location['query'];
  98. tab: 'flamechart' | 'details';
  99. transaction: string;
  100. };
  101. type: 'flamechart';
  102. };
  103. type Trail = ProfilingTrail | ProfileSummaryTrail | FlamegraphTrail;
  104. export {Breadcrumb};