details.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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: replayErrors,
  52. fetchError,
  53. fetching,
  54. onRetry,
  55. projectSlug,
  56. replay,
  57. replayId,
  58. replayRecord,
  59. } = useReplayReader({
  60. replaySlug,
  61. orgSlug,
  62. });
  63. useLogReplayDataLoaded({fetchError, fetching, projectSlug, replay});
  64. const initialTimeOffsetMs = useInitialTimeOffsetMs({
  65. orgSlug,
  66. projectSlug,
  67. replayId,
  68. replayStartTimestampMs: replayRecord?.started_at?.getTime(),
  69. });
  70. if (replayRecord?.is_archived) {
  71. return (
  72. <Page
  73. orgSlug={orgSlug}
  74. replayRecord={replayRecord}
  75. projectSlug={projectSlug}
  76. replayErrors={replayErrors}
  77. >
  78. <Layout.Page>
  79. <Alert system type="warning" data-test-id="replay-deleted">
  80. <Flex gap={space(0.5)}>
  81. <IconDelete color="gray500" size="sm" />
  82. {t('This replay has been deleted.')}
  83. </Flex>
  84. </Alert>
  85. </Layout.Page>
  86. </Page>
  87. );
  88. }
  89. if (fetchError) {
  90. if (fetchError.status === 404) {
  91. return (
  92. <Page
  93. orgSlug={orgSlug}
  94. replayRecord={replayRecord}
  95. projectSlug={projectSlug}
  96. replayErrors={replayErrors}
  97. >
  98. <Layout.Page withPadding>
  99. <NotFound />
  100. </Layout.Page>
  101. </Page>
  102. );
  103. }
  104. const reasons = [
  105. t('The replay is still processing'),
  106. t('The replay has been deleted by a member in your organization'),
  107. t('There is an internal systems error'),
  108. ];
  109. return (
  110. <Page
  111. orgSlug={orgSlug}
  112. replayRecord={replayRecord}
  113. projectSlug={projectSlug}
  114. replayErrors={replayErrors}
  115. >
  116. <Layout.Page>
  117. <DetailedError
  118. onRetry={onRetry}
  119. hideSupportLinks
  120. heading={t('There was an error while fetching this Replay')}
  121. message={
  122. <Fragment>
  123. <p>{t('This could be due to these reasons:')}</p>
  124. <List symbol="bullet">
  125. {reasons.map((reason, i) => (
  126. <ListItem key={i}>{reason}</ListItem>
  127. ))}
  128. </List>
  129. </Fragment>
  130. }
  131. />
  132. </Layout.Page>
  133. </Page>
  134. );
  135. }
  136. return (
  137. <ReplayContextProvider
  138. analyticsContext="replay_details"
  139. initialTimeOffsetMs={initialTimeOffsetMs}
  140. isFetching={fetching}
  141. prefsStrategy={LocalStorageReplayPreferences}
  142. replay={replay}
  143. >
  144. <ReplayTransactionContext replayRecord={replayRecord}>
  145. <Page
  146. orgSlug={orgSlug}
  147. replayRecord={replayRecord}
  148. projectSlug={projectSlug}
  149. replayErrors={replayErrors}
  150. >
  151. <ReplaysLayout />
  152. </Page>
  153. </ReplayTransactionContext>
  154. </ReplayContextProvider>
  155. );
  156. }
  157. export default ReplayDetails;