webVitalsLandingPage.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 ButtonBar from 'sentry/components/buttonBar';
  9. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  10. import * as Layout from 'sentry/components/layouts/thirds';
  11. import ExternalLink from 'sentry/components/links/externalLink';
  12. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  13. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  14. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  15. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  16. import {IconClose} from 'sentry/icons';
  17. import {t, tct} from 'sentry/locale';
  18. import ConfigStore from 'sentry/stores/configStore';
  19. import {space} from 'sentry/styles/space';
  20. import useDismissAlert from 'sentry/utils/useDismissAlert';
  21. import {useLocation} from 'sentry/utils/useLocation';
  22. import useOrganization from 'sentry/utils/useOrganization';
  23. import useRouter from 'sentry/utils/useRouter';
  24. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  25. import {FID_DEPRECATION_DATE} from 'sentry/views/performance/browser/webVitals/components/performanceScoreBreakdownChart';
  26. import WebVitalMeters from 'sentry/views/performance/browser/webVitals/components/webVitalMeters';
  27. import {PagePerformanceTable} from 'sentry/views/performance/browser/webVitals/pagePerformanceTable';
  28. import {PerformanceScoreChart} from 'sentry/views/performance/browser/webVitals/performanceScoreChart';
  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 {WebVitalsDetailPanel} from 'sentry/views/performance/browser/webVitals/webVitalsDetailPanel';
  35. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  36. import Onboarding from 'sentry/views/performance/onboarding';
  37. export default function WebVitalsLandingPage() {
  38. const organization = useOrganization();
  39. const location = useLocation();
  40. const onboardingProject = useOnboardingProject();
  41. const router = useRouter();
  42. const [state, setState] = useState<{webVital: WebVitals | null}>({
  43. webVital: (location.query.webVital as WebVitals) ?? null,
  44. });
  45. const user = ConfigStore.get('user');
  46. const {dismiss, isDismissed} = useDismissAlert({
  47. key: `${organization.slug}-${user.id}:fid-deprecation-message-dismissed`,
  48. });
  49. const {data: projectData, isLoading} = useProjectRawWebVitalsQuery({});
  50. const {data: projectScores, isLoading: isProjectScoresLoading} =
  51. useProjectWebVitalsScoresQuery();
  52. const noTransactions = !isLoading && !projectData?.data?.[0]?.['count()'];
  53. const projectScore =
  54. isProjectScoresLoading || isLoading || noTransactions
  55. ? undefined
  56. : calculatePerformanceScoreFromStoredTableDataRow(projectScores?.data?.[0]);
  57. const fidDeprecationTimestampString =
  58. moment(FID_DEPRECATION_DATE).format('DD MMMM YYYY');
  59. return (
  60. <ModulePageProviders
  61. title={[t('Performance'), t('Web Vitals')].join(' — ')}
  62. baseURL="/performance/browser/pageloads"
  63. features="spans-first-ui"
  64. >
  65. <Layout.Header>
  66. <Layout.HeaderContent>
  67. <Breadcrumbs
  68. crumbs={[
  69. {
  70. label: 'Performance',
  71. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  72. preservePageFilters: true,
  73. },
  74. {
  75. label: 'Web Vitals',
  76. },
  77. ]}
  78. />
  79. <Layout.Title>{t('Web Vitals')}</Layout.Title>
  80. </Layout.HeaderContent>
  81. <Layout.HeaderActions>
  82. <ButtonBar gap={1}>
  83. <FeedbackWidgetButton />
  84. </ButtonBar>
  85. </Layout.HeaderActions>
  86. </Layout.Header>
  87. <Layout.Body>
  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={isLoading || isProjectScoresLoading}
  142. webVital={state.webVital}
  143. />
  144. </PerformanceScoreChartContainer>
  145. <WebVitalMetersContainer>
  146. <WebVitalMeters
  147. projectData={projectData}
  148. projectScore={projectScore}
  149. onClick={webVital => setState({...state, webVital})}
  150. />
  151. </WebVitalMetersContainer>
  152. <PagePerformanceTable />
  153. </Fragment>
  154. )}
  155. </Layout.Main>
  156. </Layout.Body>
  157. <WebVitalsDetailPanel
  158. webVital={state.webVital}
  159. onClose={() => {
  160. router.replace({
  161. pathname: router.location.pathname,
  162. query: omit(router.location.query, 'webVital'),
  163. });
  164. setState({...state, webVital: null});
  165. }}
  166. />
  167. </ModulePageProviders>
  168. );
  169. }
  170. const TopMenuContainer = styled('div')`
  171. display: flex;
  172. `;
  173. const PerformanceScoreChartContainer = styled('div')`
  174. margin-bottom: ${space(1)};
  175. `;
  176. const OnboardingContainer = styled('div')`
  177. margin-top: ${space(2)};
  178. `;
  179. const WebVitalMetersContainer = styled('div')`
  180. margin-bottom: ${space(4)};
  181. `;
  182. export const AlertContent = styled('div')`
  183. display: grid;
  184. grid-template-columns: 1fr max-content;
  185. gap: ${space(1)};
  186. align-items: center;
  187. `;
  188. export const DismissButton = styled(Button)`
  189. color: ${p => p.theme.alert.info.color};
  190. pointer-events: all;
  191. &:hover {
  192. opacity: 0.5;
  193. }
  194. `;
  195. export const StyledAlert = styled(Alert)`
  196. margin-top: ${space(2)};
  197. `;