pageOverview.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. import React, {useMemo, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import omit from 'lodash/omit';
  4. import moment from 'moment';
  5. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  6. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  7. import {LinkButton} from 'sentry/components/button';
  8. import ButtonBar from 'sentry/components/buttonBar';
  9. import {AggregateSpans} from 'sentry/components/events/interfaces/spans/aggregateSpans';
  10. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  11. import * as Layout from 'sentry/components/layouts/thirds';
  12. import ExternalLink from 'sentry/components/links/externalLink';
  13. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  14. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  15. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  16. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  17. import {TabList, Tabs} from 'sentry/components/tabs';
  18. import {IconChevron, IconClose} from 'sentry/icons';
  19. import {t, tct} from 'sentry/locale';
  20. import ConfigStore from 'sentry/stores/configStore';
  21. import {space} from 'sentry/styles/space';
  22. import {defined} from 'sentry/utils';
  23. import {browserHistory} from 'sentry/utils/browserHistory';
  24. import {decodeScalar} from 'sentry/utils/queryString';
  25. import useDismissAlert from 'sentry/utils/useDismissAlert';
  26. import {useLocation} from 'sentry/utils/useLocation';
  27. import useOrganization from 'sentry/utils/useOrganization';
  28. import useProjects from 'sentry/utils/useProjects';
  29. import useRouter from 'sentry/utils/useRouter';
  30. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  31. import {PageOverviewSidebar} from 'sentry/views/performance/browser/webVitals/components/pageOverviewSidebar';
  32. import {
  33. FID_DEPRECATION_DATE,
  34. PerformanceScoreBreakdownChart,
  35. } from 'sentry/views/performance/browser/webVitals/components/performanceScoreBreakdownChart';
  36. import WebVitalMeters from 'sentry/views/performance/browser/webVitals/components/webVitalMeters';
  37. import {PageOverviewWebVitalsDetailPanel} from 'sentry/views/performance/browser/webVitals/pageOverviewWebVitalsDetailPanel';
  38. import {PageSamplePerformanceTable} from 'sentry/views/performance/browser/webVitals/pageSamplePerformanceTable';
  39. import {useProjectRawWebVitalsQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/rawWebVitalsQueries/useProjectRawWebVitalsQuery';
  40. import {calculatePerformanceScoreFromStoredTableDataRow} from 'sentry/views/performance/browser/webVitals/utils/queries/storedScoreQueries/calculatePerformanceScoreFromStored';
  41. import {useProjectWebVitalsScoresQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/storedScoreQueries/useProjectWebVitalsScoresQuery';
  42. import type {WebVitals} from 'sentry/views/performance/browser/webVitals/utils/types';
  43. import {
  44. AlertContent,
  45. DismissButton,
  46. StyledAlert,
  47. } from 'sentry/views/performance/browser/webVitals/webVitalsLandingPage';
  48. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  49. import {transactionSummaryRouteWithQuery} from '../../transactionSummary/utils';
  50. export enum LandingDisplayField {
  51. OVERVIEW = 'overview',
  52. SPANS = 'spans',
  53. }
  54. const LANDING_DISPLAYS = [
  55. {
  56. label: t('Overview'),
  57. field: LandingDisplayField.OVERVIEW,
  58. },
  59. {
  60. label: t('Aggregate Spans'),
  61. field: LandingDisplayField.SPANS,
  62. },
  63. ];
  64. function getCurrentTabSelection(selectedTab) {
  65. const tab = decodeScalar(selectedTab);
  66. if (tab && Object.values(LandingDisplayField).includes(tab as LandingDisplayField)) {
  67. return tab as LandingDisplayField;
  68. }
  69. return LandingDisplayField.OVERVIEW;
  70. }
  71. export function PageOverview() {
  72. const organization = useOrganization();
  73. const location = useLocation();
  74. const {projects} = useProjects();
  75. const router = useRouter();
  76. const transaction = location.query.transaction
  77. ? Array.isArray(location.query.transaction)
  78. ? location.query.transaction[0]
  79. : location.query.transaction
  80. : undefined;
  81. const project = useMemo(
  82. () => projects.find(p => p.id === String(location.query.project)),
  83. [projects, location.query.project]
  84. );
  85. const tab = getCurrentTabSelection(location.query.tab);
  86. // TODO: When visiting page overview from a specific webvital detail panel in the landing page,
  87. // we should automatically default this webvital state to the respective webvital so the detail
  88. // panel in this page opens automatically.
  89. const [state, setState] = useState<{webVital: WebVitals | null}>({
  90. webVital: (location.query.webVital as WebVitals) ?? null,
  91. });
  92. const user = ConfigStore.get('user');
  93. const {dismiss, isDismissed} = useDismissAlert({
  94. key: `${organization.slug}-${user.id}:fid-deprecation-message-dismissed`,
  95. });
  96. const query = decodeScalar(location.query.query);
  97. const {data: pageData, isLoading} = useProjectRawWebVitalsQuery({transaction});
  98. const {data: projectScores, isLoading: isProjectScoresLoading} =
  99. useProjectWebVitalsScoresQuery({transaction});
  100. if (transaction === undefined) {
  101. // redirect user to webvitals landing page
  102. window.location.href = normalizeUrl(
  103. `/organizations/${organization.slug}/performance/browser/pageloads/`
  104. );
  105. return null;
  106. }
  107. const transactionSummaryTarget =
  108. project &&
  109. !Array.isArray(location.query.project) && // Only render button to transaction summary when one project is selected.
  110. transaction &&
  111. transactionSummaryRouteWithQuery({
  112. orgSlug: organization.slug,
  113. transaction,
  114. query: {...location.query},
  115. projectID: project.id,
  116. });
  117. const projectScore =
  118. isProjectScoresLoading || isLoading
  119. ? undefined
  120. : calculatePerformanceScoreFromStoredTableDataRow(projectScores?.data?.[0]);
  121. const fidDeprecationTimestampString =
  122. moment(FID_DEPRECATION_DATE).format('DD MMMM YYYY');
  123. return (
  124. <React.Fragment>
  125. <Tabs
  126. value={tab}
  127. onChange={value => {
  128. browserHistory.push({
  129. ...location,
  130. query: {
  131. ...location.query,
  132. tab: value,
  133. },
  134. });
  135. }}
  136. >
  137. <Layout.Header>
  138. <Layout.HeaderContent>
  139. <Breadcrumbs
  140. crumbs={[
  141. {
  142. label: 'Performance',
  143. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  144. preservePageFilters: true,
  145. },
  146. {
  147. label: 'Web Vitals',
  148. to: normalizeUrl(
  149. `/organizations/${organization.slug}/performance/browser/pageloads/`
  150. ),
  151. preservePageFilters: true,
  152. },
  153. ...(transaction ? [{label: 'Page Overview'}] : []),
  154. ]}
  155. />
  156. <Layout.Title>
  157. {transaction && project && <ProjectAvatar project={project} size={24} />}
  158. {transaction ?? t('Page Loads')}
  159. </Layout.Title>
  160. </Layout.HeaderContent>
  161. <Layout.HeaderActions>
  162. <ButtonBar gap={1}>
  163. <FeedbackWidgetButton />
  164. {transactionSummaryTarget && (
  165. <LinkButton to={transactionSummaryTarget} size="sm">
  166. {t('View Transaction Summary')}
  167. </LinkButton>
  168. )}
  169. </ButtonBar>
  170. </Layout.HeaderActions>
  171. <TabList hideBorder>
  172. {LANDING_DISPLAYS.map(({label, field}) => (
  173. <TabList.Item key={field}>{label}</TabList.Item>
  174. ))}
  175. </TabList>
  176. </Layout.Header>
  177. {tab === LandingDisplayField.SPANS ? (
  178. <Layout.Body>
  179. <Layout.Main fullWidth>
  180. {defined(transaction) && <AggregateSpans transaction={transaction} />}
  181. </Layout.Main>
  182. </Layout.Body>
  183. ) : (
  184. <Layout.Body>
  185. <Layout.Main>
  186. <TopMenuContainer>
  187. {transaction && (
  188. <ViewAllPagesButton
  189. to={{
  190. ...location,
  191. pathname: '/performance/browser/pageloads/',
  192. query: {...location.query, transaction: undefined},
  193. }}
  194. >
  195. <IconChevron direction="left" /> {t('View All Pages')}
  196. </ViewAllPagesButton>
  197. )}
  198. <PageFilterBar condensed>
  199. <ProjectPageFilter />
  200. <EnvironmentPageFilter />
  201. <DatePageFilter />
  202. </PageFilterBar>
  203. </TopMenuContainer>
  204. {!isDismissed && (
  205. <StyledAlert type="info" showIcon>
  206. <AlertContent>
  207. <span>
  208. {tct(
  209. `Starting on [fidDeprecationTimestampString], [inpStrong:INP] (Interaction to Next Paint) will replace [fidStrong:FID] (First Input Delay) in our performance score calculation.`,
  210. {
  211. fidDeprecationTimestampString,
  212. inpStrong: <strong />,
  213. fidStrong: <strong />,
  214. }
  215. )}
  216. <br />
  217. {tct(
  218. `Users should update their Sentry SDKs to the [link:latest version (7.104.0+)] and [enableInp:enable the INP option] to start receiving updated Performance Scores.`,
  219. {
  220. link: (
  221. <ExternalLink href="https://github.com/getsentry/sentry-javascript/releases/tag/7.104.0" />
  222. ),
  223. enableInp: (
  224. <ExternalLink href="https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#enableinp" />
  225. ),
  226. }
  227. )}
  228. </span>
  229. <DismissButton
  230. priority="link"
  231. icon={<IconClose />}
  232. onClick={dismiss}
  233. aria-label={t('Dismiss Alert')}
  234. title={t('Dismiss Alert')}
  235. />
  236. </AlertContent>
  237. </StyledAlert>
  238. )}
  239. <Flex>
  240. <PerformanceScoreBreakdownChart transaction={transaction} />
  241. </Flex>
  242. <WebVitalMetersContainer>
  243. <WebVitalMeters
  244. projectData={pageData}
  245. projectScore={projectScore}
  246. onClick={webVital => {
  247. router.replace({
  248. pathname: location.pathname,
  249. query: {...location.query, webVital},
  250. });
  251. setState({...state, webVital});
  252. }}
  253. transaction={transaction}
  254. showTooltip={false}
  255. />
  256. </WebVitalMetersContainer>
  257. <PageSamplePerformanceTableContainer>
  258. <PageSamplePerformanceTable
  259. transaction={transaction}
  260. limit={15}
  261. search={query}
  262. />
  263. </PageSamplePerformanceTableContainer>
  264. </Layout.Main>
  265. <Layout.Side>
  266. <PageOverviewSidebar
  267. projectScore={projectScore}
  268. transaction={transaction}
  269. projectScoreIsLoading={isLoading}
  270. />
  271. </Layout.Side>
  272. </Layout.Body>
  273. )}
  274. <PageOverviewWebVitalsDetailPanel
  275. webVital={state.webVital}
  276. onClose={() => {
  277. router.replace({
  278. pathname: router.location.pathname,
  279. query: omit(router.location.query, 'webVital'),
  280. });
  281. setState({...state, webVital: null});
  282. }}
  283. />
  284. </Tabs>
  285. </React.Fragment>
  286. );
  287. }
  288. function PageWithProviders() {
  289. return (
  290. <ModulePageProviders
  291. title={[t('Performance'), t('Web Vitals')].join(' — ')}
  292. baseURL="/performance/browser/pageloads"
  293. features="spans-first-ui"
  294. >
  295. <PageOverview />
  296. </ModulePageProviders>
  297. );
  298. }
  299. export default PageWithProviders;
  300. const ViewAllPagesButton = styled(LinkButton)`
  301. margin-right: ${space(1)};
  302. `;
  303. const TopMenuContainer = styled('div')`
  304. margin-bottom: ${space(1)};
  305. display: flex;
  306. `;
  307. const Flex = styled('div')`
  308. display: flex;
  309. flex-direction: row;
  310. justify-content: space-between;
  311. width: 100%;
  312. gap: ${space(1)};
  313. `;
  314. const PageSamplePerformanceTableContainer = styled('div')`
  315. margin-top: ${space(1)};
  316. `;
  317. const WebVitalMetersContainer = styled('div')`
  318. margin: ${space(2)} 0 ${space(4)} 0;
  319. `;