Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

IssueDetailPanel.tsx

975 lines33.9 KB

1import { RegistryContext, useAtomValue } from "@effect/atom-react";
2import { issueEventSentence, issueWriteAccess } from "@t3tools/client-runtime/issue-presentation";
3import { createIssueCommentPager } from "@t3tools/client-runtime/state/issues";
4import {
5 issueAssigneeHeld,
6 issueAssigneesAfterPicks,
7 issueLabelsAfterPicks,
8 issuePicksAfterFailedWrite,
9 issuePicksFor,
10 issueWriteAfterPicks,
11 noIssuePicks,
12} from "@t3tools/client-runtime/issue-selection";
13import { isSelected, toggleSelection } from "@t3tools/client-runtime/pull-request-selection";
14import { executeAtomQuery, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
15import type {
16 EnvironmentId,
17 IssueAssigneeCandidate,
18 IssueComment,
19 IssueDetail,
20 IssueEvent,
21 IssueEventReference,
22 IssueLabelCandidate,
23 IssueLinkedPullRequest,
24 IssueListEntry,
25 IssueReaction,
26 IssueRef,
27 PullRequestRef,
28 ScopedThreadRef,
29} from "@t3tools/contracts";
30import {
31 CheckIcon,
32 ChevronDownIcon,
33 ExternalLinkIcon,
34 TagIcon,
35 UserPlusIcon,
36 UsersIcon,
37} from "lucide-react";
38import { msg, T, useGT, useMessages, Var } from "gt-react";
39import { useContext, useState, type ReactNode } from "react";
40​
41import { RefreshIcon } from "~/components/ui/refresh-icon";
42import { m } from "~/i18n/messages";
43import { issueEnvironment, refreshIssueLists } from "~/state/issues";
44import { useProjects } from "~/state/entities";
45import { useEnvironmentQuery } from "~/state/query";
46import { useOpenLink } from "~/browser/useOpenLink";
47import { useAtomCommand } from "~/state/use-atom-command";
48import { formatRelativeTimeLabel } from "~/timestampFormat";
49​
50import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
51import { Button, InlineButton } from "../ui/button";
52import { Input } from "../ui/input";
53import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
54import { cn } from "~/lib/utils";
55import { PullRequestMetaRow, PullRequestSection } from "../pullRequest/PullRequestSummaryTab";
56import { toastManager } from "../ui/toast";
57import { PullRequestCandidatePicker } from "../pullRequest/PullRequestCandidatePicker";
58import { PullRequestCommentBody } from "../pullRequest/PullRequestCommentBody";
59import { PullRequestDetailTitleRow } from "../pullRequest/PullRequestDetailLayout";
60import { PullRequestEditButton } from "../pullRequest/PullRequestEditButton";
61import { PullRequestMarkdown } from "../pullRequest/PullRequestMarkdown";
62import { PullRequestMarkdownEditor } from "../pullRequest/PullRequestMarkdownEditor";
63import { readableFailure } from "../pullRequest/pullRequestDetail.logic";
64import { pullRequestLabelColor } from "../pullRequest/pullRequestList.logic";
65import {
66 PullRequestActorLabel,
67 PullRequestLabelChip,
68 PullRequestMetaLine,
69 PullRequestStateGlyph,
70} from "../pullRequest/pullRequestPresentation";
71import { IssueCommentComposer } from "./IssueCommentComposer";
72import { IssueDetailGhost } from "./IssueDetailGhost";
73import { IssueThreadLinks } from "./IssueThreadLinks";
74import { WorkflowRunsAbout } from "../workflows/WorkflowRunsAbout";
75import { ReactionBar } from "../pullRequest/PullRequestReactions";
76import { PullRequestsUnavailableState } from "../pullRequest/PullRequestsUnavailableState";
77import { issueTrackerPresentation, issueStatePresentation } from "./issuePresentation";
78​
79function IssueReactionBar({
80 reactions,
81 canReact,
82 subjectId,
83 environmentId,
84 reference,
85}: {
86 reactions: ReadonlyArray<IssueReaction>;
87 canReact: boolean;
88 subjectId?: string | undefined;
89 environmentId: EnvironmentId;
90 reference: IssueRef;
91}) {
92 const react = useAtomCommand(issueEnvironment.react, { reportFailure: false });
93 return (
94 <ReactionBar
95 reactions={reactions}
96 canReact={canReact}
97 onReact={async (content, reacted) => {
98 const result = await react({
99 environmentId,
100 input: {
101 ...reference,
102 ...(subjectId === undefined ? {} : { subjectId }),
103 content,
104 reacted,
105 },
106 });
107 return result._tag !== "Failure";
108 }}
109 />
110 );
112​
113function IssueLabelPicker({
114 environmentId,
115 reference,
116 detail,
117 allowed,
118 disabledReason,
119}: {
120 environmentId: EnvironmentId;
121 reference: IssueRef;
122 detail: IssueDetail;
123 allowed: boolean;
124 disabledReason: string;
125}) {
126 const gt = useGT();
127 const [open, setOpen] = useState(false);
128 const [query, setQuery] = useState("");
129 const [picks, setPicks] = useState(noIssuePicks<IssueLabelCandidate>);
130 const current = issuePicksFor(picks, detail, open);
131 const draft = current.draft;
132 const candidatesQuery = useEnvironmentQuery(
133 open ? issueEnvironment.candidates({ environmentId, input: reference }) : null,
134 );
135 const update = useAtomCommand(issueEnvironment.update, { reportFailure: false });
136 const applied = new Set(detail.labels.map((label) => label.name));
137 const needle = query.toLowerCase();
138 const candidates = (candidatesQuery.data?.labels ?? []).filter(
139 (label) =>
140 needle.length === 0 ||
141 label.name.toLowerCase().includes(needle) ||
142 (label.description ?? "").toLowerCase().includes(needle),
143 );
144 const onOpenChange = (nextOpen: boolean) => {
145 setOpen(nextOpen);
146 if (nextOpen) {
147 // Picks made against an older read are not this picker's any more.
148 setPicks(issuePicksFor(picks, detail, false));
149 return;
150 }
151 const labels = issueWriteAfterPicks(
152 issueLabelsAfterPicks(detail, draft),
153 detail.labels.map((label) => label.name),
154 current.written,
155 );
156 if (labels === null) return;
157 const sent = { ...current, written: labels };
158 setPicks(sent);
159 void update({ environmentId, input: { ...reference, labels } }).then((result) => {
160 if (result._tag !== "Failure") {
161 refreshIssueLists(environmentId);
162 return;
163 }
164 setPicks((latest) => issuePicksAfterFailedWrite(latest, sent));
165 toastManager.add({
166 type: "error",
167 title: m(msg("Could not change labels")),
168 description: readableFailure(
169 squashAtomCommandFailure(result),
170 m(msg("The tracker refused it.")),
171 ),
172 });
173 });
174 };
175 return (
176 <PullRequestCandidatePicker
177 icon={<TagIcon className="size-3.5" />}
178 label={gt("Change labels")}
179 allowed={allowed}
180 disabledReason={disabledReason}
181 open={open}
182 onOpenChange={onOpenChange}
183 query={query}
184 onQueryChange={setQuery}
185 searchLabel={gt("Search labels")}
186 isPending={candidatesQuery.isPending && candidatesQuery.data === null}
187 error={candidatesQuery.data === null ? candidatesQuery.error : null}
188 candidates={candidates}
189 emptyLabel={gt("This tracker has no labels.")}
190 noMatchLabel={gt("No label matches that.")}
191 errorLabel={gt("The labels could not be read.")}
192 truncated={candidatesQuery.data?.truncated === true}
193 truncatedLabel={gt("More labels exist than are listed here.")}
194 candidateKey={(candidate) => candidate.name}
195 onSelect={(candidate) =>
196 setPicks({
197 ...current,
198 draft: toggleSelection(draft, candidate.name, candidate, applied.has(candidate.name)),
199 })
200 }
201 >
202 {(candidate) => {
203 const dot = pullRequestLabelColor(candidate.color);
204 return (
205 <>
206 <span
207 aria-hidden
208 className="size-2 shrink-0 rounded-full bg-muted-foreground"
209 {...(dot ? { style: { backgroundColor: dot } } : {})}
210 />
211 <span className="min-w-0 flex-1 truncate">
212 {candidate.name}
213 {candidate.description ? (
214 <span className="text-muted-foreground"> · {candidate.description}</span>
215 ) : null}
216 </span>
217 {isSelected(draft, candidate.name, applied.has(candidate.name)) ? (
218 <CheckIcon
219 aria-label={gt("Applied", { $context: "label is applied to the issue" })}
220 className="size-3.5 shrink-0"
221 />
222 ) : null}
223 </>
224 );
225 }}
226 </PullRequestCandidatePicker>
227 );
229​
230function IssueAssigneePicker({
231 environmentId,
232 reference,
233 detail,
234 allowed,
235 disabledReason,
236}: {
237 environmentId: EnvironmentId;
238 reference: IssueRef;
239 detail: IssueDetail;
240 allowed: boolean;
241 disabledReason: string;
242}) {
243 const gt = useGT();
244 const [open, setOpen] = useState(false);
245 const [query, setQuery] = useState("");
246 const [picks, setPicks] = useState(noIssuePicks<IssueAssigneeCandidate>);
247 const current = issuePicksFor(picks, detail, open);
248 const draft = current.draft;
249 const candidatesQuery = useEnvironmentQuery(
250 open ? issueEnvironment.candidates({ environmentId, input: reference }) : null,
251 );
252 const update = useAtomCommand(issueEnvironment.update, { reportFailure: false });
253 const needle = query.toLowerCase();
254 const candidates = (candidatesQuery.data?.assignees ?? []).filter(
255 (candidate) =>
256 needle.length === 0 ||
257 candidate.login.toLowerCase().includes(needle) ||
258 (candidate.name ?? "").toLowerCase().includes(needle),
259 );
260 const onOpenChange = (nextOpen: boolean) => {
261 setOpen(nextOpen);
262 if (nextOpen) {
263 // Picks made against an older read are not this picker's any more.
264 setPicks(issuePicksFor(picks, detail, false));
265 return;
266 }
267 const assignees = issueWriteAfterPicks(
268 issueAssigneesAfterPicks(detail, draft),
269 detail.assignees.map((actor) => actor.login),
270 current.written,
271 );
272 if (assignees === null) return;
273 const sent = { ...current, written: assignees };
274 setPicks(sent);
275 void update({ environmentId, input: { ...reference, assignees } }).then((result) => {
276 if (result._tag !== "Failure") {
277 refreshIssueLists(environmentId);
278 return;
279 }
280 setPicks((latest) => issuePicksAfterFailedWrite(latest, sent));
281 toastManager.add({
282 type: "error",
283 title: m(msg("Could not change assignees")),
284 description: readableFailure(
285 squashAtomCommandFailure(result),
286 m(msg("The tracker refused it.")),
287 ),
288 });
289 });
290 };
291 return (
292 <PullRequestCandidatePicker
293 icon={<UserPlusIcon className="size-3.5" />}
294 label={gt("Change assignees")}
295 allowed={allowed}
296 disabledReason={disabledReason}
297 open={open}
298 onOpenChange={onOpenChange}
299 query={query}
300 onQueryChange={setQuery}
301 searchLabel={gt("Search people")}
302 isPending={candidatesQuery.isPending && candidatesQuery.data === null}
303 error={candidatesQuery.data === null ? candidatesQuery.error : null}
304 candidates={candidates}
305 emptyLabel={gt("Nobody can be assigned here.")}
306 noMatchLabel={gt("Nobody matches that.")}
307 errorLabel={gt("The people could not be read.")}
308 truncated={candidatesQuery.data?.truncated === true}
309 truncatedLabel={gt("More people exist than are listed here.")}
310 candidateKey={(candidate) => candidate.id}
311 onSelect={(candidate) =>
312 setPicks({
313 ...current,
314 draft: toggleSelection(
315 draft,
316 candidate.id,
317 candidate,
318 issueAssigneeHeld(detail, candidate),
319 ),
320 })
321 }
322 >
323 {(candidate) => (
324 <>
325 <PullRequestActorLabel actor={candidate} tooltip={false} className="min-w-0 flex-1" />
326 {isSelected(draft, candidate.id, issueAssigneeHeld(detail, candidate)) ? (
327 <CheckIcon
328 aria-label={gt("Assigned", { $context: "person is assigned to the issue" })}
329 className="size-3.5 shrink-0"
330 />
331 ) : null}
332 </>
333 )}
334 </PullRequestCandidatePicker>
335 );
337​
338type TimelineItem =
339 | { kind: "comment"; at: string; comment: IssueComment }
340 | { kind: "event"; at: string; event: IssueEvent };
341​
342function LinkedPullRequestRow({
343 link,
344 scope,
345 onSelect,
346}: {
347 link: IssueLinkedPullRequest;
348 /** The issue's own repository, left off a pull request that lives in it. */
349 scope: string;
350 onSelect: (() => void) | null;
351}) {
352 const body = (
353 <>
354 <PullRequestStateGlyph state={link.state} isDraft={link.isDraft} />
355 <span className="min-w-0 flex-1 truncate text-sm">{link.title}</span>
356 <PullRequestMetaLine className="shrink-0 text-xs text-muted-foreground">
357 {link.closesIssue ? (
358 <span>
359 <T>Closes this issue</T>
360 </span>
361 ) : null}
362 <span className="tabular-nums">
363 {link.repository.toLowerCase() === scope.toLowerCase() ? "" : link.repository}#
364 {link.number}
365 </span>
366 </PullRequestMetaLine>
367 </>
368 );
369 const className =
370 "flex w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-left hover:bg-accent";
371 return onSelect ? (
372 <button type="button" className={className} onClick={onSelect}>
373 {body}
374 </button>
375 ) : (
376 <a href={link.url} target="_blank" rel="noopener noreferrer" className={className}>
377 {body}
378 </a>
379 );
381​
382/** The sentence for an event, its source shown as a link where the tracker named one. */
383function IssueEventText({
384 event,
385 sentence,
386 onOpen,
387}: {
388 event: IssueEvent;
389 sentence: string;
390 /** Opens the source beside this issue, and says whether it did; if not, the link goes to the host. */
391 onOpen: (source: IssueEventReference) => boolean;
392}) {
393 const source = event.reference;
394 const at = event.detail === null ? -1 : sentence.indexOf(event.detail);
395 if (source === undefined || event.detail === null || at < 0) return <span>{sentence}</span>;
396 return (
397 <span>
398 {sentence.slice(0, at)}
399 <InlineButton
400 tone="muted"
401 render={<a href={source.url} target="_blank" rel="noopener noreferrer" />}
402 onClick={(click) => {
403 if (!click.metaKey && !click.ctrlKey && onOpen(source)) click.preventDefault();
404 }}
405 >
406 {event.detail}
407 </InlineButton>
408 {sentence.slice(at + event.detail.length)}
409 </span>
410 );
412​
413export function IssueDetailPanel({
414 environmentId,
415 reference,
416 threadRef = null,
417 listEntry = null,
418 onSelectPullRequest,
419 onSelectIssue,
420}: {
421 environmentId: EnvironmentId;
422 reference: IssueRef;
423 /** The list row this issue was opened from, shown until the detail arrives. */
424 listEntry?: IssueListEntry | null;
425 threadRef?: ScopedThreadRef | null;
426 /** Opens a linked change request beside this one; absent, the link goes to the host. */
427 onSelectPullRequest?: ((reference: PullRequestRef) => void) | undefined;
428 /** Opens a referenced issue beside this one; absent, the link goes to the host. */
429 onSelectIssue?: ((reference: IssueRef & { readonly url: string }) => void) | undefined;
430}) {
431 const gt = useGT();
432 const messages = useMessages();
433 const detailAtom = issueEnvironment.detail({ environmentId, input: reference });
434 const detailQuery = useEnvironmentQuery(detailAtom);
435 const registry = useContext(RegistryContext);
436 const [pager] = useState(() => createIssueCommentPager(detailAtom));
437 const { comments, nextCursor, loadingOlder, canLoadOlder } = useAtomValue(pager.view);
438 const detail = detailQuery.data;
439 const canWrite = useAtomValue(issueEnvironment.comment.permissionAtom(environmentId));
440 const projects = useProjects();
441 const cwd =
442 projects.find((p) => p.environmentId === environmentId && p.id === reference.projectId)
443 ?.workspaceRoot ?? "";
444​
445 const loadComments = useAtomCommand(issueEnvironment.comments, { reportFailure: false });
446 const update = useAtomCommand(issueEnvironment.update, { reportFailure: false });
447 const setState = useAtomCommand(issueEnvironment.setState, { reportFailure: false });
448 const openLink = useOpenLink(threadRef);
449 const [editing, setEditing] = useState<"title" | "body" | null>(null);
450 const [titleDraft, setTitleDraft] = useState("");
451 const [saving, setSaving] = useState(false);
452 const [changingState, setChangingState] = useState(false);
453​
454 if (detail === null) {
455 if (detailQuery.error !== null && !detailQuery.isPending) {
456 return (
457 <PullRequestsUnavailableState
458 title={gt("Could not load this issue")}
459 error={detailQuery.error}
460 onRetry={detailQuery.refresh}
461 />
462 );
463 }
464 return <IssueDetailGhost seed={listEntry} />;
465 }
466​
467 const timeline: ReadonlyArray<TimelineItem> = [
468 ...comments.map((c): TimelineItem => ({ kind: "comment", at: c.createdAt, comment: c })),
469 ...detail.events.map((e): TimelineItem => ({ kind: "event", at: e.createdAt, event: e })),
470 ].sort((a, b) => Date.parse(a.at) - Date.parse(b.at));
471​
472 const access = issueWriteAccess(detail, canWrite, messages);
473 const { blocked } = access;
474 const canComment = access.comment;
475 const canEdit = access.edit;
476 const canLabel = access.labels;
477 const canAssign = access.assignees;
478 const canReact = access.react;
479 const otherStates = access.states;
480 const tracker = issueTrackerPresentation(detail.tracker);
481 const currentState = issueStatePresentation(detail.state);
482​
483 const host = reference.host === undefined ? {} : { host: reference.host };
484 const openEventSource = (source: IssueEventReference) => {
485 if (source.kind === "pull-request") {
486 if (!onSelectPullRequest) return false;
487 onSelectPullRequest({
488 projectId: reference.projectId,
489 ...host,
490 repository: source.repository,
491 number: source.number,
492 });
493 return true;
494 }
495 if (!onSelectIssue) return false;
496 onSelectIssue({
497 projectId: reference.projectId,
498 tracker: reference.tracker,
499 ...host,
500 scope: source.repository,
501 key: String(source.number),
502 url: source.url,
503 });
504 return true;
505 };
506​
507 const loadOlder = async () => {
508 const failure = await pager.loadOlder(registry, (cursor) =>
509 loadComments({ environmentId, input: { ...reference, cursor } }),
510 );
511 if (failure) {
512 toastManager.add({ type: "error", title: m(msg("Older comments could not be read")) });
513 }
514 };
515​
516 const save = async (patch: { title?: string; body?: string }) => {
517 setSaving(true);
518 const result = await update({ environmentId, input: { ...reference, ...patch } });
519 setSaving(false);
520 if (result._tag === "Failure") {
521 toastManager.add({
522 type: "error",
523 title: m(msg("The issue could not be updated")),
524 description: readableFailure(
525 squashAtomCommandFailure(result),
526 m(msg("The tracker refused it.")),
527 ),
528 });
529 return;
530 }
531 refreshIssueLists(environmentId);
532 setEditing(null);
533 };
534​
535 const moveTo = async (state: string) => {
536 if (changingState) return;
537 setChangingState(true);
538 const result = await setState({
539 environmentId,
540 input: { ...reference, state },
541 });
542 setChangingState(false);
543 if (result._tag === "Failure") {
544 toastManager.add({
545 type: "error",
546 title: m(msg("The state could not be changed")),
547 description: readableFailure(
548 squashAtomCommandFailure(result),
549 m(msg("The tracker refused it.")),
550 ),
551 });
552 return;
553 }
554 refreshIssueLists(environmentId);
555 };
556​
557 const currentStateIcon = (
558 <currentState.Icon
559 aria-hidden
560 className={cn("size-3.5 shrink-0", currentState.toneClassName)}
561 />
562 );
563 const stateControl: ReactNode =
564 otherStates.length > 0 ? (
565 <Menu>
566 <MenuTrigger
567 render={
568 <Button
569 size="xs"
570 variant="outline"
571 aria-label={gt("Issue state, {state}", { state: currentState.label })}
572 disabled={changingState}
573 />
574 }
575 >
576 {currentStateIcon}
577 {currentState.label}
578 <ChevronDownIcon aria-hidden className="size-3" />
579 </MenuTrigger>
580 <MenuPopup align="end">
581 {otherStates.map((state) => {
582 const presentation = issueStatePresentation(state);
583 return (
584 <MenuItem key={state.name} onClick={() => void moveTo(state.name)}>
585 <presentation.Icon
586 aria-hidden
587 className={cn("size-3.5 shrink-0", presentation.toneClassName)}
588 />
589 {state.name}
590 </MenuItem>
591 );
592 })}
593 </MenuPopup>
594 </Menu>
595 ) : (
596 <span className="flex shrink-0 items-center gap-1 font-medium">
597 {currentStateIcon}
598 {currentState.label}
599 </span>
600 );
601​
602 return (
603 <div className="relative flex h-full min-h-0 flex-col">
604 <div
605 className={cn(
606 "min-h-0 flex-1 overflow-y-auto",
607 // Room for the floating composer, so the last comment can scroll clear of it.
608 detail.capabilities.comment && "pb-32",
609 )}
610 data-pull-request-summary-scroll
611 >
612 <div className="px-4 pb-1">
613 <PullRequestDetailTitleRow className="h-7 gap-1 text-sm sm:text-xs">
614 <span className="min-w-0 truncate font-medium text-muted-foreground">
615 {detail.scope}
616 </span>
617 <InlineButton
618 className={cn("shrink-0 font-medium", currentState.toneClassName)}
619 aria-label={gt("Open {issue} on {provider}", {
620 issue: detail.displayKey,
621 provider: tracker.providerName,
622 })}
623 render={<a href={detail.url} target="_blank" rel="noopener noreferrer" />}
624 onClick={(event) => {
625 event.preventDefault();
626 void openLink(detail.url, { event }).catch(console.error);
627 }}
628 >
629 {detail.displayKey}
630 <ExternalLinkIcon aria-hidden className="size-2.5" />
631 </InlineButton>
632 <span className="flex-1" />
633 {stateControl}
634 <IssueThreadLinks
635 key={`${environmentId}:${detail.url}`}
636 environmentId={environmentId}
637 reference={{ ...reference, host: reference.host ?? detail.host }}
638 issue={detail}
639 threadRef={threadRef}
640 />
641 <Button
642 size="icon-xs"
643 variant="ghost"
644 aria-label={gt("Refresh issue")}
645 disabled={detailQuery.isPending}
646 onClick={() =>
647 void pager.refresh(registry, () =>
648 executeAtomQuery(registry, detailAtom, { refresh: true, reportFailure: false }),
649 )
650 }
651 >
652 <RefreshIcon size="sm" refreshing={detailQuery.isPending} />
653 </Button>
654 </PullRequestDetailTitleRow>
655​
656 {detailQuery.error !== null && !detailQuery.isPending ? (
657 <div className="mt-2">
658 <Alert variant="error">
659 <AlertTitle>{gt("Could not refresh this issue")}</AlertTitle>
660 <AlertDescription>{detailQuery.error}</AlertDescription>
661 </Alert>
662 </div>
663 ) : null}
664​
665 {editing === "title" ? (
666 <form
667 className="mt-1 flex items-center gap-2"
668 onSubmit={(event) => {
669 event.preventDefault();
670 const next = titleDraft.trim();
671 if (next.length > 0 && next !== detail.title) void save({ title: next });
672 else setEditing(null);
673 }}
674 >
675 <Input
676 autoFocus
677 aria-label={gt("Issue title")}
678 value={titleDraft}
679 disabled={saving}
680 onChange={(event) => setTitleDraft(event.target.value)}
681 onKeyDown={(event) => {
682 if (event.key !== "Escape") return;
683 event.preventDefault();
684 event.stopPropagation();
685 setEditing(null);
686 }}
687 />
688 <Button type="submit" size="sm" disabled={saving}>
689 <T>Save</T>
690 </Button>
691 <Button
692 type="button"
693 size="sm"
694 variant="outline"
695 disabled={saving}
696 onClick={() => setEditing(null)}
697 >
698 <T>Cancel</T>
699 </Button>
700 </form>
701 ) : (
702 <PullRequestDetailTitleRow className="group mt-1 gap-1">
703 <h2 className="min-w-0 flex-1 text-base font-semibold leading-snug">
704 {detail.title}
705 </h2>
706 {canEdit ? (
707 <PullRequestEditButton
708 aria-label={gt("Edit title")}
709 onClick={() => {
710 setTitleDraft(detail.title);
711 setEditing("title");
712 }}
713 />
714 ) : null}
715 </PullRequestDetailTitleRow>
716 )}
717​
718 <PullRequestMetaLine className="mt-2 min-h-5 text-xs text-muted-foreground">
719 <PullRequestActorLabel actor={detail.author} />
720 <span>
721 <T>
722 opened <Var>{formatRelativeTimeLabel(detail.createdAt, undefined, messages)}</Var>
723 </T>
724 </span>
725 {detail.closedAt ? (
726 <span>
727 <T>
728 closed <Var>{formatRelativeTimeLabel(detail.closedAt, undefined, messages)}</Var>
729 </T>
730 </span>
731 ) : null}
732 {detail.writable ? null : (
733 <span>
734 <T>Read-only</T>
735 </span>
736 )}
737 </PullRequestMetaLine>
738​
739 <WorkflowRunsAbout
740 environmentId={environmentId}
741 item={{
742 subject: detail.url,
743 issue: { ...reference, host: reference.host ?? detail.host },
744 }}
745 />
746​
747 <div className="mt-4 space-y-2">
748 <PullRequestMetaRow icon={<TagIcon className="size-3.5" />} label={gt("Labels")}>
749 <span className="flex min-w-0 flex-wrap items-center gap-1">
750 {detail.labels.length === 0 ? (
751 <span className="text-muted-foreground">
752 <T context="no labels">None</T>
753 </span>
754 ) : (
755 detail.labels.map((label) => (
756 <PullRequestLabelChip
757 key={label.name}
758 label={label}
759 size="default"
760 className="max-w-48"
761 />
762 ))
763 )}
764 {detail.capabilities.labels ? (
765 <IssueLabelPicker
766 environmentId={environmentId}
767 reference={reference}
768 detail={detail}
769 allowed={canLabel}
770 disabledReason={
771 blocked ?? gt("Changing labels needs triage access on this tracker.")
772 }
773 />
774 ) : null}
775 </span>
776 </PullRequestMetaRow>
777 <PullRequestMetaRow icon={<UsersIcon className="size-3.5" />} label={gt("Assignees")}>
778 <span className="flex min-w-0 flex-wrap items-center gap-1.5">
779 {detail.assignees.length === 0 ? (
780 <span className="text-muted-foreground">
781 <T context="no assignees">None</T>
782 </span>
783 ) : (
784 detail.assignees.map((actor) => (
785 <PullRequestActorLabel key={actor.login} actor={actor} />
786 ))
787 )}
788 {detail.capabilities.assignees ? (
789 <IssueAssigneePicker
790 environmentId={environmentId}
791 reference={reference}
792 detail={detail}
793 allowed={canAssign}
794 disabledReason={
795 blocked ?? gt("Changing assignees needs triage access on this tracker.")
796 }
797 />
798 ) : null}
799 </span>
800 </PullRequestMetaRow>
801 </div>
802 </div>
803​
804 <PullRequestSection
805 key={`description:${detail.url}`}
806 title={gt("Description")}
807 keepMounted
808 actions={
809 canEdit && editing !== "body" ? (
810 <PullRequestEditButton
811 aria-label={gt("Edit description")}
812 onClick={() => setEditing("body")}
813 />
814 ) : null
815 }
816 >
817 <div className="flex flex-col gap-2">
818 {editing === "body" ? (
819 <PullRequestMarkdownEditor
820 value={detail.body}
821 cwd={cwd}
822 environmentId={environmentId}
823 threadRef={threadRef}
824 label={gt("Description")}
825 completionScope={null}
826 saving={saving}
827 allowEmpty
828 onSave={(next) => void save({ body: next })}
829 onCancel={() => setEditing(null)}
830 />
831 ) : (
832 <PullRequestMarkdown
833 text={
834 detail.body.trim().length > 0 ? detail.body : gt("_No description provided._")
835 }
836 cwd={cwd}
837 environmentId={environmentId}
838 threadRef={threadRef}
839 />
840 )}
841 {detail.reactions !== undefined ? (
842 <IssueReactionBar
843 reactions={detail.reactions}
844 canReact={canReact}
845 environmentId={environmentId}
846 reference={reference}
847 />
848 ) : null}
849 </div>
850 </PullRequestSection>
851​
852 {detail.linkedPullRequests.length > 0 ? (
853 <PullRequestSection key={`linked:${detail.url}`} title={gt("Linked pull requests")}>
854 <div className="flex flex-col gap-1">
855 {detail.linkedPullRequests.map((link) => (
856 <LinkedPullRequestRow
857 key={`${link.repository}#${link.number}`}
858 link={link}
859 scope={detail.scope}
860 onSelect={
861 onSelectPullRequest
862 ? () =>
863 onSelectPullRequest({
864 projectId: reference.projectId,
865 ...(reference.host === undefined ? {} : { host: reference.host }),
866 repository: link.repository,
867 number: link.number,
868 })
869 : null
870 }
871 />
872 ))}
873 </div>
874 </PullRequestSection>
875 ) : null}
876​
877 <PullRequestSection
878 key={`activity:${detail.url}`}
879 title={
880 detail.commentCount > 0
881 ? gt("Activity ({count})", { count: detail.commentCount })
882 : gt("Activity")
883 }
884 >
885 <div className="flex flex-col gap-3">
886 {nextCursor !== null ? (
887 <Button
888 size="sm"
889 variant="outline"
890 className="self-start"
891 disabled={!canLoadOlder}
892 onClick={() => void loadOlder()}
893 >
894 {loadingOlder ? <T>Loading…</T> : <T>Load older comments</T>}
895 </Button>
896 ) : null}
897 {timeline.length === 0 ? (
898 <p className="text-sm text-muted-foreground">
899 <T>Nothing has happened here yet.</T>
900 </p>
901 ) : null}
902 {timeline.map((item) =>
903 item.kind === "comment" ? (
904 <article
905 key={`c:${item.comment.id}`}
906 className="flex flex-col gap-2 rounded-lg border border-border/60 p-3"
907 >
908 <h3>
909 <PullRequestMetaLine className="text-xs text-muted-foreground">
910 <PullRequestActorLabel actor={item.comment.author} />
911 {item.comment.url ? (
912 <InlineButton
913 tone="muted"
914 render={
915 <a href={item.comment.url} target="_blank" rel="noopener noreferrer" />
916 }
917 onClick={(event) => {
918 event.preventDefault();
919 void openLink(item.comment.url!, { event }).catch(console.error);
920 }}
921 >
922 {formatRelativeTimeLabel(item.comment.createdAt, undefined, messages)}
923 </InlineButton>
924 ) : (
925 <span>
926 {formatRelativeTimeLabel(item.comment.createdAt, undefined, messages)}
927 </span>
928 )}
929 </PullRequestMetaLine>
930 </h3>
931 <PullRequestCommentBody
932 text={item.comment.body}
933 cwd={cwd}
934 environmentId={environmentId}
935 threadRef={threadRef}
936 />
937 {item.comment.reactions !== undefined ? (
938 <IssueReactionBar
939 reactions={item.comment.reactions}
940 canReact={canReact}
941 subjectId={item.comment.id}
942 environmentId={environmentId}
943 reference={reference}
944 />
945 ) : null}
946 </article>
947 ) : (
948 <PullRequestMetaLine
949 key={`e:${item.event.id}`}
950 className="px-1 text-xs text-muted-foreground"
951 >
952 <PullRequestActorLabel actor={item.event.actor} />
953 <IssueEventText
954 event={item.event}
955 sentence={issueEventSentence(item.event, messages)}
956 onOpen={openEventSource}
957 />
958 <span>{formatRelativeTimeLabel(item.event.createdAt, undefined, messages)}</span>
959 </PullRequestMetaLine>
960 ),
961 )}
962 </div>
963 </PullRequestSection>
964 </div>
965​
966 {detail.capabilities.comment ? (
967 <IssueCommentComposer
968 environmentId={environmentId}
969 reference={reference}
970 blocked={canComment ? null : (blocked ?? gt("You cannot comment here."))}
971 />
972 ) : null}
973 </div>
974 );