header.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 ReplaysFeatureBadge from 'sentry/components/replays/replaysFeatureBadge';
  12. import {Item, TabList} from 'sentry/components/tabs';
  13. import {t} from 'sentry/locale';
  14. import space from 'sentry/styles/space';
  15. import {Organization, Project} from 'sentry/types';
  16. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  17. import EventView from 'sentry/utils/discover/eventView';
  18. import {MetricsCardinalityContext} from 'sentry/utils/performance/contexts/metricsCardinality';
  19. import HasMeasurementsQuery from 'sentry/utils/performance/vitals/hasMeasurementsQuery';
  20. import Breadcrumb from 'sentry/views/performance/breadcrumb';
  21. import {getCurrentLandingDisplay, LandingDisplayField} from '../landing/utils';
  22. import Tab from './tabs';
  23. import TeamKeyTransactionButton from './teamKeyTransactionButton';
  24. import TransactionThresholdButton from './transactionThresholdButton';
  25. import {TransactionThresholdMetric} from './transactionThresholdModal';
  26. type Props = {
  27. currentTab: Tab;
  28. eventView: EventView;
  29. hasWebVitals: 'maybe' | 'yes' | 'no';
  30. location: Location;
  31. organization: Organization;
  32. projectId: string;
  33. projects: Project[];
  34. transactionName: string;
  35. metricsCardinality?: MetricsCardinalityContext;
  36. onChangeThreshold?: (threshold: number, metric: TransactionThresholdMetric) => void;
  37. };
  38. function TransactionHeader({
  39. eventView,
  40. organization,
  41. projects,
  42. projectId,
  43. metricsCardinality,
  44. location,
  45. transactionName,
  46. onChangeThreshold,
  47. currentTab,
  48. hasWebVitals,
  49. }: Props) {
  50. function handleCreateAlertSuccess() {
  51. trackAnalyticsEvent({
  52. eventKey: 'performance_views.summary.create_alert_clicked',
  53. eventName: 'Performance Views: Create alert clicked',
  54. organization_id: organization.id,
  55. });
  56. }
  57. const project = projects.find(p => p.id === projectId);
  58. const hasSuspectSpansView = organization.features?.includes(
  59. 'performance-suspect-spans-view'
  60. );
  61. const hasAnomalyDetection = organization.features?.includes(
  62. 'performance-anomaly-detection-ui'
  63. );
  64. const hasSessionReplay = organization.features?.includes('session-replay-ui');
  65. const getWebVitals = useCallback(
  66. (hasMeasurements: boolean) => {
  67. switch (hasWebVitals) {
  68. case 'maybe':
  69. // need to check if the web vitals tab should be shown
  70. // frontend projects should always show the web vitals tab
  71. if (
  72. getCurrentLandingDisplay(location, projects, eventView).field ===
  73. LandingDisplayField.FRONTEND_PAGELOAD
  74. ) {
  75. return true;
  76. }
  77. // if it is not a frontend project, then we check to see if there
  78. // are any web vitals associated with the transaction recently
  79. return hasMeasurements;
  80. case 'yes':
  81. // always show the web vitals tab
  82. return true;
  83. case 'no':
  84. default:
  85. // never show the web vitals tab
  86. return false;
  87. }
  88. },
  89. [hasWebVitals, location, projects, eventView]
  90. );
  91. return (
  92. <Layout.Header>
  93. <Layout.HeaderContent>
  94. <Breadcrumb
  95. organization={organization}
  96. location={location}
  97. transaction={{
  98. project: projectId,
  99. name: transactionName,
  100. }}
  101. tab={currentTab}
  102. />
  103. <Layout.Title>
  104. <TransactionName>
  105. {project && (
  106. <IdBadge
  107. project={project}
  108. avatarSize={28}
  109. hideName
  110. avatarProps={{hasTooltip: true, tooltip: project.slug}}
  111. />
  112. )}
  113. {transactionName}
  114. </TransactionName>
  115. </Layout.Title>
  116. </Layout.HeaderContent>
  117. <Layout.HeaderActions>
  118. <ButtonBar gap={1}>
  119. <Feature organization={organization} features={['incidents']}>
  120. {({hasFeature}) =>
  121. hasFeature && !metricsCardinality?.isLoading ? (
  122. <CreateAlertFromViewButton
  123. size="sm"
  124. eventView={eventView}
  125. organization={organization}
  126. projects={projects}
  127. onClick={handleCreateAlertSuccess}
  128. referrer="performance"
  129. alertType="trans_duration"
  130. aria-label={t('Create Alert')}
  131. disableMetricDataset={
  132. metricsCardinality?.outcome?.forceTransactionsOnly
  133. }
  134. />
  135. ) : null
  136. }
  137. </Feature>
  138. <TeamKeyTransactionButton
  139. transactionName={transactionName}
  140. eventView={eventView}
  141. organization={organization}
  142. />
  143. <GuideAnchor target="project_transaction_threshold_override" position="bottom">
  144. <TransactionThresholdButton
  145. organization={organization}
  146. transactionName={transactionName}
  147. eventView={eventView}
  148. onChangeThreshold={onChangeThreshold}
  149. />
  150. </GuideAnchor>
  151. </ButtonBar>
  152. </Layout.HeaderActions>
  153. <HasMeasurementsQuery
  154. location={location}
  155. orgSlug={organization.slug}
  156. eventView={eventView}
  157. transaction={transactionName}
  158. type="web"
  159. >
  160. {({hasMeasurements}) => {
  161. const renderWebVitals = getWebVitals(!!hasMeasurements);
  162. return (
  163. <TabList hideBorder>
  164. <Item key={Tab.TransactionSummary}>{t('Overview')}</Item>
  165. <Item key={Tab.Events}>{t('All Events')}</Item>
  166. <Item key={Tab.Tags}>{t('Tags')}</Item>
  167. <Item key={Tab.Spans} hidden={!hasSuspectSpansView}>
  168. {t('Spans')}
  169. </Item>
  170. <Item
  171. key={Tab.Anomalies}
  172. textValue={t('Anomalies')}
  173. hidden={!hasAnomalyDetection}
  174. >
  175. {t('Anomalies')}
  176. <FeatureBadge type="alpha" noTooltip />
  177. </Item>
  178. <Item
  179. key={Tab.WebVitals}
  180. textValue={t('Web Vitals')}
  181. hidden={!renderWebVitals}
  182. >
  183. {t('Web Vitals')}
  184. </Item>
  185. <Item key={Tab.Replays} textValue={t('Replays')} hidden={!hasSessionReplay}>
  186. {t('Replays')}
  187. <ReplaysFeatureBadge noTooltip />
  188. </Item>
  189. </TabList>
  190. );
  191. }}
  192. </HasMeasurementsQuery>
  193. </Layout.Header>
  194. );
  195. }
  196. const TransactionName = styled('div')`
  197. display: grid;
  198. grid-template-columns: max-content 1fr;
  199. grid-column-gap: ${space(1)};
  200. align-items: center;
  201. `;
  202. export default TransactionHeader;