groupEventAttachmentsTableRow.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {DateTime} from 'sentry/components/dateTime';
  4. import EventAttachmentActions from 'sentry/components/events/eventAttachmentActions';
  5. import FileSize from 'sentry/components/fileSize';
  6. import Link from 'sentry/components/links/link';
  7. import {Tooltip} from 'sentry/components/tooltip';
  8. import {t} from 'sentry/locale';
  9. import type {IssueAttachment} from 'sentry/types/group';
  10. import {getShortEventId} from 'sentry/utils/events';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import {InlineEventAttachment} from 'sentry/views/issueDetails/groupEventAttachments/inlineEventAttachment';
  13. const friendlyAttachmentType = {
  14. 'event.minidump': t('Minidump'),
  15. 'event.applecrashreport': t('Apple Crash Report'),
  16. 'event.attachment': t('Other'),
  17. };
  18. type Props = {
  19. attachment: IssueAttachment;
  20. groupId: string;
  21. onDelete: (attachment: IssueAttachment) => void;
  22. projectSlug: string;
  23. };
  24. function GroupEventAttachmentsTableRow({
  25. attachment,
  26. projectSlug,
  27. onDelete,
  28. groupId,
  29. }: Props) {
  30. const organization = useOrganization();
  31. const [previewIsOpen, setPreviewIsOpen] = useState(false);
  32. const handlePreviewClick = () => {
  33. setPreviewIsOpen(!previewIsOpen);
  34. };
  35. const sharedClassName = previewIsOpen ? 'preview-open' : undefined;
  36. return (
  37. <Fragment>
  38. <FlexCenter className={sharedClassName}>
  39. <div>
  40. <AttachmentName>{attachment.name}</AttachmentName>
  41. <div>
  42. <DateTime date={attachment.dateCreated} /> &middot;{' '}
  43. <Link
  44. to={`/organizations/${organization.slug}/issues/${groupId}/events/${attachment.event_id}/`}
  45. >
  46. <Tooltip skipWrapper title={t('View Event')}>
  47. {getShortEventId(attachment.event_id)}
  48. </Tooltip>
  49. </Link>
  50. </div>
  51. </div>
  52. </FlexCenter>
  53. <FlexCenter className={sharedClassName}>
  54. {friendlyAttachmentType[attachment.type] ?? t('Other')}
  55. </FlexCenter>
  56. <FlexCenter className={sharedClassName}>
  57. <FileSize bytes={attachment.size} />
  58. </FlexCenter>
  59. <FlexCenter className={sharedClassName}>
  60. <EventAttachmentActions
  61. withPreviewButton
  62. attachment={attachment}
  63. onDelete={() => onDelete(attachment)}
  64. onPreviewClick={handlePreviewClick}
  65. previewIsOpen={previewIsOpen}
  66. projectSlug={projectSlug}
  67. />
  68. </FlexCenter>
  69. {previewIsOpen && (
  70. <InlineAttachment className="preview">
  71. <InlineEventAttachment
  72. attachment={attachment}
  73. projectSlug={projectSlug}
  74. eventId={attachment.event_id}
  75. />
  76. </InlineAttachment>
  77. )}
  78. </Fragment>
  79. );
  80. }
  81. const AttachmentName = styled('div')`
  82. font-weight: bold;
  83. `;
  84. const FlexCenter = styled('div')`
  85. display: flex;
  86. align-items: center;
  87. white-space: nowrap;
  88. `;
  89. const InlineAttachment = styled('div')`
  90. grid-column: 1/-1;
  91. `;
  92. export default GroupEventAttachmentsTableRow;