webVitalsLandingPage.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import React, {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import omit from 'lodash/omit';
  4. import Alert from 'sentry/components/alert';
  5. import {Breadcrumbs} from 'sentry/components/breadcrumbs';
  6. import {Button} from 'sentry/components/button';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  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 {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  16. import {Tooltip} from 'sentry/components/tooltip';
  17. import {t, tct} from 'sentry/locale';
  18. import {space} from 'sentry/styles/space';
  19. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  20. import {useLocation} from 'sentry/utils/useLocation';
  21. import useOrganization from 'sentry/utils/useOrganization';
  22. import useRouter from 'sentry/utils/useRouter';
  23. import WebVitalMeters from 'sentry/views/performance/browser/webVitals/components/webVitalMeters';
  24. import {PagePerformanceTable} from 'sentry/views/performance/browser/webVitals/pagePerformanceTable';
  25. import {PerformanceScoreChart} from 'sentry/views/performance/browser/webVitals/performanceScoreChart';
  26. import {
  27. MODULE_DESCRIPTION,
  28. MODULE_DOC_LINK,
  29. MODULE_TITLE,
  30. } from 'sentry/views/performance/browser/webVitals/settings';
  31. import {useProjectRawWebVitalsQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/rawWebVitalsQueries/useProjectRawWebVitalsQuery';
  32. import {calculatePerformanceScoreFromStoredTableDataRow} from 'sentry/views/performance/browser/webVitals/utils/queries/storedScoreQueries/calculatePerformanceScoreFromStored';
  33. import {useProjectWebVitalsScoresQuery} from 'sentry/views/performance/browser/webVitals/utils/queries/storedScoreQueries/useProjectWebVitalsScoresQuery';
  34. import type {WebVitals} from 'sentry/views/performance/browser/webVitals/utils/types';
  35. import {useOnboardingProject} from 'sentry/views/performance/browser/webVitals/utils/useOnboardingProject';
  36. import {WebVitalsDetailPanel} from 'sentry/views/performance/browser/webVitals/webVitalsDetailPanel';
  37. import {ModulePageProviders} from 'sentry/views/performance/modulePageProviders';
  38. import Onboarding from 'sentry/views/performance/onboarding';
  39. import {useHasDataTrackAnalytics} from 'sentry/views/performance/utils/analytics/useHasDataTrackAnalytics';
  40. import {useModuleBreadcrumbs} from 'sentry/views/performance/utils/useModuleBreadcrumbs';
  41. export function WebVitalsLandingPage() {
  42. const organization = useOrganization();
  43. const location = useLocation();
  44. const onboardingProject = useOnboardingProject();
  45. const router = useRouter();
  46. const [state, setState] = useState<{webVital: WebVitals | null}>({
  47. webVital: (location.query.webVital as WebVitals) ?? null,
  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. useHasDataTrackAnalytics(
  58. new MutableSearch(
  59. // TODO: check for all possible WebVital data sources
  60. 'span.op:[ui.interaction.click,ui.interaction.hover,ui.interaction.drag,ui.interaction.press]'
  61. ),
  62. 'api.performance.vital.vital-landing',
  63. 'insight.page_loads.vital'
  64. );
  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. <PerformanceScoreChartContainer>
  102. <PerformanceScoreChart
  103. projectScore={projectScore}
  104. isProjectScoreLoading={isLoading || isProjectScoresLoading}
  105. webVital={state.webVital}
  106. />
  107. </PerformanceScoreChartContainer>
  108. <WebVitalMetersContainer>
  109. <WebVitalMeters
  110. projectData={projectData}
  111. projectScore={projectScore}
  112. onClick={webVital => setState({...state, webVital})}
  113. />
  114. </WebVitalMetersContainer>
  115. <PagePerformanceTable />
  116. <PagesTooltipContainer>
  117. <Tooltip
  118. isHoverable
  119. title={
  120. <div>
  121. <div>
  122. {tct(
  123. 'If pages you expect to see are missing, your framework is most likely not supported by the SDK, or your traffic is coming from unsupported browsers. Find supported browsers and frameworks [link:here].',
  124. {
  125. link: (
  126. <ExternalLink href="https://docs.sentry.io/product/insights/web-vitals/#prerequisites-and-limitations" />
  127. ),
  128. }
  129. )}
  130. </div>
  131. <br />
  132. <div>
  133. {t(
  134. 'Keep your JavaScript SDK updated to the latest version for the best Web Vitals support.'
  135. )}
  136. </div>
  137. </div>
  138. }
  139. >
  140. <PagesTooltip>{t('Why are my pages not showing up?')}</PagesTooltip>
  141. </Tooltip>
  142. </PagesTooltipContainer>
  143. </Fragment>
  144. )}
  145. </Layout.Main>
  146. </Layout.Body>
  147. <WebVitalsDetailPanel
  148. webVital={state.webVital}
  149. onClose={() => {
  150. router.replace({
  151. pathname: router.location.pathname,
  152. query: omit(router.location.query, 'webVital'),
  153. });
  154. setState({...state, webVital: null});
  155. }}
  156. />
  157. </React.Fragment>
  158. );
  159. }
  160. function PageWithProviders() {
  161. return (
  162. <ModulePageProviders moduleName="vital" features="insights-initial-modules">
  163. <WebVitalsLandingPage />
  164. </ModulePageProviders>
  165. );
  166. }
  167. export default PageWithProviders;
  168. const TopMenuContainer = styled('div')`
  169. display: flex;
  170. `;
  171. const PerformanceScoreChartContainer = styled('div')`
  172. margin-bottom: ${space(1)};
  173. `;
  174. const OnboardingContainer = styled('div')`
  175. margin-top: ${space(2)};
  176. `;
  177. const WebVitalMetersContainer = styled('div')`
  178. margin-bottom: ${space(4)};
  179. `;
  180. export const AlertContent = styled('div')`
  181. display: grid;
  182. grid-template-columns: 1fr max-content;
  183. gap: ${space(1)};
  184. align-items: center;
  185. `;
  186. export const DismissButton = styled(Button)`
  187. color: ${p => p.theme.alert.info.color};
  188. pointer-events: all;
  189. &:hover {
  190. opacity: 0.5;
  191. }
  192. `;
  193. export const StyledAlert = styled(Alert)`
  194. margin-top: ${space(2)};
  195. `;
  196. export const PagesTooltip = styled('span')`
  197. font-size: ${p => p.theme.fontSizeSmall};
  198. color: ${p => p.theme.gray300};
  199. text-decoration: underline dotted ${p => p.theme.gray300};
  200. `;
  201. export const PagesTooltipContainer = styled('div')`
  202. display: flex;
  203. `;