pageOverview.tsx 13 KB

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