mobileOverviewPage.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import styled from '@emotion/styled';
  2. import Feature from 'sentry/components/acl/feature';
  3. import * as Layout from 'sentry/components/layouts/thirds';
  4. import {NoAccess} from 'sentry/components/noAccess';
  5. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  6. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  7. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  8. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  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 SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  13. import {trackAnalytics} from 'sentry/utils/analytics';
  14. import {
  15. canUseMetricsData,
  16. MEPSettingProvider,
  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 {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
  30. import {ViewTrendsButton} from 'sentry/views/insights/common/viewTrendsButton';
  31. import {MobileHeader} from 'sentry/views/insights/pages/mobile/mobilePageHeader';
  32. import {
  33. MOBILE_LANDING_TITLE,
  34. OVERVIEW_PAGE_ALLOWED_OPS,
  35. } from 'sentry/views/insights/pages/mobile/settings';
  36. import {OVERVIEW_PAGE_TITLE} from 'sentry/views/insights/pages/settings';
  37. import {
  38. generateGenericPerformanceEventView,
  39. generateMobilePerformanceEventView,
  40. } from 'sentry/views/performance/data';
  41. import {checkIsReactNative} from 'sentry/views/performance/landing/utils';
  42. import {
  43. DoubleChartRow,
  44. TripleChartRow,
  45. } from 'sentry/views/performance/landing/widgets/components/widgetChartRow';
  46. import {filterAllowedChartsMetrics} from 'sentry/views/performance/landing/widgets/utils';
  47. import {PerformanceWidgetSetting} from 'sentry/views/performance/landing/widgets/widgetDefinitions';
  48. import Onboarding from 'sentry/views/performance/onboarding';
  49. import Table from 'sentry/views/performance/table';
  50. import {
  51. getTransactionSearchQuery,
  52. ProjectPerformanceType,
  53. } from 'sentry/views/performance/utils';
  54. const MOBILE_COLUMN_TITLES = [
  55. 'transaction',
  56. 'operation',
  57. 'project',
  58. 'tpm',
  59. 'slow frame %',
  60. 'frozen frame %',
  61. 'users',
  62. 'user misery',
  63. ];
  64. const REACT_NATIVE_COLUMN_TITLES = [
  65. 'transaction',
  66. 'operation',
  67. 'project',
  68. 'tpm',
  69. 'slow frame %',
  70. 'frozen frame %',
  71. 'stall %',
  72. 'users',
  73. 'user misery',
  74. ];
  75. function MobileOverviewPage() {
  76. const organization = useOrganization();
  77. const location = useLocation();
  78. const {setPageError} = usePageAlert();
  79. const {projects} = useProjects();
  80. const onboardingProject = useOnboardingProject();
  81. const navigate = useNavigate();
  82. const {teams} = useUserTeams();
  83. const mepSetting = useMEPSettingContext();
  84. const withStaticFilters = canUseMetricsData(organization);
  85. const eventView = generateMobilePerformanceEventView(
  86. location,
  87. projects,
  88. generateGenericPerformanceEventView(location, withStaticFilters, organization),
  89. withStaticFilters,
  90. organization
  91. );
  92. let columnTitles = checkIsReactNative(eventView)
  93. ? REACT_NATIVE_COLUMN_TITLES
  94. : MOBILE_COLUMN_TITLES;
  95. const doubleChartRowEventView = eventView.clone(); // some of the double chart rows rely on span metrics, so they can't be queried the same way
  96. const existingQuery = new MutableSearch(eventView.query);
  97. existingQuery.addDisjunctionFilterValues('transaction.op', OVERVIEW_PAGE_ALLOWED_OPS);
  98. eventView.query = existingQuery.formatString();
  99. const showOnboarding = onboardingProject !== undefined;
  100. const doubleChartRowCharts = [
  101. PerformanceWidgetSetting.MOST_SLOW_FRAMES,
  102. PerformanceWidgetSetting.MOST_FROZEN_FRAMES,
  103. ];
  104. const tripleChartRowCharts = filterAllowedChartsMetrics(
  105. organization,
  106. [
  107. PerformanceWidgetSetting.TPM_AREA,
  108. PerformanceWidgetSetting.DURATION_HISTOGRAM,
  109. PerformanceWidgetSetting.P50_DURATION_AREA,
  110. PerformanceWidgetSetting.P75_DURATION_AREA,
  111. PerformanceWidgetSetting.P95_DURATION_AREA,
  112. PerformanceWidgetSetting.P99_DURATION_AREA,
  113. PerformanceWidgetSetting.FAILURE_RATE_AREA,
  114. ],
  115. mepSetting
  116. );
  117. if (organization.features.includes('mobile-vitals')) {
  118. columnTitles = [...columnTitles.slice(0, 5), 'ttid', ...columnTitles.slice(5, 0)];
  119. tripleChartRowCharts.push(
  120. ...[
  121. PerformanceWidgetSetting.TIME_TO_INITIAL_DISPLAY,
  122. PerformanceWidgetSetting.TIME_TO_FULL_DISPLAY,
  123. ]
  124. );
  125. }
  126. if (organization.features.includes('insights-initial-modules')) {
  127. doubleChartRowCharts[0] = PerformanceWidgetSetting.SLOW_SCREENS_BY_TTID;
  128. }
  129. if (organization.features.includes('starfish-mobile-appstart')) {
  130. doubleChartRowCharts.push(
  131. PerformanceWidgetSetting.SLOW_SCREENS_BY_COLD_START,
  132. PerformanceWidgetSetting.SLOW_SCREENS_BY_WARM_START
  133. );
  134. }
  135. if (organization.features.includes('insights-initial-modules')) {
  136. doubleChartRowCharts.push(PerformanceWidgetSetting.MOST_TIME_CONSUMING_DOMAINS);
  137. }
  138. const sharedProps = {eventView, location, organization, withStaticFilters};
  139. const getFreeTextFromQuery = (query: string) => {
  140. const conditions = new MutableSearch(query);
  141. const transactionValues = conditions.getFilterValues('transaction');
  142. if (transactionValues.length) {
  143. return transactionValues[0];
  144. }
  145. if (conditions.freeText.length > 0) {
  146. // raw text query will be wrapped in wildcards in generatePerformanceEventView
  147. // so no need to wrap it here
  148. return conditions.freeText.join(' ');
  149. }
  150. return '';
  151. };
  152. function handleSearch(searchQuery: string) {
  153. trackAnalytics('performance.domains.mobile.search', {organization});
  154. navigate({
  155. pathname: location.pathname,
  156. query: {
  157. ...location.query,
  158. cursor: undefined,
  159. query: String(searchQuery).trim() || undefined,
  160. isDefaultQuery: false,
  161. },
  162. });
  163. }
  164. const derivedQuery = getTransactionSearchQuery(location, eventView.query);
  165. return (
  166. <Feature
  167. features="insights-domain-view"
  168. organization={organization}
  169. renderDisabled={NoAccess}
  170. >
  171. <MobileHeader
  172. headerTitle={MOBILE_LANDING_TITLE}
  173. headerActions={<ViewTrendsButton />}
  174. />
  175. <Layout.Body>
  176. <Layout.Main fullWidth>
  177. <ModuleLayout.Layout>
  178. <ModuleLayout.Full>
  179. <ToolRibbon>
  180. <PageFilterBar condensed>
  181. <ProjectPageFilter />
  182. <EnvironmentPageFilter />
  183. <DatePageFilter />
  184. </PageFilterBar>
  185. {!showOnboarding && (
  186. <StyledTransactionNameSearchBar
  187. organization={organization}
  188. eventView={eventView}
  189. onSearch={(query: string) => {
  190. handleSearch(query);
  191. }}
  192. query={getFreeTextFromQuery(derivedQuery)}
  193. />
  194. )}
  195. </ToolRibbon>
  196. </ModuleLayout.Full>
  197. <PageAlert />
  198. <ModuleLayout.Full>
  199. {!showOnboarding && (
  200. <PerformanceDisplayProvider
  201. value={{performanceType: ProjectPerformanceType.MOBILE}}
  202. >
  203. <TeamKeyTransactionManager.Provider
  204. organization={organization}
  205. teams={teams}
  206. selectedTeams={['myteams']}
  207. selectedProjects={eventView.project.map(String)}
  208. >
  209. <DoubleChartRow
  210. allowedCharts={doubleChartRowCharts}
  211. {...sharedProps}
  212. eventView={doubleChartRowEventView}
  213. />
  214. <TripleChartRow
  215. allowedCharts={tripleChartRowCharts}
  216. {...sharedProps}
  217. />
  218. <Table
  219. projects={projects}
  220. columnTitles={columnTitles}
  221. setError={setPageError}
  222. {...sharedProps}
  223. />
  224. </TeamKeyTransactionManager.Provider>
  225. </PerformanceDisplayProvider>
  226. )}
  227. {showOnboarding && (
  228. <Onboarding project={onboardingProject} organization={organization} />
  229. )}
  230. </ModuleLayout.Full>
  231. </ModuleLayout.Layout>
  232. </Layout.Main>
  233. </Layout.Body>
  234. </Feature>
  235. );
  236. }
  237. function MobileOverviewPageWithProviders() {
  238. const organization = useOrganization();
  239. const location = useLocation();
  240. return (
  241. <PageFiltersContainer>
  242. <SentryDocumentTitle title={OVERVIEW_PAGE_TITLE} orgSlug={organization.slug}>
  243. <MEPSettingProvider location={location}>
  244. <MobileOverviewPage />
  245. </MEPSettingProvider>
  246. </SentryDocumentTitle>
  247. </PageFiltersContainer>
  248. );
  249. }
  250. const StyledTransactionNameSearchBar = styled(TransactionNameSearchBar)`
  251. flex: 2;
  252. `;
  253. export default MobileOverviewPageWithProviders;