@@ -19,7 +19,11 @@ import { PULL_REQUESTS_PANEL_REF } from "~/rightPanelStore";
1919
2020import ChatMarkdown from "../ChatMarkdown" ;
2121import { MediaVideoPlayer } from "../media/MediaVideoPlayer" ;
22- import { remarkPullRequestAutolinks , splitPullRequestBody } from "./pullRequestMarkdown.logic" ;
22+ import {
23+ remarkPullRequestAutolinks ,
24+ splitPullRequestBody ,
25+ type PullRequestBodySegment ,
26+ } from "./pullRequestMarkdown.logic" ;
2327
2428export const PullRequestMarkdownContext = createContext < {
2529 autolinks : ( ( text : string ) => ReadonlyArray < ReferenceAutolink > ) | null ;
@@ -54,6 +58,106 @@ function PullRequestHostVideo({
5458 ) ;
5559}
5660
61+ function PullRequestBodySegmentView ( {
62+ segment,
63+ cwd,
64+ environmentId,
65+ threadRef,
66+ extraRemarkPlugins,
67+ } : {
68+ segment : PullRequestBodySegment ;
69+ cwd : string ;
70+ environmentId : EnvironmentId ;
71+ threadRef : ScopedThreadRef | undefined ;
72+ extraRemarkPlugins : NonNullable < ReactMarkdownOptions [ "remarkPlugins" ] > ;
73+ } ) {
74+ if ( segment . kind === "table" ) {
75+ return (
76+ < div className = "space-y-3" >
77+ { segment . rows . map ( ( cells , rowIndex ) => (
78+ < div
79+ // oxlint-disable-next-line react/no-array-index-key -- rows have no identity besides position
80+ key = { rowIndex }
81+ className = "grid gap-3"
82+ style = { { gridTemplateColumns : `repeat(${ cells . length } , minmax(0, 1fr))` } }
83+ >
84+ { cells . map ( ( cell , cellIndex ) => (
85+ < div
86+ // oxlint-disable-next-line react/no-array-index-key -- cells have no identity besides position
87+ key = { cellIndex }
88+ className = { cn ( "min-w-0 space-y-3" , cell . header && "font-medium" ) }
89+ >
90+ { cell . segments . map ( ( cellSegment ) => (
91+ < PullRequestBodySegmentView
92+ key = { cellSegment . id }
93+ segment = { cellSegment }
94+ cwd = { cwd }
95+ environmentId = { environmentId }
96+ threadRef = { threadRef }
97+ extraRemarkPlugins = { extraRemarkPlugins }
98+ />
99+ ) ) }
100+ </ div >
101+ ) ) }
102+ </ div >
103+ ) ) }
104+ </ div >
105+ ) ;
106+ }
107+ if ( segment . kind === "markdown" || segment . media === "image" ) {
108+ return (
109+ < ChatMarkdown
110+ text = { segment . kind === "markdown" ? segment . text : `` }
111+ cwd = { cwd }
112+ threadRef = { threadRef }
113+ pullRequestPanelRef = { threadRef ?? PULL_REQUESTS_PANEL_REF }
114+ environmentId = { environmentId }
115+ extraRemarkPlugins = { extraRemarkPlugins }
116+ sourceControlMedia
117+ />
118+ ) ;
119+ }
120+ const hostMedia = sourceControlClients . mediaUrl ( segment . url ) ;
121+ if ( segment . media === "video" && hostMedia !== null ) {
122+ return (
123+ < PullRequestHostVideo
124+ key = { `${ segment . id } :${ segment . url } ` }
125+ environmentId = { environmentId }
126+ cwd = { cwd }
127+ url = { segment . url }
128+ fetchUrl = { hostMedia . fetchUrl }
129+ />
130+ ) ;
131+ }
132+ if ( segment . media === "video" ) {
133+ return (
134+ < MediaVideoPlayer
135+ key = { `${ segment . id } :${ segment . url } ` }
136+ src = { segment . url }
137+ originalUrl = { segment . url }
138+ label = "Pull request video"
139+ className = "w-full"
140+ videoClassName = "rounded-lg border border-border/60"
141+ />
142+ ) ;
143+ }
144+ return (
145+ // Desktop converts blocked _blank navigation to openExternal.
146+ < a
147+ href = { segment . url }
148+ rel = "noreferrer noopener"
149+ target = "_blank"
150+ className = "flex items-center gap-2 rounded-lg border border-border/60 bg-muted/30 px-3 py-2 text-sm hover:bg-muted/60"
151+ >
152+ < PaperclipIcon aria-hidden className = "size-3.5 shrink-0 text-muted-foreground" />
153+ < span className = "min-w-0 flex-1 truncate" >
154+ Open attachment on { hostMedia ?. definition . label ?? new URL ( segment . url ) . hostname }
155+ </ span >
156+ < ExternalLinkIcon aria-hidden className = "size-3 shrink-0 text-muted-foreground" />
157+ </ a >
158+ ) ;
159+ }
160+
57161export function PullRequestMarkdown ( {
58162 text,
59163 cwd,
@@ -82,62 +186,16 @@ export function PullRequestMarkdown({
82186 ) }
83187 data-image-gallery
84188 >
85- { segments . map ( ( segment ) => {
86- if ( segment . kind === "markdown" || segment . media === "image" ) {
87- return (
88- < ChatMarkdown
89- key = { segment . id }
90- text = { segment . kind === "markdown" ? segment . text : `` }
91- cwd = { cwd }
92- threadRef = { resolvedThreadRef }
93- pullRequestPanelRef = { resolvedThreadRef ?? PULL_REQUESTS_PANEL_REF }
94- environmentId = { environmentId }
95- extraRemarkPlugins = { extraRemarkPlugins }
96- sourceControlMedia
97- />
98- ) ;
99- }
100- const hostMedia = sourceControlClients . mediaUrl ( segment . url ) ;
101- if ( segment . media === "video" && hostMedia !== null ) {
102- return (
103- < PullRequestHostVideo
104- key = { `${ segment . id } :${ segment . url } ` }
105- environmentId = { environmentId }
106- cwd = { cwd }
107- url = { segment . url }
108- fetchUrl = { hostMedia . fetchUrl }
109- />
110- ) ;
111- }
112- if ( segment . media === "video" ) {
113- return (
114- < MediaVideoPlayer
115- key = { `${ segment . id } :${ segment . url } ` }
116- src = { segment . url }
117- originalUrl = { segment . url }
118- label = "Pull request video"
119- className = "w-full"
120- videoClassName = "rounded-lg border border-border/60"
121- />
122- ) ;
123- }
124- return (
125- // Desktop converts blocked _blank navigation to openExternal.
126- < a
127- key = { segment . id }
128- href = { segment . url }
129- rel = "noreferrer noopener"
130- target = "_blank"
131- className = "flex items-center gap-2 rounded-lg border border-border/60 bg-muted/30 px-3 py-2 text-sm hover:bg-muted/60"
132- >
133- < PaperclipIcon aria-hidden className = "size-3.5 shrink-0 text-muted-foreground" />
134- < span className = "min-w-0 flex-1 truncate" >
135- Open attachment on { hostMedia ?. definition . label ?? new URL ( segment . url ) . hostname }
136- </ span >
137- < ExternalLinkIcon aria-hidden className = "size-3 shrink-0 text-muted-foreground" />
138- </ a >
139- ) ;
140- } ) }
189+ { segments . map ( ( segment ) => (
190+ < PullRequestBodySegmentView
191+ key = { segment . id }
192+ segment = { segment }
193+ cwd = { cwd }
194+ environmentId = { environmentId }
195+ threadRef = { resolvedThreadRef }
196+ extraRemarkPlugins = { extraRemarkPlugins }
197+ />
198+ ) ) }
141199 </ div >
142200 ) ;
143201}
0 commit comments