feat(web): prioritize pull request row actions

- Add conflict, draft, failing-check, and merge action ranking
- Show check progress and pull request details in row tooltips
This commit is contained in:
Julius Marminge committed 2026-08-15 16:51:44 +02:00
1 parent c3c01cba3d
commit 0e370e7521
3 files changed
+363 -71

No files matched your search

@@ -3,17 +3,19 @@
* thing worth doing to it right now.
*
* The row itself opens the pull request in the right panel, exactly as it always has. Around
* that, the host's richer answer — draft, mergeable, conflicting — turns into at most one
* trailing action ("Ready" on a clean draft, "Merge" on a mergeable branch) and a conflict line
* below when the branch cannot merge. All of it runs through the same hooks as the detail panel,
* so the row can never offer something the panel would refuse.
* that, the host's richer answer collapses into a single trailing slot, ranked by what unblocks
* the merge next: "Resolve" on conflicts, "Ready" on a draft, "Fix" under failing checks, and
* "Merge" only once the branch is clean and its checks pass. While checks run the slot reports
* that instead — a merge offered mid-run would race the very runs that gate it. Everything else
* the host knows (title, state, checks tally, diff size) lives in the row's tooltip, so a hover
* answers what previously took opening the panel.
*
* Until the detail arrives — or where pull requests are not supported at all — the row renders
* from the `vcs.status` summary alone, which is the plain row this panel showed before.
*/
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
import type { EnvironmentId, ProjectId, PullRequestRef } from "@t3tools/contracts";
import { ArrowUpRightIcon, TriangleAlertIcon } from "lucide-react";
import { ArrowUpRightIcon, FileDiffIcon, GitBranchIcon, TriangleAlertIcon } from "lucide-react";
import { useState, type MouseEvent as ReactMouseEvent } from "react";
import { cn } from "~/lib/utils";
@@ -22,13 +24,20 @@ import { pullRequestEnvironment } from "~/state/pullRequests";
import { useEnvironmentQuery } from "~/state/query";
import {
allowedPullRequestMergeMethods,
buildFixFindingsHandoff,
buildResolveConflictsPrompt,
classifyPullRequestChecks,
describePullRequestChecks,
isPullRequestConflicting,
resolvePullRequestPrimaryAction,
resolveSelectedMergeMethod,
allowedPullRequestMergeMethods,
resolveThreadPanelPullRequestAction,
} from "../pullRequest/pullRequestDetail.logic";
import { resolvePullRequestState } from "../pullRequest/pullRequestPresentation";
import {
PullRequestCheckStatusIcon,
PullRequestDiffStat,
resolvePullRequestState,
} from "../pullRequest/pullRequestPresentation";
import {
usePullRequestActionRunner,
usePullRequestHandoffs,
@@ -107,8 +116,10 @@ export function ThreadDetailsPrRow({
const { handoff, startHandoff } = usePullRequestHandoffs({ environmentId, detail });
const [confirmingMerge, setConfirmingMerge] = useState(false);
const primaryAction = resolvePullRequestPrimaryAction(detail);
const rowAction = resolveThreadPanelPullRequestAction(detail);
const conflicting = isPullRequestConflicting(detail);
const checksState = detail === null ? "none" : classifyPullRequestChecks(detail.checks);
const checksRunning = detail?.state === "open" && rowAction === null && checksState === "pending";
const selectedMergeMethod = resolveSelectedMergeMethod(
allowedPullRequestMergeMethods(detail),
"merge",
@@ -126,11 +137,37 @@ export function ThreadDetailsPrRow({
});
};
// Once the host has answered, the glyph knows about drafts, which the vcs summary does not.
const startFixChecks = () => {
if (detail === null) return;
// The compact row fetches no conversation, so the handoff carries the failing checks alone;
// review threads keep arriving through the full panel's richer version of this action.
void startHandoff(
"findings",
buildFixFindingsHandoff({
number: detail.number,
title: detail.title,
url: detail.url,
headBranch: detail.headBranch,
baseBranch: detail.baseBranch,
reviewThreads: [],
comments: [],
checks: detail.checks,
commentsTruncated: false,
}),
);
};
// Once the host has answered, the glyph knows about drafts and conflicts, which the vcs
// summary does not. Draft outranks conflicts in it, same as the detail panel.
const statePresentation =
detail === null
? null
: resolvePullRequestState({ state: detail.state, isDraft: detail.isDraft });
: resolvePullRequestState({
state: detail.state,
isDraft: detail.isDraft,
mergeability: detail.mergeability,
baseBranch: detail.baseBranch,
});
const icon = statePresentation ? (
<statePresentation.Icon
aria-hidden
@@ -140,22 +177,118 @@ export function ThreadDetailsPrRow({
<ChangeRequestStatusIcon className={cn(THREAD_DETAILS_PANEL_ICON_CLASS, status.colorClass)} />
);
// Everything the host reported, at a glance. The row stays one line; the tooltip is where the
// rest of the answer lives — styled like the sidebar's thread tooltip, title above icon-led
// detail rows, so the two read as one family.
const rowTooltip =
detail === null || statePresentation === null ? (
<TooltipPopup side="top">{status.tooltip}</TooltipPopup>
) : (
<TooltipPopup
side="top"
align="start"
sideOffset={4}
variant="glass"
className="max-w-80 text-left whitespace-normal [&_[data-slot=tooltip-viewport]]:p-0"
>
<div className="flex min-w-0 max-w-80 flex-col gap-2 p-[var(--floating-content-inset)]">
<div className="flex min-w-0 items-baseline gap-1.5 text-xs leading-none">
<span className="min-w-0 truncate font-medium text-foreground">{detail.title}</span>
<span className="shrink-0 text-muted-foreground">#{detail.number}</span>
</div>
<div className="grid gap-1.5 pl-0.5 text-xs text-muted-foreground">
<div className="flex min-w-0 items-center gap-2">
<statePresentation.Icon
aria-hidden
className={cn("size-3 shrink-0", statePresentation.toneClassName)}
/>
<div className="min-w-0 truncate text-foreground/75">{statePresentation.label}</div>
</div>
<div className="flex min-w-0 items-center gap-2">
<GitBranchIcon className="size-3 shrink-0 stroke-muted-foreground" />
<div className="min-w-0 truncate text-foreground/75">
{detail.baseBranch} ← {detail.headBranch}
</div>
</div>
{detail.state === "open" && checksState !== "none" ? (
<div className="flex min-w-0 items-center gap-2">
<PullRequestCheckStatusIcon
status={
checksState === "failing"
? "failure"
: checksState === "pending"
? "pending"
: "success"
}
/>
<div className="min-w-0 truncate text-foreground/75">
{describePullRequestChecks(detail.checks)}
</div>
</div>
) : null}
{detail.isDraft && conflicting ? (
<div className="flex min-w-0 items-start gap-2 text-destructive">
<TriangleAlertIcon aria-hidden className="mt-0.5 size-3 shrink-0 stroke-current" />
<div className="min-w-0 flex-1 wrap-break-word leading-5">
Merge conflicts with {detail.baseBranch}
</div>
</div>
) : null}
<div className="flex min-w-0 items-center gap-2">
<FileDiffIcon className="size-3 shrink-0 stroke-muted-foreground" />
<div className="min-w-0 flex items-baseline gap-1 truncate text-foreground/75">
{detail.changedFiles.toLocaleString()}{" "}
{detail.changedFiles === 1 ? "file" : "files"}
<PullRequestDiffStat additions={detail.additions} deletions={detail.deletions} />
</div>
</div>
</div>
</div>
</TooltipPopup>
);
const trailingAction =
primaryAction === "ready"
rowAction === "resolve"
? {
label: "Ready",
pendingLabel: "Marking...",
tooltip: "Mark this pull request as ready for review",
onClick: () => void perform("ready"),
label: "Resolve",
pendingLabel: "Preparing...",
pending: handoff === "conflicts",
destructive: true,
suffix: <ArrowUpRightIcon aria-hidden className="size-3 shrink-0" />,
tooltip: "Check the branch out and resolve the conflicts in a new thread",
onClick: startResolveConflicts,
}
: primaryAction === "merge"
: rowAction === "ready"
? {
label: "Merge",
pendingLabel: "Merging...",
tooltip: `Merge this pull request (${selectedMergeMethod})`,
onClick: () => setConfirmingMerge(true),
label: "Ready",
pendingLabel: "Marking...",
pending: actionPending,
destructive: false,
suffix: null,
tooltip: "Mark this pull request as ready for review",
onClick: () => void perform("ready"),
}
: null;
: rowAction === "fix"
? {
label: "Fix",
pendingLabel: "Preparing...",
pending: handoff === "findings",
destructive: true,
suffix: <ArrowUpRightIcon aria-hidden className="size-3 shrink-0" />,
tooltip: "Fix the failing checks in a new thread",
onClick: startFixChecks,
}
: rowAction === "merge"
? {
label: "Merge",
pendingLabel: "Merging...",
pending: actionPending,
destructive: false,
suffix: null,
tooltip: `Merge this pull request (${selectedMergeMethod})`,
onClick: () => setConfirmingMerge(true),
}
: null;
const rowContent = (
<>
@@ -166,7 +299,7 @@ export function ThreadDetailsPrRow({
return (
<>
{trailingAction ? (
{trailingAction || checksRunning ? (
<div className={THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS}>
<Tooltip>
<TooltipTrigger
@@ -183,26 +316,53 @@ export function ThreadDetailsPrRow({
>
{rowContent}
</TooltipTrigger>
<TooltipPopup side="top">{status.tooltip}</TooltipPopup>
{rowTooltip}
</Tooltip>
<span aria-hidden="true" className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS} />
<Tooltip>
<TooltipTrigger
render={
<Button
type="button"
variant="ghost"
size="sm"
className={THREAD_DETAILS_PANEL_LINK_SPLIT_ACTION_CLASS}
disabled={actionPending}
onClick={trailingAction.onClick}
/>
}
>
{actionPending ? trailingAction.pendingLabel : trailingAction.label}
</TooltipTrigger>
<TooltipPopup side="top">{trailingAction.tooltip}</TooltipPopup>
</Tooltip>
{trailingAction ? (
<Tooltip>
<TooltipTrigger
render={
<Button
type="button"
variant="ghost"
size="sm"
className={cn(
THREAD_DETAILS_PANEL_LINK_SPLIT_ACTION_CLASS,
trailingAction.destructive &&
"text-destructive hover:text-destructive data-pressed:text-destructive",
)}
disabled={actionPending || handoff !== null}
onClick={trailingAction.onClick}
/>
}
>
{trailingAction.pending ? trailingAction.pendingLabel : trailingAction.label}
{trailingAction.suffix}
</TooltipTrigger>
<TooltipPopup side="top">{trailingAction.tooltip}</TooltipPopup>
</Tooltip>
) : (
// Checks are still running: the slot reports that instead of offering a merge that
// would race them. Not a button — there is nothing to press until they finish.
<Tooltip>
<TooltipTrigger
render={
<span className="flex h-9 shrink-0 cursor-default items-center gap-1.5 px-2.5 text-[13px] font-medium text-muted-foreground" />
}
>
<PullRequestCheckStatusIcon status="pending" />
<span className="tabular-nums">
{detail === null
? null
: `${detail.checks.filter((check) => check.status === "pending").length}/${detail.checks.length}`}
</span>
</TooltipTrigger>
<TooltipPopup side="top">
{detail ? describePullRequestChecks(detail.checks) : "Checks are running"}
</TooltipPopup>
</Tooltip>
)}
</div>
) : (
<Tooltip>
@@ -220,38 +380,10 @@ export function ThreadDetailsPrRow({
>
{rowContent}
</TooltipTrigger>
<TooltipPopup side="top">{status.tooltip}</TooltipPopup>
{rowTooltip}
</Tooltip>
)}
{conflicting ? (
// The same words the detail panel says, one click away, so the two read as one thing.
<div className="flex h-8 items-center gap-1.5 ps-2.5 pe-1">
<TriangleAlertIcon aria-hidden className="size-3.5 shrink-0 text-destructive" />
<span className="min-w-0 truncate text-xs font-medium text-destructive">
Merge conflicts
</span>
<Tooltip>
<TooltipTrigger
render={
<Button
size="xs"
variant="ghost"
className="ml-auto h-6 shrink-0 gap-1 px-1.5 text-xs text-destructive hover:bg-destructive/8 hover:text-destructive"
disabled={handoff !== null}
onClick={startResolveConflicts}
/>
}
>
{handoff === "conflicts" ? "Preparing..." : "Resolve"}
<ArrowUpRightIcon aria-hidden className="size-3 text-destructive" />
</TooltipTrigger>
<TooltipPopup side="top">
Check the branch out and resolve the conflicts in a new thread
</TooltipPopup>
</Tooltip>
</div>
) : null}
{primaryAction === "merge" ? (
{rowAction === "merge" ? (
<AlertDialog open={confirmingMerge} onOpenChange={(open) => setConfirmingMerge(open)}>
<AlertDialogPopup>
<AlertDialogHeader>
@@ -9,6 +9,9 @@ import { describe, expect, it } from "vite-plus/test";
import {
buildAskAboutLinesHandoff,
classifyPullRequestChecks,
describePullRequestChecks,
resolveThreadPanelPullRequestAction,
buildAskAboutPullRequestHandoff,
buildExplainPullRequestHandoff,
buildFixFindingHandoff,
@@ -944,3 +947,98 @@ describe("which actions need the host read again after they run", () => {
}
});
});
describe("the compact row's single action slot", () => {
const check = (status: PullRequestCheck["status"]): PullRequestCheck => ({
name: "ci",
status,
description: null,
url: null,
});
const openDetail = (
overrides: Partial<Parameters<typeof resolveThreadPanelPullRequestAction>[0] & object> = {},
) =>
({
state: "open",
isDraft: false,
mergeability: "mergeable",
capabilities: {
actions: ["merge", "ready", "draft", "close", "reopen"],
mergeMethods: ["merge", "squash"],
} as unknown as PullRequestDetailView["capabilities"],
viewerPermissions: {
actions: ["merge", "ready", "draft", "close", "reopen"],
} as unknown as PullRequestDetailView["viewerPermissions"],
mergeCapabilities: { merge: true, squash: true, rebase: false },
checks: [check("success")],
...overrides,
}) as NonNullable<Parameters<typeof resolveThreadPanelPullRequestAction>[0]>;
it("offers Merge only for a clean pull request whose checks pass", () => {
expect(resolveThreadPanelPullRequestAction(openDetail())).toBe("merge");
expect(resolveThreadPanelPullRequestAction(openDetail({ checks: [] }))).toBe("merge");
});
it("holds the slot while checks run rather than offering a merge that races them", () => {
expect(
resolveThreadPanelPullRequestAction(
openDetail({ checks: [check("success"), check("pending")] }),
),
).toBeNull();
});
it("ranks conflicts above everything, then draft, then failing checks", () => {
expect(
resolveThreadPanelPullRequestAction(
openDetail({ mergeability: "conflicting", isDraft: true, checks: [check("failure")] }),
),
).toBe("resolve");
expect(
resolveThreadPanelPullRequestAction(
openDetail({ isDraft: true, checks: [check("failure")] }),
),
).toBe("ready");
expect(
resolveThreadPanelPullRequestAction(
openDetail({ checks: [check("failure"), check("pending")] }),
),
).toBe("fix");
});
it("offers nothing the viewer may not do, and nothing on settled pull requests", () => {
expect(
resolveThreadPanelPullRequestAction(
openDetail({
viewerPermissions: {
actions: [],
} as unknown as PullRequestDetailView["viewerPermissions"],
}),
),
).toBeNull();
expect(resolveThreadPanelPullRequestAction(openDetail({ state: "merged" }))).toBeNull();
expect(resolveThreadPanelPullRequestAction(null)).toBeNull();
});
it("describes every live facet of the checks at once", () => {
expect(describePullRequestChecks([])).toBe("No checks reported");
expect(describePullRequestChecks([check("success"), check("success")])).toBe(
"All checks passed",
);
expect(describePullRequestChecks([check("success"), check("skipped")])).toBe("1 of 2 passing");
expect(
describePullRequestChecks([
...Array.from({ length: 7 }, () => check("pending")),
...Array.from({ length: 8 }, () => check("success")),
check("failure"),
]),
).toBe("7 of 16 running · 1 failed");
expect(describePullRequestChecks([check("failure"), check("success")])).toBe("1 of 2 failing");
});
it("reads the checks as one word, failing outranking running", () => {
expect(classifyPullRequestChecks([])).toBe("none");
expect(classifyPullRequestChecks([check("success"), check("skipped")])).toBe("passing");
expect(classifyPullRequestChecks([check("success"), check("pending")])).toBe("pending");
expect(classifyPullRequestChecks([check("pending"), check("cancelled")])).toBe("failing");
});
});
@@ -137,6 +137,68 @@ export function resolvePullRequestPrimaryAction(
return allowedPullRequestMergeMethods(detail).length > 0 ? "merge" : null;
}
/** The checks as one word. Failing outranks running: a red run is already worth acting on. */
export type PullRequestChecksState = "none" | "pending" | "failing" | "passing";
export function classifyPullRequestChecks(
checks: ReadonlyArray<PullRequestCheck>,
): PullRequestChecksState {
if (checks.length === 0) return "none";
if (checks.some((check) => check.status === "failure" || check.status === "cancelled")) {
return "failing";
}
if (checks.some((check) => check.status === "pending")) return "pending";
return "passing";
}
/**
* The checks with every live facet, unlike the single-facet summary: a run with failures in it
* still says how much is in flight — "7 of 16 running · 1 failed" — because both numbers change
* what a reader does next.
*/
export function describePullRequestChecks(checks: ReadonlyArray<PullRequestCheck>): string {
if (checks.length === 0) return "No checks reported";
const failed = checks.filter(
(check) => check.status === "failure" || check.status === "cancelled",
).length;
const pending = checks.filter((check) => check.status === "pending").length;
const passed = checks.filter((check) => check.status === "success").length;
const parts: string[] = [];
if (pending > 0) parts.push(`${pending} of ${checks.length} running`);
if (failed > 0) {
parts.push(pending > 0 ? `${failed} failed` : `${failed} of ${checks.length} failing`);
}
if (parts.length === 0) {
return passed === checks.length ? "All checks passed" : `${passed} of ${checks.length} passing`;
}
return parts.join(" · ");
}
export type ThreadPanelPullRequestAction = "resolve" | "ready" | "fix" | "merge";
/**
* Which single action the thread panel's compact pull request row offers, ranked by what
* unblocks the merge next: conflicts stop everything, a draft is not up for review yet, failing
* checks want fixing, and only a clean open pull request earns Merge. While checks run the slot
* stays empty — the row shows their progress instead of an action that would race them.
*/
export function resolveThreadPanelPullRequestAction(
detail: (PullRequestActionableDetail & Pick<PullRequestDetail, "checks">) | null,
): ThreadPanelPullRequestAction | null {
if (detail === null || detail.state !== "open") return null;
if (isPullRequestConflicting(detail)) return "resolve";
if (detail.isDraft) {
return canPerformPullRequestAction(detail, "ready") ? "ready" : null;
}
const checks = classifyPullRequestChecks(detail.checks);
if (checks === "failing") return "fix";
if (checks === "pending") return null;
return canPerformPullRequestAction(detail, "merge") &&
allowedPullRequestMergeMethods(detail).length > 0
? "merge"
: null;
}
/** Chronological ascending, oldest to newest — reversed for the "newest" reading order. */
export function orderPullRequestComments<T extends { readonly createdAt: string }>(
comments: ReadonlyArray<T>,