header.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import {useCallback, useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import Feature from 'sentry/components/acl/feature';
  5. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import {CreateAlertFromViewButton} from 'sentry/components/createAlertButton';
  8. import FeatureBadge from 'sentry/components/featureBadge';
  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 ReplaysFeatureBadge from 'sentry/components/replays/replaysFeatureBadge';
  13. import useReplaysCount from 'sentry/components/replays/useReplaysCount';
  14. import {TabList} from 'sentry/components/tabs';
  15. import {Tooltip} from 'sentry/components/tooltip';
  16. import {t} from 'sentry/locale';
  17. import {Organization, Project} from 'sentry/types';
  18. import {trackAnalytics} from 'sentry/utils/analytics';
  19. import EventView from 'sentry/utils/discover/eventView';
  20. import {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 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 {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 getWebVitals = useCallback(
  72. (hasMeasurements: boolean) => {
  73. switch (hasWebVitals) {
  74. case 'maybe':
  75. // need to check if the web vitals tab should be shown
  76. // frontend projects should always show the web vitals tab
  77. if (
  78. getCurrentLandingDisplay(location, projects, eventView).field ===
  79. LandingDisplayField.FRONTEND_PAGELOAD
  80. ) {
  81. return true;
  82. }
  83. // if it is not a frontend project, then we check to see if there
  84. // are any web vitals associated with the transaction recently
  85. return hasMeasurements;
  86. case 'yes':
  87. // always show the web vitals tab
  88. return true;
  89. case 'no':
  90. default:
  91. // never show the web vitals tab
  92. return false;
  93. }
  94. },
  95. [hasWebVitals, location, projects, eventView]
  96. );
  97. const projectIds = useMemo(
  98. () => (project?.id ? [Number(project.id)] : []),
  99. [project?.id]
  100. );
  101. const replaysCount = useReplaysCount({
  102. transactionNames: transactionName,
  103. organization,
  104. projectIds,
  105. })[transactionName];
  106. return (
  107. <Layout.Header>
  108. <Layout.HeaderContent>
  109. <Breadcrumb
  110. organization={organization}
  111. location={location}
  112. transaction={{
  113. project: projectId,
  114. name: transactionName,
  115. }}
  116. tab={currentTab}
  117. />
  118. <Layout.Title>
  119. {project && (
  120. <IdBadge
  121. project={project}
  122. avatarSize={28}
  123. hideName
  124. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  125. />
  126. )}
  127. <Tooltip showOnlyOnOverflow skipWrapper title={transactionName}>
  128. <TransactionName>{transactionName}</TransactionName>
  129. </Tooltip>
  130. </Layout.Title>
  131. </Layout.HeaderContent>
  132. <Layout.HeaderActions>
  133. <ButtonBar gap={1}>
  134. <Feature organization={organization} features={['incidents']}>
  135. {({hasFeature}) =>
  136. hasFeature && !metricsCardinality?.isLoading ? (
  137. <CreateAlertFromViewButton
  138. size="sm"
  139. eventView={eventView}
  140. organization={organization}
  141. projects={projects}
  142. onClick={handleCreateAlertSuccess}
  143. referrer="performance"
  144. alertType="trans_duration"
  145. aria-label={t('Create Alert')}
  146. disableMetricDataset={
  147. metricsCardinality?.outcome?.forceTransactionsOnly
  148. }
  149. />
  150. ) : null
  151. }
  152. </Feature>
  153. <TeamKeyTransactionButton
  154. transactionName={transactionName}
  155. eventView={eventView}
  156. organization={organization}
  157. />
  158. <GuideAnchor target="project_transaction_threshold_override" position="bottom">
  159. <TransactionThresholdButton
  160. organization={organization}
  161. transactionName={transactionName}
  162. eventView={eventView}
  163. onChangeThreshold={onChangeThreshold}
  164. />
  165. </GuideAnchor>
  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.TransactionSummary}>{t('Overview')}</TabList.Item>
  185. <TabList.Item key={Tab.Events}>{t('All 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.WebVitals}
  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. <ReplaysFeatureBadge tooltipProps={{disabled: true}} />
  211. </TabList.Item>
  212. <TabList.Item
  213. key={Tab.Profiling}
  214. textValue={t('Profiling')}
  215. hidden={!hasProfiling}
  216. >
  217. {t('Profiles')}
  218. {organization.features.includes('profiling-ga') ? (
  219. <FeatureBadge type="new" tooltipProps={{disabled: true}} />
  220. ) : (
  221. <FeatureBadge type="beta" tooltipProps={{disabled: true}} />
  222. )}
  223. </TabList.Item>
  224. </TabList>
  225. );
  226. }}
  227. </HasMeasurementsQuery>
  228. </Layout.Header>
  229. );
  230. }
  231. const TransactionName = styled('div')`
  232. ${p => p.theme.overflowEllipsis}
  233. `;
  234. export default TransactionHeader;