webVitalsLandingPage.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 {SCORE_MIGRATION_TIMESTAMP} 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}:performance-score-migration-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 scoreMigrationTimestampString = moment(SCORE_MIGRATION_TIMESTAMP).format(
  62. 'DD MMMM YYYY'
  63. );
  64. return (
  65. <ModulePageProviders
  66. title={[t('Performance'), t('Web Vitals')].join(' — ')}
  67. baseURL="/performance/browser/pageloads"
  68. features="starfish-browser-webvitals"
  69. >
  70. <Layout.Header>
  71. <Layout.HeaderContent>
  72. <Breadcrumbs
  73. crumbs={[
  74. {
  75. label: 'Performance',
  76. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  77. preservePageFilters: true,
  78. },
  79. {
  80. label: 'Web Vitals',
  81. },
  82. ]}
  83. />
  84. <Layout.Title>{t('Web Vitals')}</Layout.Title>
  85. </Layout.HeaderContent>
  86. </Layout.Header>
  87. <Layout.Body>
  88. <FloatingFeedbackWidget />
  89. <Layout.Main fullWidth>
  90. <TopMenuContainer>
  91. <PageFilterBar condensed>
  92. <ProjectPageFilter />
  93. <EnvironmentPageFilter />
  94. <DatePageFilter />
  95. </PageFilterBar>
  96. </TopMenuContainer>
  97. {onboardingProject && (
  98. <OnboardingContainer>
  99. <Onboarding organization={organization} project={onboardingProject} />
  100. </OnboardingContainer>
  101. )}
  102. {!onboardingProject && (
  103. <Fragment>
  104. {shouldUseStoredScores && !isDismissed && (
  105. <StyledAlert type="info" showIcon>
  106. <AlertContent>
  107. <span>
  108. {tct(
  109. `We made improvements to how Performance Scores are calculated for your projects. Starting on [scoreMigrationTimestampString], scores are updated to more accurately reflect user experiences. [link:Read more about these improvements].`,
  110. {
  111. scoreMigrationTimestampString,
  112. link: (
  113. <ExternalLink href="https://sentry.engineering/blog/how-we-improved-performance-score-accuracy" />
  114. ),
  115. }
  116. )}
  117. </span>
  118. <DismissButton
  119. priority="link"
  120. icon={<IconClose />}
  121. onClick={dismiss}
  122. aria-label={t('Dismiss Alert')}
  123. title={t('Dismiss Alert')}
  124. />
  125. </AlertContent>
  126. </StyledAlert>
  127. )}
  128. <PerformanceScoreChartContainer>
  129. <PerformanceScoreChart
  130. projectScore={projectScore}
  131. isProjectScoreLoading={
  132. isLoading || (shouldUseStoredScores && isProjectScoresLoading)
  133. }
  134. webVital={state.webVital}
  135. />
  136. </PerformanceScoreChartContainer>
  137. <WebVitalMetersContainer>
  138. <WebVitalMeters
  139. projectData={projectData}
  140. projectScore={projectScore}
  141. onClick={webVital => setState({...state, webVital})}
  142. />
  143. </WebVitalMetersContainer>
  144. <PagePerformanceTable />
  145. </Fragment>
  146. )}
  147. </Layout.Main>
  148. </Layout.Body>
  149. <WebVitalsDetailPanel
  150. webVital={state.webVital}
  151. onClose={() => {
  152. router.replace({
  153. pathname: router.location.pathname,
  154. query: omit(router.location.query, 'webVital'),
  155. });
  156. setState({...state, webVital: null});
  157. }}
  158. />
  159. </ModulePageProviders>
  160. );
  161. }
  162. const TopMenuContainer = styled('div')`
  163. display: flex;
  164. `;
  165. const PerformanceScoreChartContainer = styled('div')`
  166. margin-bottom: ${space(1)};
  167. `;
  168. const OnboardingContainer = styled('div')`
  169. margin-top: ${space(2)};
  170. `;
  171. const WebVitalMetersContainer = styled('div')`
  172. margin-bottom: ${space(4)};
  173. `;
  174. export const AlertContent = styled('div')`
  175. display: grid;
  176. grid-template-columns: 1fr max-content;
  177. gap: ${space(1)};
  178. align-items: center;
  179. `;
  180. export const DismissButton = styled(Button)`
  181. color: ${p => p.theme.alert.info.iconColor};
  182. pointer-events: all;
  183. &:hover {
  184. color: ${p => p.theme.alert.info.iconHoverColor};
  185. opacity: 0.5;
  186. }
  187. `;
  188. export const StyledAlert = styled(Alert)`
  189. margin-top: ${space(2)};
  190. `;