pageOverview.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import {useMemo, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import ProjectAvatar from 'sentry/components/avatar/projectAvatar';
  4. import Breadcrumbs from 'sentry/components/breadcrumbs';
  5. import {LinkButton} from 'sentry/components/button';
  6. import FeatureBadge from 'sentry/components/featureBadge';
  7. import FeedbackWidget from 'sentry/components/feedback/widget/feedbackWidget';
  8. import * as Layout from 'sentry/components/layouts/thirds';
  9. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  10. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  11. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  12. import {TabList, Tabs} from 'sentry/components/tabs';
  13. import {IconChevron} from 'sentry/icons';
  14. import {t} from 'sentry/locale';
  15. import {space} from 'sentry/styles/space';
  16. import {useLocation} from 'sentry/utils/useLocation';
  17. import useOrganization from 'sentry/utils/useOrganization';
  18. import useProjects from 'sentry/utils/useProjects';
  19. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  20. import {PageOverviewFeaturedTagsList} from 'sentry/views/performance/browser/webVitals/components/pageOverviewFeaturedTagsList';
  21. import {PageOverviewSidebar} from 'sentry/views/performance/browser/webVitals/components/pageOverviewSidebar';
  22. import {PerformanceScoreBreakdownChart} from 'sentry/views/performance/browser/webVitals/components/performanceScoreBreakdownChart';
  23. import WebVitalsRingMeters from 'sentry/views/performance/browser/webVitals/components/webVitalsRingMeters';
  24. import {PageOverviewWebVitalsDetailPanel} from 'sentry/views/performance/browser/webVitals/pageOverviewWebVitalsDetailPanel';
  25. import {calculatePerformanceScore} from 'sentry/views/performance/browser/webVitals/utils/calculatePerformanceScore';
  26. import {WebVitals} from 'sentry/views/performance/browser/webVitals/utils/types';
  27. import {useProjectWebVitalsQuery} from 'sentry/views/performance/browser/webVitals/utils/useProjectWebVitalsQuery';
  28. import {ModulePageProviders} from 'sentry/views/performance/database/modulePageProviders';
  29. enum LandingDisplayField {
  30. OVERVIEW = 'overview',
  31. SPANS = 'spans',
  32. }
  33. const LANDING_DISPLAYS = [
  34. {
  35. label: t('Overview'),
  36. field: LandingDisplayField.OVERVIEW,
  37. },
  38. {
  39. label: t('Spans'),
  40. field: LandingDisplayField.SPANS,
  41. },
  42. ];
  43. export default function PageOverview() {
  44. const organization = useOrganization();
  45. const location = useLocation();
  46. const {projects} = useProjects();
  47. const transaction = location.query.transaction
  48. ? Array.isArray(location.query.transaction)
  49. ? location.query.transaction[0]
  50. : location.query.transaction
  51. : undefined;
  52. const project = useMemo(
  53. () => projects.find(p => p.id === String(location.query.project)),
  54. [projects, location.query.project]
  55. );
  56. // TODO: When visiting page overview from a specific webvital detail panel in the landing page,
  57. // we should automatically default this webvital state to the respective webvital so the detail
  58. // panel in this page opens automatically.
  59. const [state, setState] = useState<{webVital: WebVitals | null}>({
  60. webVital: null,
  61. });
  62. const {data: pageData, isLoading} = useProjectWebVitalsQuery({transaction});
  63. if (transaction === undefined) {
  64. // redirect user to webvitals landing page
  65. window.location.href = normalizeUrl(
  66. `/organizations/${organization.slug}/performance/browser/pageloads/`
  67. );
  68. return null;
  69. }
  70. const projectScore = isLoading
  71. ? undefined
  72. : calculatePerformanceScore({
  73. lcp: pageData?.data[0]['p75(measurements.lcp)'] as number,
  74. fcp: pageData?.data[0]['p75(measurements.fcp)'] as number,
  75. cls: pageData?.data[0]['p75(measurements.cls)'] as number,
  76. ttfb: pageData?.data[0]['p75(measurements.ttfb)'] as number,
  77. fid: pageData?.data[0]['p75(measurements.fid)'] as number,
  78. });
  79. return (
  80. <ModulePageProviders title={[t('Performance'), t('Web Vitals')].join(' — ')}>
  81. <Tabs value={LandingDisplayField.OVERVIEW}>
  82. <Layout.Header>
  83. <Layout.HeaderContent>
  84. <Breadcrumbs
  85. crumbs={[
  86. {
  87. label: 'Performance',
  88. to: normalizeUrl(`/organizations/${organization.slug}/performance/`),
  89. preservePageFilters: true,
  90. },
  91. {
  92. label: 'Web Vitals',
  93. to: normalizeUrl(
  94. `/organizations/${organization.slug}/performance/browser/pageloads/`
  95. ),
  96. preservePageFilters: true,
  97. },
  98. ...(transaction ? [{label: 'Page Overview'}] : []),
  99. ]}
  100. />
  101. <Layout.Title>
  102. {transaction && project && <ProjectAvatar project={project} size={24} />}
  103. {transaction ?? t('Page Loads')}
  104. <FeatureBadge type="alpha" />
  105. </Layout.Title>
  106. </Layout.HeaderContent>
  107. <Layout.HeaderActions />
  108. <TabList hideBorder>
  109. {LANDING_DISPLAYS.map(({label, field}) => (
  110. <TabList.Item key={field}>{label}</TabList.Item>
  111. ))}
  112. </TabList>
  113. </Layout.Header>
  114. <Layout.Body>
  115. <FeedbackWidget />
  116. <Layout.Main>
  117. <TopMenuContainer>
  118. {transaction && (
  119. <ViewAllPagesButton
  120. to={{
  121. ...location,
  122. pathname: '/performance/browser/pageloads/',
  123. query: {...location.query, transaction: undefined},
  124. }}
  125. >
  126. <IconChevron direction="left" /> {t('View All Pages')}
  127. </ViewAllPagesButton>
  128. )}
  129. <PageFilterBar condensed>
  130. <ProjectPageFilter />
  131. <DatePageFilter />
  132. </PageFilterBar>
  133. </TopMenuContainer>
  134. <Flex>
  135. <PerformanceScoreBreakdownChart transaction={transaction} />
  136. </Flex>
  137. <WebVitalsRingMeters
  138. projectScore={projectScore}
  139. onClick={webVital => setState({...state, webVital})}
  140. transaction={transaction}
  141. />
  142. {/* TODO: Need to pass in a handler function to each tag list here to handle opening detail panel for tags */}
  143. <Flex>
  144. <PageOverviewFeaturedTagsList
  145. tag="browser.name"
  146. transaction={transaction}
  147. />
  148. <PageOverviewFeaturedTagsList tag="release" transaction={transaction} />
  149. <PageOverviewFeaturedTagsList
  150. tag="geo.country_code"
  151. transaction={transaction}
  152. />
  153. </Flex>
  154. </Layout.Main>
  155. <Layout.Side>
  156. <PageOverviewSidebar projectScore={projectScore} transaction={transaction} />
  157. </Layout.Side>
  158. </Layout.Body>
  159. <PageOverviewWebVitalsDetailPanel
  160. webVital={state.webVital}
  161. onClose={() => {
  162. setState({...state, webVital: null});
  163. }}
  164. />
  165. {/* TODO: Add the detail panel for tags here. Can copy foundation from PageOverviewWebVitalsDetailPanel above. */}
  166. </Tabs>
  167. </ModulePageProviders>
  168. );
  169. }
  170. const ViewAllPagesButton = styled(LinkButton)`
  171. margin-right: ${space(1)};
  172. `;
  173. const TopMenuContainer = styled('div')`
  174. display: flex;
  175. `;
  176. const Flex = styled('div')`
  177. display: flex;
  178. flex-direction: row;
  179. justify-content: space-between;
  180. width: 100%;
  181. gap: ${space(1)};
  182. margin-top: ${space(1)};
  183. `;