attachmentUrl.tsx 905 B

12345678910111213141516171819202122232425262728293031323334
  1. import {memo} from 'react';
  2. import {Role} from 'sentry/components/acl/role';
  3. import type {IssueAttachment} from 'sentry/types/group';
  4. import type {Organization} from 'sentry/types/organization';
  5. import withOrganization from 'sentry/utils/withOrganization';
  6. type Props = {
  7. attachment: IssueAttachment;
  8. children: (downloadUrl: string | null) => React.ReactElement | null;
  9. eventId: string;
  10. organization: Organization;
  11. projectSlug: string;
  12. };
  13. function AttachmentUrl({
  14. attachment,
  15. organization,
  16. eventId,
  17. projectSlug,
  18. children,
  19. }: Props) {
  20. function getDownloadUrl() {
  21. return `/api/0/projects/${organization.slug}/${projectSlug}/events/${eventId}/attachments/${attachment.id}/`;
  22. }
  23. return (
  24. <Role role={organization.attachmentsRole}>
  25. {({hasRole}) => children(hasRole ? getDownloadUrl() : null)}
  26. </Role>
  27. );
  28. }
  29. export default withOrganization(memo(AttachmentUrl));