attachmentUrl.tsx 828 B

123456789101112131415161718192021222324252627
  1. import {memo} from 'react';
  2. import {Role} from 'sentry/components/acl/role';
  3. import {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. projectId: string;
  11. };
  12. function AttachmentUrl({attachment, organization, eventId, projectId, children}: Props) {
  13. function getDownloadUrl() {
  14. return `/api/0/projects/${organization.slug}/${projectId}/events/${eventId}/attachments/${attachment.id}/`;
  15. }
  16. return (
  17. <Role role={organization.attachmentsRole}>
  18. {({hasRole}) => children(hasRole ? getDownloadUrl() : null)}
  19. </Role>
  20. );
  21. }
  22. export default withOrganization(memo(AttachmentUrl));