fetchReplayClicks.tsx 934 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import * as Sentry from '@sentry/react';
  2. import type {Client} from 'sentry/api';
  3. type Props = {
  4. api: Client;
  5. orgSlug: string;
  6. projectSlug: string;
  7. query: string;
  8. replayId: string;
  9. };
  10. type NodeMarker = {
  11. node_id: number;
  12. timestamp: string;
  13. };
  14. async function fetchReplayClicks({api, orgSlug, projectSlug, query, replayId}: Props) {
  15. const path = `/projects/${orgSlug}/${projectSlug}/replays/${replayId}/clicks/`;
  16. try {
  17. const [{data}, _textStatus, resp] = await api.requestPromise(path, {
  18. includeAllArgs: true,
  19. query: {
  20. query,
  21. },
  22. });
  23. const pageLinks = resp?.getResponseHeader('Link') ?? '';
  24. return {
  25. fetchError: undefined,
  26. pageLinks,
  27. clicks: data as NodeMarker[],
  28. };
  29. } catch (error) {
  30. Sentry.captureException(error);
  31. return {
  32. fetchError: error,
  33. pageLinks: null,
  34. clicks: [],
  35. };
  36. }
  37. }
  38. export default fetchReplayClicks;