pageOverview.tsx 12 KB

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