rrwebIntegration.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import AsyncComponent from 'sentry/components/asyncComponent';
  2. import LazyLoad from 'sentry/components/lazyLoad';
  3. import {IssueAttachment, Organization, Project} from 'sentry/types';
  4. import {Event} from 'sentry/types/event';
  5. type Props = {
  6. event: Event;
  7. orgId: Organization['id'];
  8. projectId: Project['id'];
  9. renderer?: Function;
  10. } & AsyncComponent['props'];
  11. type State = {
  12. attachmentList: Array<IssueAttachment> | null;
  13. } & AsyncComponent['state'];
  14. class RRWebIntegration extends AsyncComponent<Props, State> {
  15. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  16. const {orgId, projectId, event} = this.props;
  17. return [
  18. [
  19. 'attachmentList',
  20. `/projects/${orgId}/${projectId}/events/${event.id}/attachments/`,
  21. // This was changed from `rrweb.json`, so that we can instead
  22. // support incremental rrweb events as attachments. This is to avoid
  23. // having clients uploading a single, large sized replay.
  24. //
  25. // Note: This will include all attachments that contain `rrweb`
  26. // anywhere its name. We need to maintain compatibility with existing
  27. // rrweb plugin users (single replay), but also support incremental
  28. // replays as well. I can't think of a reason why someone would have
  29. // a non-rrweb replay containing the string `rrweb`, but people have
  30. // surprised me before.
  31. {query: {query: 'rrweb'}},
  32. ],
  33. ];
  34. }
  35. renderLoading() {
  36. // hide loading indicator
  37. return null;
  38. }
  39. renderBody() {
  40. const {attachmentList} = this.state;
  41. const renderer = this.props.renderer || (children => children);
  42. if (!attachmentList?.length) {
  43. return null;
  44. }
  45. const {orgId, projectId, event} = this.props;
  46. function createAttachmentUrl(attachment: IssueAttachment) {
  47. return `/api/0/projects/${orgId}/${projectId}/events/${event.id}/attachments/${attachment.id}/?download`;
  48. }
  49. return renderer(
  50. <LazyLoad
  51. component={() => import('./rrwebReplayer')}
  52. urls={attachmentList.map(createAttachmentUrl)}
  53. />
  54. );
  55. }
  56. }
  57. export default RRWebIntegration;