frontendOverviewPage.tsx 8.9 KB

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