eventAttachmentActions.tsx 2.2 KB

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