index.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {useCallback} from 'react';
  2. import ErrorBoundary from 'sentry/components/errorBoundary';
  3. import LazyLoad from 'sentry/components/lazyLoad';
  4. import {Organization} from 'sentry/types';
  5. import {Event} from 'sentry/types/event';
  6. import {useHasOrganizationSentAnyReplayEvents} from 'sentry/utils/replays/hooks/useReplayOnboarding';
  7. import {projectCanLinkToReplay} from 'sentry/utils/replays/projectSupportsReplay';
  8. import useProjectFromSlug from 'sentry/utils/useProjectFromSlug';
  9. type Props = {
  10. event: Event;
  11. organization: Organization;
  12. projectSlug: string;
  13. replayId: undefined | string;
  14. };
  15. export default function EventReplay({replayId, organization, projectSlug, event}: Props) {
  16. const hasReplaysFeature = organization.features.includes('session-replay');
  17. const {hasOrgSentReplays, fetching} = useHasOrganizationSentAnyReplayEvents();
  18. const onboardingPanel = useCallback(() => import('./replayInlineOnboardingPanel'), []);
  19. const replayPreview = useCallback(() => import('./replayPreview'), []);
  20. const project = useProjectFromSlug({organization, projectSlug});
  21. const isReplayRelated = projectCanLinkToReplay(project);
  22. if (!hasReplaysFeature || fetching || !isReplayRelated) {
  23. return null;
  24. }
  25. if (!hasOrgSentReplays) {
  26. return (
  27. <ErrorBoundary mini>
  28. <LazyLoad component={onboardingPanel} />
  29. </ErrorBoundary>
  30. );
  31. }
  32. if (!replayId) {
  33. return null;
  34. }
  35. return (
  36. <ErrorBoundary mini>
  37. <LazyLoad
  38. component={replayPreview}
  39. replaySlug={`${projectSlug}:${replayId}`}
  40. orgSlug={organization.slug}
  41. event={event}
  42. />
  43. </ErrorBoundary>
  44. );
  45. }