header.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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(
  72. 'insights-initial-modules'
  73. );
  74. const getWebVitals = useCallback(
  75. (hasMeasurements: boolean) => {
  76. switch (hasWebVitals) {
  77. case 'maybe':
  78. // need to check if the web vitals tab should be shown
  79. // frontend projects should always show the web vitals tab
  80. if (
  81. getCurrentLandingDisplay(location, projects, eventView).field ===
  82. LandingDisplayField.FRONTEND_OTHER
  83. ) {
  84. return true;
  85. }
  86. // if it is not a frontend project, then we check to see if there
  87. // are any web vitals associated with the transaction recently
  88. return hasMeasurements;
  89. case 'yes':
  90. // always show the web vitals tab
  91. return true;
  92. case 'no':
  93. default:
  94. // never show the web vitals tab
  95. return false;
  96. }
  97. },
  98. [hasWebVitals, location, projects, eventView]
  99. );
  100. const {getReplayCountForTransaction} = useReplayCountForTransactions({
  101. statsPeriod: '90d',
  102. });
  103. const replaysCount = getReplayCountForTransaction(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. <Tooltip showOnlyOnOverflow skipWrapper title={transactionName}>
  126. <TransactionName>{transactionName}</TransactionName>
  127. </Tooltip>
  128. </Layout.Title>
  129. </Layout.HeaderContent>
  130. <Layout.HeaderActions>
  131. <ButtonBar gap={1}>
  132. <Feature organization={organization} features="incidents">
  133. {({hasFeature}) =>
  134. hasFeature && !metricsCardinality?.isLoading ? (
  135. <CreateAlertFromViewButton
  136. size="sm"
  137. eventView={eventView}
  138. organization={organization}
  139. projects={projects}
  140. onClick={handleCreateAlertSuccess}
  141. referrer="performance"
  142. alertType="trans_duration"
  143. aria-label={t('Create Alert')}
  144. disableMetricDataset={
  145. metricsCardinality?.outcome?.forceTransactionsOnly
  146. }
  147. />
  148. ) : null
  149. }
  150. </Feature>
  151. <TeamKeyTransactionButton
  152. transactionName={transactionName}
  153. eventView={eventView}
  154. organization={organization}
  155. />
  156. <GuideAnchor target="project_transaction_threshold_override" position="bottom">
  157. <TransactionThresholdButton
  158. organization={organization}
  159. transactionName={transactionName}
  160. eventView={eventView}
  161. onChangeThreshold={onChangeThreshold}
  162. />
  163. </GuideAnchor>
  164. </ButtonBar>
  165. </Layout.HeaderActions>
  166. <HasMeasurementsQuery
  167. location={location}
  168. orgSlug={organization.slug}
  169. eventView={eventView}
  170. transaction={transactionName}
  171. type="web"
  172. >
  173. {({hasMeasurements}) => {
  174. const renderWebVitals = getWebVitals(!!hasMeasurements);
  175. return (
  176. <TabList
  177. hideBorder
  178. outerWrapStyles={{
  179. gridColumn: '1 / -1',
  180. }}
  181. >
  182. <TabList.Item key={Tab.TRANSACTION_SUMMARY}>{t('Overview')}</TabList.Item>
  183. <TabList.Item key={Tab.EVENTS}>{t('Sampled Events')}</TabList.Item>
  184. <TabList.Item key={Tab.TAGS}>{t('Tags')}</TabList.Item>
  185. <TabList.Item key={Tab.SPANS}>{t('Spans')}</TabList.Item>
  186. <TabList.Item
  187. key={Tab.ANOMALIES}
  188. textValue={t('Anomalies')}
  189. hidden={!hasAnomalyDetection}
  190. >
  191. {t('Anomalies')}
  192. <FeatureBadge type="alpha" tooltipProps={{disabled: true}} />
  193. </TabList.Item>
  194. <TabList.Item
  195. key={Tab.WEB_VITALS}
  196. textValue={t('Web Vitals')}
  197. hidden={!renderWebVitals}
  198. >
  199. {t('Web Vitals')}
  200. </TabList.Item>
  201. <TabList.Item
  202. key={Tab.REPLAYS}
  203. textValue={t('Replays')}
  204. hidden={!hasSessionReplay}
  205. >
  206. {t('Replays')}
  207. <ReplayCountBadge count={replaysCount} />
  208. </TabList.Item>
  209. <TabList.Item
  210. key={Tab.PROFILING}
  211. textValue={t('Profiling')}
  212. hidden={!hasProfiling}
  213. >
  214. {t('Profiles')}
  215. </TabList.Item>
  216. <TabList.Item
  217. key={Tab.AGGREGATE_WATERFALL}
  218. textValue={t('Aggregate Spans')}
  219. hidden={!hasAggregateWaterfall}
  220. >
  221. {t('Aggregate Spans')}
  222. </TabList.Item>
  223. </TabList>
  224. );
  225. }}
  226. </HasMeasurementsQuery>
  227. </Layout.Header>
  228. );
  229. }
  230. const TransactionName = styled('div')`
  231. ${p => p.theme.overflowEllipsis}
  232. `;
  233. export default TransactionHeader;