eventAttachmentActions.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Button} from 'sentry/components/button';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import Confirm from 'sentry/components/confirm';
  6. import {IconDelete, IconDownload, IconShow} from 'sentry/icons';
  7. import {t} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. type Props = {
  10. attachmentId: string;
  11. onDelete: (attachmentId: string) => void;
  12. url: string | null;
  13. hasPreview?: boolean;
  14. onPreview?: (attachmentId: string) => void;
  15. previewIsOpen?: boolean;
  16. withPreviewButton?: boolean;
  17. };
  18. class EventAttachmentActions extends Component<Props> {
  19. handlePreview() {
  20. const {onPreview, attachmentId} = this.props;
  21. if (onPreview) {
  22. onPreview(attachmentId);
  23. }
  24. }
  25. render() {
  26. const {url, withPreviewButton, hasPreview, previewIsOpen, onDelete, attachmentId} =
  27. this.props;
  28. return (
  29. <ButtonBar gap={1}>
  30. <Confirm
  31. confirmText={t('Delete')}
  32. message={t('Are you sure you wish to delete this file?')}
  33. priority="danger"
  34. onConfirm={() => onDelete(attachmentId)}
  35. disabled={!url}
  36. >
  37. <Button
  38. size="xs"
  39. icon={<IconDelete size="xs" />}
  40. aria-label={t('Delete')}
  41. disabled={!url}
  42. title={!url ? t('Insufficient permissions to delete attachments') : undefined}
  43. />
  44. </Confirm>
  45. <DownloadButton
  46. size="xs"
  47. icon={<IconDownload size="xs" />}
  48. href={url ? `${url}?download=1` : ''}
  49. disabled={!url}
  50. title={!url ? t('Insufficient permissions to download attachments') : undefined}
  51. aria-label={t('Download')}
  52. />
  53. {withPreviewButton && (
  54. <DownloadButton
  55. size="xs"
  56. disabled={!url || !hasPreview}
  57. priority={previewIsOpen ? 'primary' : 'default'}
  58. icon={<IconShow size="xs" />}
  59. onClick={() => this.handlePreview()}
  60. title={
  61. !url
  62. ? t('Insufficient permissions to preview attachments')
  63. : !hasPreview
  64. ? t('This attachment cannot be previewed')
  65. : undefined
  66. }
  67. >
  68. {t('Preview')}
  69. </DownloadButton>
  70. )}
  71. </ButtonBar>
  72. );
  73. }
  74. }
  75. const DownloadButton = styled(Button)`
  76. margin-right: ${space(0.5)};
  77. `;
  78. export default EventAttachmentActions;