attachmentUrl.tsx 852 B

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