webVitalsLandingPage.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import omit from 'lodash/omit';
  4. import moment from 'moment';
  5. import Alert from 'sentry/components/alert';
  6. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  7. import {Button} from 'sentry/components/button';
  8. import FloatingFeedbackWidget from 'sentry/components/feedback/widget/floatingFeedbackWidget';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import ExternalLink from 'sentry/components/links/externalLink';
  11. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  12. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  13. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  14. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  15. import {IconClose} from 'sentry/icons';
  16. import {t, tct} from 'sentry/locale';
  17. import ConfigStore from 'sentry/stores/configStore';
  18. import {space} from 'sentry/styles/space';
  19. import useDismissAlert from 'sentry/utils/useDismissAlert';
  20. import {useLocation} from 'sentry/utils/useLocation';
  21. import useOrganization from 'sentry/utils/useOrganization';
  22. import useRouter from 'sentry/utils/useRouter';
  23. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  24. import {FID_DEPRECATION_DATE} from 'sentry/views/performance/browser/webVitals/components/performanceScoreBreakdownChart';
  25. import WebVitalMeters from 'sentry/views/performance/browser/webVitals/components/webVitalMeters';
  26. import {PagePerformanceTable} from 'sentry/views/performance/browser/webVitals/pagePerformanceTable';
  27. import {PerformanceScoreChart} from 'sentry/views/performance/browser/webVitals/performanceScoreChart';
  28. import {calculatePerformanceScoreFromTableDataRow} from 'sentry/views/performance/browser/webVitals/utils/queries/rawWebVitalsQueries/calculatePerformanceScore';
  29. import {useProjectRawWebVitalsQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/rawWebVitalsQueries/useProjectRawWebVitalsQuery';
  30. import {calculatePerformanceScoreFromStoredTableDataRow} from 'sentry/views/performance/browser/webVitals/utils/queries/storedScoreQueries/calculatePerformanceScoreFromStored';
  31. import {useProjectWebVitalsScoresQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/storedScoreQueries/useProjectWebVitalsScoresQuery';
  32. import type {WebVitals} from 'sentry/views/performance/browser/webVitals/utils/types';
  33. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  34. import {useStoredScoresSetting} from 'sentry/views/performance/browser/webVitals/utils/useStoredScoresSetting';
  35. import {WebVitalsDetailPanel} from 'sentry/views/performance/browser/webVitals/webVitalsDetailPanel';
  36. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  37. import Onboarding from 'sentry/views/performance/onboarding';
  38. export default function WebVitalsLandingPage() {
  39. const organization = useOrganization();
  40. const location = useLocation();
  41. const onboardingProject = useOnboardingProject();
  42. const shouldUseStoredScores = useStoredScoresSetting();
  43. const router = useRouter();
  44. const [state, setState] = useState<{webVital: WebVitals | null}>({
  45. webVital: (location.query.webVital as WebVitals) ?? null,
  46. });
  47. const user = ConfigStore.get('user');
  48. const {dismiss, isDismissed} = useDismissAlert({
  49. key: `${organization.slug}-${user.id}:fid-deprecation-message-dismissed`,
  50. });
  51. const {data: projectData, isLoading} = useProjectRawWebVitalsQuery({});
  52. const {data: projectScores, isLoading: isProjectScoresLoading} =
  53. useProjectWebVitalsScoresQuery({enabled: shouldUseStoredScores});
  54. const noTransactions = !isLoading && !projectData?.data?.[0]?.['count()'];
  55. const projectScore =
  56. (shouldUseStoredScores && isProjectScoresLoading) || isLoading || noTransactions
  57. ? undefined
  58. : shouldUseStoredScores
  59. ? calculatePerformanceScoreFromStoredTableDataRow(projectScores?.data?.[0])
  60. : calculatePerformanceScoreFromTableDataRow(projectData?.data?.[0]);
  61. const fidDeprecationTimestampString =
  62. moment(FID_DEPRECATION_DATE).format('DD MMMM YYYY');
  63. return (
  64. <ModulePageProviders
  65. title={[t('Performance'), t('Web Vitals')].join(' — ')}
  66. baseURL="/performance/browser/pageloads"
  67. features="starfish-browser-webvitals"
  68. >
  69. <Layout.Header>
  70. <Layout.HeaderContent>
  71. <Breadcrumbs
  72. crumbs={[
  73. {
  74. label: 'Performance',
  75. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  76. preservePageFilters: true,
  77. },
  78. {
  79. label: 'Web Vitals',
  80. },
  81. ]}
  82. />
  83. <Layout.Title>{t('Web Vitals')}</Layout.Title>
  84. </Layout.HeaderContent>
  85. </Layout.Header>
  86. <Layout.Body>
  87. <FloatingFeedbackWidget />
  88. <Layout.Main fullWidth>
  89. <TopMenuContainer>
  90. <PageFilterBar condensed>
  91. <ProjectPageFilter />
  92. <EnvironmentPageFilter />
  93. <DatePageFilter />
  94. </PageFilterBar>
  95. </TopMenuContainer>
  96. {onboardingProject && (
  97. <OnboardingContainer>
  98. <Onboarding organization={organization} project={onboardingProject} />
  99. </OnboardingContainer>
  100. )}
  101. {!onboardingProject && (
  102. <Fragment>
  103. {!isDismissed && (
  104. <StyledAlert type="info" showIcon>
  105. <AlertContent>
  106. <span>
  107. {tct(
  108. `Starting on [fidDeprecationTimestampString], [inpStrong:INP] (Interaction to Next Paint) will replace [fidStrong:FID] (First Input Delay) in our performance score calculation.`,
  109. {
  110. fidDeprecationTimestampString,
  111. inpStrong: <strong />,
  112. fidStrong: <strong />,
  113. }
  114. )}
  115. <br />
  116. {tct(
  117. `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.`,
  118. {
  119. link: (
  120. <ExternalLink href="https://github.com/getsentry/sentry-javascript/releases/tag/7.104.0" />
  121. ),
  122. enableInp: (
  123. <ExternalLink href="https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#enableinp" />
  124. ),
  125. }
  126. )}
  127. </span>
  128. <DismissButton
  129. priority="link"
  130. icon={<IconClose />}
  131. onClick={dismiss}
  132. aria-label={t('Dismiss Alert')}
  133. title={t('Dismiss Alert')}
  134. />
  135. </AlertContent>
  136. </StyledAlert>
  137. )}
  138. <PerformanceScoreChartContainer>
  139. <PerformanceScoreChart
  140. projectScore={projectScore}
  141. isProjectScoreLoading={
  142. isLoading || (shouldUseStoredScores && isProjectScoresLoading)
  143. }
  144. webVital={state.webVital}
  145. />
  146. </PerformanceScoreChartContainer>
  147. <WebVitalMetersContainer>
  148. <WebVitalMeters
  149. projectData={projectData}
  150. projectScore={projectScore}
  151. onClick={webVital => setState({...state, webVital})}
  152. />
  153. </WebVitalMetersContainer>
  154. <PagePerformanceTable />
  155. </Fragment>
  156. )}
  157. </Layout.Main>
  158. </Layout.Body>
  159. <WebVitalsDetailPanel
  160. webVital={state.webVital}
  161. onClose={() => {
  162. router.replace({
  163. pathname: router.location.pathname,
  164. query: omit(router.location.query, 'webVital'),
  165. });
  166. setState({...state, webVital: null});
  167. }}
  168. />
  169. </ModulePageProviders>
  170. );
  171. }
  172. const TopMenuContainer = styled('div')`
  173. display: flex;
  174. `;
  175. const PerformanceScoreChartContainer = styled('div')`
  176. margin-bottom: ${space(1)};
  177. `;
  178. const OnboardingContainer = styled('div')`
  179. margin-top: ${space(2)};
  180. `;
  181. const WebVitalMetersContainer = styled('div')`
  182. margin-bottom: ${space(4)};
  183. `;
  184. export const AlertContent = styled('div')`
  185. display: grid;
  186. grid-template-columns: 1fr max-content;
  187. gap: ${space(1)};
  188. align-items: center;
  189. `;
  190. export const DismissButton = styled(Button)`
  191. color: ${p => p.theme.alert.info.color};
  192. pointer-events: all;
  193. &:hover {
  194. opacity: 0.5;
  195. }
  196. `;
  197. export const StyledAlert = styled(Alert)`
  198. margin-top: ${space(2)};
  199. `;