webVitalsLandingPage.tsx 8.3 KB

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