useReplayReader.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {useMemo} from 'react';
  2. import useReplayData from 'sentry/utils/replays/hooks/useReplayData';
  3. import ReplayReader from 'sentry/utils/replays/replayReader';
  4. type Props = {
  5. orgSlug: string;
  6. replaySlug: string;
  7. };
  8. export default function useReplayReader({orgSlug, replaySlug}: Props) {
  9. const replayId = parseReplayId(replaySlug);
  10. const {attachments, errors, replayRecord, ...replayData} = useReplayData({
  11. orgSlug,
  12. replayId,
  13. });
  14. const replay = useMemo(
  15. () => ReplayReader.factory({attachments, errors, replayRecord}),
  16. [attachments, errors, replayRecord]
  17. );
  18. return {
  19. ...replayData,
  20. attachments,
  21. errors,
  22. replay,
  23. replayId,
  24. replayRecord,
  25. };
  26. }
  27. // see https://github.com/getsentry/sentry/pull/47859
  28. // replays can apply to many projects when incorporating backend errors
  29. // this makes having project in the `replaySlug` obsolete
  30. // we must keep this url schema for now for backward compat but we should remove it at some point
  31. // TODO: remove support for projectSlug in replay url?
  32. function parseReplayId(replaySlug: string) {
  33. const maybeProjectSlugAndReplayId = replaySlug.split(':');
  34. if (maybeProjectSlugAndReplayId.length === 2) {
  35. return maybeProjectSlugAndReplayId[1];
  36. }
  37. // if there is no projectSlug then we assume we just have the replayId
  38. // all other cases would be a malformed url
  39. return maybeProjectSlugAndReplayId[0];
  40. }