details.tsx 5.2 KB

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