details.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 ConfigStore from 'sentry/stores/configStore';
  14. import {useLegacyStore} from 'sentry/stores/useLegacyStore';
  15. import {space} from 'sentry/styles/space';
  16. import {decodeScalar} from 'sentry/utils/queryString';
  17. import useInitialTimeOffsetMs, {
  18. TimeOffsetLocationQueryParams,
  19. } from 'sentry/utils/replays/hooks/useInitialTimeOffsetMs';
  20. import useLogReplayDataLoaded from 'sentry/utils/replays/hooks/useLogReplayDataLoaded';
  21. import useReplayPageview from 'sentry/utils/replays/hooks/useReplayPageview';
  22. import useReplayReader from 'sentry/utils/replays/hooks/useReplayReader';
  23. import useRouteAnalyticsEventNames from 'sentry/utils/routeAnalytics/useRouteAnalyticsEventNames';
  24. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  25. import {useLocation} from 'sentry/utils/useLocation';
  26. import useOrganization from 'sentry/utils/useOrganization';
  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 config = useLegacyStore(ConfigStore);
  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: config.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: replayErrors,
  53. fetchError,
  54. fetching,
  55. onRetry,
  56. projectSlug,
  57. replay,
  58. replayId,
  59. replayRecord,
  60. } = useReplayReader({
  61. replaySlug,
  62. orgSlug,
  63. });
  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.statusText === 'Not Found') {
  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. return (
  138. <ReplayContextProvider
  139. isFetching={fetching}
  140. replay={replay}
  141. initialTimeOffsetMs={initialTimeOffsetMs}
  142. >
  143. <ReplayTransactionContext replayRecord={replayRecord}>
  144. <Page
  145. orgSlug={orgSlug}
  146. replayRecord={replayRecord}
  147. projectSlug={projectSlug}
  148. replayErrors={replayErrors}
  149. >
  150. <ReplaysLayout />
  151. </Page>
  152. </ReplayTransactionContext>
  153. </ReplayContextProvider>
  154. );
  155. }
  156. export default ReplayDetails;