webVitalsLandingPage.tsx 8.6 KB

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