header.tsx 8.2 KB

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