index.tsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {LocationDescriptor} from 'history';
  4. import omit from 'lodash/omit';
  5. import type {Crumb} from 'sentry/components/breadcrumbs';
  6. import Breadcrumbs from 'sentry/components/breadcrumbs';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import ErrorBoundary from 'sentry/components/errorBoundary';
  9. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  10. import * as Layout from 'sentry/components/layouts/thirds';
  11. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  12. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  13. import {t} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import {DurationUnit} from 'sentry/utils/discover/fields';
  16. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  17. import {PageAlert, PageAlertProvider} from 'sentry/utils/performance/contexts/pageAlert';
  18. import {useLocation} from 'sentry/utils/useLocation';
  19. import useOrganization from 'sentry/utils/useOrganization';
  20. import useProjects from 'sentry/utils/useProjects';
  21. import useRouter from 'sentry/utils/useRouter';
  22. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  23. import {
  24. ScreenCharts,
  25. YAxis,
  26. } from 'sentry/views/performance/mobile/screenload/screenLoadSpans/charts';
  27. import {ScreenLoadEventSamples} from 'sentry/views/performance/mobile/screenload/screenLoadSpans/eventSamples';
  28. import {MetricsRibbon} from 'sentry/views/performance/mobile/screenload/screenLoadSpans/metricsRibbon';
  29. import {ScreenLoadSpanSamples} from 'sentry/views/performance/mobile/screenload/screenLoadSpans/samples';
  30. import {ScreenLoadSpansTable} from 'sentry/views/performance/mobile/screenload/screenLoadSpans/table';
  31. import {
  32. MobileCursors,
  33. MobileSortKeys,
  34. } from 'sentry/views/performance/mobile/screenload/screens/constants';
  35. import {PlatformSelector} from 'sentry/views/performance/mobile/screenload/screens/platformSelector';
  36. import {isCrossPlatform} from 'sentry/views/performance/mobile/screenload/screens/utils';
  37. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  38. import {
  39. PRIMARY_RELEASE_ALIAS,
  40. ReleaseComparisonSelector,
  41. SECONDARY_RELEASE_ALIAS,
  42. } from 'sentry/views/starfish/components/releaseSelector';
  43. import {SpanMetricsField} from 'sentry/views/starfish/types';
  44. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  45. type Query = {
  46. primaryRelease: string;
  47. project: string;
  48. secondaryRelease: string;
  49. spanGroup: string;
  50. transaction: string;
  51. [QueryParameterNames.SPANS_SORT]: string;
  52. spanDescription?: string;
  53. };
  54. function ScreenLoadSpans() {
  55. const location = useLocation<Query>();
  56. const organization = useOrganization();
  57. const router = useRouter();
  58. const {projects} = useProjects();
  59. const project = useMemo(() => {
  60. return projects.find(p => p.id === location.query.project);
  61. }, [location.query.project, projects]);
  62. const screenLoadModule: LocationDescriptor = {
  63. pathname: `/organizations/${organization.slug}/performance/mobile/screens/`,
  64. query: {
  65. ...omit(location.query, [
  66. QueryParameterNames.SPANS_SORT,
  67. 'transaction',
  68. SpanMetricsField.SPAN_OP,
  69. ]),
  70. },
  71. };
  72. const crumbs: Crumb[] = [
  73. {
  74. label: t('Performance'),
  75. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  76. preservePageFilters: true,
  77. },
  78. {
  79. to: screenLoadModule,
  80. label: t('Screen Loads'),
  81. preservePageFilters: true,
  82. },
  83. {
  84. to: '',
  85. label: t('Screen Summary'),
  86. },
  87. ];
  88. const {
  89. spanGroup,
  90. primaryRelease,
  91. secondaryRelease,
  92. transaction: transactionName,
  93. spanDescription,
  94. } = location.query;
  95. return (
  96. <Layout.Page>
  97. <PageAlertProvider>
  98. <Layout.Header>
  99. <Layout.HeaderContent>
  100. <Breadcrumbs crumbs={crumbs} />
  101. <HeaderWrapper>
  102. <Layout.Title>{transactionName}</Layout.Title>
  103. {organization.features.includes('spans-first-ui') &&
  104. project &&
  105. isCrossPlatform(project) && <PlatformSelector />}
  106. </HeaderWrapper>
  107. </Layout.HeaderContent>
  108. <Layout.HeaderActions>
  109. <ButtonBar gap={1}>
  110. <FeedbackWidgetButton />
  111. </ButtonBar>
  112. </Layout.HeaderActions>
  113. </Layout.Header>
  114. <Layout.Body>
  115. <Layout.Main fullWidth>
  116. <PageAlert />
  117. <Container>
  118. <FilterContainer>
  119. <PageFilterBar condensed>
  120. <DatePageFilter />
  121. </PageFilterBar>
  122. <ReleaseComparisonSelector />
  123. </FilterContainer>
  124. <MetricsRibbon
  125. dataset={DiscoverDatasets.METRICS}
  126. filters={[
  127. 'event.type:transaction',
  128. 'transaction.op:ui.load',
  129. `transaction:${transactionName}`,
  130. ]}
  131. fields={[
  132. `avg_if(measurements.time_to_initial_display,release,${primaryRelease})`,
  133. `avg_if(measurements.time_to_initial_display,release,${secondaryRelease})`,
  134. `avg_if(measurements.time_to_full_display,release,${primaryRelease})`,
  135. `avg_if(measurements.time_to_full_display,release,${secondaryRelease})`,
  136. 'count()',
  137. ]}
  138. blocks={[
  139. {
  140. unit: DurationUnit.MILLISECOND,
  141. dataKey: `avg_if(measurements.time_to_initial_display,release,${primaryRelease})`,
  142. title: t('TTID (%s)', PRIMARY_RELEASE_ALIAS),
  143. },
  144. {
  145. unit: DurationUnit.MILLISECOND,
  146. dataKey: `avg_if(measurements.time_to_initial_display,release,${secondaryRelease})`,
  147. title: t('TTID (%s)', SECONDARY_RELEASE_ALIAS),
  148. },
  149. {
  150. unit: DurationUnit.MILLISECOND,
  151. dataKey: `avg_if(measurements.time_to_full_display,release,${primaryRelease})`,
  152. title: t('TTFD (%s)', PRIMARY_RELEASE_ALIAS),
  153. },
  154. {
  155. unit: DurationUnit.MILLISECOND,
  156. dataKey: `avg_if(measurements.time_to_full_display,release,${secondaryRelease})`,
  157. title: t('TTFD (%s)', SECONDARY_RELEASE_ALIAS),
  158. },
  159. {
  160. unit: 'count',
  161. dataKey: 'count()',
  162. title: t('Count'),
  163. },
  164. ]}
  165. referrer="api.starfish.mobile-screen-totals"
  166. />
  167. </Container>
  168. <ErrorBoundary mini>
  169. <ScreenCharts
  170. yAxes={[YAxis.TTID, YAxis.TTFD, YAxis.COUNT]}
  171. additionalFilters={[`transaction:${transactionName}`]}
  172. chartHeight={120}
  173. project={project}
  174. />
  175. <SampleContainer>
  176. <SampleContainerItem>
  177. <ScreenLoadEventSamples
  178. release={primaryRelease}
  179. sortKey={MobileSortKeys.RELEASE_1_EVENT_SAMPLE_TABLE}
  180. cursorName={MobileCursors.RELEASE_1_EVENT_SAMPLE_TABLE}
  181. transaction={transactionName}
  182. showDeviceClassSelector
  183. project={project}
  184. />
  185. </SampleContainerItem>
  186. <SampleContainerItem>
  187. <ScreenLoadEventSamples
  188. release={secondaryRelease}
  189. sortKey={MobileSortKeys.RELEASE_2_EVENT_SAMPLE_TABLE}
  190. cursorName={MobileCursors.RELEASE_2_EVENT_SAMPLE_TABLE}
  191. transaction={transactionName}
  192. project={project}
  193. />
  194. </SampleContainerItem>
  195. </SampleContainer>
  196. <ScreenLoadSpansTable
  197. transaction={transactionName}
  198. primaryRelease={primaryRelease}
  199. secondaryRelease={secondaryRelease}
  200. project={project}
  201. />
  202. {spanGroup && (
  203. <ScreenLoadSpanSamples
  204. groupId={spanGroup}
  205. transactionName={transactionName}
  206. spanDescription={spanDescription}
  207. onClose={() => {
  208. router.replace({
  209. pathname: router.location.pathname,
  210. query: omit(
  211. router.location.query,
  212. 'spanGroup',
  213. 'transactionMethod'
  214. ),
  215. });
  216. }}
  217. />
  218. )}
  219. </ErrorBoundary>
  220. </Layout.Main>
  221. </Layout.Body>
  222. </PageAlertProvider>
  223. </Layout.Page>
  224. );
  225. }
  226. function PageWithProviders() {
  227. const location = useLocation<Query>();
  228. const {transaction} = location.query;
  229. return (
  230. <ModulePageProviders
  231. title={[transaction, t('Screen Loads')].join(' — ')}
  232. baseURL="/performance/mobile/screens"
  233. features="spans-first-ui"
  234. >
  235. <ScreenLoadSpans />
  236. </ModulePageProviders>
  237. );
  238. }
  239. export default PageWithProviders;
  240. const Container = styled('div')`
  241. display: grid;
  242. grid-template-rows: 1fr 1fr;
  243. grid-template-columns: 1fr;
  244. column-gap: ${space(2)};
  245. @media (min-width: ${p => p.theme.breakpoints.large}) {
  246. grid-template-rows: auto;
  247. grid-template-columns: auto minmax(100px, max-content);
  248. }
  249. `;
  250. const FilterContainer = styled('div')`
  251. display: grid;
  252. column-gap: ${space(1)};
  253. grid-template-rows: auto;
  254. grid-template-columns: auto 1fr;
  255. `;
  256. const SampleContainer = styled('div')`
  257. display: flex;
  258. flex-direction: row;
  259. flex-wrap: wrap;
  260. gap: ${space(2)};
  261. `;
  262. const SampleContainerItem = styled('div')`
  263. flex: 1;
  264. `;
  265. const HeaderWrapper = styled('div')`
  266. display: flex;
  267. `;