webVitalsLandingPage.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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/database/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 title={[t('Performance'), t('Web Vitals')].join(' — ')}>
  66. <Layout.Header>
  67. <Layout.HeaderContent>
  68. <Breadcrumbs
  69. crumbs={[
  70. {
  71. label: 'Performance',
  72. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  73. preservePageFilters: true,
  74. },
  75. {
  76. label: 'Web Vitals',
  77. },
  78. ]}
  79. />
  80. <Layout.Title>{t('Web Vitals')}</Layout.Title>
  81. </Layout.HeaderContent>
  82. </Layout.Header>
  83. <Layout.Body>
  84. <FloatingFeedbackWidget />
  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. {shouldUseStoredScores && !isDismissed && (
  101. <StyledAlert type="info" showIcon>
  102. <AlertContent>
  103. <span>
  104. {tct(
  105. `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].`,
  106. {
  107. scoreMigrationTimestampString,
  108. link: (
  109. <ExternalLink href="https://sentry.engineering/blog/how-we-improved-performance-score-accuracy" />
  110. ),
  111. }
  112. )}
  113. </span>
  114. <DismissButton
  115. priority="link"
  116. icon={<IconClose />}
  117. onClick={dismiss}
  118. aria-label={t('Dismiss Alert')}
  119. title={t('Dismiss Alert')}
  120. />
  121. </AlertContent>
  122. </StyledAlert>
  123. )}
  124. <PerformanceScoreChartContainer>
  125. <PerformanceScoreChart
  126. projectScore={projectScore}
  127. isProjectScoreLoading={
  128. isLoading || (shouldUseStoredScores && isProjectScoresLoading)
  129. }
  130. webVital={state.webVital}
  131. />
  132. </PerformanceScoreChartContainer>
  133. <WebVitalMetersContainer>
  134. <WebVitalMeters
  135. projectData={projectData}
  136. projectScore={projectScore}
  137. onClick={webVital => setState({...state, webVital})}
  138. />
  139. </WebVitalMetersContainer>
  140. <PagePerformanceTable />
  141. </Fragment>
  142. )}
  143. </Layout.Main>
  144. </Layout.Body>
  145. <WebVitalsDetailPanel
  146. webVital={state.webVital}
  147. onClose={() => {
  148. router.replace({
  149. pathname: router.location.pathname,
  150. query: omit(router.location.query, 'webVital'),
  151. });
  152. setState({...state, webVital: null});
  153. }}
  154. />
  155. </ModulePageProviders>
  156. );
  157. }
  158. const TopMenuContainer = styled('div')`
  159. display: flex;
  160. `;
  161. const PerformanceScoreChartContainer = styled('div')`
  162. margin-bottom: ${space(1)};
  163. `;
  164. const OnboardingContainer = styled('div')`
  165. margin-top: ${space(2)};
  166. `;
  167. const WebVitalMetersContainer = styled('div')`
  168. margin-bottom: ${space(4)};
  169. `;
  170. export const AlertContent = styled('div')`
  171. display: grid;
  172. grid-template-columns: 1fr max-content;
  173. gap: ${space(1)};
  174. align-items: center;
  175. `;
  176. export const DismissButton = styled(Button)`
  177. color: ${p => p.theme.alert.info.iconColor};
  178. pointer-events: all;
  179. &:hover {
  180. color: ${p => p.theme.alert.info.iconHoverColor};
  181. opacity: 0.5;
  182. }
  183. `;
  184. export const StyledAlert = styled(Alert)`
  185. margin-top: ${space(2)};
  186. `;