From c8f87b3fdbe6bada2c6d50f4b6200114b47c89be Mon Sep 17 00:00:00 2001 From: Nithin RG <2275985+nithinrgaddam@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:57:02 -0600 Subject: [PATCH 1/7] feat(issues): Attach videos to issue comments Add an attach button to the issue comment composer. The chosen video is uploaded to the issue's comment-attachments endpoint and a link to it is added to the comment text. Note bodies render links to those uploads as an inline video player, with the link kept below it. The button only shows for organizations with the issue-comment-attachments feature. Size and type limits are enforced by the backend and its error is shown in a toast. --- static/app/components/activity/note/body.tsx | 43 +++++- .../activity/note/commentAttachmentButton.tsx | 115 +++++++++++++++ .../note/mentionComposer/mentionComposer.tsx | 22 +++ .../activitySection/activityNoteInput.tsx | 3 + .../activitySection/index.spec.tsx | 132 ++++++++++++++++++ .../issueDetails/activitySection/index.tsx | 1 + 6 files changed, 314 insertions(+), 2 deletions(-) create mode 100644 static/app/components/activity/note/commentAttachmentButton.tsx diff --git a/static/app/components/activity/note/body.tsx b/static/app/components/activity/note/body.tsx index 0db775c65d94..a27a65ae1282 100644 --- a/static/app/components/activity/note/body.tsx +++ b/static/app/components/activity/note/body.tsx @@ -1,15 +1,54 @@ -import {Markdown} from '@sentry/scraps/markdown'; +import {Fragment} from 'react'; +import styled from '@emotion/styled'; + +import {Markdown, type MarkdownProps} from '@sentry/scraps/markdown'; + +import {COMMENT_ATTACHMENT_URL_PATTERN} from './commentAttachmentButton'; type Props = { text: string; }; +type MarkdownComponents = NonNullable; +type NoteLinkProps = React.ComponentProps>; + +/** + * Links to videos uploaded to the comment play inline, with the link kept + * below the player so the file can still be opened directly. + */ +function NoteLink({Default, href, title, children}: NoteLinkProps) { + const link = ( + + {children} + + ); + if (!COMMENT_ATTACHMENT_URL_PATTERN.test(href)) { + return link; + } + return ( + + + ); +} + +const components: MarkdownComponents = {Link: NoteLink}; + function NoteBody({text}: Props) { return (
- +
); } +const Video = styled('video')` + display: block; + max-width: 100%; + max-height: 480px; + border-radius: ${p => p.theme.radius.md}; + margin-bottom: ${p => p.theme.space.xs}; +`; + export {NoteBody}; diff --git a/static/app/components/activity/note/commentAttachmentButton.tsx b/static/app/components/activity/note/commentAttachmentButton.tsx new file mode 100644 index 000000000000..06f924130bff --- /dev/null +++ b/static/app/components/activity/note/commentAttachmentButton.tsx @@ -0,0 +1,115 @@ +import {Fragment, useRef, useState} from 'react'; +import {IconUpload} from '@sentry/icons/upload'; + +import {Button} from '@sentry/scraps/button'; +import {toast} from '@sentry/scraps/toast'; + +import {t} from 'sentry/locale'; +import {RequestError} from 'sentry/utils/requestError/requestError'; +import {useApi} from 'sentry/utils/useApi'; +import {useOrganization} from 'sentry/utils/useOrganization'; + +const ACCEPTED_VIDEO_TYPES = 'video/mp4,video/quicktime,video/webm,video/ogg'; + +/** + * Matches the URL the comment attachment endpoint returns, so notes can render + * those links as an inline video player. + */ +export const COMMENT_ATTACHMENT_URL_PATTERN = + /^\/api\/0\/organizations\/[^/]+\/issues\/[^/]+\/comment-attachments\/\d+\/$/; + +export interface CommentAttachment { + contentType: string; + id: string; + name: string; + size: number; + url: string; +} + +/** + * Markdown link to an uploaded attachment, with the characters that would end + * the link text escaped. + */ +export function commentAttachmentMarkdown(attachment: CommentAttachment): string { + const label = attachment.name.replace(/([\\[\]])/g, '\\$1'); + return `[${label}](${attachment.url})`; +} + +function uploadErrorMessage(error: unknown): string { + const detail = + error instanceof RequestError && typeof error.responseJSON?.detail === 'string' + ? error.responseJSON.detail + : null; + if (detail) { + return detail; + } + if (error instanceof RequestError && error.status === 413) { + return t('This video is too large to upload.'); + } + return t('Unable to upload video'); +} + +interface CommentAttachmentButtonProps { + issueId: string; + onUploaded: (attachment: CommentAttachment) => void; +} + +export function CommentAttachmentButton({ + issueId, + onUploaded, +}: CommentAttachmentButtonProps) { + const organization = useOrganization(); + const api = useApi(); + const fileInputRef = useRef(null); + const [isUploading, setIsUploading] = useState(false); + + if (!organization.features.includes('issue-comment-attachments')) { + return null; + } + + async function handleSelectFile(event: React.ChangeEvent) { + const file = event.target.files?.[0]; + // Reset so selecting the same file again still fires a change. + event.target.value = ''; + if (!file) { + return; + } + + const data = new FormData(); + data.set('file', file); + setIsUploading(true); + try { + const attachment: CommentAttachment = await api.requestPromise( + `/organizations/${organization.slug}/issues/${issueId}/comment-attachments/`, + {method: 'POST', data} + ); + setIsUploading(false); + onUploaded(attachment); + } catch (error) { + setIsUploading(false); + toast.error(uploadErrorMessage(error)); + } + } + + return ( + + +