header.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import {useCallback, useMemo} from 'react';
  2. import {Location} from 'history';
  3. import Feature from 'sentry/components/acl/feature';
  4. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  5. import ButtonBar from 'sentry/components/buttonBar';
  6. import {CreateAlertFromViewButton} from 'sentry/components/createAlertButton';
  7. import FeatureBadge from 'sentry/components/featureBadge';
  8. import IdBadge from 'sentry/components/idBadge';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import ReplayCountBadge from 'sentry/components/replays/replayCountBadge';
  11. import ReplaysFeatureBadge from 'sentry/components/replays/replaysFeatureBadge';
  12. import useReplaysCount from 'sentry/components/replays/useReplaysCount';
  13. import {TabList} from 'sentry/components/tabs';
  14. import {t} from 'sentry/locale';
  15. import {Organization, Project} from 'sentry/types';
  16. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  17. import EventView from 'sentry/utils/discover/eventView';
  18. import {MetricsCardinalityContext} from 'sentry/utils/performance/contexts/metricsCardinality';
  19. import HasMeasurementsQuery from 'sentry/utils/performance/vitals/hasMeasurementsQuery';
  20. import {isProfilingSupportedOrProjectHasProfiles} from 'sentry/utils/profiling/platforms';
  21. import projectSupportsReplay from 'sentry/utils/replays/projectSupportsReplay';
  22. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  23. import {getCurrentLandingDisplay, LandingDisplayField} from '../landing/utils';
  24. import Tab from './tabs';
  25. import TeamKeyTransactionButton from './teamKeyTransactionButton';
  26. import TransactionThresholdButton from './transactionThresholdButton';
  27. import {TransactionThresholdMetric} from './transactionThresholdModal';
  28. type Props = {
  29. currentTab: Tab;
  30. eventView: EventView;
  31. hasWebVitals: 'maybe' | 'yes' | 'no';
  32. location: Location;
  33. organization: Organization;
  34. projectId: string;
  35. projects: Project[];
  36. transactionName: string;
  37. metricsCardinality?: MetricsCardinalityContext;
  38. onChangeThreshold?: (threshold: number, metric: TransactionThresholdMetric) => void;
  39. };
  40. function TransactionHeader({
  41. eventView,
  42. organization,
  43. projects,
  44. projectId,
  45. metricsCardinality,
  46. location,
  47. transactionName,
  48. onChangeThreshold,
  49. currentTab,
  50. hasWebVitals,
  51. }: Props) {
  52. function handleCreateAlertSuccess() {
  53. trackAdvancedAnalyticsEvent('performance_views.summary.create_alert_clicked', {
  54. organization,
  55. });
  56. }
  57. const project = projects.find(p => p.id === projectId);
  58. const hasAnomalyDetection = organization.features?.includes(
  59. 'performance-anomaly-detection-ui'
  60. );
  61. const hasSessionReplay =
  62. organization.features.includes('session-replay') &&
  63. project &&
  64. projectSupportsReplay(project);
  65. const hasProfiling =
  66. project &&
  67. organization.features.includes('profiling') &&
  68. isProfilingSupportedOrProjectHasProfiles(project);
  69. const getWebVitals = useCallback(
  70. (hasMeasurements: boolean) => {
  71. switch (hasWebVitals) {
  72. case 'maybe':
  73. // need to check if the web vitals tab should be shown
  74. // frontend projects should always show the web vitals tab
  75. if (
  76. getCurrentLandingDisplay(location, projects, eventView).field ===
  77. LandingDisplayField.FRONTEND_PAGELOAD
  78. ) {
  79. return true;
  80. }
  81. // if it is not a frontend project, then we check to see if there
  82. // are any web vitals associated with the transaction recently
  83. return hasMeasurements;
  84. case 'yes':
  85. // always show the web vitals tab
  86. return true;
  87. case 'no':
  88. default:
  89. // never show the web vitals tab
  90. return false;
  91. }
  92. },
  93. [hasWebVitals, location, projects, eventView]
  94. );
  95. const projectIds = useMemo(
  96. () => (project?.id ? [Number(project.id)] : []),
  97. [project?.id]
  98. );
  99. const replaysCount = useReplaysCount({
  100. transactionNames: transactionName,
  101. organization,
  102. projectIds,
  103. })[transactionName];
  104. return (
  105. <Layout.Header>
  106. <Layout.HeaderContent>
  107. <Breadcrumb
  108. organization={organization}
  109. location={location}
  110. transaction={{
  111. project: projectId,
  112. name: transactionName,
  113. }}
  114. tab={currentTab}
  115. />
  116. <Layout.Title>
  117. {project && (
  118. <IdBadge
  119. project={project}
  120. avatarSize={28}
  121. hideName
  122. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  123. />
  124. )}
  125. {transactionName}
  126. </Layout.Title>
  127. </Layout.HeaderContent>
  128. <Layout.HeaderActions>
  129. <ButtonBar gap={1}>
  130. <Feature organization={organization} features={['incidents']}>
  131. {({hasFeature}) =>
  132. hasFeature && !metricsCardinality?.isLoading ? (
  133. <CreateAlertFromViewButton
  134. size="sm"
  135. eventView={eventView}
  136. organization={organization}
  137. projects={projects}
  138. onClick={handleCreateAlertSuccess}
  139. referrer="performance"
  140. alertType="trans_duration"
  141. aria-label={t('Create Alert')}
  142. disableMetricDataset={
  143. metricsCardinality?.outcome?.forceTransactionsOnly
  144. }
  145. />
  146. ) : null
  147. }
  148. </Feature>
  149. <TeamKeyTransactionButton
  150. transactionName={transactionName}
  151. eventView={eventView}
  152. organization={organization}
  153. />
  154. <GuideAnchor target="project_transaction_threshold_override" position="bottom">
  155. <TransactionThresholdButton
  156. organization={organization}
  157. transactionName={transactionName}
  158. eventView={eventView}
  159. onChangeThreshold={onChangeThreshold}
  160. />
  161. </GuideAnchor>
  162. </ButtonBar>
  163. </Layout.HeaderActions>
  164. <HasMeasurementsQuery
  165. location={location}
  166. orgSlug={organization.slug}
  167. eventView={eventView}
  168. transaction={transactionName}
  169. type="web"
  170. >
  171. {({hasMeasurements}) => {
  172. const renderWebVitals = getWebVitals(!!hasMeasurements);
  173. return (
  174. <TabList
  175. hideBorder
  176. outerWrapStyles={{
  177. gridColumn: '1 / -1',
  178. }}
  179. >
  180. <TabList.Item key={Tab.TransactionSummary}>{t('Overview')}</TabList.Item>
  181. <TabList.Item key={Tab.Events}>{t('All Events')}</TabList.Item>
  182. <TabList.Item key={Tab.Tags}>{t('Tags')}</TabList.Item>
  183. <TabList.Item key={Tab.Spans}>{t('Spans')}</TabList.Item>
  184. <TabList.Item
  185. key={Tab.Anomalies}
  186. textValue={t('Anomalies')}
  187. hidden={!hasAnomalyDetection}
  188. >
  189. {t('Anomalies')}
  190. <FeatureBadge type="alpha" noTooltip />
  191. </TabList.Item>
  192. <TabList.Item
  193. key={Tab.WebVitals}
  194. textValue={t('Web Vitals')}
  195. hidden={!renderWebVitals}
  196. >
  197. {t('Web Vitals')}
  198. </TabList.Item>
  199. <TabList.Item
  200. key={Tab.Replays}
  201. textValue={t('Replays')}
  202. hidden={!hasSessionReplay}
  203. >
  204. {t('Replays')}
  205. <ReplayCountBadge count={replaysCount} />
  206. <ReplaysFeatureBadge noTooltip />
  207. </TabList.Item>
  208. <TabList.Item
  209. key={Tab.Profiling}
  210. textValue={t('Profiling')}
  211. hidden={!hasProfiling}
  212. >
  213. {t('Profiling')}
  214. <FeatureBadge type="beta" noTooltip />
  215. </TabList.Item>
  216. </TabList>
  217. );
  218. }}
  219. </HasMeasurementsQuery>
  220. </Layout.Header>
  221. );
  222. }
  223. export default TransactionHeader;