details.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 {
  11. Provider as ReplayContextProvider,
  12. useReplayContext,
  13. } from 'sentry/components/replays/replayContext';
  14. import {IconDelete} from 'sentry/icons';
  15. import {t} from 'sentry/locale';
  16. import ConfigStore from 'sentry/stores/configStore';
  17. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  18. import {space} from 'sentry/styles/space';
  19. import {decodeScalar} from 'sentry/utils/queryString';
  20. import useInitialTimeOffsetMs, {
  21. TimeOffsetLocationQueryParams,
  22. } from 'sentry/utils/replays/hooks/useInitialTimeOffsetMs';
  23. import useLogReplayDataLoaded from 'sentry/utils/replays/hooks/useLogReplayDataLoaded';
  24. import useReplayLayout from 'sentry/utils/replays/hooks/useReplayLayout';
  25. import useReplayPageview from 'sentry/utils/replays/hooks/useReplayPageview';
  26. import useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';
  27. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  28. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  29. import {useLocation} from 'sentry/utils/useLocation';
  30. import useOrganization from 'sentry/utils/useOrganization';
  31. import ReplaysLayout from 'sentry/views/replays/detail/layout';
  32. import Page from 'sentry/views/replays/detail/page';
  33. import ReplayTransactionContext from 'sentry/views/replays/detail/trace/replayTransactionContext';
  34. import type {ReplayError, ReplayRecord} from 'sentry/views/replays/types';
  35. type Props = RouteComponentProps<
  36. {replaySlug: string},
  37. {},
  38. any,
  39. TimeOffsetLocationQueryParams
  40. >;
  41. function ReplayDetails({params: {replaySlug}}: Props) {
  42. const config = useLegacyStore(ConfigStore);
  43. const location = useLocation();
  44. const organization = useOrganization();
  45. useReplayPageview('replay.details-time-spent');
  46. useRouteAnalyticsEventNames('replay_details.viewed', 'Replay Details: Viewed');
  47. useRouteAnalyticsParams({
  48. organization,
  49. referrer: decodeScalar(location.query.referrer),
  50. user_email: config.user.email,
  51. tab: location.query.t_main,
  52. });
  53. const {slug: orgSlug} = organization;
  54. // TODO: replayId is known ahead of time and useReplayData is parsing it from the replaySlug
  55. // once we fix the route params and links we should fix this to accept replayId and stop returning it
  56. const {
  57. errors: replayErrors,
  58. fetchError,
  59. fetching,
  60. onRetry,
  61. projectSlug,
  62. replay,
  63. replayId,
  64. replayRecord,
  65. } = useReplayReader({
  66. replaySlug,
  67. orgSlug,
  68. });
  69. useLogReplayDataLoaded({fetchError, fetching, projectSlug, replay});
  70. const initialTimeOffsetMs = useInitialTimeOffsetMs({
  71. orgSlug,
  72. projectSlug,
  73. replayId,
  74. replayStartTimestampMs: replayRecord?.started_at?.getTime(),
  75. });
  76. if (replayRecord?.is_archived) {
  77. return (
  78. <Page
  79. orgSlug={orgSlug}
  80. replayRecord={replayRecord}
  81. projectSlug={projectSlug}
  82. replayErrors={replayErrors}
  83. >
  84. <Layout.Page>
  85. <Alert system type="warning" data-test-id="replay-deleted">
  86. <Flex gap={space(0.5)}>
  87. <IconDelete color="gray500" size="sm" />
  88. {t('This replay has been deleted.')}
  89. </Flex>
  90. </Alert>
  91. </Layout.Page>
  92. </Page>
  93. );
  94. }
  95. if (fetchError) {
  96. if (fetchError.statusText === 'Not Found') {
  97. return (
  98. <Page
  99. orgSlug={orgSlug}
  100. replayRecord={replayRecord}
  101. projectSlug={projectSlug}
  102. replayErrors={replayErrors}
  103. >
  104. <Layout.Page withPadding>
  105. <NotFound />
  106. </Layout.Page>
  107. </Page>
  108. );
  109. }
  110. const reasons = [
  111. t('The replay is still processing'),
  112. t('The replay has been deleted by a member in your organization'),
  113. t('There is an internal systems error'),
  114. ];
  115. return (
  116. <Page
  117. orgSlug={orgSlug}
  118. replayRecord={replayRecord}
  119. projectSlug={projectSlug}
  120. replayErrors={replayErrors}
  121. >
  122. <Layout.Page>
  123. <DetailedError
  124. onRetry={onRetry}
  125. hideSupportLinks
  126. heading={t('There was an error while fetching this Replay')}
  127. message={
  128. <Fragment>
  129. <p>{t('This could be due to these reasons:')}</p>
  130. <List symbol="bullet">
  131. {reasons.map((reason, i) => (
  132. <ListItem key={i}>{reason}</ListItem>
  133. ))}
  134. </List>
  135. </Fragment>
  136. }
  137. />
  138. </Layout.Page>
  139. </Page>
  140. );
  141. }
  142. if (!fetching && replay && replay.getRRWebFrames().length < 2) {
  143. return (
  144. <Page
  145. orgSlug={orgSlug}
  146. replayRecord={replayRecord}
  147. projectSlug={projectSlug}
  148. replayErrors={replayErrors}
  149. >
  150. <DetailedError
  151. hideSupportLinks
  152. heading={t('Error loading replay')}
  153. message={
  154. <Fragment>
  155. <p>
  156. {t(
  157. 'Expected two or more replay events. This Replay may not have captured any user actions.'
  158. )}
  159. </p>
  160. <p>
  161. {t(
  162. 'Or there may be an issue loading the actions from the server, click to try loading the Replay again.'
  163. )}
  164. </p>
  165. </Fragment>
  166. }
  167. />
  168. </Page>
  169. );
  170. }
  171. return (
  172. <ReplayContextProvider
  173. isFetching={fetching}
  174. replay={replay}
  175. initialTimeOffsetMs={initialTimeOffsetMs}
  176. >
  177. <ReplayTransactionContext replayRecord={replayRecord}>
  178. <DetailsInsideContext
  179. orgSlug={orgSlug}
  180. replayRecord={replayRecord}
  181. projectSlug={projectSlug}
  182. replayErrors={replayErrors}
  183. />
  184. </ReplayTransactionContext>
  185. </ReplayContextProvider>
  186. );
  187. }
  188. function DetailsInsideContext({
  189. orgSlug,
  190. replayRecord,
  191. projectSlug,
  192. replayErrors,
  193. }: {
  194. orgSlug: string;
  195. projectSlug: string | null;
  196. replayErrors: ReplayError[];
  197. replayRecord: ReplayRecord | undefined;
  198. }) {
  199. const {getLayout} = useReplayLayout();
  200. const {replay} = useReplayContext();
  201. return (
  202. <Page
  203. orgSlug={orgSlug}
  204. frames={replay?.getNavigationFrames()}
  205. replayRecord={replayRecord}
  206. projectSlug={projectSlug}
  207. replayErrors={replayErrors}
  208. >
  209. <ReplaysLayout layout={getLayout()} />
  210. </Page>
  211. );
  212. }
  213. export default ReplayDetails;