webVitalsLandingPage.tsx 8.7 KB

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