details.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 (
  69. !fetchError &&
  70. replayRecord &&
  71. !replayRecord.has_viewed &&
  72. projectSlug &&
  73. !fetching
  74. ) {
  75. markAsViewed({projectSlug, replayId});
  76. }
  77. }, [
  78. fetchError,
  79. fetching,
  80. markAsViewed,
  81. organization,
  82. projectSlug,
  83. replayId,
  84. replayRecord,
  85. ]);
  86. const initialTimeOffsetMs = useInitialTimeOffsetMs({
  87. orgSlug,
  88. projectSlug,
  89. replayId,
  90. replayStartTimestampMs: replayRecord?.started_at?.getTime(),
  91. });
  92. if (replayRecord?.is_archived) {
  93. return (
  94. <Page
  95. orgSlug={orgSlug}
  96. replayRecord={replayRecord}
  97. projectSlug={projectSlug}
  98. replayErrors={replayErrors}
  99. >
  100. <Layout.Page>
  101. <Alert system type="warning" data-test-id="replay-deleted">
  102. <Flex gap={space(0.5)}>
  103. <IconDelete color="gray500" size="sm" />
  104. {t('This replay has been deleted.')}
  105. </Flex>
  106. </Alert>
  107. </Layout.Page>
  108. </Page>
  109. );
  110. }
  111. if (fetchError) {
  112. if (fetchError.status === 404) {
  113. return (
  114. <Page
  115. orgSlug={orgSlug}
  116. replayRecord={replayRecord}
  117. projectSlug={projectSlug}
  118. replayErrors={replayErrors}
  119. >
  120. <Layout.Page withPadding>
  121. <NotFound />
  122. </Layout.Page>
  123. </Page>
  124. );
  125. }
  126. const reasons = [
  127. t('The replay is still processing'),
  128. t('The replay has been deleted by a member in your organization'),
  129. t('There is an internal systems error'),
  130. ];
  131. return (
  132. <Page
  133. orgSlug={orgSlug}
  134. replayRecord={replayRecord}
  135. projectSlug={projectSlug}
  136. replayErrors={replayErrors}
  137. >
  138. <Layout.Page>
  139. <DetailedError
  140. onRetry={onRetry}
  141. hideSupportLinks
  142. heading={t('There was an error while fetching this Replay')}
  143. message={
  144. <Fragment>
  145. <p>{t('This could be due to these reasons:')}</p>
  146. <List symbol="bullet">
  147. {reasons.map((reason, i) => (
  148. <ListItem key={i}>{reason}</ListItem>
  149. ))}
  150. </List>
  151. </Fragment>
  152. }
  153. />
  154. </Layout.Page>
  155. </Page>
  156. );
  157. }
  158. const isVideoReplay = Boolean(
  159. organization.features.includes('session-replay-mobile-player') &&
  160. replay?.isVideoReplay()
  161. );
  162. return (
  163. <ReplayContextProvider
  164. analyticsContext="replay_details"
  165. initialTimeOffsetMs={initialTimeOffsetMs}
  166. isFetching={fetching}
  167. prefsStrategy={LocalStorageReplayPreferences}
  168. replay={replay}
  169. >
  170. <ReplayTransactionContext replayRecord={replayRecord}>
  171. <Page
  172. isVideoReplay={isVideoReplay}
  173. orgSlug={orgSlug}
  174. replayRecord={replayRecord}
  175. projectSlug={projectSlug}
  176. replayErrors={replayErrors}
  177. >
  178. <ReplaysLayout isVideoReplay={isVideoReplay} />
  179. </Page>
  180. </ReplayTransactionContext>
  181. </ReplayContextProvider>
  182. );
  183. }
  184. export default ReplayDetails;