details.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 and is on its way'),
  55. t('There is an internal systems error or active issue'),
  56. ];
  57. return (
  58. <Page orgSlug={orgSlug} replayRecord={replayRecord}>
  59. <Layout.Page>
  60. <DetailedError
  61. onRetry={onRetry}
  62. hideSupportLinks
  63. heading={t('There was an error while fetching this Replay')}
  64. message={
  65. <Fragment>
  66. <p>{t('This could be due to a couple of reasons:')}</p>
  67. <List symbol="bullet">
  68. {reasons.map((reason, i) => (
  69. <ListItem key={i}>{reason}</ListItem>
  70. ))}
  71. </List>
  72. </Fragment>
  73. }
  74. />
  75. </Layout.Page>
  76. </Page>
  77. );
  78. }
  79. if (!fetching && replay && replay.getRRWebEvents().length < 2) {
  80. return (
  81. <Page orgSlug={orgSlug} replayRecord={replayRecord}>
  82. <DetailedError
  83. hideSupportLinks
  84. heading={t('Expected two or more replay events')}
  85. message={
  86. <Fragment>
  87. <p>{t('This Replay may not have captured any user actions.')}</p>
  88. <p>
  89. {t(
  90. 'Or there may be an issue loading the actions from the server, click to try loading the Replay again.'
  91. )}
  92. </p>
  93. </Fragment>
  94. }
  95. />
  96. </Page>
  97. );
  98. }
  99. return (
  100. <ReplayContextProvider
  101. isFetching={fetching}
  102. replay={replay}
  103. initialTimeOffset={getInitialTimeOffset({
  104. eventTimestamp,
  105. initialTimeOffset,
  106. startTimestampMs,
  107. })}
  108. >
  109. <LoadedDetails orgSlug={orgSlug} replayRecord={replayRecord} />
  110. </ReplayContextProvider>
  111. );
  112. }
  113. function LoadedDetails({
  114. orgSlug,
  115. replayRecord,
  116. }: {
  117. orgSlug: string;
  118. replayRecord: ReplayRecord | undefined;
  119. }) {
  120. const {getLayout} = useReplayLayout();
  121. const {replay} = useReplayContext();
  122. return (
  123. <Page orgSlug={orgSlug} crumbs={replay?.getRawCrumbs()} replayRecord={replayRecord}>
  124. <ReplaysLayout layout={getLayout()} />
  125. </Page>
  126. );
  127. }
  128. export default ReplayDetails;