fix(web): stabilize pull request loading layout (#12721)

Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
oliverandJulius Marminge authored and GitHub committed 2026-09-20 13:25:46 -07:00
1 parent 9f0c9f725d
commit 6a699f0f2f
6 files changed
+419 -214

No files matched your search

@@ -0,0 +1,66 @@
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
import { cn } from "~/lib/utils";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
export function PullRequestCopyableCode({
value,
target,
copyLabel,
copiedLabel,
className,
tooltipSide = "top",
onError,
}: {
readonly value: string;
readonly target: string;
readonly copyLabel: string;
readonly copiedLabel: string;
readonly className?: string;
readonly tooltipSide?: "top" | "bottom";
readonly onError?: (error: Error) => void;
}) {
const { copyToClipboard, isCopied } = useCopyToClipboard({
target,
timeout: 1600,
...(onError ? { onError } : {}),
});
return (
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
className={cn(
"relative grid w-fit min-w-0 max-w-full shrink cursor-pointer rounded px-1 py-0.5 text-left outline-none transition-colors pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:bg-accent/45 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
className,
)}
aria-label={isCopied ? copiedLabel : copyLabel}
onClick={() => copyToClipboard(value)}
/>
}
>
<code
className={cn(
"col-start-1 row-start-1 min-w-0 truncate transition-opacity duration-150 motion-reduce:transition-none",
isCopied ? "opacity-0" : "opacity-100",
)}
>
{value}
</code>
<span
aria-hidden="true"
className={cn(
"col-start-1 row-start-1 truncate text-center transition-opacity duration-150 motion-reduce:transition-none",
isCopied ? "opacity-100" : "opacity-0",
)}
>
Copied
</span>
</TooltipTrigger>
<TooltipPopup className="max-w-96 wrap-anywhere font-mono" side={tooltipSide}>
{`${isCopied ? "Copied" : copyLabel}: ${value}`}
</TooltipPopup>
</Tooltip>
);
}
@@ -121,6 +121,7 @@ import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
import { toastManager } from "../ui/toast";
import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "../ui/tooltip";
import { PullRequestDetailGhost, PullRequestTimelineGhost } from "./PullRequestGhosts";
import { PullRequestCopyableCode } from "./PullRequestCopyableCode";
import { PullRequestActivityUnavailableState } from "./PullRequestActivityUnavailableState";
import { DiffPanelLoadingState } from "../DiffPanelShell";
import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
@@ -140,6 +141,7 @@ import {
handoffPrompt,
handoffReviewComments,
latestPullRequestReviewOutcomes,
loadingPullRequestCheckoutCommand,
isStackedPullRequestBase,
pullRequestActionMenuHasGroup,
pullRequestActionNeedsHostRefresh,
@@ -326,68 +328,6 @@ const openNumberContextMenu = (
});
};
function PullRequestCopyableCode({
value,
target,
copyLabel,
copiedLabel,
className,
tooltipSide = "top",
onError,
}: {
readonly value: string;
readonly target: string;
readonly copyLabel: string;
readonly copiedLabel: string;
readonly className?: string;
readonly tooltipSide?: "top" | "bottom";
readonly onError?: (error: Error) => void;
}) {
const { copyToClipboard, isCopied } = useCopyToClipboard({
target,
timeout: 1600,
...(onError ? { onError } : {}),
});
return (
<Tooltip>
<TooltipTrigger
render={
<button
type="button"
className={cn(
"relative grid w-fit min-w-0 max-w-full shrink cursor-pointer rounded px-1 py-0.5 text-left outline-none transition-colors pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:bg-accent/45 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
className,
)}
aria-label={isCopied ? copiedLabel : copyLabel}
onClick={() => copyToClipboard(value)}
/>
}
>
<code
className={cn(
"col-start-1 row-start-1 min-w-0 truncate transition-opacity duration-150 motion-reduce:transition-none",
isCopied ? "opacity-0" : "opacity-100",
)}
>
{value}
</code>
<span
aria-hidden="true"
className={cn(
"col-start-1 row-start-1 truncate text-center transition-opacity duration-150 motion-reduce:transition-none",
isCopied ? "opacity-100" : "opacity-0",
)}
>
Copied
</span>
</TooltipTrigger>
<TooltipPopup className="max-w-96 wrap-anywhere font-mono" side={tooltipSide}>
{`${isCopied ? "Copied" : copyLabel}: ${value}`}
</TooltipPopup>
</Tooltip>
);
}
/**
* The stale-branch warning, said beside the branch it is about rather than as a bar of its own.
* The banner this replaces held a row of chrome open across the top of every pull request that
@@ -804,15 +744,22 @@ export function PullRequestDetailPanel({
repositoryUrl !== null
? new URL(`/${encodeURIComponent(detail.author.login)}`, repositoryUrl).toString()
: null;
const checkoutCommand = detail
const checkoutCommand = handoffSummary
? pullRequestCheckoutCommand(
detail.provider,
detail.number,
detail.headBranch,
detail.headRepositoryNameWithOwner,
repositoryUrl,
handoffSummary.provider,
handoffSummary.number,
handoffSummary.headBranch,
detail?.headRepositoryNameWithOwner,
changeRequestRepositoryUrl(handoffSummary.url),
)
: null;
: loadingPullRequestCheckoutCommand(reference, repositoryIdentity);
const onCheckoutCommandError = useCallback((error: Error) => {
toastManager.add({
type: "error",
title: "Could not copy checkout command",
description: error.message,
});
}, []);
const branchRefsQuery = useEnvironmentQuery(
detail === null
? null
@@ -1475,8 +1422,9 @@ export function PullRequestDetailPanel({
// Out of date with the base, and still cleanly mergeable — the one pairing an update button
// exists for. Null everywhere else, including hosts that cannot compare at all.
const freshness = detail === null ? null : resolveBaseFreshness(detail);
// A host that cannot produce a patch has no Code tab to open. The tabs themselves stay hidden
// until the detail arrives, so the loading ghost is the panel's only unfinished UI.
// A host that cannot produce a patch has no Code tab to open. While detail is loading the ghost
// uses this optimistic tab set to reserve the same chrome; a host without a patch removes Code
// when its capabilities arrive.
const visibleTabs = TABS.filter(
(item) => item.value !== "code" || detail === null || detail.capabilities.diff,
);
@@ -1664,6 +1612,13 @@ export function PullRequestDetailPanel({
<PullRequestDetailGhost
seed={matchingListEntry}
summary={sharedSummary}
checkoutCommand={checkoutCommand}
onCheckoutError={onCheckoutCommandError}
number={reference.number}
tabs={visibleTabs}
activeTab={tab}
{...(onBack ? { onBack } : {})}
{...(onClose ? { onClose } : {})}
actions={
handoffSummary ? (
<TooltipProvider delay={150} closeDelay={150} timeout={400}>
@@ -2371,7 +2326,7 @@ export function PullRequestDetailPanel({
{detail ? (
<div className="col-span-2 mt-1 min-w-0 px-4 pb-4">
{titleDraft === null ? (
<div className="group flex min-w-0 items-center gap-1">
<div className="group flex min-h-7 min-w-0 items-center gap-1 sm:min-h-6">
<Tooltip>
<TooltipTrigger
render={
@@ -2432,7 +2387,7 @@ export function PullRequestDetailPanel({
</div>
</div>
)}
<div className="mt-2 flex min-w-0 items-center gap-2 text-xs text-muted-foreground">
<div className="mt-2 flex min-h-5 min-w-0 items-center gap-2 text-xs text-muted-foreground">
<PullRequestMetaLine className="min-w-0 whitespace-nowrap">
<PullRequestActorLabel
actor={detail.author}
@@ -2450,18 +2405,12 @@ export function PullRequestDetailPanel({
copiedLabel="Checkout command copied"
className="ml-auto font-mono"
tooltipSide="bottom"
onError={(error) =>
toastManager.add({
type: "error",
title: "Could not copy checkout command",
description: error.message,
})
}
onError={onCheckoutCommandError}
/>
) : null}
</div>
<div className="mt-4 flex min-w-0 items-center gap-2 text-xs text-muted-foreground">
<div className="mt-4 flex min-h-5 min-w-0 items-center gap-2 text-xs text-muted-foreground">
<span className="flex min-w-0 flex-1 items-center gap-1.5 font-mono text-xs text-muted-foreground/70">
<Tooltip>
<TooltipTrigger
@@ -2504,7 +2453,7 @@ export function PullRequestDetailPanel({
/>
</span>
<span className="ml-auto inline-flex shrink-0 items-center justify-end gap-2">
<span className="inline-flex items-center gap-1.5 tabular-nums">
<span className="inline-flex min-w-16 items-center justify-end gap-1.5 tabular-nums">
<FileDiffIcon className="size-3.5" />
{detail.changedFiles.toLocaleString()}{" "}
{detail.changedFiles === 1 ? "file" : "files"}
@@ -8,16 +8,31 @@
* number of bars costs one opacity animation.
*/
import type { PullRequestListEntry, PullRequestSummary } from "@t3tools/contracts";
import { ArrowLeftIcon } from "lucide-react";
import {
ArrowLeftIcon,
ChevronRightIcon,
EllipsisIcon,
ExternalLinkIcon,
FileDiffIcon,
PanelRightIcon,
TagIcon,
UserPlusIcon,
UsersIcon,
} from "lucide-react";
import type { ReactNode } from "react";
import { readLocalApi } from "~/localApi";
import { cn } from "~/lib/utils";
import { formatRelativeTimeLabel } from "~/timestampFormat";
import { Button, InlineButton } from "../ui/button";
import { Toggle, ToggleGroup } from "../ui/toggle-group";
import { PullRequestCopyableCode } from "./PullRequestCopyableCode";
import { pullRequestLabelColor } from "./pullRequestList.logic";
import {
PullRequestActorLabel,
PullRequestDiffStat,
PullRequestMetaLine,
pullRequestChecksStatePresentation,
resolvePullRequestState,
} from "./pullRequestPresentation";
@@ -29,6 +44,11 @@ function GhostBar({ className }: { className?: string | undefined }) {
/** Widths cycle rather than randomize, so the ghost renders the same on every pass. */
const TITLE_WIDTHS = ["w-3/5", "w-2/5", "w-1/2", "w-2/3", "w-2/5", "w-3/5", "w-1/2"];
const META_WIDTHS = ["w-2/5", "w-1/3", "w-2/5", "w-1/4", "w-1/3", "w-2/5", "w-1/3"];
const DEFAULT_DETAIL_TABS = [
{ value: "summary", label: "Summary" },
{ value: "timeline", label: "Timeline" },
{ value: "code", label: "Code" },
] as const;
/** Rows in the list's own grid — glyph, title over meta, time over diffstat. */
export function PullRequestListGhost({
@@ -77,10 +97,25 @@ export function PullRequestDetailGhost({
seed: entry,
summary,
actions,
checkoutCommand,
tabs = DEFAULT_DETAIL_TABS,
activeTab,
number,
onBack,
onClose,
onCheckoutError,
}: {
seed?: PullRequestListEntry | null;
summary?: PullRequestSummary | null;
actions?: ReactNode;
checkoutCommand?: string | null;
tabs?: ReadonlyArray<{ value: string; label: string }>;
/** The panel's current tab, so the highlight does not jump when the detail arrives. */
activeTab?: string;
number?: number;
onBack?: (() => void) | undefined;
onClose?: (() => void) | undefined;
onCheckoutError?: ((error: Error) => void) | undefined;
}) {
const seed = summary
? {
@@ -100,6 +135,10 @@ export function PullRequestDetailGhost({
seed?.checksState === "failing" || seed?.checksState === "pending"
? pullRequestChecksStatePresentation(seed.checksState)
: null;
const checkout = checkoutCommand ?? null;
const changedFiles = summary?.changedFiles ?? null;
const selectedTab =
tabs.find((item) => item.value === activeTab)?.value ?? tabs[0]?.value ?? "summary";
return (
<div
@@ -110,100 +149,178 @@ export function PullRequestDetailGhost({
!seed && "motion-safe:animate-skeleton",
)}
>
<div className="@container/pr-header shrink-0 border-b border-border/60">
<div className="flex h-7 items-center justify-between gap-3 px-4">
<div className="flex min-w-0 flex-1 items-center gap-1.5">
{seed && statePresentation ? (
<div className="@container/pr-header grid min-w-0 shrink-0 grid-cols-[minmax(0,1fr)_auto] items-start gap-x-2 border-b border-border/60">
<div className="pl-4 grid h-7 min-w-0 items-center overflow-hidden">
<div className="flex min-w-0 items-center gap-1 text-sm text-muted-foreground sm:text-xs">
{onBack ? (
<Button
size="icon-micro"
variant="ghost-muted"
className="-ml-1.5"
onClick={onBack}
aria-label="Back to this thread's pull requests"
>
<ArrowLeftIcon aria-hidden className="size-3.5" />
</Button>
) : null}
{seed ? (
<>
<span className="min-w-0 truncate text-xs font-medium text-muted-foreground">
{seed.repository}
</span>
<span
className={cn("shrink-0 text-xs font-medium", statePresentation.toneClassName)}
<span className="min-w-0 truncate font-medium">{seed.repository}</span>
<InlineButton
onClick={() => void readLocalApi()?.shell.openExternal(seed.url)}
className={cn(
"font-medium underline-offset-2 hover:underline",
statePresentation?.toneClassName,
)}
aria-label={`Open pull request #${seed.number} on host`}
>
#{seed.number}
</span>
<ExternalLinkIcon aria-hidden className="size-2.5" />
</InlineButton>
</>
) : (
<>
<GhostBar className="w-24" />
<GhostBar className="w-9" />
<span className="shrink-0 text-xs text-muted-foreground">#{number ?? "…"}</span>
</>
)}
</div>
<div className="flex shrink-0 items-center gap-1">
{actions ?? <GhostBar className="h-5 w-16 rounded-md" />}
<GhostBar className="size-6 rounded-md" />
</div>
</div>
<div className="mr-4 flex h-7 shrink-0 items-center justify-end gap-1">
{actions ?? <GhostBar className="h-6 w-16 rounded-md" />}
<Button size="icon-xs" variant="ghost" disabled aria-label="Pull request actions loading">
<EllipsisIcon aria-hidden className="size-4" />
</Button>
{onClose ? (
<Button
size="icon-xs"
variant="ghost"
aria-label="Collapse pull request panel"
onClick={onClose}
>
<PanelRightIcon aria-hidden className="size-3.5" />
</Button>
) : null}
</div>
<div className="px-4 pb-4 pt-1">
{seed ? (
<h1 className="truncate text-base font-semibold leading-snug">{seed.title}</h1>
) : (
<GhostBar className="h-5 w-4/5 max-w-md" />
)}
<div className="mt-2 flex items-center gap-1.5">
{seed ? (
<>
<PullRequestActorLabel
actor={seed.author ?? null}
className="font-medium"
tooltip={false}
/>
<span className="text-xs text-muted-foreground">
updated {formatRelativeTimeLabel(seed.updatedAt)}
</span>
</>
) : (
<>
<GhostBar className="size-4 rounded-full" />
<GhostBar className="w-24" />
</>
)}
</div>
<div className="mt-4 flex min-w-0 items-center gap-2">
{seed ? (
<span className="flex min-w-0 flex-1 items-center gap-1.5 font-mono text-xs text-muted-foreground/70">
<code className="min-w-0 max-w-[40%] shrink-0 truncate">{seed.baseBranch}</code>
<ArrowLeftIcon
aria-label="receives changes from"
className="size-3.5 shrink-0 opacity-60"
/>
<code className="min-w-0 flex-1 truncate">{seed.headBranch}</code>
</span>
) : (
<>
<GhostBar className="h-6 w-24 rounded-md" />
<GhostBar className="size-3 rounded-full" />
<GhostBar className="h-6 w-32 rounded-md" />
</>
)}
<div className="ml-auto flex shrink-0 items-center gap-2">
<GhostBar className="w-10" />
<div className="col-span-2 grid grid-rows-[1fr]">
<div className="min-h-0 overflow-hidden">
<div className="col-span-2 mt-1 min-w-0 px-4 pb-4">
{seed ? (
<PullRequestDiffStat
additions={seed.additions ?? 0}
deletions={seed.deletions ?? 0}
className="font-mono text-xs"
/>
<div className="flex min-h-7 min-w-0 items-center sm:min-h-6">
<h1 className="truncate text-base font-semibold leading-snug">{seed.title}</h1>
</div>
) : (
<GhostBar className="w-20" />
<div className="flex min-h-7 min-w-0 items-center sm:min-h-6">
<GhostBar className="h-5 w-4/5 max-w-md" />
</div>
)}
<div className="mt-2 flex min-h-5 min-w-0 items-center gap-2 text-xs text-muted-foreground">
{seed ? (
<PullRequestMetaLine className="min-w-0 whitespace-nowrap">
<PullRequestActorLabel
actor={seed.author ?? null}
className="font-medium"
tooltip={false}
/>
<span>updated {formatRelativeTimeLabel(seed.updatedAt)}</span>
</PullRequestMetaLine>
) : (
<PullRequestMetaLine className="min-w-0 whitespace-nowrap">
<span className="flex items-center gap-1.5">
<GhostBar className="size-4 rounded-full" />
<GhostBar className="h-3 w-14" />
</span>
<GhostBar className="h-3 w-16" />
</PullRequestMetaLine>
)}
{checkout ? (
<PullRequestCopyableCode
key={checkout}
value={checkout}
target="pull request checkout command"
copyLabel="Copy checkout command"
copiedLabel="Checkout command copied"
className="ml-auto font-mono"
tooltipSide="bottom"
{...(onCheckoutError ? { onError: onCheckoutError } : {})}
/>
) : null}
</div>
<div className="mt-4 flex min-h-5 min-w-0 items-center gap-2 text-xs text-muted-foreground">
<span className="flex min-w-0 flex-1 items-center gap-1.5 font-mono text-xs text-muted-foreground/70">
{seed ? (
<span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1">
<code className="min-w-0 truncate">{seed.baseBranch}</code>
</span>
) : (
<span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1">
<GhostBar className="h-3 w-12" />
</span>
)}
<ArrowLeftIcon
aria-label="receives changes from"
className="size-3.5 shrink-0 opacity-60"
/>
{seed ? (
<PullRequestCopyableCode
key={seed.headBranch}
value={seed.headBranch}
target="branch name"
copyLabel="Copy pull request branch"
copiedLabel="Branch name copied"
className="min-w-0 font-mono"
/>
) : (
<GhostBar className="h-3 w-32 flex-1" />
)}
</span>
<span className="ml-auto inline-flex shrink-0 items-center justify-end gap-2">
<span className="inline-flex min-w-16 items-center justify-end gap-1.5 tabular-nums">
<FileDiffIcon aria-hidden className="size-3.5" />
{changedFiles === null ? (
<GhostBar className="h-3 w-10" />
) : (
`${changedFiles.toLocaleString()} ${changedFiles === 1 ? "file" : "files"}`
)}
</span>
{seed ? (
<PullRequestDiffStat
additions={seed.additions ?? 0}
deletions={seed.deletions ?? 0}
className="shrink-0 font-mono text-xs"
/>
) : (
<GhostBar className="h-3 w-20" />
)}
</span>
</div>
</div>
</div>
</div>
<div className="flex min-h-10 items-center justify-between gap-3 border-t border-border/60 px-4 py-2">
<div className="flex items-center gap-1 p-0.5">
<GhostBar className="h-6 w-16 rounded-md" />
<GhostBar className="h-6 w-16 rounded-md" />
<GhostBar className="h-6 w-12 rounded-md" />
</div>
<nav
className="col-span-2 flex min-w-0 flex-wrap items-center gap-2 border-t border-border/60 px-4 py-2"
aria-label="Pull request tabs"
inert
>
<ToggleGroup
className="shrink-0"
size="segmented"
variant="segmented"
value={[selectedTab]}
>
{tabs.map((tab) => (
<Toggle key={tab.value} value={tab.value} tabIndex={-1}>
{tab.label}
</Toggle>
))}
</ToggleGroup>
{checksPresentation ? (
<span
className={cn(
"inline-flex items-center gap-1.5 text-xs",
"ml-auto inline-flex items-center gap-1.5 text-xs",
checksPresentation.toneClassName,
)}
>
@@ -211,74 +328,85 @@ export function PullRequestDetailGhost({
{checksPresentation.label}
</span>
) : (
<GhostBar className="w-20" />
<GhostBar className="ml-auto h-3 w-32" />
)}
</div>
</nav>
</div>
<div className="min-h-0 flex-1 overflow-hidden">
<section className="px-4 py-3">
<div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
<div className="flex items-center gap-1.5">
<GhostBar className="size-3.5 rounded-full" />
<GhostBar className="w-14" />
<section className="px-4 pt-2.5 pb-1">
<div className="space-y-2">
<div className="grid min-h-7 min-w-0 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2 text-xs sm:min-h-6">
<span className="flex items-center gap-1.5 text-muted-foreground">
<UsersIcon aria-hidden className="size-3.5" />
Reviewers
</span>
<span className="flex min-w-0 items-center gap-1.5 text-foreground">
<GhostBar className="h-3 w-10" />
<Button size="icon-xs" variant="ghost" disabled aria-label="Reviewers loading">
<UserPlusIcon aria-hidden className="size-3.5" />
</Button>
</span>
</div>
<div className="flex items-center gap-1">
<GhostBar className="size-4 rounded-full" />
<GhostBar className="size-4 rounded-full" />
<GhostBar className="ml-1 size-5 rounded-md" />
<div className="grid min-h-7 min-w-0 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2 text-xs sm:min-h-6">
<span className="flex items-center gap-1.5 text-muted-foreground">
<TagIcon aria-hidden className="size-3.5" />
Labels
</span>
<span className="flex min-w-0 flex-wrap items-center gap-1 text-foreground">
{entry?.labels ? (
entry.labels.length > 0 ? (
entry.labels.map((label) => {
const color = pullRequestLabelColor(label.color);
return (
<span
key={label.name}
className="inline-flex max-w-48 items-center gap-1.5 truncate rounded-full bg-muted/40 py-0.5 pl-1.5 pr-2 text-xs"
>
<span
aria-hidden
className="size-2 shrink-0 rounded-full bg-muted-foreground"
{...(color ? { style: { backgroundColor: color } } : {})}
/>
<span className="truncate">{label.name}</span>
</span>
);
})
) : (
<span className="text-muted-foreground">None</span>
)
) : (
<>
<GhostBar className="h-4 w-24 rounded-full" />
<GhostBar className="h-4 w-20 rounded-full" />
</>
)}
<Button size="icon-xs" variant="ghost" disabled aria-label="Labels loading">
<TagIcon aria-hidden className="size-3.5" />
</Button>
</span>
</div>
</div>
<div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
<div className="flex items-center gap-1.5">
<GhostBar className="size-3.5 rounded-full" />
<GhostBar className="w-10" />
</div>
<div className="flex items-center gap-1">
{seed?.labels ? (
seed.labels.slice(0, 3).map((label) => {
const color = pullRequestLabelColor(label.color);
return (
<span
key={label.name}
className="inline-flex h-5 max-w-32 items-center gap-1 truncate rounded-full border border-border/70 bg-muted/40 px-2 text-[10px] text-muted-foreground"
>
<span
aria-hidden
className="size-2 shrink-0 rounded-full bg-muted-foreground"
{...(color ? { style: { backgroundColor: color } } : {})}
/>
<span className="truncate">{label.name}</span>
</span>
);
})
) : (
<>
<GhostBar className="h-5 w-24 rounded-full" />
<GhostBar className="h-5 w-20 rounded-full" />
</>
)}
</div>
</div>
<div className="grid min-h-8 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2">
<div className="flex items-center gap-1.5">
<GhostBar className="size-3.5 rounded-full" />
<GhostBar className="w-14" />
</div>
<GhostBar className="w-20" />
</div>
</section>
<section className="border-t border-border/60">
<div className="flex min-h-11 items-center gap-1.5 px-4 py-3">
<GhostBar className="h-4 w-24" />
<GhostBar className="size-3.5 rounded-full" />
<section>
<div className="sticky top-0 z-10 flex w-full items-center bg-background pr-4">
<div className="flex min-w-0 flex-1 items-center gap-1.5 px-4 py-3 text-left text-xs font-medium text-muted-foreground">
<span>Description</span>
<ChevronRightIcon
aria-hidden
className="size-3.5 rotate-90 text-muted-foreground/60"
/>
</div>
</div>
<div className="space-y-2 px-4 pb-4">
<GhostBar className="w-full" />
<GhostBar className="w-11/12" />
<GhostBar className="w-4/5" />
<GhostBar className="w-2/3" />
<div className="space-y-3 px-4 pb-4">
<GhostBar className="h-5 w-40" />
<div className="space-y-2">
<GhostBar className="h-4 w-full" />
<GhostBar className="h-4 w-11/12" />
<GhostBar className="h-4 w-4/5" />
<GhostBar className="h-4 w-2/3" />
</div>
</div>
</section>
</div>
@@ -275,7 +275,7 @@ function MetaRow({
children: ReactNode;
}) {
return (
<div className="grid min-w-0 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2 text-xs">
<div className="grid min-h-7 min-w-0 grid-cols-[6rem_minmax(0,1fr)] items-center gap-2 text-xs sm:min-h-6">
<span className="flex items-center gap-1.5 text-muted-foreground">
{icon}
{label}
@@ -7,7 +7,9 @@ import {
type PullRequestComment,
type PullRequestDetail,
type PullRequestDetailView,
type PullRequestRef,
type PullRequestReviewThread,
type RepositoryIdentity,
type ThreadPullRequestLink,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
@@ -27,6 +29,7 @@ import {
stripPullRequestHandoffReferences,
isPullRequestVerdictStale,
isStackedPullRequestBase,
loadingPullRequestCheckoutCommand,
pullRequestPanelContext,
latestPullRequestReviewOutcomes,
newestPullRequestCommitAt,
@@ -94,6 +97,49 @@ describe("pull request checkout commands", () => {
"git fetch 'https://forgejo.local/maria/repo'\\''$(echo nope)' refs/pull/42/head && git checkout -B pulls/42 FETCH_HEAD",
);
});
const reference = (host?: string): PullRequestRef => ({
projectId: ProjectId.make("project-1"),
...(host === undefined ? {} : { host }),
repository: "acme/web",
number: 42,
});
const identity = (provider: string, canonicalKey: string): RepositoryIdentity => ({
canonicalKey,
locator: {
source: "git-remote",
remoteName: "origin",
remoteUrl: "[email protected]:acme/web.git",
},
provider,
});
it("uses a public host when no repository identity is available", () => {
expect(loadingPullRequestCheckoutCommand(reference("github.com"), undefined)).toBe(
"gh pr checkout 42",
);
expect(loadingPullRequestCheckoutCommand(reference("gitlab.com"), null)).toBe(
"glab mr checkout 42",
);
});
it("uses a matching enterprise identity and rejects an explicit host mismatch", () => {
const enterprise = identity("github", "github.example.test/acme/web");
expect(loadingPullRequestCheckoutCommand(reference("github.example.test"), enterprise)).toBe(
"gh pr checkout 42",
);
expect(loadingPullRequestCheckoutCommand(reference("github.com"), enterprise)).toBeNull();
});
it("does not infer a number-only command without a trusted provider", () => {
expect(loadingPullRequestCheckoutCommand(reference(), undefined)).toBeNull();
expect(
loadingPullRequestCheckoutCommand(
reference("github.com"),
identity("gitlab", "gitlab.com/acme/web"),
),
).toBeNull();
});
});
const TIMELINE_SOURCE: Pick<
@@ -140,6 +140,22 @@ export function pullRequestCheckoutCommand(
}
}
/** Build a checkout command from identity metadata while the detail request is still pending. */
export function loadingPullRequestCheckoutCommand(
reference: PullRequestRef,
identity: RepositoryIdentity | null | undefined,
): string | null {
const host = reference.host?.trim().toLowerCase();
const provider =
identity?.provider ??
(host === "github.com" ? "github" : host === "gitlab.com" ? "gitlab" : null);
if (provider !== "github" && provider !== "gitlab" && provider !== "azure-devops") return null;
if (identity?.provider !== undefined && host && pullRequestHostOf(identity, provider) !== host) {
return null;
}
return pullRequestCheckoutCommand(provider, reference.number, "");
}
/** Activity changes only when the same host resource reports a newer revision. */
export function shouldRefreshPullRequestActivity(
previous: { readonly key: string; readonly updatedAt: string } | null,