profileHeader.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import {Link} from 'react-router';
  2. import Button from 'sentry/components/button';
  3. import * as Layout from 'sentry/components/layouts/thirds';
  4. import {Breadcrumb} from 'sentry/components/profiling/breadcrumb';
  5. import {t} from 'sentry/locale';
  6. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  7. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  8. import {ProfileGroup} from 'sentry/utils/profiling/profile/importProfile';
  9. import {
  10. generateProfileDetailsRouteWithQuery,
  11. generateProfileFlamechartRouteWithQuery,
  12. } from 'sentry/utils/profiling/routes';
  13. import {useLocation} from 'sentry/utils/useLocation';
  14. import useOrganization from 'sentry/utils/useOrganization';
  15. import {useParams} from 'sentry/utils/useParams';
  16. import {useProfileGroup} from 'sentry/views/profiling/profileGroupProvider';
  17. interface ProfileHeaderProps {
  18. profiles: ProfileGroup | null;
  19. }
  20. function ProfileHeader({profiles}: ProfileHeaderProps) {
  21. const params = useParams();
  22. const location = useLocation();
  23. const organization = useOrganization();
  24. const [profileGroup] = useProfileGroup();
  25. const transaction = profileGroup.type === 'resolved' ? profileGroup.data.name : '';
  26. const profileId = params.eventId ?? '';
  27. const projectSlug = params.projectId ?? '';
  28. const transactionId = profiles?.metadata?.transactionID;
  29. const transactionTarget = transactionId
  30. ? getTransactionDetailsUrl(organization.slug, `${projectSlug}:${transactionId}`)
  31. : null;
  32. function handleGoToTransaction() {
  33. trackAdvancedAnalyticsEvent('profiling_views.go_to_transaction', {
  34. organization,
  35. source: 'transaction_details',
  36. });
  37. }
  38. return (
  39. <Layout.Header>
  40. <Layout.HeaderContent>
  41. <Breadcrumb
  42. organization={organization}
  43. trails={[
  44. {type: 'landing', payload: {query: location.query}},
  45. {
  46. type: 'profile summary',
  47. payload: {
  48. projectSlug,
  49. transaction,
  50. query: location.query,
  51. },
  52. },
  53. {
  54. type: 'flamechart',
  55. payload: {
  56. transaction,
  57. profileId,
  58. projectSlug,
  59. query: location.query,
  60. tab: location.pathname.endsWith('details/') ? 'details' : 'flamechart',
  61. },
  62. },
  63. ]}
  64. />
  65. </Layout.HeaderContent>
  66. <Layout.HeaderActions>
  67. {transactionTarget && (
  68. <Button size="sm" onClick={handleGoToTransaction} to={transactionTarget}>
  69. {t('Go to Transaction')}
  70. </Button>
  71. )}
  72. </Layout.HeaderActions>
  73. <Layout.HeaderNavTabs underlined>
  74. <li className={location.pathname.endsWith('flamechart/') ? 'active' : undefined}>
  75. <Link
  76. to={generateProfileFlamechartRouteWithQuery({
  77. orgSlug: organization.slug,
  78. projectSlug,
  79. profileId,
  80. query: location.query,
  81. })}
  82. >
  83. {t('Flamechart')}
  84. </Link>
  85. </li>
  86. <li className={location.pathname.endsWith('details/') ? 'active' : undefined}>
  87. <Link
  88. to={generateProfileDetailsRouteWithQuery({
  89. orgSlug: organization.slug,
  90. projectSlug,
  91. profileId,
  92. query: location.query,
  93. })}
  94. >
  95. {t('Details')}
  96. </Link>
  97. </li>
  98. </Layout.HeaderNavTabs>
  99. </Layout.Header>
  100. );
  101. }
  102. export {ProfileHeader};