details.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 useInitialTimeOffsetMs, {
  14. TimeOffsetLocationQueryParams,
  15. } from 'sentry/utils/replays/hooks/useInitialTimeOffsetMs';
  16. import useReplayData from 'sentry/utils/replays/hooks/useReplayData';
  17. import useReplayLayout from 'sentry/utils/replays/hooks/useReplayLayout';
  18. import useReplayPageview from 'sentry/utils/replays/hooks/useReplayPageview';
  19. import useOrganization from 'sentry/utils/useOrganization';
  20. import ReplaysLayout from 'sentry/views/replays/detail/layout';
  21. import Page from 'sentry/views/replays/detail/page';
  22. import type {ReplayRecord} from 'sentry/views/replays/types';
  23. type Props = RouteComponentProps<
  24. {replaySlug: string},
  25. {},
  26. any,
  27. TimeOffsetLocationQueryParams
  28. >;
  29. function ReplayDetails({params: {replaySlug}}: Props) {
  30. useReplayPageview('replay.details-time-spent');
  31. const organization = useOrganization();
  32. const {slug: orgSlug} = organization;
  33. const {fetching, onRetry, replay, replayRecord, fetchError} = useReplayData({
  34. replaySlug,
  35. orgSlug,
  36. });
  37. const initialTimeOffsetMs = useInitialTimeOffsetMs({
  38. orgSlug,
  39. replaySlug,
  40. replayStartTimestampMs: replayRecord?.started_at.getTime(),
  41. });
  42. if (fetchError) {
  43. if (fetchError.statusText === 'Not Found') {
  44. return (
  45. <Page orgSlug={orgSlug} replayRecord={replayRecord}>
  46. <Layout.Page withPadding>
  47. <NotFound />
  48. </Layout.Page>
  49. </Page>
  50. );
  51. }
  52. const reasons = [
  53. t('The replay is still processing'),
  54. t('The replay has been deleted by a member in your organization'),
  55. t('There is an internal systems error'),
  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 these 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. initialTimeOffsetMs={initialTimeOffsetMs}
  104. >
  105. <LoadedDetails orgSlug={orgSlug} replayRecord={replayRecord} />
  106. </ReplayContextProvider>
  107. );
  108. }
  109. function LoadedDetails({
  110. orgSlug,
  111. replayRecord,
  112. }: {
  113. orgSlug: string;
  114. replayRecord: ReplayRecord | undefined;
  115. }) {
  116. const {getLayout} = useReplayLayout();
  117. const {replay} = useReplayContext();
  118. return (
  119. <Page orgSlug={orgSlug} crumbs={replay?.getRawCrumbs()} replayRecord={replayRecord}>
  120. <ReplaysLayout layout={getLayout()} />
  121. </Page>
  122. );
  123. }
  124. export default ReplayDetails;