frontendOverviewPage.tsx 9.2 KB

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