frontendOverviewPage.tsx 9.3 KB

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