header.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 ReplaysFeatureBadge from 'sentry/components/replays/replaysFeatureBadge';
  13. import useReplaysCount from 'sentry/components/replays/useReplaysCount';
  14. import {Item, TabList} from 'sentry/components/tabs';
  15. import {t} from 'sentry/locale';
  16. import space from 'sentry/styles/space';
  17. import {Organization, Project} from 'sentry/types';
  18. import {trackAnalyticsEvent} 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 projectSupportsReplay from 'sentry/utils/replays/projectSupportsReplay';
  23. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  24. import {isProfilingSupportedForProject} from '../../../components/profiling/ProfilingOnboarding/util';
  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. trackAnalyticsEvent({
  56. eventKey: 'performance_views.summary.create_alert_clicked',
  57. eventName: 'Performance Views: Create alert clicked',
  58. organization_id: organization.id,
  59. });
  60. }
  61. const project = projects.find(p => p.id === projectId);
  62. const hasAnomalyDetection = organization.features?.includes(
  63. 'performance-anomaly-detection-ui'
  64. );
  65. const hasSessionReplay =
  66. organization.features.includes('session-replay-ui') && projectSupportsReplay(project);
  67. const hasProfiling =
  68. project &&
  69. organization.features.includes('profiling') &&
  70. isProfilingSupportedForProject(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 replaysCount = useReplaysCount({
  98. transactionNames: transactionName,
  99. organization,
  100. project,
  101. })[transactionName];
  102. return (
  103. <Layout.Header>
  104. <Layout.HeaderContent>
  105. <Breadcrumb
  106. organization={organization}
  107. location={location}
  108. transaction={{
  109. project: projectId,
  110. name: transactionName,
  111. }}
  112. tab={currentTab}
  113. />
  114. <Layout.Title>
  115. <TransactionName>
  116. {project && (
  117. <IdBadge
  118. project={project}
  119. avatarSize={28}
  120. hideName
  121. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  122. />
  123. )}
  124. {transactionName}
  125. </TransactionName>
  126. </Layout.Title>
  127. </Layout.HeaderContent>
  128. <Layout.HeaderActions>
  129. <ButtonBar gap={1}>
  130. <Feature organization={organization} features={['incidents']}>
  131. {({hasFeature}) =>
  132. hasFeature && !metricsCardinality?.isLoading ? (
  133. <CreateAlertFromViewButton
  134. size="sm"
  135. eventView={eventView}
  136. organization={organization}
  137. projects={projects}
  138. onClick={handleCreateAlertSuccess}
  139. referrer="performance"
  140. alertType="trans_duration"
  141. aria-label={t('Create Alert')}
  142. disableMetricDataset={
  143. metricsCardinality?.outcome?.forceTransactionsOnly
  144. }
  145. />
  146. ) : null
  147. }
  148. </Feature>
  149. <TeamKeyTransactionButton
  150. transactionName={transactionName}
  151. eventView={eventView}
  152. organization={organization}
  153. />
  154. <GuideAnchor target="project_transaction_threshold_override" position="bottom">
  155. <TransactionThresholdButton
  156. organization={organization}
  157. transactionName={transactionName}
  158. eventView={eventView}
  159. onChangeThreshold={onChangeThreshold}
  160. />
  161. </GuideAnchor>
  162. </ButtonBar>
  163. </Layout.HeaderActions>
  164. <HasMeasurementsQuery
  165. location={location}
  166. orgSlug={organization.slug}
  167. eventView={eventView}
  168. transaction={transactionName}
  169. type="web"
  170. >
  171. {({hasMeasurements}) => {
  172. const renderWebVitals = getWebVitals(!!hasMeasurements);
  173. return (
  174. <TabList
  175. hideBorder
  176. outerWrapStyles={{
  177. gridColumn: '1 / -1',
  178. }}
  179. >
  180. <Item key={Tab.TransactionSummary}>{t('Overview')}</Item>
  181. <Item key={Tab.Events}>{t('All Events')}</Item>
  182. <Item key={Tab.Tags}>{t('Tags')}</Item>
  183. <Item key={Tab.Spans}>{t('Spans')}</Item>
  184. <Item
  185. key={Tab.Anomalies}
  186. textValue={t('Anomalies')}
  187. hidden={!hasAnomalyDetection}
  188. >
  189. {t('Anomalies')}
  190. <FeatureBadge type="alpha" noTooltip />
  191. </Item>
  192. <Item
  193. key={Tab.WebVitals}
  194. textValue={t('Web Vitals')}
  195. hidden={!renderWebVitals}
  196. >
  197. {t('Web Vitals')}
  198. </Item>
  199. <Item key={Tab.Replays} textValue={t('Replays')} hidden={!hasSessionReplay}>
  200. {t('Replays')}
  201. <ReplayCountBadge count={replaysCount} />
  202. <ReplaysFeatureBadge noTooltip />
  203. </Item>
  204. <Item key={Tab.Profiling} textValue={t('Profiling')} hidden={!hasProfiling}>
  205. {t('Profiling')}
  206. <FeatureBadge type="beta" noTooltip />
  207. </Item>
  208. </TabList>
  209. );
  210. }}
  211. </HasMeasurementsQuery>
  212. </Layout.Header>
  213. );
  214. }
  215. const TransactionName = styled('div')`
  216. display: grid;
  217. grid-template-columns: max-content 1fr;
  218. grid-column-gap: ${space(1)};
  219. align-items: center;
  220. `;
  221. export default TransactionHeader;