pageOverview.tsx 13 KB

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