pageOverview.tsx 12 KB

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