frontendOverviewPage.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import styled from '@emotion/styled';
  2. import Feature from 'sentry/components/acl/feature';
  3. import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  4. import * as Layout from 'sentry/components/layouts/thirds';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import {NoAccess} from 'sentry/components/noAccess';
  7. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  8. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  9. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  10. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  11. import TransactionNameSearchBar from 'sentry/components/performance/searchBar';
  12. import * as TeamKeyTransactionManager from 'sentry/components/performance/teamKeyTransactionsManager';
  13. import {tct} from 'sentry/locale';
  14. import {trackAnalytics} from 'sentry/utils/analytics';
  15. import {
  16. canUseMetricsData,
  17. useMEPSettingContext,
  18. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  19. import {PageAlert, usePageAlert} from 'sentry/utils/performance/contexts/pageAlert';
  20. import {PerformanceDisplayProvider} from 'sentry/utils/performance/contexts/performanceDisplayContext';
  21. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  22. import {useLocation} from 'sentry/utils/useLocation';
  23. import {useNavigate} from 'sentry/utils/useNavigate';
  24. import useOrganization from 'sentry/utils/useOrganization';
  25. import useProjects from 'sentry/utils/useProjects';
  26. import {useUserTeams} from 'sentry/utils/useUserTeams';
  27. import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLayout';
  28. import {ToolRibbon} from 'sentry/views/insights/common/components/ribbon';
  29. import {ViewTrendsButton} from 'sentry/views/insights/common/components/viewTrendsButton';
  30. import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
  31. import {DomainOverviewPageProviders} from 'sentry/views/insights/pages/domainOverviewPageProviders';
  32. import {FrontendHeader} from 'sentry/views/insights/pages/frontend/frontendPageHeader';
  33. import {
  34. FRONTEND_LANDING_TITLE,
  35. OVERVIEW_PAGE_ALLOWED_OPS,
  36. } from 'sentry/views/insights/pages/frontend/settings';
  37. import {
  38. generateFrontendOtherPerformanceEventView,
  39. USER_MISERY_TOOLTIP,
  40. } from 'sentry/views/performance/data';
  41. import {
  42. DoubleChartRow,
  43. TripleChartRow,
  44. } from 'sentry/views/performance/landing/widgets/components/widgetChartRow';
  45. import {filterAllowedChartsMetrics} from 'sentry/views/performance/landing/widgets/utils';
  46. import {PerformanceWidgetSetting} from 'sentry/views/performance/landing/widgets/widgetDefinitions';
  47. import Onboarding from 'sentry/views/performance/onboarding';
  48. import Table from 'sentry/views/performance/table';
  49. import {
  50. getTransactionSearchQuery,
  51. ProjectPerformanceType,
  52. } from 'sentry/views/performance/utils';
  53. const DURATION_TOOLTIP = tct(
  54. 'A heuristic measuring when a pageload or navigation completes. Based on whether the initial load of the webpage has become idle. [link:Learn more.]',
  55. {
  56. link: (
  57. <ExternalLink href="https://docs.sentry.io/platforms/javascript/tracing/instrumentation/automatic-instrumentation/#idletimeout" />
  58. ),
  59. }
  60. );
  61. export const FRONTEND_COLUMN_TITLES = [
  62. {title: 'transaction'},
  63. {title: 'operation'},
  64. {title: 'project'},
  65. {title: 'tpm'},
  66. {title: 'p50()', tooltip: DURATION_TOOLTIP},
  67. {title: 'p75()', tooltip: DURATION_TOOLTIP},
  68. {title: 'p95()', tooltip: DURATION_TOOLTIP},
  69. {title: 'users'},
  70. {title: 'user misery', tooltip: USER_MISERY_TOOLTIP},
  71. ];
  72. function FrontendOverviewPage() {
  73. const organization = useOrganization();
  74. const location = useLocation();
  75. const {setPageError} = usePageAlert();
  76. const {projects} = useProjects();
  77. const onboardingProject = useOnboardingProject();
  78. const navigate = useNavigate();
  79. const {teams} = useUserTeams();
  80. const mepSetting = useMEPSettingContext();
  81. const withStaticFilters = canUseMetricsData(organization);
  82. const eventView = generateFrontendOtherPerformanceEventView(
  83. location,
  84. withStaticFilters,
  85. organization
  86. );
  87. // TODO - this should come from MetricsField / EAP fields
  88. eventView.fields = [
  89. {field: 'team_key_transaction'},
  90. {field: 'transaction'},
  91. {field: 'transaction.op'},
  92. {field: 'project'},
  93. {field: 'tpm()'},
  94. {field: 'p50(transaction.duration)'},
  95. {field: 'p75(transaction.duration)'},
  96. {field: 'p95(transaction.duration)'},
  97. {field: 'count_unique(user)'},
  98. {field: 'count_miserable(user)'},
  99. {field: 'user_misery()'},
  100. ].map(field => ({...field, width: COL_WIDTH_UNDEFINED}));
  101. const doubleChartRowEventView = eventView.clone(); // some of the double chart rows rely on span metrics, so they can't be queried the same way
  102. const existingQuery = new MutableSearch(eventView.query);
  103. existingQuery.addDisjunctionFilterValues('transaction.op', OVERVIEW_PAGE_ALLOWED_OPS);
  104. eventView.query = existingQuery.formatString();
  105. const showOnboarding = onboardingProject !== undefined;
  106. const doubleChartRowCharts = [
  107. PerformanceWidgetSetting.SLOW_HTTP_OPS,
  108. PerformanceWidgetSetting.SLOW_RESOURCE_OPS,
  109. ];
  110. const tripleChartRowCharts = filterAllowedChartsMetrics(
  111. organization,
  112. [
  113. PerformanceWidgetSetting.TPM_AREA,
  114. PerformanceWidgetSetting.DURATION_HISTOGRAM,
  115. PerformanceWidgetSetting.P50_DURATION_AREA,
  116. PerformanceWidgetSetting.P75_DURATION_AREA,
  117. PerformanceWidgetSetting.P95_DURATION_AREA,
  118. PerformanceWidgetSetting.P99_DURATION_AREA,
  119. PerformanceWidgetSetting.FAILURE_RATE_AREA,
  120. ],
  121. mepSetting
  122. );
  123. if (organization.features.includes('insights-initial-modules')) {
  124. doubleChartRowCharts.unshift(PerformanceWidgetSetting.MOST_TIME_CONSUMING_DOMAINS);
  125. doubleChartRowCharts.unshift(PerformanceWidgetSetting.MOST_TIME_CONSUMING_RESOURCES);
  126. doubleChartRowCharts.unshift(PerformanceWidgetSetting.HIGHEST_OPPORTUNITY_PAGES);
  127. }
  128. const sharedProps = {eventView, location, organization, withStaticFilters};
  129. const getFreeTextFromQuery = (query: string) => {
  130. const conditions = new MutableSearch(query);
  131. const transactionValues = conditions.getFilterValues('transaction');
  132. if (transactionValues.length) {
  133. return transactionValues[0];
  134. }
  135. if (conditions.freeText.length > 0) {
  136. // raw text query will be wrapped in wildcards in generatePerformanceEventView
  137. // so no need to wrap it here
  138. return conditions.freeText.join(' ');
  139. }
  140. return '';
  141. };
  142. function handleSearch(searchQuery: string) {
  143. trackAnalytics('performance.domains.frontend.search', {organization});
  144. navigate({
  145. pathname: location.pathname,
  146. query: {
  147. ...location.query,
  148. cursor: undefined,
  149. query: String(searchQuery).trim() || undefined,
  150. isDefaultQuery: false,
  151. },
  152. });
  153. }
  154. const derivedQuery = getTransactionSearchQuery(location, eventView.query);
  155. return (
  156. <Feature
  157. features="performance-view"
  158. organization={organization}
  159. renderDisabled={NoAccess}
  160. >
  161. <FrontendHeader
  162. headerTitle={FRONTEND_LANDING_TITLE}
  163. headerActions={<ViewTrendsButton />}
  164. />
  165. <Layout.Body>
  166. <Layout.Main fullWidth>
  167. <ModuleLayout.Layout>
  168. <ModuleLayout.Full>
  169. <ToolRibbon>
  170. <PageFilterBar condensed>
  171. <ProjectPageFilter />
  172. <EnvironmentPageFilter />
  173. <DatePageFilter />
  174. </PageFilterBar>
  175. {!showOnboarding && (
  176. <StyledTransactionNameSearchBar
  177. organization={organization}
  178. eventView={eventView}
  179. onSearch={(query: string) => {
  180. handleSearch(query);
  181. }}
  182. query={getFreeTextFromQuery(derivedQuery)!}
  183. />
  184. )}
  185. </ToolRibbon>
  186. </ModuleLayout.Full>
  187. <PageAlert />
  188. <ModuleLayout.Full>
  189. {!showOnboarding && (
  190. <PerformanceDisplayProvider
  191. value={{performanceType: ProjectPerformanceType.FRONTEND_OTHER}}
  192. >
  193. <DoubleChartRow
  194. allowedCharts={doubleChartRowCharts}
  195. {...sharedProps}
  196. eventView={doubleChartRowEventView}
  197. />
  198. <TripleChartRow allowedCharts={tripleChartRowCharts} {...sharedProps} />
  199. <TeamKeyTransactionManager.Provider
  200. organization={organization}
  201. teams={teams}
  202. selectedTeams={['myteams']}
  203. selectedProjects={eventView.project.map(String)}
  204. >
  205. <Table
  206. projects={projects}
  207. columnTitles={FRONTEND_COLUMN_TITLES}
  208. setError={setPageError}
  209. {...sharedProps}
  210. />
  211. </TeamKeyTransactionManager.Provider>
  212. </PerformanceDisplayProvider>
  213. )}
  214. {showOnboarding && (
  215. <Onboarding project={onboardingProject} organization={organization} />
  216. )}
  217. </ModuleLayout.Full>
  218. </ModuleLayout.Layout>
  219. </Layout.Main>
  220. </Layout.Body>
  221. </Feature>
  222. );
  223. }
  224. function FrontendOverviewPageWithProviders() {
  225. return (
  226. <DomainOverviewPageProviders>
  227. <FrontendOverviewPage />
  228. </DomainOverviewPageProviders>
  229. );
  230. }
  231. const StyledTransactionNameSearchBar = styled(TransactionNameSearchBar)`
  232. flex: 2;
  233. `;
  234. export default FrontendOverviewPageWithProviders;