details.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import DetailedError from 'sentry/components/errors/detailedError';
  4. import NotFound from 'sentry/components/errors/notFound';
  5. import * as Layout from 'sentry/components/layouts/thirds';
  6. import List from 'sentry/components/list';
  7. import ListItem from 'sentry/components/list/listItem';
  8. import {
  9. Provider as ReplayContextProvider,
  10. useReplayContext,
  11. } from 'sentry/components/replays/replayContext';
  12. import {t} from 'sentry/locale';
  13. import useReplayData from 'sentry/utils/replays/hooks/useReplayData';
  14. import useReplayLayout from 'sentry/utils/replays/hooks/useReplayLayout';
  15. import useReplayPageview from 'sentry/utils/replays/hooks/useReplayPageview';
  16. import useOrganization from 'sentry/utils/useOrganization';
  17. import ReplaysLayout from 'sentry/views/replays/detail/layout';
  18. import Page from 'sentry/views/replays/detail/page';
  19. import type {ReplayRecord} from 'sentry/views/replays/types';
  20. import {getInitialTimeOffset} from 'sentry/views/replays/utils';
  21. type Props = RouteComponentProps<
  22. {replaySlug: string},
  23. {},
  24. any,
  25. {event_t: string; t: number}
  26. >;
  27. function ReplayDetails({
  28. location: {
  29. query: {
  30. event_t: eventTimestamp, // Timestamp of the event or activity that was selected
  31. t: initialTimeOffset, // Time, in seconds, where the video should start
  32. },
  33. },
  34. params: {replaySlug},
  35. }: Props) {
  36. useReplayPageview('replay.details-time-spent');
  37. const {slug: orgSlug} = useOrganization();
  38. const {fetching, onRetry, replay, replayRecord, fetchError} = useReplayData({
  39. replaySlug,
  40. orgSlug,
  41. });
  42. const startTimestampMs = replayRecord?.started_at.getTime() ?? 0;
  43. if (fetchError) {
  44. if (fetchError.statusText === 'Not Found') {
  45. return (
  46. <Page orgSlug={orgSlug} replayRecord={replayRecord}>
  47. <Layout.Page withPadding>
  48. <NotFound />
  49. </Layout.Page>
  50. </Page>
  51. );
  52. }
  53. const reasons = [
  54. t('The replay is still processing'),
  55. t('The replay has been deleted by a member in your organization'),
  56. t('There is an internal systems error'),
  57. ];
  58. return (
  59. <Page orgSlug={orgSlug} replayRecord={replayRecord}>
  60. <Layout.Page>
  61. <DetailedError
  62. onRetry={onRetry}
  63. hideSupportLinks
  64. heading={t('There was an error while fetching this Replay')}
  65. message={
  66. <Fragment>
  67. <p>{t('This could be due to these reasons:')}</p>
  68. <List symbol="bullet">
  69. {reasons.map((reason, i) => (
  70. <ListItem key={i}>{reason}</ListItem>
  71. ))}
  72. </List>
  73. </Fragment>
  74. }
  75. />
  76. </Layout.Page>
  77. </Page>
  78. );
  79. }
  80. if (!fetching && replay && replay.getRRWebEvents().length < 2) {
  81. return (
  82. <Page orgSlug={orgSlug} replayRecord={replayRecord}>
  83. <DetailedError
  84. hideSupportLinks
  85. heading={t('Expected two or more replay events')}
  86. message={
  87. <Fragment>
  88. <p>{t('This Replay may not have captured any user actions.')}</p>
  89. <p>
  90. {t(
  91. 'Or there may be an issue loading the actions from the server, click to try loading the Replay again.'
  92. )}
  93. </p>
  94. </Fragment>
  95. }
  96. />
  97. </Page>
  98. );
  99. }
  100. return (
  101. <ReplayContextProvider
  102. isFetching={fetching}
  103. replay={replay}
  104. initialTimeOffset={getInitialTimeOffset({
  105. eventTimestamp,
  106. initialTimeOffset,
  107. startTimestampMs,
  108. })}
  109. >
  110. <LoadedDetails orgSlug={orgSlug} replayRecord={replayRecord} />
  111. </ReplayContextProvider>
  112. );
  113. }
  114. function LoadedDetails({
  115. orgSlug,
  116. replayRecord,
  117. }: {
  118. orgSlug: string;
  119. replayRecord: ReplayRecord | undefined;
  120. }) {
  121. const {getLayout} = useReplayLayout();
  122. const {replay} = useReplayContext();
  123. return (
  124. <Page orgSlug={orgSlug} crumbs={replay?.getRawCrumbs()} replayRecord={replayRecord}>
  125. <ReplaysLayout layout={getLayout()} />
  126. </Page>
  127. );
  128. }
  129. export default ReplayDetails;