mobileOverviewPage.tsx 9.3 KB

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