@devries-cameron20 / t3code-1 / commits / b302290c17
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): the pull request header's crumbs, title editor and base branch live in their own components (#22672)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:28 UTC b302290c17a02d988db67ba4e2f0eda0c4615a03
4 files changed +492 -424
apps/web/src/components/pullRequest/PullRequestBaseBranch.tsx new
+137
@@ -0,0 +1,137 @@
1 +import type { PullRequestUpdateMethod } from "@t3tools/contracts";
2 +import { TriangleAlertIcon } from "lucide-react";
3 +import type { ReactNode } from "react";
4 +
5 +import { cn } from "~/lib/utils";
6 +import { Button } from "../ui/button";
7 +import { MiddleTruncate } from "../ui/middle-truncate";
8 +import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
9 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
10 +import { PullRequestGlyph } from "./pullRequestIcons";
11 +
12 +interface BaseFreshness {
13 + readonly behindBy: number | null;
14 + readonly methods: ReadonlyArray<PullRequestUpdateMethod>;
15 +}
16 +
17 +function PullRequestBaseFreshnessWarning({
18 + baseBranch,
19 + freshness,
20 + pending,
21 + onUpdate,
22 + iconClassName,
23 + className,
24 + children,
25 +}: {
26 + readonly baseBranch: string;
27 + readonly freshness: BaseFreshness;
28 + readonly pending: boolean;
29 + readonly onUpdate: (method: PullRequestUpdateMethod) => void;
30 + readonly iconClassName?: string | undefined;
31 + readonly className?: string;
32 + readonly children?: ReactNode;
33 +}) {
34 + const behind =
35 + freshness.behindBy === null
36 + ? ""
37 + : ` by ${freshness.behindBy.toLocaleString()} ${
38 + freshness.behindBy === 1 ? "commit" : "commits"
39 + }`;
40 + const summary = `This branch is out-of-date with ${baseBranch}${behind}.`;
41 + return (
42 + <Popover>
43 + <PopoverTrigger
44 + openOnHover
45 + delay={0}
46 + closeDelay={120}
47 + render={
48 + <button
49 + type="button"
50 + aria-label={summary}
51 + className={cn(
52 + "inline-flex min-w-0 shrink-0 cursor-help items-center gap-1 rounded-sm text-warning-foreground outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
53 + className,
54 + )}
55 + />
56 + }
57 + >
58 + {children}
59 + <TriangleAlertIcon aria-hidden className={cn("size-3.5 shrink-0", iconClassName)} />
60 + </PopoverTrigger>
61 + <PopoverPopup align="start" side="bottom" className="max-w-80" padding="compact">
62 + <p className="text-xs text-foreground">{summary}</p>
63 + <p className="mt-0.5 text-xs text-muted-foreground">Changes can be cleanly merged.</p>
64 + {freshness.methods.length > 0 ? (
65 + <span className="mt-2 flex flex-wrap items-center gap-1.5">
66 + {freshness.methods.map((method) => (
67 + <Button
68 + key={method}
69 + size="xs"
70 + variant="outline"
71 + disabled={pending}
72 + onClick={() => onUpdate(method)}
73 + >
74 + <PullRequestGlyph.merged aria-hidden className="size-3" />
75 + {method === "rebase" ? "Update with rebase" : "Update branch"}
76 + </Button>
77 + ))}
78 + </span>
79 + ) : null}
80 + </PopoverPopup>
81 + </Popover>
82 + );
83 +}
84 +
85 +/** The base branch, warning when the pull request has fallen behind it. */
86 +export function PullRequestBaseBranch({
87 + baseBranch,
88 + freshness,
89 + stacked,
90 + pending,
91 + onUpdate,
92 + iconClassName,
93 +}: {
94 + readonly baseBranch: string;
95 + readonly freshness: BaseFreshness | null;
96 + readonly stacked: boolean;
97 + readonly pending: boolean;
98 + readonly onUpdate: (method: PullRequestUpdateMethod) => void;
99 + readonly iconClassName?: string;
100 +}) {
101 + const label = (
102 + <>
103 + {stacked ? (
104 + <PullRequestGlyph.stack aria-label="Stacked pull request" className="size-3 shrink-0" />
105 + ) : null}
106 + <code className="flex min-w-0">
107 + <MiddleTruncate value={baseBranch} showTitle={false} />
108 + </code>
109 + </>
110 + );
111 + if (freshness) {
112 + return (
113 + <PullRequestBaseFreshnessWarning
114 + baseBranch={baseBranch}
115 + freshness={freshness}
116 + pending={pending}
117 + onUpdate={onUpdate}
118 + iconClassName={iconClassName}
119 + className="max-w-[40%]"
120 + >
121 + {label}
122 + </PullRequestBaseFreshnessWarning>
123 + );
124 + }
125 + return (
126 + <Tooltip>
127 + <TooltipTrigger
128 + render={
129 + <span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1">
130 + {label}
131 + </span>
132 + }
133 + />
134 + <TooltipPopup side="top">{stacked ? `Stacked on ${baseBranch}` : baseBranch}</TooltipPopup>
135 + </Tooltip>
136 + );
137 +}
apps/web/src/components/pullRequest/PullRequestDetailCrumbs.tsx new
+193
@@ -0,0 +1,193 @@
1 +import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
2 +import { ArrowLeftIcon, ExternalLinkIcon } from "lucide-react";
3 +import type { MouseEvent as ReactMouseEvent } from "react";
4 +
5 +import { cn } from "~/lib/utils";
6 +import { readLocalApi } from "~/localApi";
7 +import { Button } from "../ui/button";
8 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
9 +import { openOnHostLabel, showPullRequestLinkContextMenu } from "./pullRequestLinkContextMenu";
10 +
11 +interface CrumbsPullRequest {
12 + readonly url: string;
13 + readonly provider: string;
14 + readonly number: number;
15 + readonly repository: string;
16 + readonly title: string;
17 +}
18 +
19 +const openNumberContextMenu = (event: ReactMouseEvent, detail: CrumbsPullRequest): void => {
20 + event.preventDefault();
21 + event.stopPropagation();
22 + void showPullRequestLinkContextMenu({
23 + url: detail.url,
24 + openLabel: openOnHostLabel(sourceControlClients.get(detail.provider)),
25 + position: { x: event.clientX, y: event.clientY },
26 + });
27 +};
28 +
29 +const ROW_CLASS_NAME =
30 + "col-start-1 row-start-1 flex min-w-0 items-center gap-1 text-sm text-muted-foreground transition-[opacity,transform] ease-out motion-reduce:transform-none motion-reduce:transition-none sm:text-xs";
31 +
32 +function BackButton({ onBack, focusable }: { onBack: () => void; focusable: boolean }) {
33 + return (
34 + <Tooltip>
35 + <TooltipTrigger
36 + render={
37 + <Button
38 + size="icon-micro"
39 + variant="ghost-muted"
40 + {...(focusable ? {} : { tabIndex: -1 })}
41 + onClick={onBack}
42 + className="-ml-1.5"
43 + aria-label="Back to this thread's pull requests"
44 + >
45 + <ArrowLeftIcon aria-hidden className="size-3.5" />
46 + </Button>
47 + }
48 + />
49 + <TooltipPopup side="top">Back to pull requests</TooltipPopup>
50 + </Tooltip>
51 + );
52 +}
53 +
54 +function NumberLink({
55 + detail,
56 + toneClassName,
57 + openOnHostText,
58 + focusable,
59 +}: {
60 + detail: CrumbsPullRequest;
61 + toneClassName: string;
62 + openOnHostText: string;
63 + focusable: boolean;
64 +}) {
65 + return (
66 + <Tooltip>
67 + <TooltipTrigger
68 + render={
69 + <button
70 + type="button"
71 + {...(focusable ? {} : { tabIndex: -1 })}
72 + onClick={() => void readLocalApi()?.shell.openExternal(detail.url)}
73 + onAuxClick={(event) => {
74 + if (event.button === 1) void readLocalApi()?.shell.openExternal(detail.url);
75 + }}
76 + onContextMenu={(event) => openNumberContextMenu(event, detail)}
77 + className={cn(
78 + "inline-flex shrink-0 cursor-pointer items-center gap-0.5 font-medium underline-offset-2 hover:underline",
79 + toneClassName,
80 + )}
81 + aria-label={`Open pull request #${detail.number} on host`}
82 + >
83 + #{detail.number}
84 + <ExternalLinkIcon aria-hidden className="size-2.5" />
85 + </button>
86 + }
87 + />
88 + <TooltipPopup side="top">{openOnHostText}</TooltipPopup>
89 + </Tooltip>
90 + );
91 +}
92 +
93 +/**
94 + * The repository and number above the title, swapped for the number and title once the reader has
95 + * scrolled the title away.
96 + */
97 +export function PullRequestDetailCrumbs({
98 + detail,
99 + toneClassName,
100 + condensed,
101 + repositoryUrl,
102 + openOnHostText,
103 + onBack,
104 +}: {
105 + detail: CrumbsPullRequest | null;
106 + toneClassName: string | null;
107 + condensed: boolean;
108 + repositoryUrl: string | null;
109 + openOnHostText: string;
110 + onBack: (() => void) | undefined;
111 +}) {
112 + const ready = detail !== null && toneClassName !== null;
113 + return (
114 + <div className="pl-4 grid h-7 min-w-0 items-center overflow-hidden">
115 + <div
116 + aria-hidden={condensed}
117 + inert={condensed}
118 + className={cn(
119 + ROW_CLASS_NAME,
120 + condensed
121 + ? "pointer-events-none -translate-y-1 opacity-0 duration-100"
122 + : "translate-y-0 opacity-100 delay-50 duration-150",
123 + )}
124 + >
125 + {ready ? (
126 + <>
127 + {onBack ? <BackButton onBack={onBack} focusable /> : null}
128 + <Tooltip>
129 + <TooltipTrigger
130 + render={
131 + repositoryUrl ? (
132 + <button
133 + type="button"
134 + onClick={() => void readLocalApi()?.shell.openExternal(repositoryUrl)}
135 + className="min-w-0 cursor-pointer truncate text-left font-medium text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
136 + >
137 + {detail.repository}
138 + </button>
139 + ) : (
140 + <span className="min-w-0 truncate font-medium text-muted-foreground">
141 + {detail.repository}
142 + </span>
143 + )
144 + }
145 + />
146 + <TooltipPopup side="top">
147 + {repositoryUrl ? `Open ${detail.repository} repository` : detail.repository}
148 + </TooltipPopup>
149 + </Tooltip>
150 + <NumberLink
151 + detail={detail}
152 + toneClassName={toneClassName}
153 + openOnHostText={openOnHostText}
154 + focusable
155 + />
156 + </>
157 + ) : null}
158 + </div>
159 + <div
160 + aria-hidden={!condensed}
161 + inert={!condensed}
162 + className={cn(
163 + ROW_CLASS_NAME,
164 + condensed
165 + ? "translate-y-0 opacity-100 delay-50 duration-150"
166 + : "pointer-events-none translate-y-1 opacity-0 duration-100",
167 + )}
168 + >
169 + {ready ? (
170 + <>
171 + {onBack ? <BackButton onBack={onBack} focusable={condensed} /> : null}
172 + <NumberLink
173 + detail={detail}
174 + toneClassName={toneClassName}
175 + openOnHostText={openOnHostText}
176 + focusable={condensed}
177 + />
178 + <Tooltip>
179 + <TooltipTrigger
180 + render={
181 + <span className="min-w-0 truncate font-medium text-foreground">
182 + {detail.title}
183 + </span>
184 + }
185 + />
186 + <TooltipPopup side="top">{detail.title}</TooltipPopup>
187 + </Tooltip>
188 + </>
189 + ) : null}
190 + </div>
191 + </div>
192 + );
193 +}
apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx
+35 -424
@@ -35,7 +35,6 @@ import {
35 CircleDotIcon,
36 CopyIcon,
37 ChevronDownIcon,
38 - ExternalLinkIcon,
38 FileDiffIcon,
39 FolderGit2Icon,
40 GitBranchIcon,
@@ -50,18 +49,15 @@ import {
49 RotateCcwIcon,
50 SparklesIcon,
51 Trash2Icon,
53 - TriangleAlertIcon,
52 } from "lucide-react";
53 import {
54 lazy,
55 Suspense,
58 - type MouseEvent as ReactMouseEvent,
56 useEffect,
57 useEffectEvent,
58 useLayoutEffect,
59 useRef,
60 useState,
64 - type ReactNode,
61 } from "react";
62
63 import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
@@ -107,8 +103,6 @@ import { useUiStateStore } from "~/uiStateStore";
103 import { EnvironmentMachineIcon } from "../EnvironmentMachineIcon";
104 import { Badge } from "../ui/badge";
105 import { Button } from "../ui/button";
110 -import { PullRequestEditButton } from "./PullRequestEditButton";
111 -import { Input } from "../ui/input";
106 import {
107 Menu,
108 MenuItem,
@@ -119,7 +113,6 @@ import {
113 MenuShortcut,
114 MenuTrigger,
115 } from "../ui/menu";
122 -import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
116 import { toastManager } from "../ui/toast";
117 import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "../ui/tooltip";
118 import { MiddleTruncate } from "../ui/middle-truncate";
@@ -127,15 +120,17 @@ import {
120 PullRequestChecksStatusLine,
121 PullRequestDetailHeaderBody,
122 PullRequestDetailTabBar,
130 - PullRequestDetailTitleRow,
123 } from "./PullRequestDetailLayout";
124 import { PullRequestDetailGhost, PullRequestTimelineGhost } from "./PullRequestGhosts";
125 import { PullRequestCopyableCode } from "./PullRequestCopyableCode";
126 +import { PullRequestBaseBranch } from "./PullRequestBaseBranch";
127 +import { PullRequestDetailCrumbs } from "./PullRequestDetailCrumbs";
128 +import { PullRequestTitleEditor } from "./PullRequestTitleEditor";
129 import { PullRequestActivityUnavailableState } from "./PullRequestActivityUnavailableState";
130 import { DiffPanelLoadingState } from "../DiffPanelShell";
131 import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
132 import type { PullRequestAgentSelectionInput } from "./PullRequestCodeTab";
138 -import { openOnHostLabel, showPullRequestLinkContextMenu } from "./pullRequestLinkContextMenu";
133 +import { openOnHostLabel } from "./pullRequestLinkContextMenu";
134 import { PullRequestMarkdownContext } from "./PullRequestMarkdown";
135 import { PullRequestComposer } from "./PullRequestComposer";
136 import { PullRequestSummaryTab } from "./PullRequestSummaryTab";
@@ -175,7 +170,6 @@ import {
170 stripPullRequestHandoffReferences,
171 writePullRequestDetailSnapshot,
172 } from "./pullRequestDetail.logic";
178 -import { canEditPullRequestChangeRequest } from "./pullRequestEditing.logic";
173 import {
174 resolvePickableEnvironments,
175 type PickableEnvironment,
@@ -295,90 +289,6 @@ function ActOnEnvironmentPicker({
289 );
290 }
291
298 -const openNumberContextMenu = (
299 - event: ReactMouseEvent,
300 - detail: { readonly url: string; readonly provider: string },
301 -): void => {
302 - event.preventDefault();
303 - event.stopPropagation();
304 - void showPullRequestLinkContextMenu({
305 - url: detail.url,
306 - openLabel: openOnHostLabel(sourceControlClients.get(detail.provider)),
307 - position: { x: event.clientX, y: event.clientY },
308 - });
309 -};
310 -
311 -function PullRequestBaseFreshnessWarning({
312 - baseBranch,
313 - freshness,
314 - pending,
315 - onUpdate,
316 - iconClassName,
317 - className,
318 - children,
319 -}: {
320 - readonly baseBranch: string;
321 - readonly freshness: {
322 - readonly behindBy: number | null;
323 - readonly methods: ReadonlyArray<PullRequestUpdateMethod>;
324 - };
325 - readonly pending: boolean;
326 - readonly onUpdate: (method: PullRequestUpdateMethod) => void;
327 - readonly iconClassName?: string;
328 - readonly className?: string;
329 - readonly children?: ReactNode;
330 -}) {
331 - const behind =
332 - freshness.behindBy === null
333 - ? ""
334 - : ` by ${freshness.behindBy.toLocaleString()} ${
335 - freshness.behindBy === 1 ? "commit" : "commits"
336 - }`;
337 - const summary = `This branch is out-of-date with ${baseBranch}${behind}.`;
338 - return (
339 - <Popover>
340 - <PopoverTrigger
341 - openOnHover
342 - delay={0}
343 - closeDelay={120}
344 - render={
345 - <button
346 - type="button"
347 - aria-label={summary}
348 - className={cn(
349 - "inline-flex min-w-0 shrink-0 cursor-help items-center gap-1 rounded-sm text-warning-foreground outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
350 - className,
351 - )}
352 - />
353 - }
354 - >
355 - {children}
356 - <TriangleAlertIcon aria-hidden className={cn("size-3.5 shrink-0", iconClassName)} />
357 - </PopoverTrigger>
358 - <PopoverPopup align="start" side="bottom" className="max-w-80" padding="compact">
359 - <p className="text-xs text-foreground">{summary}</p>
360 - <p className="mt-0.5 text-xs text-muted-foreground">Changes can be cleanly merged.</p>
361 - {freshness.methods.length > 0 ? (
362 - <span className="mt-2 flex flex-wrap items-center gap-1.5">
363 - {freshness.methods.map((method) => (
364 - <Button
365 - key={method}
366 - size="xs"
367 - variant="outline"
368 - disabled={pending}
369 - onClick={() => onUpdate(method)}
370 - >
371 - <PullRequestGlyph.merged aria-hidden className="size-3" />
372 - {method === "rebase" ? "Update with rebase" : "Update branch"}
373 - </Button>
374 - ))}
375 - </span>
376 - ) : null}
377 - </PopoverPopup>
378 - </Popover>
379 - );
380 -}
381 -
292 function reportCheckoutCommandError(error: Error) {
293 toastManager.add({
294 type: "error",
@@ -906,13 +816,6 @@ export function PullRequestDetailPanel({
816 });
817 const [pendingAction, setPendingAction] = useState<PullRequestAction | null>(null);
818 const actionPending = pendingAction !== null;
909 - const update = useAtomCommand(pullRequestEnvironment.update, { reportFailure: false });
910 - const [titleScope, setTitleScope] = useState<{
911 - readonly pullRequestKey: string;
912 - readonly text: string;
913 - } | null>(null);
914 - const titleDraft = titleScope?.pullRequestKey === pullRequestKey ? titleScope.text : null;
915 - const [titleSaving, setTitleSaving] = useState(false);
819 const newThread = useNewThreadHandler();
820 const { environments } = useEnvironments();
821 const pickableEnvironments =
@@ -1021,31 +924,6 @@ export function PullRequestDetailPanel({
924 return { commentPosted: true };
925 };
926
1024 - const saveTitle = async (next: string) => {
1025 - const title = next.trim();
1026 - if (!canWriteSourceControl || detail === null || titleSaving) return;
1027 - if (title.length === 0 || title === detail.title) {
1028 - setTitleScope(null);
1029 - return;
1030 - }
1031 - setTitleSaving(true);
1032 - const result = await update({ environmentId, input: { ...reference, title } });
1033 - setTitleSaving(false);
1034 - if (result._tag === "Failure") {
1035 - toastManager.add({
1036 - type: "error",
1037 - title: "The title could not be saved",
1038 - description: readableFailure(
1039 - squashAtomCommandFailure(result),
1040 - "The host refused the new title.",
1041 - ),
1042 - });
1043 - return;
1044 - }
1045 - setTitleScope(null);
1046 - refreshDetail();
1047 - };
1048 -
927 type ThreadTask = {
928 prompt: string;
929 reviewComments?: ReadonlyArray<ReviewCommentContext>;
@@ -1672,156 +1550,14 @@ export function PullRequestDetailPanel({
1550 !detail && !onClose && "hidden",
1551 )}
1552 >
1675 - <div className="pl-4 grid h-7 min-w-0 items-center overflow-hidden">
1676 - <div
1677 - aria-hidden={condensed}
1678 - inert={condensed}
1679 - className={cn(
1680 - "col-start-1 row-start-1 flex min-w-0 items-center gap-1 text-sm text-muted-foreground transition-[opacity,transform] ease-out motion-reduce:transform-none motion-reduce:transition-none sm:text-xs",
1681 - condensed
1682 - ? "pointer-events-none -translate-y-1 opacity-0 duration-100"
1683 - : "translate-y-0 opacity-100 delay-50 duration-150",
1684 - )}
1685 - >
1686 - {detail && statePresentation ? (
1687 - <>
1688 - {onBack ? (
1689 - <Tooltip>
1690 - <TooltipTrigger
1691 - render={
1692 - <Button
1693 - size="icon-micro"
1694 - variant="ghost-muted"
1695 - onClick={onBack}
1696 - className="-ml-1.5"
1697 - aria-label="Back to this thread's pull requests"
1698 - >
1699 - <ArrowLeftIcon aria-hidden className="size-3.5" />
1700 - </Button>
1701 - }
1702 - />
1703 - <TooltipPopup side="top">Back to pull requests</TooltipPopup>
1704 - </Tooltip>
1705 - ) : null}
1706 - <Tooltip>
1707 - <TooltipTrigger
1708 - render={
1709 - repositoryUrl ? (
1710 - <button
1711 - type="button"
1712 - onClick={() => void readLocalApi()?.shell.openExternal(repositoryUrl)}
1713 - className="min-w-0 cursor-pointer truncate text-left font-medium text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
1714 - >
1715 - {detail.repository}
1716 - </button>
1717 - ) : (
1718 - <span className="min-w-0 truncate font-medium text-muted-foreground">
1719 - {detail.repository}
1720 - </span>
1721 - )
1722 - }
1723 - />
1724 - <TooltipPopup side="top">
1725 - {repositoryUrl ? `Open ${detail.repository} repository` : detail.repository}
1726 - </TooltipPopup>
1727 - </Tooltip>
1728 - <Tooltip>
1729 - <TooltipTrigger
1730 - render={
1731 - <button
1732 - type="button"
1733 - onClick={() => void readLocalApi()?.shell.openExternal(detail.url)}
1734 - onAuxClick={(event) => {
1735 - if (event.button === 1)
1736 - void readLocalApi()?.shell.openExternal(detail.url);
1737 - }}
1738 - onContextMenu={(event) => openNumberContextMenu(event, detail)}
1739 - className={cn(
1740 - "inline-flex shrink-0 cursor-pointer items-center gap-0.5 font-medium underline-offset-2 hover:underline",
1741 - statePresentation.toneClassName,
1742 - )}
1743 - aria-label={`Open pull request #${detail.number} on host`}
1744 - >
1745 - #{detail.number}
1746 - <ExternalLinkIcon aria-hidden className="size-2.5" />
1747 - </button>
1748 - }
1749 - />
1750 - <TooltipPopup side="top">{openOnHostText}</TooltipPopup>
1751 - </Tooltip>
1752 - </>
1753 - ) : null}
1754 - </div>
1755 - <div
1756 - aria-hidden={!condensed}
1757 - inert={!condensed}
1758 - className={cn(
1759 - "col-start-1 row-start-1 flex min-w-0 items-center gap-1 text-sm text-muted-foreground transition-[opacity,transform] ease-out motion-reduce:transform-none motion-reduce:transition-none sm:text-xs",
1760 - condensed
1761 - ? "translate-y-0 opacity-100 delay-50 duration-150"
1762 - : "pointer-events-none translate-y-1 opacity-0 duration-100",
1763 - )}
1764 - >
1765 - {detail && statePresentation ? (
1766 - <>
1767 - {onBack ? (
1768 - <Tooltip>
1769 - <TooltipTrigger
1770 - render={
1771 - <Button
1772 - size="icon-micro"
1773 - variant="ghost-muted"
1774 - tabIndex={condensed ? 0 : -1}
1775 - onClick={onBack}
1776 - className="-ml-1.5"
1777 - aria-label="Back to this thread's pull requests"
1778 - >
1779 - <ArrowLeftIcon aria-hidden className="size-3.5" />
1780 - </Button>
1781 - }
1782 - />
1783 - <TooltipPopup side="top">Back to pull requests</TooltipPopup>
1784 - </Tooltip>
1785 - ) : null}
1786 - <Tooltip>
1787 - <TooltipTrigger
1788 - render={
1789 - <button
1790 - type="button"
1791 - tabIndex={condensed ? 0 : -1}
1792 - onClick={() => void readLocalApi()?.shell.openExternal(detail.url)}
1793 - onAuxClick={(event) => {
1794 - if (event.button === 1)
1795 - void readLocalApi()?.shell.openExternal(detail.url);
1796 - }}
1797 - onContextMenu={(event) => openNumberContextMenu(event, detail)}
1798 - className={cn(
1799 - "inline-flex shrink-0 cursor-pointer items-center gap-0.5 font-medium underline-offset-2 hover:underline",
1800 - statePresentation.toneClassName,
1801 - )}
1802 - aria-label={`Open pull request #${detail.number} on host`}
1803 - >
1804 - #{detail.number}
1805 - <ExternalLinkIcon aria-hidden className="size-2.5" />
1806 - </button>
1807 - }
1808 - />
1809 - <TooltipPopup side="top">{openOnHostText}</TooltipPopup>
1810 - </Tooltip>
1811 - <Tooltip>
1812 - <TooltipTrigger
1813 - render={
1814 - <span className="min-w-0 truncate font-medium text-foreground">
1815 - {detail.title}
1816 - </span>
1817 - }
1818 - />
1819 - <TooltipPopup side="top">{detail.title}</TooltipPopup>
1820 - </Tooltip>
1821 - </>
1822 - ) : null}
1823 - </div>
1824 - </div>
1553 + <PullRequestDetailCrumbs
1554 + detail={detail}
1555 + toneClassName={statePresentation?.toneClassName ?? null}
1556 + condensed={condensed}
1557 + repositoryUrl={repositoryUrl}
1558 + openOnHostText={openOnHostText}
1559 + onBack={onBack}
1560 + />
1561 <div className="mr-4 flex h-7 shrink-0 items-center justify-end gap-1">
1562 {detail ? (
1563 <TooltipProvider delay={150} closeDelay={150} timeout={400}>
@@ -2362,49 +2098,14 @@ export function PullRequestDetailPanel({
2098 </span>
2099 <span aria-hidden className="h-3 w-px shrink-0 bg-border/70" />
2100 <span className="flex min-w-0 flex-1 items-center gap-1.5 font-mono text-2xs text-muted-foreground/65">
2365 - {freshness ? (
2366 - <PullRequestBaseFreshnessWarning
2367 - baseBranch={detail.baseBranch}
2368 - freshness={freshness}
2369 - pending={actionPending}
2370 - onUpdate={(method) => void perform("update-branch", undefined, method)}
2371 - iconClassName="size-3"
2372 - className="max-w-[40%]"
2373 - >
2374 - {isStackedPullRequest ? (
2375 - <PullRequestGlyph.stack
2376 - aria-label="Stacked pull request"
2377 - className="size-3 shrink-0"
2378 - />
2379 - ) : null}
2380 - <code className="flex min-w-0">
2381 - <MiddleTruncate value={detail.baseBranch} showTitle={false} />
2382 - </code>
2383 - </PullRequestBaseFreshnessWarning>
2384 - ) : (
2385 - <Tooltip>
2386 - <TooltipTrigger
2387 - render={
2388 - <span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1">
2389 - {isStackedPullRequest ? (
2390 - <PullRequestGlyph.stack
2391 - aria-label="Stacked pull request"
2392 - className="size-3 shrink-0"
2393 - />
2394 - ) : null}
2395 - <code className="flex min-w-0">
2396 - <MiddleTruncate value={detail.baseBranch} showTitle={false} />
2397 - </code>
2398 - </span>
2399 - }
2400 - />
2401 - <TooltipPopup side="top">
2402 - {isStackedPullRequest
2403 - ? `Stacked on ${detail.baseBranch}`
2404 - : detail.baseBranch}
2405 - </TooltipPopup>
2406 - </Tooltip>
2407 - )}
2101 + <PullRequestBaseBranch
2102 + baseBranch={detail.baseBranch}
2103 + freshness={freshness}
2104 + stacked={isStackedPullRequest}
2105 + pending={actionPending}
2106 + onUpdate={(method) => void perform("update-branch", undefined, method)}
2107 + iconClassName="size-3"
2108 + />
2109 <ArrowLeftIcon
2110 aria-label="receives changes from"
2111 className="size-3 shrink-0 opacity-60"
@@ -2466,69 +2167,14 @@ export function PullRequestDetailPanel({
2167 {detail ? (
2168 <PullRequestDetailHeaderBody
2169 title={
2469 - titleDraft === null ? (
2470 - <PullRequestDetailTitleRow className="group gap-1">
2471 - <Tooltip>
2472 - <TooltipTrigger
2473 - render={
2474 - <h1 className="min-w-0 flex-1 truncate text-base font-semibold leading-snug">
2475 - {detail.title}
2476 - </h1>
2477 - }
2478 - />
2479 - <TooltipPopup side="top">{detail.title}</TooltipPopup>
2480 - </Tooltip>
2481 - {canEditPullRequestChangeRequest(detail) ? (
2482 - <PullRequestEditButton
2483 - aria-label="Edit title"
2484 - onClick={() => setTitleScope({ pullRequestKey, text: detail.title })}
2485 - />
2486 - ) : null}
2487 - </PullRequestDetailTitleRow>
2488 - ) : (
2489 - <div className="space-y-2">
2490 - <Input
2491 - autoFocus
2492 - size="sm"
2493 - disabled={titleSaving}
2494 - value={titleDraft}
2495 - aria-label="Pull request title"
2496 - onChange={(event) =>
2497 - setTitleScope({ pullRequestKey, text: event.target.value })
2498 - }
2499 - onKeyDown={(event) => {
2500 - if (event.nativeEvent.isComposing || event.keyCode === 229) return;
2501 - if (event.key === "Enter") {
2502 - event.preventDefault();
2503 - void saveTitle(titleDraft);
2504 - } else if (event.key === "Escape") {
2505 - event.preventDefault();
2506 - setTitleScope(null);
2507 - }
2508 - }}
2509 - />
2510 - <div className="flex justify-end gap-2">
2511 - <Button
2512 - size="xs"
2513 - variant="ghost"
2514 - disabled={titleSaving}
2515 - onClick={() => setTitleScope(null)}
2516 - >
2517 - Cancel
2518 - </Button>
2519 - <Button
2520 - size="xs"
2521 - variant="outline"
2522 - disabled={
2523 - !canWriteSourceControl || titleSaving || titleDraft.trim().length === 0
2524 - }
2525 - onClick={() => void saveTitle(titleDraft)}
2526 - >
2527 - {titleSaving ? "Saving..." : "Save"}
2528 - </Button>
2529 - </div>
2530 - </div>
2531 - )
2170 + <PullRequestTitleEditor
2171 + environmentId={environmentId}
2172 + reference={reference}
2173 + pullRequestKey={pullRequestKey}
2174 + detail={detail}
2175 + canWriteSourceControl={canWriteSourceControl}
2176 + onSaved={refreshDetail}
2177 + />
2178 }
2179 author={
2180 <PullRequestActorLabel actor={detail.author} profileUrl={authorProfileUrl} />
@@ -2553,48 +2199,13 @@ export function PullRequestDetailPanel({
2199 ) : null
2200 }
2201 base={
2556 - freshness ? (
2557 - <PullRequestBaseFreshnessWarning
2558 - baseBranch={detail.baseBranch}
2559 - freshness={freshness}
2560 - pending={actionPending}
2561 - onUpdate={(method) => void perform("update-branch", undefined, method)}
2562 - className="max-w-[40%]"
2563 - >
2564 - {isStackedPullRequest ? (
2565 - <PullRequestGlyph.stack
2566 - aria-label="Stacked pull request"
2567 - className="size-3 shrink-0"
2568 - />
2569 - ) : null}
2570 - <code className="flex min-w-0">
2571 - <MiddleTruncate value={detail.baseBranch} showTitle={false} />
2572 - </code>
2573 - </PullRequestBaseFreshnessWarning>
2574 - ) : (
2575 - <Tooltip>
2576 - <TooltipTrigger
2577 - render={
2578 - <span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1">
2579 - {isStackedPullRequest ? (
2580 - <PullRequestGlyph.stack
2581 - aria-label="Stacked pull request"
2582 - className="size-3 shrink-0"
2583 - />
2584 - ) : null}
2585 - <code className="flex min-w-0">
2586 - <MiddleTruncate value={detail.baseBranch} showTitle={false} />
2587 - </code>
2588 - </span>
2589 - }
2590 - />
2591 - <TooltipPopup side="top">
2592 - {isStackedPullRequest
2593 - ? `Stacked on ${detail.baseBranch}`
2594 - : detail.baseBranch}
2595 - </TooltipPopup>
2596 - </Tooltip>
2597 - )
2202 + <PullRequestBaseBranch
2203 + baseBranch={detail.baseBranch}
2204 + freshness={freshness}
2205 + stacked={isStackedPullRequest}
2206 + pending={actionPending}
2207 + onUpdate={(method) => void perform("update-branch", undefined, method)}
2208 + />
2209 }
2210 head={
2211 <PullRequestCopyableCode
apps/web/src/components/pullRequest/PullRequestTitleEditor.tsx new
+127
@@ -0,0 +1,127 @@
1 +import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
2 +import type { EnvironmentId, PullRequestDetail, PullRequestRef } from "@t3tools/contracts";
3 +import { useState } from "react";
4 +
5 +import { pullRequestEnvironment } from "~/state/pullRequests";
6 +import { useAtomCommand } from "~/state/use-atom-command";
7 +import { Button } from "../ui/button";
8 +import { Input } from "../ui/input";
9 +import { toastManager } from "../ui/toast";
10 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
11 +import { PullRequestDetailTitleRow } from "./PullRequestDetailLayout";
12 +import { PullRequestEditButton } from "./PullRequestEditButton";
13 +import { readableFailure } from "./pullRequestDetail.logic";
14 +import { canEditPullRequestChangeRequest } from "./pullRequestEditing.logic";
15 +
16 +/** The pull request title, which the reader can rename in place when the host allows it. */
17 +export function PullRequestTitleEditor({
18 + environmentId,
19 + reference,
20 + pullRequestKey,
21 + detail,
22 + canWriteSourceControl,
23 + onSaved,
24 +}: {
25 + environmentId: EnvironmentId;
26 + reference: PullRequestRef;
27 + pullRequestKey: string;
28 + detail: PullRequestDetail;
29 + canWriteSourceControl: boolean;
30 + onSaved: () => void;
31 +}) {
32 + const update = useAtomCommand(pullRequestEnvironment.update, { reportFailure: false });
33 + const [titleScope, setTitleScope] = useState<{
34 + readonly pullRequestKey: string;
35 + readonly text: string;
36 + } | null>(null);
37 + const titleDraft = titleScope?.pullRequestKey === pullRequestKey ? titleScope.text : null;
38 + const [titleSaving, setTitleSaving] = useState(false);
39 +
40 + const saveTitle = async (next: string) => {
41 + const title = next.trim();
42 + if (!canWriteSourceControl || titleSaving) return;
43 + if (title.length === 0 || title === detail.title) {
44 + setTitleScope(null);
45 + return;
46 + }
47 + setTitleSaving(true);
48 + const result = await update({ environmentId, input: { ...reference, title } });
49 + setTitleSaving(false);
50 + if (result._tag === "Failure") {
51 + toastManager.add({
52 + type: "error",
53 + title: "The title could not be saved",
54 + description: readableFailure(
55 + squashAtomCommandFailure(result),
56 + "The host refused the new title.",
57 + ),
58 + });
59 + return;
60 + }
61 + setTitleScope(null);
62 + onSaved();
63 + };
64 +
65 + if (titleDraft === null) {
66 + return (
67 + <PullRequestDetailTitleRow className="group gap-1">
68 + <Tooltip>
69 + <TooltipTrigger
70 + render={
71 + <h1 className="min-w-0 flex-1 truncate text-base font-semibold leading-snug">
72 + {detail.title}
73 + </h1>
74 + }
75 + />
76 + <TooltipPopup side="top">{detail.title}</TooltipPopup>
77 + </Tooltip>
78 + {canEditPullRequestChangeRequest(detail) ? (
79 + <PullRequestEditButton
80 + aria-label="Edit title"
81 + onClick={() => setTitleScope({ pullRequestKey, text: detail.title })}
82 + />
83 + ) : null}
84 + </PullRequestDetailTitleRow>
85 + );
86 + }
87 + return (
88 + <div className="space-y-2">
89 + <Input
90 + autoFocus
91 + size="sm"
92 + disabled={titleSaving}
93 + value={titleDraft}
94 + aria-label="Pull request title"
95 + onChange={(event) => setTitleScope({ pullRequestKey, text: event.target.value })}
96 + onKeyDown={(event) => {
97 + if (event.nativeEvent.isComposing || event.keyCode === 229) return;
98 + if (event.key === "Enter") {
99 + event.preventDefault();
100 + void saveTitle(titleDraft);
101 + } else if (event.key === "Escape") {
102 + event.preventDefault();
103 + setTitleScope(null);
104 + }
105 + }}
106 + />
107 + <div className="flex justify-end gap-2">
108 + <Button
109 + size="xs"
110 + variant="ghost"
111 + disabled={titleSaving}
112 + onClick={() => setTitleScope(null)}
113 + >
114 + Cancel
115 + </Button>
116 + <Button
117 + size="xs"
118 + variant="outline"
119 + disabled={!canWriteSourceControl || titleSaving || titleDraft.trim().length === 0}
120 + onClick={() => void saveTitle(titleDraft)}
121 + >
122 + {titleSaving ? "Saving..." : "Save"}
123 + </Button>
124 + </div>
125 + </div>
126 + );
127 +}