header.tsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  10. import IdBadge from 'sentry/components/idBadge';
  11. import * as Layout from 'sentry/components/layouts/thirds';
  12. import ReplayCountBadge from 'sentry/components/replays/replayCountBadge';
  13. import {TabList} from 'sentry/components/tabs';
  14. import {Tooltip} from 'sentry/components/tooltip';
  15. import {t} from 'sentry/locale';
  16. import type {Organization} from 'sentry/types/organization';
  17. import type {Project} from 'sentry/types/project';
  18. import {trackAnalytics} from 'sentry/utils/analytics';
  19. import type EventView from 'sentry/utils/discover/eventView';
  20. import type {MetricsCardinalityContext} from 'sentry/utils/performance/contexts/metricsCardinality';
  21. import HasMeasurementsQuery from 'sentry/utils/performance/vitals/hasMeasurementsQuery';
  22. import {isProfilingSupportedOrProjectHasProfiles} from 'sentry/utils/profiling/platforms';
  23. import useReplayCountForTransactions from 'sentry/utils/replayCount/useReplayCountForTransactions';
  24. import projectSupportsReplay from 'sentry/utils/replays/projectSupportsReplay';
  25. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  26. import {getCurrentLandingDisplay, LandingDisplayField} from '../landing/utils';
  27. import Tab from './tabs';
  28. import TeamKeyTransactionButton from './teamKeyTransactionButton';
  29. import TransactionThresholdButton from './transactionThresholdButton';
  30. import type {TransactionThresholdMetric} from './transactionThresholdModal';
  31. type Props = {
  32. currentTab: Tab;
  33. eventView: EventView;
  34. hasWebVitals: 'maybe' | 'yes' | 'no';
  35. location: Location;
  36. organization: Organization;
  37. projectId: string;
  38. projects: Project[];
  39. transactionName: string;
  40. metricsCardinality?: MetricsCardinalityContext;
  41. onChangeThreshold?: (threshold: number, metric: TransactionThresholdMetric) => void;
  42. };
  43. function TransactionHeader({
  44. eventView,
  45. organization,
  46. projects,
  47. projectId,
  48. metricsCardinality,
  49. location,
  50. transactionName,
  51. onChangeThreshold,
  52. currentTab,
  53. hasWebVitals,
  54. }: Props) {
  55. function handleCreateAlertSuccess() {
  56. trackAnalytics('performance_views.summary.create_alert_clicked', {
  57. organization,
  58. });
  59. }
  60. const project = projects.find(p => p.id === projectId);
  61. const hasAnomalyDetection = organization.features?.includes(
  62. 'performance-anomaly-detection-ui'
  63. );
  64. const hasSessionReplay =
  65. organization.features.includes('session-replay') &&
  66. project &&
  67. projectSupportsReplay(project);
  68. const hasProfiling =
  69. project &&
  70. organization.features.includes('profiling') &&
  71. isProfilingSupportedOrProjectHasProfiles(project);
  72. const hasAggregateWaterfall = organization.features.includes(
  73. 'insights-initial-modules'
  74. );
  75. const getWebVitals = useCallback(
  76. (hasMeasurements: boolean) => {
  77. switch (hasWebVitals) {
  78. case 'maybe':
  79. // need to check if the web vitals tab should be shown
  80. // frontend projects should always show the web vitals tab
  81. if (
  82. getCurrentLandingDisplay(location, projects, eventView).field ===
  83. LandingDisplayField.FRONTEND_OTHER
  84. ) {
  85. return true;
  86. }
  87. // if it is not a frontend project, then we check to see if there
  88. // are any web vitals associated with the transaction recently
  89. return hasMeasurements;
  90. case 'yes':
  91. // always show the web vitals tab
  92. return true;
  93. case 'no':
  94. default:
  95. // never show the web vitals tab
  96. return false;
  97. }
  98. },
  99. [hasWebVitals, location, projects, eventView]
  100. );
  101. const {getReplayCountForTransaction} = useReplayCountForTransactions({
  102. statsPeriod: '90d',
  103. });
  104. const replaysCount = getReplayCountForTransaction(transactionName);
  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. <FeedbackWidgetButton />
  166. </ButtonBar>
  167. </Layout.HeaderActions>
  168. <HasMeasurementsQuery
  169. location={location}
  170. orgSlug={organization.slug}
  171. eventView={eventView}
  172. transaction={transactionName}
  173. type="web"
  174. >
  175. {({hasMeasurements}) => {
  176. const renderWebVitals = getWebVitals(!!hasMeasurements);
  177. return (
  178. <TabList
  179. hideBorder
  180. outerWrapStyles={{
  181. gridColumn: '1 / -1',
  182. }}
  183. >
  184. <TabList.Item key={Tab.TRANSACTION_SUMMARY}>{t('Overview')}</TabList.Item>
  185. <TabList.Item key={Tab.EVENTS}>{t('Sampled Events')}</TabList.Item>
  186. <TabList.Item key={Tab.TAGS}>{t('Tags')}</TabList.Item>
  187. <TabList.Item key={Tab.SPANS}>{t('Spans')}</TabList.Item>
  188. <TabList.Item
  189. key={Tab.ANOMALIES}
  190. textValue={t('Anomalies')}
  191. hidden={!hasAnomalyDetection}
  192. >
  193. {t('Anomalies')}
  194. <FeatureBadge type="alpha" tooltipProps={{disabled: true}} />
  195. </TabList.Item>
  196. <TabList.Item
  197. key={Tab.WEB_VITALS}
  198. textValue={t('Web Vitals')}
  199. hidden={!renderWebVitals}
  200. >
  201. {t('Web Vitals')}
  202. </TabList.Item>
  203. <TabList.Item
  204. key={Tab.REPLAYS}
  205. textValue={t('Replays')}
  206. hidden={!hasSessionReplay}
  207. >
  208. {t('Replays')}
  209. <ReplayCountBadge count={replaysCount} />
  210. </TabList.Item>
  211. <TabList.Item
  212. key={Tab.PROFILING}
  213. textValue={t('Profiling')}
  214. hidden={!hasProfiling}
  215. >
  216. {t('Profiles')}
  217. </TabList.Item>
  218. <TabList.Item
  219. key={Tab.AGGREGATE_WATERFALL}
  220. textValue={t('Aggregate Spans')}
  221. hidden={!hasAggregateWaterfall}
  222. >
  223. {t('Aggregate Spans')}
  224. </TabList.Item>
  225. </TabList>
  226. );
  227. }}
  228. </HasMeasurementsQuery>
  229. </Layout.Header>
  230. );
  231. }
  232. const TransactionName = styled('div')`
  233. ${p => p.theme.overflowEllipsis}
  234. `;
  235. export default TransactionHeader;