pageOverview.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 {trackAnalytics} from 'sentry/utils/analytics';
  24. import {browserHistory} from 'sentry/utils/browserHistory';
  25. import {decodeScalar} from 'sentry/utils/queryString';
  26. import useDismissAlert from 'sentry/utils/useDismissAlert';
  27. import {useLocation} from 'sentry/utils/useLocation';
  28. import useOrganization from 'sentry/utils/useOrganization';
  29. import useProjects from 'sentry/utils/useProjects';
  30. import useRouter from 'sentry/utils/useRouter';
  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 {useModuleBreadcrumbs} from 'sentry/views/performance/utils/useModuleBreadcrumbs';
  50. import {useModuleURL} 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 = useModuleURL('vital');
  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 crumbs = useModuleBreadcrumbs('vital');
  100. const query = decodeScalar(location.query.query);
  101. const {data: pageData, isLoading} = useProjectRawWebVitalsQuery({transaction});
  102. const {data: projectScores, isLoading: isProjectScoresLoading} =
  103. useProjectWebVitalsScoresQuery({transaction});
  104. if (transaction === undefined) {
  105. // redirect user to webvitals landing page
  106. window.location.href = moduleURL;
  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. isProjectScoresLoading || isLoading
  121. ? undefined
  122. : calculatePerformanceScoreFromStoredTableDataRow(projectScores?.data?.[0]);
  123. const fidDeprecationTimestampString =
  124. moment(FID_DEPRECATION_DATE).format('DD MMMM YYYY');
  125. return (
  126. <React.Fragment>
  127. <Tabs
  128. value={tab}
  129. onChange={value => {
  130. trackAnalytics('insight.vital.overview.toggle_tab', {
  131. organization,
  132. tab: value,
  133. });
  134. browserHistory.push({
  135. ...location,
  136. query: {
  137. ...location.query,
  138. tab: value,
  139. },
  140. });
  141. }}
  142. >
  143. <Layout.Header>
  144. <Layout.HeaderContent>
  145. <Breadcrumbs
  146. crumbs={[...crumbs, ...(transaction ? [{label: 'Page Overview'}] : [])]}
  147. />
  148. <Layout.Title>
  149. {transaction && project && <ProjectAvatar project={project} size={24} />}
  150. {transaction ?? t('Page Loads')}
  151. </Layout.Title>
  152. </Layout.HeaderContent>
  153. <Layout.HeaderActions>
  154. <ButtonBar gap={1}>
  155. <FeedbackWidgetButton />
  156. {transactionSummaryTarget && (
  157. <LinkButton
  158. to={transactionSummaryTarget}
  159. onClick={() => {
  160. trackAnalytics('insight.vital.overview.open_transaction_summary', {
  161. organization,
  162. });
  163. }}
  164. size="sm"
  165. >
  166. {t('View Transaction Summary')}
  167. </LinkButton>
  168. )}
  169. </ButtonBar>
  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. <Layout.Main>
  186. <TopMenuContainer>
  187. {transaction && (
  188. <ViewAllPagesButton
  189. to={{
  190. ...location,
  191. pathname: '/performance/browser/pageloads/',
  192. query: {...location.query, transaction: undefined},
  193. }}
  194. >
  195. <IconChevron direction="left" /> {t('View All Pages')}
  196. </ViewAllPagesButton>
  197. )}
  198. <PageFilterBar condensed>
  199. <ProjectPageFilter />
  200. <EnvironmentPageFilter />
  201. <DatePageFilter />
  202. </PageFilterBar>
  203. </TopMenuContainer>
  204. {!isDismissed && (
  205. <StyledAlert type="info" showIcon>
  206. <AlertContent>
  207. <span>
  208. {tct(
  209. `Starting on [fidDeprecationTimestampString], [inpStrong:INP] (Interaction to Next Paint) will replace [fidStrong:FID] (First Input Delay) in our performance score calculation.`,
  210. {
  211. fidDeprecationTimestampString,
  212. inpStrong: <strong />,
  213. fidStrong: <strong />,
  214. }
  215. )}
  216. <br />
  217. {tct(
  218. `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.`,
  219. {
  220. link: (
  221. <ExternalLink href="https://github.com/getsentry/sentry-javascript/releases/tag/7.104.0" />
  222. ),
  223. enableInp: (
  224. <ExternalLink href="https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#enableinp" />
  225. ),
  226. }
  227. )}
  228. </span>
  229. <DismissButton
  230. priority="link"
  231. icon={<IconClose />}
  232. onClick={dismiss}
  233. aria-label={t('Dismiss Alert')}
  234. title={t('Dismiss Alert')}
  235. />
  236. </AlertContent>
  237. </StyledAlert>
  238. )}
  239. <Flex>
  240. <PerformanceScoreBreakdownChart transaction={transaction} />
  241. </Flex>
  242. <WebVitalMetersContainer>
  243. <WebVitalMeters
  244. projectData={pageData}
  245. projectScore={projectScore}
  246. onClick={webVital => {
  247. router.replace({
  248. pathname: location.pathname,
  249. query: {...location.query, webVital},
  250. });
  251. setState({...state, webVital});
  252. }}
  253. transaction={transaction}
  254. showTooltip={false}
  255. />
  256. </WebVitalMetersContainer>
  257. <PageSamplePerformanceTableContainer>
  258. <PageSamplePerformanceTable
  259. transaction={transaction}
  260. limit={15}
  261. search={query}
  262. />
  263. </PageSamplePerformanceTableContainer>
  264. </Layout.Main>
  265. <Layout.Side>
  266. <PageOverviewSidebar
  267. projectScore={projectScore}
  268. transaction={transaction}
  269. projectScoreIsLoading={isLoading}
  270. />
  271. </Layout.Side>
  272. </Layout.Body>
  273. )}
  274. <PageOverviewWebVitalsDetailPanel
  275. webVital={state.webVital}
  276. onClose={() => {
  277. router.replace({
  278. pathname: router.location.pathname,
  279. query: omit(router.location.query, 'webVital'),
  280. });
  281. setState({...state, webVital: null});
  282. }}
  283. />
  284. </Tabs>
  285. </React.Fragment>
  286. );
  287. }
  288. function PageWithProviders() {
  289. return (
  290. <ModulePageProviders moduleName="vital" features="insights-initial-modules">
  291. <PageOverview />
  292. </ModulePageProviders>
  293. );
  294. }
  295. export default PageWithProviders;
  296. const ViewAllPagesButton = styled(LinkButton)`
  297. margin-right: ${space(1)};
  298. `;
  299. const TopMenuContainer = styled('div')`
  300. margin-bottom: ${space(1)};
  301. display: flex;
  302. `;
  303. const Flex = styled('div')`
  304. display: flex;
  305. flex-direction: row;
  306. justify-content: space-between;
  307. width: 100%;
  308. gap: ${space(1)};
  309. `;
  310. const PageSamplePerformanceTableContainer = styled('div')`
  311. margin-top: ${space(1)};
  312. `;
  313. const WebVitalMetersContainer = styled('div')`
  314. margin: ${space(2)} 0 ${space(4)} 0;
  315. `;