header.tsx 8.5 KB

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