details.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import DetailedError from 'sentry/components/errors/detailedError';
  4. import NotFound from 'sentry/components/errors/notFound';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import List from 'sentry/components/list';
  7. import ListItem from 'sentry/components/list/listItem';
  8. import {
  9. Provider as ReplayContextProvider,
  10. useReplayContext,
  11. } from 'sentry/components/replays/replayContext';
  12. import {t} from 'sentry/locale';
  13. import ConfigStore from 'sentry/stores/configStore';
  14. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  15. import {decodeScalar} from 'sentry/utils/queryString';
  16. import useInitialTimeOffsetMs, {
  17. TimeOffsetLocationQueryParams,
  18. } from 'sentry/utils/replays/hooks/useInitialTimeOffsetMs';
  19. import useLogReplayDataLoaded from 'sentry/utils/replays/hooks/useLogReplayDataLoaded';
  20. import useReplayLayout from 'sentry/utils/replays/hooks/useReplayLayout';
  21. import useReplayPageview from 'sentry/utils/replays/hooks/useReplayPageview';
  22. import useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';
  23. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  24. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  25. import {useLocation} from 'sentry/utils/useLocation';
  26. import useOrganization from 'sentry/utils/useOrganization';
  27. import ReplaysLayout from 'sentry/views/replays/detail/layout';
  28. import Page from 'sentry/views/replays/detail/page';
  29. import ReplayTransactionContext from 'sentry/views/replays/detail/trace/replayTransactionContext';
  30. import type {ReplayError, ReplayRecord} from 'sentry/views/replays/types';
  31. type Props = RouteComponentProps<
  32. {replaySlug: string},
  33. {},
  34. any,
  35. TimeOffsetLocationQueryParams
  36. >;
  37. function ReplayDetails({params: {replaySlug}}: Props) {
  38. const config = useLegacyStore(ConfigStore);
  39. const location = useLocation();
  40. const organization = useOrganization();
  41. useReplayPageview('replay.details-time-spent');
  42. useRouteAnalyticsEventNames('replay_details.viewed', 'Replay Details: Viewed');
  43. useRouteAnalyticsParams({
  44. organization,
  45. referrer: decodeScalar(location.query.referrer),
  46. user_email: config.user.email,
  47. tab: location.query.t_main,
  48. });
  49. const {slug: orgSlug} = organization;
  50. // TODO: replayId is known ahead of time and useReplayData is parsing it from the replaySlug
  51. // once we fix the route params and links we should fix this to accept replayId and stop returning it
  52. const {
  53. errors: replayErrors,
  54. fetchError,
  55. fetching,
  56. onRetry,
  57. projectSlug,
  58. replay,
  59. replayId,
  60. replayRecord,
  61. } = useReplayReader({
  62. replaySlug,
  63. orgSlug,
  64. });
  65. useLogReplayDataLoaded({fetchError, fetching, projectSlug, replay});
  66. const initialTimeOffsetMs = useInitialTimeOffsetMs({
  67. orgSlug,
  68. projectSlug,
  69. replayId,
  70. replayStartTimestampMs: replayRecord?.started_at.getTime(),
  71. });
  72. if (fetchError) {
  73. if (fetchError.statusText === 'Not Found') {
  74. return (
  75. <Page
  76. orgSlug={orgSlug}
  77. replayRecord={replayRecord}
  78. projectSlug={projectSlug}
  79. replayErrors={replayErrors}
  80. >
  81. <Layout.Page withPadding>
  82. <NotFound />
  83. </Layout.Page>
  84. </Page>
  85. );
  86. }
  87. const reasons = [
  88. t('The replay is still processing'),
  89. t('The replay has been deleted by a member in your organization'),
  90. t('There is an internal systems error'),
  91. ];
  92. return (
  93. <Page
  94. orgSlug={orgSlug}
  95. replayRecord={replayRecord}
  96. projectSlug={projectSlug}
  97. replayErrors={replayErrors}
  98. >
  99. <Layout.Page>
  100. <DetailedError
  101. onRetry={onRetry}
  102. hideSupportLinks
  103. heading={t('There was an error while fetching this Replay')}
  104. message={
  105. <Fragment>
  106. <p>{t('This could be due to these reasons:')}</p>
  107. <List symbol="bullet">
  108. {reasons.map((reason, i) => (
  109. <ListItem key={i}>{reason}</ListItem>
  110. ))}
  111. </List>
  112. </Fragment>
  113. }
  114. />
  115. </Layout.Page>
  116. </Page>
  117. );
  118. }
  119. if (!fetching && replay && replay.getRRWebFrames().length < 2) {
  120. return (
  121. <Page
  122. orgSlug={orgSlug}
  123. replayRecord={replayRecord}
  124. projectSlug={projectSlug}
  125. replayErrors={replayErrors}
  126. >
  127. <DetailedError
  128. hideSupportLinks
  129. heading={t('Error loading replay')}
  130. message={
  131. <Fragment>
  132. <p>
  133. {t(
  134. 'Expected two or more replay events. This Replay may not have captured any user actions.'
  135. )}
  136. </p>
  137. <p>
  138. {t(
  139. 'Or there may be an issue loading the actions from the server, click to try loading the Replay again.'
  140. )}
  141. </p>
  142. </Fragment>
  143. }
  144. />
  145. </Page>
  146. );
  147. }
  148. return (
  149. <ReplayContextProvider
  150. isFetching={fetching}
  151. replay={replay}
  152. initialTimeOffsetMs={initialTimeOffsetMs}
  153. >
  154. <ReplayTransactionContext replayRecord={replayRecord}>
  155. <DetailsInsideContext
  156. orgSlug={orgSlug}
  157. replayRecord={replayRecord}
  158. projectSlug={projectSlug}
  159. replayErrors={replayErrors}
  160. />
  161. </ReplayTransactionContext>
  162. </ReplayContextProvider>
  163. );
  164. }
  165. function DetailsInsideContext({
  166. orgSlug,
  167. replayRecord,
  168. projectSlug,
  169. replayErrors,
  170. }: {
  171. orgSlug: string;
  172. projectSlug: string | null;
  173. replayErrors: ReplayError[];
  174. replayRecord: ReplayRecord | undefined;
  175. }) {
  176. const {getLayout} = useReplayLayout();
  177. const {replay} = useReplayContext();
  178. return (
  179. <Page
  180. orgSlug={orgSlug}
  181. frames={replay?.getNavigationFrames()}
  182. replayRecord={replayRecord}
  183. projectSlug={projectSlug}
  184. replayErrors={replayErrors}
  185. >
  186. <ReplaysLayout layout={getLayout()} />
  187. </Page>
  188. );
  189. }
  190. export default ReplayDetails;