details.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import {Fragment} 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 useReplayPageview from 'sentry/utils/replays/hooks/useReplayPageview';
  20. import useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';
  21. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  22. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  23. import {useLocation} from 'sentry/utils/useLocation';
  24. import useOrganization from 'sentry/utils/useOrganization';
  25. import {useUser} from 'sentry/utils/useUser';
  26. import ReplaysLayout from 'sentry/views/replays/detail/layout';
  27. import Page from 'sentry/views/replays/detail/page';
  28. import ReplayTransactionContext from 'sentry/views/replays/detail/trace/replayTransactionContext';
  29. type Props = RouteComponentProps<
  30. {replaySlug: string},
  31. {},
  32. any,
  33. TimeOffsetLocationQueryParams
  34. >;
  35. function ReplayDetails({params: {replaySlug}}: Props) {
  36. const user = useUser();
  37. const location = useLocation();
  38. const organization = useOrganization();
  39. useReplayPageview('replay.details-time-spent');
  40. useRouteAnalyticsEventNames('replay_details.viewed', 'Replay Details: Viewed');
  41. useRouteAnalyticsParams({
  42. organization,
  43. referrer: decodeScalar(location.query.referrer),
  44. user_email: user.email,
  45. tab: location.query.t_main,
  46. });
  47. const {slug: orgSlug} = organization;
  48. // TODO: replayId is known ahead of time and useReplayData is parsing it from the replaySlug
  49. // once we fix the route params and links we should fix this to accept replayId and stop returning it
  50. const {
  51. errors,
  52. fetchError,
  53. fetching,
  54. onRetry,
  55. projectSlug,
  56. replay,
  57. replayId,
  58. replayRecord,
  59. } = useReplayReader({
  60. replaySlug,
  61. orgSlug,
  62. });
  63. const replayErrors = errors.filter(e => e.title !== 'User Feedback');
  64. useLogReplayDataLoaded({fetchError, fetching, projectSlug, replay});
  65. const initialTimeOffsetMs = useInitialTimeOffsetMs({
  66. orgSlug,
  67. projectSlug,
  68. replayId,
  69. replayStartTimestampMs: replayRecord?.started_at?.getTime(),
  70. });
  71. if (replayRecord?.is_archived) {
  72. return (
  73. <Page
  74. orgSlug={orgSlug}
  75. replayRecord={replayRecord}
  76. projectSlug={projectSlug}
  77. replayErrors={replayErrors}
  78. >
  79. <Layout.Page>
  80. <Alert system type="warning" data-test-id="replay-deleted">
  81. <Flex gap={space(0.5)}>
  82. <IconDelete color="gray500" size="sm" />
  83. {t('This replay has been deleted.')}
  84. </Flex>
  85. </Alert>
  86. </Layout.Page>
  87. </Page>
  88. );
  89. }
  90. if (fetchError) {
  91. if (fetchError.status === 404) {
  92. return (
  93. <Page
  94. orgSlug={orgSlug}
  95. replayRecord={replayRecord}
  96. projectSlug={projectSlug}
  97. replayErrors={replayErrors}
  98. >
  99. <Layout.Page withPadding>
  100. <NotFound />
  101. </Layout.Page>
  102. </Page>
  103. );
  104. }
  105. const reasons = [
  106. t('The replay is still processing'),
  107. t('The replay has been deleted by a member in your organization'),
  108. t('There is an internal systems error'),
  109. ];
  110. return (
  111. <Page
  112. orgSlug={orgSlug}
  113. replayRecord={replayRecord}
  114. projectSlug={projectSlug}
  115. replayErrors={replayErrors}
  116. >
  117. <Layout.Page>
  118. <DetailedError
  119. onRetry={onRetry}
  120. hideSupportLinks
  121. heading={t('There was an error while fetching this Replay')}
  122. message={
  123. <Fragment>
  124. <p>{t('This could be due to these reasons:')}</p>
  125. <List symbol="bullet">
  126. {reasons.map((reason, i) => (
  127. <ListItem key={i}>{reason}</ListItem>
  128. ))}
  129. </List>
  130. </Fragment>
  131. }
  132. />
  133. </Layout.Page>
  134. </Page>
  135. );
  136. }
  137. const isVideoReplay = Boolean(
  138. organization.features.includes('session-replay-mobile-player') &&
  139. replay?.isVideoReplay()
  140. );
  141. return (
  142. <ReplayContextProvider
  143. analyticsContext="replay_details"
  144. initialTimeOffsetMs={initialTimeOffsetMs}
  145. isFetching={fetching}
  146. prefsStrategy={LocalStorageReplayPreferences}
  147. replay={replay}
  148. >
  149. <ReplayTransactionContext replayRecord={replayRecord}>
  150. <Page
  151. isVideoReplay={isVideoReplay}
  152. orgSlug={orgSlug}
  153. replayRecord={replayRecord}
  154. projectSlug={projectSlug}
  155. replayErrors={replayErrors}
  156. >
  157. <ReplaysLayout isVideoReplay={isVideoReplay} />
  158. </Page>
  159. </ReplayTransactionContext>
  160. </ReplayContextProvider>
  161. );
  162. }
  163. export default ReplayDetails;