Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {JsonViewer} from 'sentry/components/events/attachmentViewers/jsonViewer';
import {LogFileViewer} from 'sentry/components/events/attachmentViewers/logFileViewer';
import {RRWebJsonViewer} from 'sentry/components/events/attachmentViewers/rrwebJsonViewer';
import type {ViewerProps} from 'sentry/components/events/attachmentViewers/utils';
import {VideoViewer} from 'sentry/components/events/attachmentViewers/videoViewer';
import type {IssueAttachment} from 'sentry/types/group';

Expand Down Expand Up @@ -91,3 +92,44 @@
}
return attachment.size > MAX_TEXT_PREVIEW_SIZE;
};

type ScreenshotAttachmentViewerProps = ViewerProps & {
controls?: boolean;
onCanPlay?: React.ReactEventHandler<HTMLVideoElement>;
onError?: React.ReactEventHandler<HTMLImageElement>;
onLoad?: React.ReactEventHandler<HTMLImageElement>;
};

/**
* Renders the appropriate viewer for a screenshot attachment using static JSX
* branches. The component type is never derived during render so React Compiler
* static-component-definitions rules are satisfied.
*/
export function ScreenshotAttachmentViewer({
attachment,
onLoad,
onError,
controls,
onCanPlay,
...viewerProps
}: ScreenshotAttachmentViewerProps) {
if (webmMimeTypes.includes(attachment.mimetype)) {
return (
<VideoViewer
attachment={attachment}
controls={controls}
onCanPlay={onCanPlay}
{...viewerProps}
/>
);
}
return (
<ImageViewer
attachment={attachment}
onLoad={onLoad}
onError={onError}
{...viewerProps}
/>
);
}
};

Check failure on line 135 in static/app/components/events/attachmentViewers/previewAttachmentTypes.tsx

View workflow job for this annotation

GitHub Actions / typescript

Declaration or statement expected.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import {Flex, Grid} from '@sentry/scraps/layout';
import {useRole} from 'sentry/components/acl/useRole';
import {openConfirmModal} from 'sentry/components/confirm';
import {DropdownMenu} from 'sentry/components/dropdownMenu';
import {ImageViewer} from 'sentry/components/events/attachmentViewers/imageViewer';
import {
getImageAttachmentRenderer,
imageMimeTypes,
ScreenshotAttachmentViewer,
webmMimeTypes,
} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes';
import {LoadingIndicator} from 'sentry/components/loadingIndicator';
Expand Down Expand Up @@ -72,7 +71,6 @@ export function Screenshot({
onDelete(screenshotAttachmentId);
}

const AttachmentComponent = getImageAttachmentRenderer(screenshot) ?? ImageViewer;
const downloadUrl = `/api/0/projects/${organization.slug}/${projectSlug}/events/${eventId}/attachments/${screenshot.id}/`;

return (
Expand Down Expand Up @@ -108,7 +106,7 @@ export function Screenshot({
<AttachmentComponentWrapper
onClick={() => openVisualizationModal(screenshot, `${downloadUrl}?download=1`)}
>
<AttachmentComponent
<ScreenshotAttachmentViewer
orgSlug={organization.slug}
projectSlug={projectSlug}
eventId={eventId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {Stack, Grid} from '@sentry/scraps/layout';
import type {ModalRenderProps} from 'sentry/actionCreators/modal';
import {Confirm} from 'sentry/components/confirm';
import {DateTime} from 'sentry/components/dateTime';
import {ImageViewer} from 'sentry/components/events/attachmentViewers/imageViewer';
import {getImageAttachmentRenderer} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes';
import {ScreenshotAttachmentViewer} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes';
import {KeyValueData} from 'sentry/components/keyValueData';
import {t, tct} from 'sentry/locale';
import type {EventAttachment} from 'sentry/types/group';
Expand Down Expand Up @@ -97,9 +96,6 @@ export function ScreenshotModal({
};
}

const AttachmentComponent =
getImageAttachmentRenderer(currentEventAttachment) ?? ImageViewer;

return (
<Fragment>
<Header closeButton>
Expand All @@ -109,7 +105,7 @@ export function ScreenshotModal({
<Stack gap="lg">
{defined(paginationProps) && <ScreenshotPagination {...paginationProps} />}
<AttachmentComponentWrapper>
<AttachmentComponent
<ScreenshotAttachmentViewer
attachment={currentEventAttachment}
orgSlug={organization.slug}
projectSlug={projectSlug}
Expand Down
Loading