header.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. return (
  103. <Layout.Header>
  104. <Layout.HeaderContent>
  105. <Breadcrumb
  106. organization={organization}
  107. location={location}
  108. transaction={{
  109. project: projectId,
  110. name: transactionName,
  111. }}
  112. tab={currentTab}
  113. />
  114. <Layout.Title>
  115. {project && (
  116. <IdBadge
  117. project={project}
  118. avatarSize={28}
  119. hideName
  120. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  121. />
  122. )}
  123. <Tooltip showOnlyOnOverflow skipWrapper title={transactionName}>
  124. <TransactionName>{transactionName}</TransactionName>
  125. </Tooltip>
  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.TRANSACTION_SUMMARY}>{t('Overview')}</TabList.Item>
  181. <TabList.Item key={Tab.EVENTS}>{t('Sampled 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" tooltipProps={{disabled: true}} />
  191. </TabList.Item>
  192. <TabList.Item
  193. key={Tab.WEB_VITALS}
  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. </TabList.Item>
  207. <TabList.Item
  208. key={Tab.PROFILING}
  209. textValue={t('Profiling')}
  210. hidden={!hasProfiling}
  211. >
  212. {t('Profiles')}
  213. </TabList.Item>
  214. <TabList.Item
  215. key={Tab.AGGREGATE_WATERFALL}
  216. textValue={t('Aggregate Spans')}
  217. hidden={!hasAggregateWaterfall}
  218. >
  219. {t('Aggregate Spans')}
  220. </TabList.Item>
  221. </TabList>
  222. );
  223. }}
  224. </HasMeasurementsQuery>
  225. </Layout.Header>
  226. );
  227. }
  228. const TransactionName = styled('div')`
  229. ${p => p.theme.overflowEllipsis}
  230. `;
  231. export default TransactionHeader;