mobileOverviewPage.tsx 9.6 KB

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