details.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import {Fragment, useEffect} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import Alert from 'sentry/components/alert';
  4. import DetailedError from 'sentry/components/errors/detailedError';
  5. import NotFound from 'sentry/components/errors/notFound';
  6. import * as Layout from 'sentry/components/layouts/thirds';
  7. import List from 'sentry/components/list';
  8. import ListItem from 'sentry/components/list/listItem';
  9. import {Flex} from 'sentry/components/profiling/flex';
  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. useReplayPageview('replay.details-time-spent');
  41. useRouteAnalyticsEventNames('replay_details.viewed', 'Replay Details: Viewed');
  42. useRouteAnalyticsParams({
  43. organization,
  44. referrer: decodeScalar(location.query.referrer),
  45. user_email: user.email,
  46. tab: location.query.t_main,
  47. });
  48. const {slug: orgSlug} = organization;
  49. // TODO: replayId is known ahead of time and useReplayData is parsing it from the replaySlug
  50. // once we fix the route params and links we should fix this to accept replayId and stop returning it
  51. const {
  52. errors,
  53. fetchError,
  54. fetching,
  55. onRetry,
  56. projectSlug,
  57. replay,
  58. replayId,
  59. replayRecord,
  60. } = useReplayReader({
  61. replaySlug,
  62. orgSlug,
  63. });
  64. const replayErrors = errors.filter(e => e.title !== 'User Feedback');
  65. useLogReplayDataLoaded({fetchError, fetching, projectSlug, replay});
  66. const {mutate: markAsViewed} = useMarkReplayViewed();
  67. useEffect(() => {
  68. if (!organization.features.includes('session-replay-viewed-by-ui')) {
  69. return;
  70. }
  71. if (
  72. !fetchError &&
  73. replayRecord &&
  74. !replayRecord.has_viewed &&
  75. projectSlug &&
  76. !fetching
  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. if (replayRecord?.is_archived) {
  96. return (
  97. <Page
  98. orgSlug={orgSlug}
  99. replayRecord={replayRecord}
  100. projectSlug={projectSlug}
  101. replayErrors={replayErrors}
  102. >
  103. <Layout.Page>
  104. <Alert system type="warning" data-test-id="replay-deleted">
  105. <Flex gap={space(0.5)}>
  106. <IconDelete color="gray500" size="sm" />
  107. {t('This replay has been deleted.')}
  108. </Flex>
  109. </Alert>
  110. </Layout.Page>
  111. </Page>
  112. );
  113. }
  114. if (fetchError) {
  115. if (fetchError.status === 404) {
  116. return (
  117. <Page
  118. orgSlug={orgSlug}
  119. replayRecord={replayRecord}
  120. projectSlug={projectSlug}
  121. replayErrors={replayErrors}
  122. >
  123. <Layout.Page withPadding>
  124. <NotFound />
  125. </Layout.Page>
  126. </Page>
  127. );
  128. }
  129. const reasons = [
  130. t('The replay is still processing'),
  131. t('The replay has been deleted by a member in your organization'),
  132. t('There is an internal systems error'),
  133. ];
  134. return (
  135. <Page
  136. orgSlug={orgSlug}
  137. replayRecord={replayRecord}
  138. projectSlug={projectSlug}
  139. replayErrors={replayErrors}
  140. >
  141. <Layout.Page>
  142. <DetailedError
  143. onRetry={onRetry}
  144. hideSupportLinks
  145. heading={t('There was an error while fetching this Replay')}
  146. message={
  147. <Fragment>
  148. <p>{t('This could be due to these reasons:')}</p>
  149. <List symbol="bullet">
  150. {reasons.map((reason, i) => (
  151. <ListItem key={i}>{reason}</ListItem>
  152. ))}
  153. </List>
  154. </Fragment>
  155. }
  156. />
  157. </Layout.Page>
  158. </Page>
  159. );
  160. }
  161. const isVideoReplay = Boolean(
  162. organization.features.includes('session-replay-mobile-player') &&
  163. replay?.isVideoReplay()
  164. );
  165. return (
  166. <ReplayContextProvider
  167. analyticsContext="replay_details"
  168. initialTimeOffsetMs={initialTimeOffsetMs}
  169. isFetching={fetching}
  170. prefsStrategy={LocalStorageReplayPreferences}
  171. replay={replay}
  172. >
  173. <ReplayTransactionContext replayRecord={replayRecord}>
  174. <Page
  175. isVideoReplay={isVideoReplay}
  176. orgSlug={orgSlug}
  177. replayRecord={replayRecord}
  178. projectSlug={projectSlug}
  179. replayErrors={replayErrors}
  180. >
  181. <ReplaysLayout isVideoReplay={isVideoReplay} />
  182. </Page>
  183. </ReplayTransactionContext>
  184. </ReplayContextProvider>
  185. );
  186. }
  187. export default ReplayDetails;