details.tsx 6.1 KB

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