header.tsx 8.1 KB

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