pageOverview.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. import {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 default 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. <ModulePageProviders
  125. title={[t('Performance'), t('Web Vitals')].join(' — ')}
  126. baseURL="/performance/browser/pageloads"
  127. features="spans-first-ui"
  128. >
  129. <Tabs
  130. value={tab}
  131. onChange={value => {
  132. browserHistory.push({
  133. ...location,
  134. query: {
  135. ...location.query,
  136. tab: value,
  137. },
  138. });
  139. }}
  140. >
  141. <Layout.Header>
  142. <Layout.HeaderContent>
  143. <Breadcrumbs
  144. crumbs={[
  145. {
  146. label: 'Performance',
  147. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  148. preservePageFilters: true,
  149. },
  150. {
  151. label: 'Web Vitals',
  152. to: normalizeUrl(
  153. `/organizations/${organization.slug}/performance/browser/pageloads/`
  154. ),
  155. preservePageFilters: true,
  156. },
  157. ...(transaction ? [{label: 'Page Overview'}] : []),
  158. ]}
  159. />
  160. <Layout.Title>
  161. {transaction && project && <ProjectAvatar project={project} size={24} />}
  162. {transaction ?? t('Page Loads')}
  163. </Layout.Title>
  164. </Layout.HeaderContent>
  165. <Layout.HeaderActions>
  166. <ButtonBar gap={1}>
  167. <FeedbackWidgetButton />
  168. {transactionSummaryTarget && (
  169. <LinkButton to={transactionSummaryTarget} size="sm">
  170. {t('View Transaction Summary')}
  171. </LinkButton>
  172. )}
  173. </ButtonBar>
  174. </Layout.HeaderActions>
  175. <TabList hideBorder>
  176. {LANDING_DISPLAYS.map(({label, field}) => (
  177. <TabList.Item key={field}>{label}</TabList.Item>
  178. ))}
  179. </TabList>
  180. </Layout.Header>
  181. {tab === LandingDisplayField.SPANS ? (
  182. <Layout.Body>
  183. <Layout.Main fullWidth>
  184. {defined(transaction) && <AggregateSpans transaction={transaction} />}
  185. </Layout.Main>
  186. </Layout.Body>
  187. ) : (
  188. <Layout.Body>
  189. <Layout.Main>
  190. <TopMenuContainer>
  191. {transaction && (
  192. <ViewAllPagesButton
  193. to={{
  194. ...location,
  195. pathname: '/performance/browser/pageloads/',
  196. query: {...location.query, transaction: undefined},
  197. }}
  198. >
  199. <IconChevron direction="left" /> {t('View All Pages')}
  200. </ViewAllPagesButton>
  201. )}
  202. <PageFilterBar condensed>
  203. <ProjectPageFilter />
  204. <EnvironmentPageFilter />
  205. <DatePageFilter />
  206. </PageFilterBar>
  207. </TopMenuContainer>
  208. {!isDismissed && (
  209. <StyledAlert type="info" showIcon>
  210. <AlertContent>
  211. <span>
  212. {tct(
  213. `Starting on [fidDeprecationTimestampString], [inpStrong:INP] (Interaction to Next Paint) will replace [fidStrong:FID] (First Input Delay) in our performance score calculation.`,
  214. {
  215. fidDeprecationTimestampString,
  216. inpStrong: <strong />,
  217. fidStrong: <strong />,
  218. }
  219. )}
  220. <br />
  221. {tct(
  222. `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.`,
  223. {
  224. link: (
  225. <ExternalLink href="https://github.com/getsentry/sentry-javascript/releases/tag/7.104.0" />
  226. ),
  227. enableInp: (
  228. <ExternalLink href="https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#enableinp" />
  229. ),
  230. }
  231. )}
  232. </span>
  233. <DismissButton
  234. priority="link"
  235. icon={<IconClose />}
  236. onClick={dismiss}
  237. aria-label={t('Dismiss Alert')}
  238. title={t('Dismiss Alert')}
  239. />
  240. </AlertContent>
  241. </StyledAlert>
  242. )}
  243. <Flex>
  244. <PerformanceScoreBreakdownChart transaction={transaction} />
  245. </Flex>
  246. <WebVitalMetersContainer>
  247. <WebVitalMeters
  248. projectData={pageData}
  249. projectScore={projectScore}
  250. onClick={webVital => {
  251. router.replace({
  252. pathname: location.pathname,
  253. query: {...location.query, webVital},
  254. });
  255. setState({...state, webVital});
  256. }}
  257. transaction={transaction}
  258. showTooltip={false}
  259. />
  260. </WebVitalMetersContainer>
  261. <PageSamplePerformanceTableContainer>
  262. <PageSamplePerformanceTable
  263. transaction={transaction}
  264. limit={15}
  265. search={query}
  266. />
  267. </PageSamplePerformanceTableContainer>
  268. </Layout.Main>
  269. <Layout.Side>
  270. <PageOverviewSidebar
  271. projectScore={projectScore}
  272. transaction={transaction}
  273. projectScoreIsLoading={isLoading}
  274. />
  275. </Layout.Side>
  276. </Layout.Body>
  277. )}
  278. <PageOverviewWebVitalsDetailPanel
  279. webVital={state.webVital}
  280. onClose={() => {
  281. router.replace({
  282. pathname: router.location.pathname,
  283. query: omit(router.location.query, 'webVital'),
  284. });
  285. setState({...state, webVital: null});
  286. }}
  287. />
  288. </Tabs>
  289. </ModulePageProviders>
  290. );
  291. }
  292. const ViewAllPagesButton = styled(LinkButton)`
  293. margin-right: ${space(1)};
  294. `;
  295. const TopMenuContainer = styled('div')`
  296. margin-bottom: ${space(1)};
  297. display: flex;
  298. `;
  299. const Flex = styled('div')`
  300. display: flex;
  301. flex-direction: row;
  302. justify-content: space-between;
  303. width: 100%;
  304. gap: ${space(1)};
  305. `;
  306. const PageSamplePerformanceTableContainer = styled('div')`
  307. margin-top: ${space(1)};
  308. `;
  309. const WebVitalMetersContainer = styled('div')`
  310. margin: ${space(2)} 0 ${space(4)} 0;
  311. `;