From 2dd5525de4577b23ff331860af354f54ead0a154 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Sat, 15 Aug 2026 21:05:58 -0400 Subject: [PATCH] feat(web): refresh pull request details --- apps/web/src/components/ChatView.tsx | 1 - apps/web/src/components/HeaderFilterMenu.tsx | 21 +- .../components/chat/PanelLayoutControls.tsx | 4 +- .../pullRequest/PullRequestDetailPanel.tsx | 918 ++++++++---------- .../pullRequest/PullRequestGhosts.tsx | 117 ++- .../pullRequest/PullRequestListFilters.tsx | 15 +- .../pullRequest/PullRequestSummaryTab.tsx | 6 +- .../pullRequestDetail.logic.test.ts | 42 + .../pullRequest/pullRequestDetail.logic.ts | 15 + apps/web/src/lib/openPullRequestLink.test.ts | 19 + apps/web/src/lib/openPullRequestLink.ts | 17 + apps/web/src/routes/_chat.pull-requests.tsx | 153 +-- 12 files changed, 726 insertions(+), 602 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index b59a15f37d..2e30e67e75 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -6160,7 +6160,6 @@ function ChatViewContent(props: ChatViewProps) { ? "thread" : "page" } - chromeVariant="collapse" composerDraftTarget={composerDraftTarget} onStateChange={handlePullRequestTabStatusChange} /> diff --git a/apps/web/src/components/HeaderFilterMenu.tsx b/apps/web/src/components/HeaderFilterMenu.tsx index 39f4ad58fe..630b8e93a5 100644 --- a/apps/web/src/components/HeaderFilterMenu.tsx +++ b/apps/web/src/components/HeaderFilterMenu.tsx @@ -1,4 +1,5 @@ import { ChevronDownIcon } from "lucide-react"; +import type { ReactNode } from "react"; import { Button } from "./ui/button"; import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "./ui/menu"; @@ -6,6 +7,8 @@ import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "./u export interface HeaderFilterMenuOption { value: Value; label: string; + icon?: ReactNode; + disabledReason?: string; } export function HeaderFilterMenu({ @@ -38,8 +41,22 @@ export function HeaderFilterMenu({ onChange(next as Value)}> {options.map((option) => ( - - {option.label} + + + + {option.icon} + {option.label} + + {option.disabledReason !== undefined ? ( + + {option.disabledReason || "Unavailable"} + + ) : null} + ))} diff --git a/apps/web/src/components/chat/PanelLayoutControls.tsx b/apps/web/src/components/chat/PanelLayoutControls.tsx index 6f281558ff..f72bd58164 100644 --- a/apps/web/src/components/chat/PanelLayoutControls.tsx +++ b/apps/web/src/components/chat/PanelLayoutControls.tsx @@ -12,6 +12,7 @@ interface PanelLayoutControlsProps { rightPanelAvailable: boolean; rightPanelOpen: boolean; rightPanelShortcutLabel: string | null; + rightPanelUnavailableLabel?: string; /** Running + waiting subagents in this thread; badges the right panel toggle. */ liveAgentCount: number; onToggleTerminal: () => void; @@ -26,6 +27,7 @@ export const PanelLayoutControls = memo(function PanelLayoutControls({ rightPanelAvailable, rightPanelOpen, rightPanelShortcutLabel, + rightPanelUnavailableLabel = "Right panel is unavailable", liveAgentCount, onToggleTerminal, onToggleRightPanel, @@ -94,7 +96,7 @@ export const PanelLayoutControls = memo(function PanelLayoutControls({ ? ` · ${liveAgentCount} ${liveAgentCount === 1 ? "agent" : "agents"} working` : "" }` - : "Right panel is unavailable"} + : rightPanelUnavailableLabel} diff --git a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx index 7eb03a863c..900e339b7f 100644 --- a/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx +++ b/apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx @@ -25,6 +25,7 @@ import { GitPullRequestDraftIcon, GitPullRequestIcon, HammerIcon, + LayersIcon, MessageCircleQuestionIcon, MessageSquareIcon, LinkIcon, @@ -50,6 +51,7 @@ import { import { type DraftId, useComposerDraftStore } from "~/composerDraftStore"; import { useNewThreadHandler } from "~/hooks/useHandleNewThread"; import { useCopyToClipboard, writeTextToClipboard } from "~/hooks/useCopyToClipboard"; +import { changeRequestRepositoryUrl } from "~/lib/openPullRequestLink"; import { usePreparePullRequestThreadAction } from "~/lib/sourceControlActions"; import { cn } from "~/lib/utils"; import { readLocalApi } from "~/localApi"; @@ -60,6 +62,7 @@ import { useEnvironmentQuery } from "~/state/query"; import { useLiveRefresh } from "~/hooks/useLiveRefresh"; import { pullRequestEnvironment } from "~/state/pullRequests"; import { useAtomCommand } from "~/state/use-atom-command"; +import { vcsEnvironment } from "~/state/vcs"; import { formatRelativeTimeLabel } from "~/timestampFormat"; import { @@ -74,6 +77,7 @@ import { import { Badge } from "../ui/badge"; import { Button } from "../ui/button"; import { Input } from "../ui/input"; +import { Toggle, ToggleGroup } from "../ui/toggle-group"; import { Menu, MenuItem, @@ -102,6 +106,7 @@ import { buildResolveConflictsPrompt, handoffPrompt, handoffReviewComments, + isStackedPullRequestBase, pullRequestActionMenuHasGroup, pullRequestActionNeedsHostRefresh, pullRequestComposerTarget, @@ -118,6 +123,7 @@ import { } from "./pullRequestProjectAssignment.logic"; import { PullRequestChecksPopover } from "./PullRequestChecksPopover"; import { + PullRequestActorAvatar, PullRequestActorLabel, PullRequestDiffStat, PullRequestMetaLine, @@ -351,7 +357,6 @@ export function PullRequestDetailPanel({ onClose, onStateChange, context = "page", - chromeVariant = "full", composerDraftTarget, }: { environmentId: EnvironmentId; @@ -383,12 +388,6 @@ export function PullRequestDetailPanel({ * again is at best a no-op and at worst git refusing a branch two checkouts. */ context?: "page" | "thread"; - /** - * How the metadata above the content behaves: `full` keeps every row pinned; `collapse` - * folds the whole of it into the top row once the active tab scrolls, and unfolds at the - * top — the chrome spends its height on what is being read. - */ - chromeVariant?: "full" | "collapse"; /** * The open thread's composer. Beside the thread whose own pull request this is, hand-offs * land here instead of opening a new thread — the branch is already under the reader's feet. @@ -425,26 +424,13 @@ export function PullRequestDetailPanel({ ); }, [tab]); const [chromeCondensed, setChromeCondensed] = useState(false); - // Each tab remembers whether its chrome was condensed. Only the active tab can emit scroll - // events, so the capture handler always writes the active tab's entry — and a tab switch - // reads the destination's memory instead of inheriting the tab being left. A tab too short - // to scroll remembers "expanded", which is what keeps it from being stranded under a chrome - // it has no scrollbar to reopen. const chromeStateByTab = useRef>>({}); useEffect(() => { setChromeCondensed(chromeStateByTab.current[tab] ?? false); }, [tab]); - const condensed = chromeVariant === "collapse" && chromeCondensed; - // Collapsing removes the fold's height from the chrome, which would otherwise hand that - // height to the scrollport and leap the content up by it mid-scroll. The cure is exact - // compensation: collapse only once the reader has scrolled at least the fold's height, - // then give that height back to `scrollTop` before the next paint — the content under - // their eyes does not move, and the collapse itself is the only thing that changes. + const condensed = chromeCondensed; const scrollerRef = useRef(null); const foldRef = useRef(null); - // The condensed chrome's second row opens as the fold closes, so the height the scrollport - // gains is the fold's minus this row's. Measured the same way the fold is: `scrollHeight` - // through a zero track reads its natural height in either state. const condensedRowRef = useRef(null); const compensationRef = useRef(null); useLayoutEffect(() => { @@ -465,7 +451,6 @@ export function PullRequestDetailPanel({ target: "branch name", timeout: 1600, }); - // The chunk is fetched as soon as the panel exists rather than waiting for the Code tab to be // clicked, so a reader who does click it lands on a chunk already in the module cache. useEffect(() => { @@ -504,6 +489,23 @@ export function PullRequestDetailPanel({ }, [activity, coreDetail], ); + const repositoryUrl = detail === null ? null : changeRequestRepositoryUrl(detail.url); + const branchRefsQuery = useEnvironmentQuery( + detail === null + ? null + : vcsEnvironment.listRefs({ + environmentId, + input: { + cwd: detail.workspaceRoot, + includeMatchingRemoteRefs: true, + // listRefs keeps the current ref first and a known default second. + limit: 2, + }, + }), + ); + const isStackedPullRequest = + detail !== null && + isStackedPullRequestBase(detail.baseBranch, branchRefsQuery.data?.refs ?? []); const activityPending = activityQuery.isPending && activity === null; const activityError = activity === null ? activityQuery.error : null; const refreshDetail = useCallback(() => { @@ -1021,17 +1023,17 @@ export function PullRequestDetailPanel({ const can = (action: PullRequestAction) => detail?.capabilities.actions.includes(action) === true && detail.viewerPermissions.actions.includes(action); - // One live action holds the slot. A conflicting change cannot be merged now, so the slot goes - // to the thing that would help instead of a Merge button that only ever says no. + // One live action holds the slot. Conflicts take priority because every other completion action + // depends on resolving them first, even for a reader who cannot merge on the host themselves. const primaryAction = detail === null || detail.state !== "open" ? null - : detail.isDraft && can("ready") - ? "ready" - : !can("merge") - ? null - : conflicting - ? "resolve" + : conflicting + ? "resolve" + : detail.isDraft && can("ready") + ? "ready" + : !can("merge") + ? null : allowedMergeMethods.length > 0 ? "merge" : null; @@ -1056,39 +1058,47 @@ export function PullRequestDetailPanel({ !conflicting && allowedMergeMethods.length > 1; // The pull request number carries this state in the overview and the right-panel tab mirrors - // it. Conflicts keep their own row below: an open pull request remains green there. + // it. The conflict action is separate from this state: an open pull request remains green. const statePresentation = detail ? resolvePullRequestState({ state: detail.state, isDraft: detail.isDraft }) : null; const checksSummary = detail ? summarizePullRequestChecks(detail.checks) : null; const checksState = detail ? pullRequestChecksState(detail.checks) : null; + if (detailQuery.isPending && !detail) { + return ; + } + return (
- {/* The top row's geometry never changes: both of its states occupy the same stacked - cell and crossfade, so the actions on the right have one home whatever the chrome - is doing below. The fold and this fade share one 200ms clock. */}
- {/* The fixed height lives on the two top-row cells — not the grid, whose later rows - are the fold — so the actions have one immovable home in both states. */} -
+
{detail && statePresentation ? ( <> - - {detail.repository} - + {repositoryUrl ? ( + + ) : ( + + {detail.repository} + + )} - +

{detail.title} - - {conflicting ? ( - - - Conflicts - - ) : checksSummary ? ( - - {detail && checksState !== null ? ( - - ) : null} - {checksSummary} - - ) : null} +

) : null}
-
+
{detail ? ( - <> - - - } - > - - - - void refreshFromHost()}> - - Refresh - - - - - {handoff === "ask" ? "Opening..." : "Ask a question"} - - {attachTarget !== null - ? "Adds the pull request to this thread's composer." - : "Opens a thread that knows which pull request you mean."} - + + + void refreshFromHost()}> + + Refresh + + + + + {handoff === "ask" ? "Opening..." : "Ask a question"} + + {attachTarget !== null + ? "Adds the pull request to this thread's composer." + : "Opens a thread that knows which pull request you mean."} - - - - - {handoff === "explain" ? "Opening..." : "Explain this PR"} - - A walk through the diff and what to read closely. - + + + + + + {handoff === "explain" ? "Opening..." : "Explain this PR"} + + A walk through the diff and what to read closely. - - - - {handoff === "findings" ? "Preparing..." : handoffLabels.fixFindings} - - {pickableEnvironments.length > 0 ? ( - setActingScope({ pullRequestKey, environmentId: next })} - disabled={handoff !== null} - /> - ) : null} - - {detail.state === "open" ? ( - <> - {/* Only where the button row could not take it: "Ready for review" on a + + + + + {handoff === "findings" ? "Preparing..." : handoffLabels.fixFindings} + + {pickableEnvironments.length > 0 ? ( + setActingScope({ pullRequestKey, environmentId: next })} + disabled={handoff !== null} + /> + ) : null} + + {detail.state === "open" ? ( + <> + {/* Only where the button row could not take it: "Ready for review" on a draft is the primary header button, so offering it here as well would show the same action twice. */} - {showsDraftToggle ? ( - void perform(detail.isDraft ? "ready" : "draft")} - > - {detail.isDraft ? ( - - ) : ( - - )} - {detail.isDraft ? "Ready for review" : "Convert to draft"} - - ) : null} - {/* The same merge, left with the host to carry out once the things it + {showsDraftToggle ? ( + void perform(detail.isDraft ? "ready" : "draft")} + > + {detail.isDraft ? ( + + ) : ( + + )} + {detail.isDraft ? "Ready for review" : "Convert to draft"} + + ) : null} + {/* The same merge, left with the host to carry out once the things it waits on are done. It is offered beside the merge rather than instead of it, because the reader who can wait and the reader who cannot are the same person on different days — and a conflicting branch is neither, since nothing the host waits for will clear it. */} - {autoMergeArmed && can("disable-auto-merge") ? ( - void perform("disable-auto-merge")} - > - - Disable auto-merge - - ) : !autoMergeArmed && - !detail.isDraft && - !conflicting && - can("enable-auto-merge") && - allowedMergeMethods.length > 0 ? ( - setConfirmAction("enable-auto-merge")} - > - - Enable auto-merge - - ) : null} - {/* A preference for the merge action rather than a second action, so it + {autoMergeArmed && can("disable-auto-merge") ? ( + void perform("disable-auto-merge")} + > + + Disable auto-merge + + ) : !autoMergeArmed && + !detail.isDraft && + !conflicting && + can("enable-auto-merge") && + allowedMergeMethods.length > 0 ? ( + setConfirmAction("enable-auto-merge")} + > + + Enable auto-merge + + ) : null} + {/* A preference for the merge action rather than a second action, so it is a radio group here instead of a chevron welded to the Merge pill. Hidden while conflicting: every method would fail. */} - {/* Only where merging is on offer at all: a strategy to merge with is not + {/* Only where merging is on offer at all: a strategy to merge with is not a choice for someone who may not merge. */} - {showsMergeMethods ? ( - <> - {/* Only below the draft control. A host with no draft of its own, or + {showsMergeMethods ? ( + <> + {/* Only below the draft control. A host with no draft of its own, or a draft whose control is already the header button, would leave this against the separator that opened the group. */} - {showsDraftToggle ? : null} - - setMergeMethod(method as PullRequestMergeMethod) - } - > - {allowedMergeMethods.map((method) => ( - - {/* The radio item lays its children out as one block, so the + {showsDraftToggle ? : null} + + setMergeMethod(method as PullRequestMergeMethod) + } + > + {allowedMergeMethods.map((method) => ( + + {/* The radio item lays its children out as one block, so the icon and the label need their own row to share a line. */} - - - {method} - - - ))} - - - ) : null} - {pullRequestActionMenuHasGroup( - showsDraftToggle, - showsAutoMerge, - showsMergeMethods, - ) ? ( - - ) : null} - - ) : null} - void readLocalApi()?.shell.openExternal(detail.url)}> - - {openOnHostLabel(detail.provider)} + + + {method} + + + ))} + + + ) : null} + {pullRequestActionMenuHasGroup( + showsDraftToggle, + showsAutoMerge, + showsMergeMethods, + ) ? ( + + ) : null} + + ) : null} + void readLocalApi()?.shell.openExternal(detail.url)}> + + {openOnHostLabel(detail.provider)} + + void writeTextToClipboard(detail.url)}> + + Copy link + + {/* Only where the button row could not take it, so it is never offered twice. */} + {conflicting && primaryAction !== "resolve" ? ( + + + {handoff === "conflicts" ? "Preparing..." : handoffLabels.resolveConflicts} - void writeTextToClipboard(detail.url)}> - - Copy link - - {/* Only where the button row could not take it, so it is never offered twice. */} - {conflicting && primaryAction !== "resolve" ? ( - - - {handoff === "conflicts" ? "Preparing..." : handoffLabels.resolveConflicts} + ) : null} + {detail.state === "open" && can("close") ? ( + <> + + setConfirmAction("close")} + > + + Close pull request - ) : null} - {detail.state === "open" && can("close") ? ( - <> - - setConfirmAction("close")} - > - - Close pull request - - - ) : detail.state === "closed" && can("reopen") ? ( - <> - - void perform("reopen")}> - - Reopen pull request - - - ) : null} - - + + ) : detail.state === "closed" && can("reopen") ? ( + <> + + void perform("reopen")}> + + Reopen pull request + + + ) : null} + {/* Checking a pull request out is the reason to open one here at all, so it is a button of its own rather than a side effect of asking an agent for something. It asks where, because the two answers are not interchangeable: one leaves your @@ -1340,15 +1320,9 @@ export function PullRequestDetailPanel({ disabled={handoff !== null} render={ } /> @@ -1394,7 +1368,17 @@ export function PullRequestDetailPanel({ Auto-merge ) : null} - {primaryAction === "ready" ? ( + {primaryAction === "resolve" ? ( + + ) : primaryAction === "ready" ? ( @@ -1407,7 +1391,19 @@ export function PullRequestDetailPanel({ {pendingAction === "merge" ? "Merging..." : "Merge"} ) : null} - + + } + > + + + ) : null} {onClose ? ( - ))} - - - {detail.baseBranch} - {freshness ? ( - void perform("update-branch", undefined, method)} - iconClassName="size-3" - /> - ) : null} - - {detail.headBranch} - - - - - {detail.changedFiles.toLocaleString()} +
+
+ + + {detail.author?.login ?? "ghost"} + {formatRelativeTimeLabel(detail.updatedAt)} - - + + + + {isStackedPullRequest ? ( + + ) : null} + {detail.baseBranch} + + {freshness ? ( + void perform("update-branch", undefined, method)} + iconClassName="size-3" + /> + ) : null} + + {detail.headBranch} + + + + + {detail.changedFiles.toLocaleString()} + + + +
) : null}
- {/* Folding is a grid track going to zero: the rows below stay mounted, the track - animates closed over them, and `inert` takes the hidden controls out of the tab - order for as long as the chrome is condensed. */} -
+
{detail ? ( -
+
{titleDraft === null ? (

@@ -1594,47 +1563,56 @@ export function PullRequestDetailPanel({
- - {detail.baseBranch} - - {freshness ? ( - void perform("update-branch", undefined, method)} - /> - ) : null} - - + {freshness ? ( + void perform("update-branch", undefined, method)} + /> + ) : null} + + + @@ -1650,147 +1628,115 @@ export function PullRequestDetailPanel({

) : null} +
+
- {detail && conflicting ? ( -
- + { + const nextTab = visibleTabs.find((item) => item.value === next[0])?.value; + if (nextTab) setTab(nextTab); + }} + > + {visibleTabs.map((item) => ( + + {item.label} + + ))} + + {tab === "summary" ? ( + + {checksState !== null ? ( + + ) : ( + + )} + {checksSummary} + + ) : tab === "timeline" ? ( +
+ - - Merge conflicts - + + + {activityError + ? "—" + : activityPending + ? "…" + : detail.commentCount.toLocaleString()} + + + + {activityError + ? "—" + : activityPending + ? "…" + : detail.commits.length.toLocaleString()} + +
) : null} - - {detail ? ( - - ) : null} -
-
+ + ) : null}
{ - if (chromeVariant !== "collapse") return; const scroller = event.target as HTMLElement; scrollerRef.current = scroller; const top = scroller.scrollTop; setChromeCondensed((previous) => { let next = previous; - // `scrollHeight` reads the fold's natural height whichever state the track is in. const foldHeight = foldRef.current?.scrollHeight ?? 0; - // The chrome trades the fold for the condensed second row, so the height the - // scrollport actually gains is the difference between the two. const chromeDelta = foldHeight - (condensedRowRef.current?.scrollHeight ?? 0); if (previous) { // The hard top reopens the chrome with no refund: the reader asked for the top, @@ -1808,17 +1754,7 @@ export function PullRequestDetailPanel({ }); }} > - {detailQuery.isPending && !detail ? ( - // The ghost wears the shape of the tab being waited on, so switching tabs mid-load - // does not flash a summary outline under a timeline heading. - tab === "timeline" ? ( - - ) : tab === "code" ? ( - - ) : ( - - ) - ) : detailQuery.error && !detail ? ( + {detailQuery.error && !detail ? ( ) : detail ? ( <> diff --git a/apps/web/src/components/pullRequest/PullRequestGhosts.tsx b/apps/web/src/components/pullRequest/PullRequestGhosts.tsx index 09b79cf340..38a3ab70d6 100644 --- a/apps/web/src/components/pullRequest/PullRequestGhosts.tsx +++ b/apps/web/src/components/pullRequest/PullRequestGhosts.tsx @@ -45,13 +45,11 @@ export function PullRequestListGhost({
- +
- +
))} @@ -59,32 +57,101 @@ export function PullRequestListGhost({ ); } -/** The summary's own shape: a title, a byline, the facts rows, the description. */ +/** + * The detail panel's current expanded shape. Keeping the chrome, summary facts, and description + * boundaries in the ghost prevents the loaded pull request from replacing one layout with + * another a moment later. + */ export function PullRequestDetailGhost() { return (
-
- - -
-
- {Array.from({ length: 4 }, (_, index) => ( -
- - - +
+
+
+ +
- ))} +
+ + +
+
+ +
+ +
+ + +
+
+ + + +
+ + +
+
+
+ +
+
+ + + +
+ +
-
- - - - + +
+
+
+
+ + +
+
+ + + +
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+ +
+
+ +
+
+ + +
+
+ + + + +
+
); @@ -113,7 +180,7 @@ export function PullRequestTimelineGhost({ rows = 6 }: { rows?: number }) {
- +
))}
@@ -134,8 +201,8 @@ export function PullRequestConversationGhost({ rows = 3 }: { rows?: number }) {
- - + +
))} diff --git a/apps/web/src/components/pullRequest/PullRequestListFilters.tsx b/apps/web/src/components/pullRequest/PullRequestListFilters.tsx index 3066eafc38..04fee465b5 100644 --- a/apps/web/src/components/pullRequest/PullRequestListFilters.tsx +++ b/apps/web/src/components/pullRequest/PullRequestListFilters.tsx @@ -25,6 +25,7 @@ import { cn } from "~/lib/utils"; import { getSourceControlPresentationForKind } from "~/sourceControlPresentation"; import { ProjectFavicon } from "../ProjectFavicon"; import { InputGroup, InputGroupAddon, InputGroupInput } from "../ui/input-group"; +import { Button } from "../ui/button"; import { Menu, @@ -261,12 +262,14 @@ export function PullRequestFiltersMenu({ return ( + } > {filtered ? ( diff --git a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx index a57f2a4d16..d189dd00aa 100644 --- a/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx @@ -196,12 +196,12 @@ function MetaRow({ children: ReactNode; }) { return ( -
- +
+ {icon} {label} - {children} + {children}
); } diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts index f9d4ce4571..dece5f7a0a 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts @@ -16,6 +16,7 @@ import { groupPullRequestTimelineConversations, handoffPrompt, handoffReviewComments, + isStackedPullRequestBase, isThreadOwnPullRequest, orderPullRequestComments, pullRequestActionMenuHasGroup, @@ -101,6 +102,47 @@ describe("pull request composer target", () => { }); }); +describe("stacked pull request classification", () => { + it("requires a known default branch", () => { + expect(isStackedPullRequestBase("main", [{ name: "main", isDefault: false }])).toBe(false); + }); + + it("recognizes local and remote forms of the default branch", () => { + expect( + isStackedPullRequestBase("main", [{ name: "main", isDefault: true, isRemote: false }]), + ).toBe(false); + expect( + isStackedPullRequestBase("main", [ + { name: "origin/main", isDefault: true, isRemote: true, remoteName: "origin" }, + ]), + ).toBe(false); + }); + + it("classifies a non-default base as stacked once the default is known", () => { + expect( + isStackedPullRequestBase("feature-base", [ + { name: "origin/main", isDefault: true, isRemote: true, remoteName: "origin" }, + ]), + ).toBe(true); + }); + + it("does not mistake a nested branch suffix for the default branch", () => { + expect( + isStackedPullRequestBase("main", [ + { + name: "origin/feature/main", + isDefault: true, + isRemote: true, + remoteName: "origin", + }, + ]), + ).toBe(true); + expect( + isStackedPullRequestBase("1.0", [{ name: "release/1.0", isDefault: true, isRemote: false }]), + ).toBe(true); + }); +}); + describe("ordering comments", () => { it("reverses the chronological list for newest first, and leaves oldest first alone", () => { const comments = [{ createdAt: "a" }, { createdAt: "b" }, { createdAt: "c" }]; diff --git a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts index 8c72b944cb..eaf61d6429 100644 --- a/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts +++ b/apps/web/src/components/pullRequest/pullRequestDetail.logic.ts @@ -10,6 +10,7 @@ import type { PullRequestReviewThread, PullRequestState, PullRequestUpdateMethod, + VcsRef, } from "@t3tools/contracts"; import { inferReviewCommentFenceLanguage, type ReviewCommentContext } from "~/reviewCommentContext"; @@ -73,6 +74,20 @@ export function pullRequestActionMenuHasGroup( return showsDraftToggle || showsAutoMerge || showsMergeMethods; } +export function isStackedPullRequestBase( + baseBranch: string, + refs: ReadonlyArray>, +): boolean { + const defaultRef = refs.find((refName) => refName.isDefault); + if (!defaultRef) return false; + if (defaultRef.isRemote !== true) return defaultRef.name !== baseBranch; + const remotePrefix = `${defaultRef.remoteName ?? defaultRef.name.split("/")[0]}/`; + const defaultBranch = defaultRef.name.startsWith(remotePrefix) + ? defaultRef.name.slice(remotePrefix.length) + : defaultRef.name; + return defaultBranch !== baseBranch; +} + /** Plain-language state, shown beside the author. Conflicts are a merge signal, not a state. */ export function describePullRequestState(state: PullRequestState, isDraft: boolean): string { if (state === "merged") return "Merged"; diff --git a/apps/web/src/lib/openPullRequestLink.test.ts b/apps/web/src/lib/openPullRequestLink.test.ts index 9d26fa2921..edba97fa7d 100644 --- a/apps/web/src/lib/openPullRequestLink.test.ts +++ b/apps/web/src/lib/openPullRequestLink.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it, vi } from "vite-plus/test"; import { + changeRequestRepositoryUrl, findProjectForChangeRequest, openPullRequestLink, parseChangeRequestUrl, @@ -8,6 +9,24 @@ import { shouldOpenPullRequestExternally, } from "./openPullRequestLink"; +describe("changeRequestRepositoryUrl", () => { + it("preserves repository path casing", () => { + expect( + changeRequestRepositoryUrl( + "https://gitlab.example.test/Team/Platform/Repo/-/merge_requests/42/diffs#note_1", + ), + ).toBe("https://gitlab.example.test/Team/Platform/Repo"); + }); + + it("keeps pull-like segments inside nested GitLab repository paths", () => { + expect( + changeRequestRepositoryUrl( + "https://gitlab.example.test/group/pull/123/repo/-/merge_requests/42", + ), + ).toBe("https://gitlab.example.test/group/pull/123/repo"); + }); +}); + describe("openPullRequestLink", () => { it("opens the requested pull request URL", async () => { const openExternal = vi.fn(async () => undefined); diff --git a/apps/web/src/lib/openPullRequestLink.ts b/apps/web/src/lib/openPullRequestLink.ts index 0b7e6bf0f9..c8ec1b7a62 100644 --- a/apps/web/src/lib/openPullRequestLink.ts +++ b/apps/web/src/lib/openPullRequestLink.ts @@ -118,6 +118,23 @@ export function parseChangeRequestUrl(targetUrl: string): ChangeRequestLink | nu return null; } +/** The repository root behind a recognised change-request URL, without PR-specific state. */ +export function changeRequestRepositoryUrl(targetUrl: string): string | null { + const changeRequest = parseChangeRequestUrl(targetUrl); + if (changeRequest === null) return null; + const url = new URL(targetUrl); + const repositoryPath = + /^(.*?)\/-\/merge_requests\/\d+(?:\/|$)/iu.exec(url.pathname)?.[1] ?? + /^(.*?)(?:\/pull\/\d+|\/-\/merge_requests\/\d+|\/pull-requests\/\d+|\/pullrequest\/\d+)(?:\/|$)/iu.exec( + url.pathname, + )?.[1]; + if (!repositoryPath) return null; + url.pathname = repositoryPath; + url.search = ""; + url.hash = ""; + return url.toString(); +} + function claim(host: string, match: RegExpExecArray | null): ChangeRequestLink | null { const repository = match?.[1]; const number = Number(match?.[2]); diff --git a/apps/web/src/routes/_chat.pull-requests.tsx b/apps/web/src/routes/_chat.pull-requests.tsx index 66d9f0caa5..3923177cc0 100644 --- a/apps/web/src/routes/_chat.pull-requests.tsx +++ b/apps/web/src/routes/_chat.pull-requests.tsx @@ -13,7 +13,6 @@ import type { } from "@t3tools/contracts"; import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { - ChevronDownIcon, EyeIcon, MonitorIcon, ServerIcon, @@ -69,14 +68,20 @@ import { PullRequestListGhost } from "../components/pullRequest/PullRequestGhost import { PullRequestRow } from "../components/pullRequest/PullRequestRow"; import { PullRequestsUnavailableState } from "../components/pullRequest/PullRequestsUnavailableState"; import { RightPanelTabs, type PullRequestTabStatus } from "../components/RightPanelTabs"; +import { HeaderFilterMenu, type HeaderFilterMenuOption } from "../components/HeaderFilterMenu"; import { WorkspaceBreadcrumb, WorkspaceBreadcrumbItem, WorkspaceBreadcrumbSeparator, } from "../components/WorkspaceBreadcrumb"; +import { + WorkspacePageContainer, + WorkspacePageHeader, + WorkspacePageHeaderEdgeControl, +} from "../components/WorkspacePageContainer"; +import { isElectron } from "../env"; import { PanelLayoutControls } from "../components/chat/PanelLayoutControls"; import { Button } from "../components/ui/button"; -import { Menu, MenuPopup, MenuRadioGroup, MenuRadioItem, MenuTrigger } from "../components/ui/menu"; import { SidebarInset } from "../components/ui/sidebar"; import { useLiveRefresh } from "../hooks/useLiveRefresh"; import { @@ -99,7 +104,6 @@ import { import { useAtomCommand } from "../state/use-atom-command"; import { cn } from "~/lib/utils"; import { getSourceControlPresentationForKind } from "~/sourceControlPresentation"; -import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar"; export interface PullRequestsSearch { readonly involvement: PullRequestInvolvement; @@ -1181,6 +1185,17 @@ function PullRequestsRouteView() { : null, [search.number, search.repository, selectedProject], ); + const linkedSelectionMatchesSurface = + linkedSelection !== null && + selectedPullRequestSurface !== null && + linkedSelection.environmentId === selectedPullRequestSurface.environmentId && + linkedSelection.projectId === selectedPullRequestSurface.projectId && + linkedSelection.repository === selectedPullRequestSurface.repository && + linkedSelection.number === selectedPullRequestSurface.number; + // A closed panel keeps its tabs so reopening does not discard work. Those retained tabs are + // history, though, not a current selection: without this check they leave the toggle looking + // available after the selected pull request has been cleared. + const rightPanelAvailable = activePullRequestSurface !== null || linkedSelectionMatchesSurface; useEffect(() => { if (!pullRequestsSupported || rightPanelRef === null || linkedSelection === null) return; useRightPanelStore.getState().openPullRequest(rightPanelRef, linkedSelection); @@ -1294,9 +1309,10 @@ function PullRequestsRouteView() { terminalAvailable={false} terminalOpen={false} terminalShortcutLabel={null} - rightPanelAvailable={rightPanelState.surfaces.length > 0} + rightPanelAvailable={rightPanelAvailable} rightPanelOpen={rightPanelState.isOpen} rightPanelShortcutLabel={null} + rightPanelUnavailableLabel="Select a pull request first" liveAgentCount={0} onToggleTerminal={() => undefined} onToggleRightPanel={toggleRightPanel} @@ -1603,7 +1619,6 @@ function PullRequestsRouteView() { reviewingQuery.refresh(); }} onStateChange={handlePullRequestTabStatusChange} - chromeVariant="collapse" /> ) : null} @@ -1612,10 +1627,7 @@ function PullRequestsRouteView() { ); } -/** - * A compact stand-in for one pill group: the trigger wears the current choice, the choices - * live in a menu. Same options, same handler — only the footprint changes. - */ +/** Adapts pull-request filter metadata to the shared header menu. */ function CompactFilterMenu({ label, value, @@ -1627,37 +1639,18 @@ function CompactFilterMenu({ options: ReadonlyArray>; onChange: (value: Value) => void; }) { - const current = options.find((option) => option.value === value) ?? options[0]!; + const headerOptions = useMemo>>( + () => + options.map((option) => ({ + value: option.value, + label: option.label, + icon: , + ...(option.unavailable !== undefined ? { disabledReason: option.unavailable } : {}), + })), + [options], + ); return ( - - - {current.label} - - - - onChange(next as Value)}> - {options.map((option) => ( - - - - {option.label} - - - ))} - - - + ); } @@ -1827,18 +1820,10 @@ function PullRequestsColumn({ // Painted flat like the chat column: the inset underneath carries the chrome grain, and a // content surface that lets it show reads as a different background than every thread.
-
+ {/* A closed right panel leaves this column full-width, so the shared header + reserves native window controls. While the panel is open, the column ends + at the panel and the absolute controls strip owns the top-right corner. */} + {condensed ? ( {/* The page name remains the foreground anchor in both states; the live filters are @@ -1880,27 +1865,24 @@ function PullRequestsColumn({ )}
{condensed ? ( - { - topbarSearchFocusedRef.current = focused; - }} - /> +
+ { + topbarSearchFocusedRef.current = focused; + }} + /> + +
) : null} - - {rightPanelControl} -
+ {rightPanelControl ? ( + {rightPanelControl} + ) : null} +
+
{searchInput} {filtersMenu} + {!condensed ? ( + + ) : null}
{/* Scrolled past this marker, the controls are gone and the title takes over. */}
{listBody} -
+
); } + +function PullRequestRefreshControl({ + compact = false, + refreshing, + onRefresh, +}: { + compact?: boolean; + refreshing: boolean; + onRefresh: () => void; +}) { + return ( + + ); +}