details.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import {Fragment, useEffect} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import Alert from 'sentry/components/alert';
  4. import {Flex} from 'sentry/components/container/flex';
  5. import DetailedError from 'sentry/components/errors/detailedError';
  6. import NotFound from 'sentry/components/errors/notFound';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import List from 'sentry/components/list';
  9. import ListItem from 'sentry/components/list/listItem';
  10. import {LocalStorageReplayPreferences} from 'sentry/components/replays/preferences/replayPreferences';
  11. import {Provider as ReplayContextProvider} from 'sentry/components/replays/replayContext';
  12. import {IconDelete} from 'sentry/icons';
  13. import {t} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import {decodeScalar} from 'sentry/utils/queryString';
  16. import type {TimeOffsetLocationQueryParams} from 'sentry/utils/replays/hooks/useInitialTimeOffsetMs';
  17. import useInitialTimeOffsetMs from 'sentry/utils/replays/hooks/useInitialTimeOffsetMs';
  18. import useLogReplayDataLoaded from 'sentry/utils/replays/hooks/useLogReplayDataLoaded';
  19. import useMarkReplayViewed from 'sentry/utils/replays/hooks/useMarkReplayViewed';
  20. import useReplayPageview from 'sentry/utils/replays/hooks/useReplayPageview';
  21. import useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';
  22. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  23. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  24. import {useLocation} from 'sentry/utils/useLocation';
  25. import useOrganization from 'sentry/utils/useOrganization';
  26. import {useUser} from 'sentry/utils/useUser';
  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. type Props = RouteComponentProps<
  31. {replaySlug: string},
  32. {},
  33. any,
  34. TimeOffsetLocationQueryParams
  35. >;
  36. function ReplayDetails({params: {replaySlug}}: Props) {
  37. const user = useUser();
  38. const location = useLocation();
  39. const organization = useOrganization();
  40. const {slug: orgSlug} = organization;
  41. // TODO: replayId is known ahead of time and useReplayData is parsing it from the replaySlug
  42. // once we fix the route params and links we should fix this to accept replayId and stop returning it
  43. const {
  44. errors,
  45. fetchError,
  46. fetching,
  47. onRetry,
  48. projectSlug,
  49. replay,
  50. replayId,
  51. replayRecord,
  52. } = useReplayReader({
  53. replaySlug,
  54. orgSlug,
  55. });
  56. const replayErrors = errors.filter(e => e.title !== 'User Feedback');
  57. const isVideoReplay = replay?.isVideoReplay();
  58. useReplayPageview('replay.details-time-spent');
  59. useRouteAnalyticsEventNames('replay_details.viewed', 'Replay Details: Viewed');
  60. useRouteAnalyticsParams({
  61. organization,
  62. referrer: decodeScalar(location.query.referrer),
  63. user_email: user.email,
  64. tab: location.query.t_main,
  65. mobile: isVideoReplay,
  66. });
  67. useLogReplayDataLoaded({fetchError, fetching, projectSlug, replay});
  68. const {mutate: markAsViewed} = useMarkReplayViewed();
  69. useEffect(() => {
  70. if (
  71. !fetchError &&
  72. replayRecord &&
  73. !replayRecord.has_viewed &&
  74. projectSlug &&
  75. !fetching &&
  76. replayId
  77. ) {
  78. markAsViewed({projectSlug, replayId});
  79. }
  80. }, [
  81. fetchError,
  82. fetching,
  83. markAsViewed,
  84. organization,
  85. projectSlug,
  86. replayId,
  87. replayRecord,
  88. ]);
  89. const initialTimeOffsetMs = useInitialTimeOffsetMs({
  90. orgSlug,
  91. projectSlug,
  92. replayId,
  93. replayStartTimestampMs: replayRecord?.started_at?.getTime(),
  94. });
  95. const rrwebFrames = replay?.getRRWebFrames();
  96. // The replay data takes a while to load in, which causes `isVideoReplay`
  97. // to return an early `false`, which used to cause UI jumping.
  98. // One way to check whether it's finished loading is by checking the length
  99. // of the rrweb frames, which should always be > 1 for any given replay.
  100. // By default, the 1 frame is replay.end
  101. const isLoading = !rrwebFrames || (rrwebFrames && rrwebFrames.length <= 1);
  102. if (replayRecord?.is_archived) {
  103. return (
  104. <Page
  105. orgSlug={orgSlug}
  106. replayRecord={replayRecord}
  107. projectSlug={projectSlug}
  108. replayErrors={replayErrors}
  109. >
  110. <Layout.Page>
  111. <Alert system type="warning" data-test-id="replay-deleted">
  112. <Flex gap={space(0.5)}>
  113. <IconDelete color="gray500" size="sm" />
  114. {t('This replay has been deleted.')}
  115. </Flex>
  116. </Alert>
  117. </Layout.Page>
  118. </Page>
  119. );
  120. }
  121. if (fetchError) {
  122. if (fetchError.status === 404) {
  123. return (
  124. <Page
  125. orgSlug={orgSlug}
  126. replayRecord={replayRecord}
  127. projectSlug={projectSlug}
  128. replayErrors={replayErrors}
  129. >
  130. <Layout.Page withPadding>
  131. <NotFound />
  132. </Layout.Page>
  133. </Page>
  134. );
  135. }
  136. const reasons = [
  137. t('The replay is still processing'),
  138. t('The replay has been deleted by a member in your organization'),
  139. t('There is an internal systems error'),
  140. ];
  141. return (
  142. <Page
  143. orgSlug={orgSlug}
  144. replayRecord={replayRecord}
  145. projectSlug={projectSlug}
  146. replayErrors={replayErrors}
  147. >
  148. <Layout.Page>
  149. <DetailedError
  150. onRetry={onRetry}
  151. hideSupportLinks
  152. heading={t('There was an error while fetching this Replay')}
  153. message={
  154. <Fragment>
  155. <p>{t('This could be due to these reasons:')}</p>
  156. <List symbol="bullet">
  157. {reasons.map((reason, i) => (
  158. <ListItem key={i}>{reason}</ListItem>
  159. ))}
  160. </List>
  161. </Fragment>
  162. }
  163. />
  164. </Layout.Page>
  165. </Page>
  166. );
  167. }
  168. return (
  169. <ReplayContextProvider
  170. analyticsContext="replay_details"
  171. initialTimeOffsetMs={initialTimeOffsetMs}
  172. isFetching={fetching}
  173. prefsStrategy={LocalStorageReplayPreferences}
  174. replay={replay}
  175. >
  176. <ReplayTransactionContext replayRecord={replayRecord}>
  177. <Page
  178. isVideoReplay={isVideoReplay}
  179. orgSlug={orgSlug}
  180. replayRecord={replayRecord}
  181. projectSlug={projectSlug}
  182. replayErrors={replayErrors}
  183. isLoading={isLoading}
  184. >
  185. <ReplaysLayout
  186. isVideoReplay={isVideoReplay}
  187. replayRecord={replayRecord}
  188. isLoading={isLoading}
  189. />
  190. </Page>
  191. </ReplayTransactionContext>
  192. </ReplayContextProvider>
  193. );
  194. }
  195. export default ReplayDetails;