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