refactor(web): centralize pull request icon state presentation (#11144)

This commit is contained in:
oliver authored and GitHub committed 2026-09-16 12:58:34 -03:00
1 parent f45c6b4a75
commit e8ca3a8280
26 files changed
+628 -307

No files matched your search

+3 -3
View File
@@ -46,7 +46,6 @@ import {
FileSearchIcon,
FolderIcon,
FolderPlusIcon,
GitPullRequestArrowIcon,
LinkIcon,
MessageSquareIcon,
PaletteIcon,
@@ -181,6 +180,7 @@ import {
buildSidebarProjectSnapshots,
} from "../sidebarProjectGrouping";
import type { Project } from "../types";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
const EMPTY_BROWSE_ENTRIES: FilesystemBrowseResult["entries"] = [];
@@ -1712,7 +1712,7 @@ function OpenCommandPaletteDialog(props: {
value: "action:link-pull-request",
searchTerms: ["link", "pull request", "pr", "attach", "stack"],
title: "Link pull request to thread",
icon: <GitPullRequestArrowIcon className={ITEM_ICON_CLASS} />,
icon: <PullRequestGlyph.link className={ITEM_ICON_CLASS} />,
run: async () => {
openLinkPullRequestDialog(threadRef);
},
@@ -1724,7 +1724,7 @@ function OpenCommandPaletteDialog(props: {
searchTerms: ["pull requests", "linked", "stack", "prs"],
title: "Show linked pull requests",
disabled: visibleThreadPullRequests(activeThread.pullRequests).length === 0,
icon: <GitPullRequestArrowIcon className={ITEM_ICON_CLASS} />,
icon: <PullRequestGlyph.link className={ITEM_ICON_CLASS} />,
run: async () => {
useRightPanelStore.getState().open(threadRef, "pull-requests");
},
+2 -2
View File
@@ -1,5 +1,4 @@
import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";
import { GitPullRequestIcon } from "lucide-react";
import { resolveThreadCurrentPullRequestLink } from "@t3tools/shared/threadPullRequests";
import { Spinner } from "~/components/ui/spinner";
import {
@@ -214,6 +213,7 @@ import {
type SidebarProjectGroupMember,
type SidebarProjectSnapshot,
} from "../sidebarProjectGrouping";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
const SIDEBAR_SORT_LABELS: Record<SidebarProjectSortOrder, string> = {
updated_at: "Last user message",
created_at: "Created at",
@@ -757,7 +757,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
className="text-muted-foreground"
aria-label={`PR #${currentLinkedPr.number}, status pending`}
>
<GitPullRequestIcon className="size-3" />
<PullRequestGlyph.pullRequest className="size-3" />
</a>
) : null}
{threadStatus && <ThreadStatusLabel status={threadStatus} />}
+10 -10
View File
@@ -21,8 +21,6 @@ import {
ChevronRight,
FileDiff,
Files,
GitPullRequest,
GitPullRequestArrow,
Globe2,
Plus,
TerminalSquare,
@@ -73,6 +71,7 @@ import { FaviconImage } from "./preview/PreviewFaviconIcon";
import { previewBridge } from "./preview/previewBridge";
import { PierreEntryIcon } from "./chat/PierreEntryIcon";
import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
interface RightPanelTabsProps {
mode: PreviewPanelMode;
@@ -373,7 +372,7 @@ function RightPanelEmptyState(props: {
},
{
label: "Pull request",
icon: GitPullRequest,
icon: PullRequestGlyph.pullRequest,
shortcut: "P",
available: props.pullRequestAvailable,
disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequest,
@@ -382,7 +381,7 @@ function RightPanelEmptyState(props: {
},
{
label: "Linked pull requests",
icon: GitPullRequestArrow,
icon: PullRequestGlyph.link,
shortcut: "L",
available: props.pullRequestsAvailable,
disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequests,
@@ -712,7 +711,7 @@ function SurfaceIcon({
/>
);
case "pull-requests":
return <GitPullRequestArrow className="size-3 shrink-0" />;
return <PullRequestGlyph.link className="size-3 shrink-0" />;
case "agents":
return <Bot className="size-3 shrink-0" />;
case "device":
@@ -801,8 +800,9 @@ function PullRequestSurfaceIcon({
},
}),
).data;
// Only state and draft reach the tab. A list seed cannot know mergeability, so feeding the
// full detail would flip an open tab to the conflict glyph the moment its read lands.
// The compact tab intentionally shows lifecycle and draft state only. Conflict warnings have
// their own presentation on surfaces that have mergeability, while this tab stays stable as
// detail data arrives.
const status =
linkedSnapshot !== null
? linkedSnapshot
@@ -810,7 +810,7 @@ function PullRequestSurfaceIcon({
? (seed ?? null)
: { state: detail.state, isDraft: detail.isDraft };
if (status === null) {
return <GitPullRequest className="size-3 shrink-0 text-muted-foreground" />;
return <PullRequestGlyph.pullRequest className="size-3 shrink-0 text-muted-foreground" />;
}
const presentation = resolvePullRequestState({ state: status.state, isDraft: status.isDraft });
return <presentation.Icon className={cn("size-3 shrink-0", presentation.toneClassName)} />;
@@ -895,7 +895,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
},
{
label: "Pull request",
icon: GitPullRequest,
icon: PullRequestGlyph.pullRequest,
shortcut: "P",
available: props.pullRequestAvailable,
disabledReason: SURFACE_DISABLED_REASONS.pullRequest,
@@ -903,7 +903,7 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
},
{
label: "Linked pull requests",
icon: GitPullRequestArrow,
icon: PullRequestGlyph.link,
shortcut: "L",
available: props.pullRequestsAvailable,
disabledReason: SURFACE_DISABLED_REASONS.pullRequests,
@@ -1,25 +1,20 @@
import { ProjectId, type PullRequestSummary, type VcsStatusResult } from "@t3tools/contracts";
import { describe, expect, it } from "@effect/vitest";
import {
GitMergeIcon,
GitPullRequestClosedIcon,
GitPullRequestDraftIcon,
GitPullRequestIcon,
} from "lucide-react";
import {
ChangeRequestStatusIcon,
prStatusIndicator,
settledPrHoverColorClass,
resolveThreadPullRequestBadgePresentation,
} from "./ThreadStatusIndicators";
import { newestPullRequestSummary } from "../state/pullRequests";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
describe("ChangeRequestStatusIcon", () => {
it.each([
["open", "open", false, GitPullRequestIcon],
["draft", "open", true, GitPullRequestDraftIcon],
["closed", "closed", false, GitPullRequestClosedIcon],
["merged", "merged", false, GitMergeIcon],
["open", "open", false, PullRequestGlyph.pullRequest],
["draft", "open", true, PullRequestGlyph.draft],
["closed", "closed", false, PullRequestGlyph.closed],
["merged", "merged", false, PullRequestGlyph.merged],
] as const)("uses the %s pull request glyph", (_label, state, isDraft, expectedIcon) => {
expect(ChangeRequestStatusIcon({ state, isDraft }).type).toBe(expectedIcon);
});
@@ -119,18 +114,131 @@ describe("prStatusIndicator", () => {
});
});
describe("settledPrHoverColorClass", () => {
it.each([
["open", "text-emerald-600"],
["merged", "text-violet-600"],
["closed", "text-red-600"],
] as const)("restores the %s pull request color on row hover", (state, colorClass) => {
expect(settledPrHoverColorClass(state)).toContain(`group-hover/sidebar-row:${colorClass}`);
describe("resolveThreadPullRequestBadgePresentation", () => {
const url = "https://github.com/pingdotgg/t3code/pull/42";
it("returns the pending pull-request badge when no snapshot is available", () => {
expect(
resolveThreadPullRequestBadgePresentation({
badge: null,
number: 42,
url,
status: null,
}),
).toEqual({
Icon: PullRequestGlyph.pullRequest,
toneClassName: "text-muted-foreground",
label: "PR #42, status pending",
text: 42,
});
});
it("keeps draft pull requests gray on row hover", () => {
expect(settledPrHoverColorClass("open", true)).toContain(
"group-hover/sidebar-row:text-zinc-500",
);
it.each([
[
"open",
{ state: "open", isDraft: false },
PullRequestGlyph.pullRequest,
"text-emerald-600 dark:text-emerald-300/90",
"PR #42 - Open: PR branch",
],
[
"draft",
{ state: "open", isDraft: true },
PullRequestGlyph.draft,
"text-zinc-500 dark:text-zinc-400/80",
"PR #42 - Draft: PR branch",
],
[
"closed",
{ state: "closed", isDraft: false },
PullRequestGlyph.closed,
"text-red-600 dark:text-red-300/90",
"PR #42 - Closed: PR branch",
],
[
"merged",
{ state: "merged", isDraft: false },
PullRequestGlyph.merged,
"text-violet-600 dark:text-violet-300/90",
"PR #42 - Merged: PR branch",
],
] as const)(
"keeps the %s state for one linked pull request",
(_state, prOverrides, expectedIcon, expectedToneClassName, expectedLabel) => {
const fixture = status().pr;
if (!fixture) throw new Error("Expected pull request fixture");
const prStatus = prStatusIndicator({ ...fixture, ...prOverrides }, undefined);
if (!prStatus) throw new Error("Expected pull request status");
expect(
resolveThreadPullRequestBadgePresentation({
badge: { kind: "pull-request", others: 0, state: "open" },
number: fixture.number,
url: fixture.url,
status: prStatus,
}),
).toEqual({
Icon: expectedIcon,
toneClassName: expectedToneClassName,
label: expectedLabel,
text: fixture.number,
});
},
);
it.each([
["open", "text-emerald-600 dark:text-emerald-300/90"],
["draft", "text-zinc-500 dark:text-zinc-400/80"],
["merged", "text-violet-600 dark:text-violet-300/90"],
] as const)(
"uses a layers badge with the %s stack tone without a link identity",
(state, expectedToneClassName) => {
expect(
resolveThreadPullRequestBadgePresentation({
badge: { kind: "stack", layers: 3, state },
status: null,
}),
).toEqual({
Icon: PullRequestGlyph.stack,
toneClassName: expectedToneClassName,
label: `Stack of 3 pull requests, ${state}`,
text: 3,
});
},
);
it.each([
["open", PullRequestGlyph.pullRequest, "text-emerald-600 dark:text-emerald-300/90"],
["draft", PullRequestGlyph.draft, "text-zinc-500 dark:text-zinc-400/80"],
["merged", PullRequestGlyph.merged, "text-violet-600 dark:text-violet-300/90"],
] as const)(
"draws the count of unrelated linked pull requests with their %s aggregate state",
(state, expectedIcon, expectedToneClassName) => {
const fixture = status().pr;
if (!fixture) throw new Error("Expected pull request fixture");
const closedStatus = prStatusIndicator(
{ ...fixture, state: "closed", isDraft: false },
undefined,
);
if (!closedStatus) throw new Error("Expected pull request status");
expect(
resolveThreadPullRequestBadgePresentation({
badge: { kind: "pull-request", others: 2, state },
number: fixture.number,
url: fixture.url,
status: closedStatus,
}),
).toEqual({
Icon: expectedIcon,
toneClassName: expectedToneClassName,
label: `PR #42 - Closed: PR branch, and 2 more linked; overall ${state}`,
text: "+3",
});
},
);
it("omits the control when neither a stack nor a linked identity can be shown", () => {
expect(resolveThreadPullRequestBadgePresentation({ badge: null, status: null })).toBeNull();
});
});
@@ -14,7 +14,7 @@ import {
visibleThreadPullRequests,
type ThreadPullRequestBadge,
} from "@t3tools/shared/threadPullRequests";
import { FolderGit2Icon, GitPullRequestArrowIcon, LayersIcon, TerminalIcon } from "lucide-react";
import { FolderGit2Icon, TerminalIcon } from "lucide-react";
import { useMemo, type MouseEvent } from "react";
import { buttonVariants, InlineButton } from "./ui/button";
import { cn } from "../lib/utils";
@@ -31,11 +31,17 @@ import type { SidebarThreadSummary } from "../types";
import { formatWorktreePathForDisplay } from "../worktreeCleanup";
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
import { pullRequestListLines } from "./pullRequest/pullRequestListLines";
import {
PULL_REQUEST_STATE_PRESENTATION,
PullRequestGlyph,
type PullRequestGlyphIcon,
} from "./pullRequest/pullRequestIcons";
import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
export interface PrStatusIndicator {
label: string;
colorClass: string;
Icon: PullRequestGlyphIcon;
tooltip: string;
tooltipLead: string;
tooltipTitle: string;
@@ -125,16 +131,55 @@ export {
type ThreadPullRequestBadge,
} from "@t3tools/shared/threadPullRequests";
/** The glyph a row's badge wears: the layers icon for a stack, the pull-request one otherwise. */
function ThreadPullRequestBadgeIcon({
icon,
className,
export interface ThreadPullRequestBadgePresentation {
readonly Icon: PullRequestGlyphIcon;
readonly toneClassName: string;
readonly label: string;
readonly text: string | number;
}
/** Resolve the complete badge appearance before rendering it in the sidebar or composer. */
export function resolveThreadPullRequestBadgePresentation({
badge,
number,
url,
status,
}: {
icon: "stack" | "pull-request";
className?: string | undefined;
}) {
const Icon = icon === "stack" ? LayersIcon : GitPullRequestArrowIcon;
return <Icon aria-hidden className={cn("size-3 shrink-0", className)} />;
readonly badge: ThreadPullRequestBadge | null;
readonly number?: number | undefined;
readonly url?: string | undefined;
readonly status: PrStatusIndicator | null;
}): ThreadPullRequestBadgePresentation | null {
// The badge already folds every visible link into one state, draft included, so both the
// stack and the linked count index the shared table directly rather than the single-PR resolver.
if (badge?.kind === "stack") {
const aggregate = PULL_REQUEST_STATE_PRESENTATION[badge.state];
return {
Icon: PullRequestGlyph.stack,
toneClassName: aggregate.toneClassName,
label: `Stack of ${badge.layers} pull requests, ${aggregate.label.toLowerCase()}`,
text: badge.layers,
};
}
if (number === undefined || url === undefined) return null;
const tooltip = status?.tooltip ?? `PR #${number}, status pending`;
if (badge?.kind === "pull-request" && badge.others > 0) {
// Unrelated links fold into one state, so a count of merged PRs reads as merged.
const aggregate = PULL_REQUEST_STATE_PRESENTATION[badge.state];
return {
Icon: aggregate.Icon,
toneClassName: aggregate.toneClassName,
label: `${tooltip}, and ${badge.others} more linked; overall ${aggregate.label.toLowerCase()}`,
text: `+${badge.others + 1}`,
};
}
return {
Icon: status?.Icon ?? PullRequestGlyph.pullRequest,
toneClassName: status?.colorClass ?? "text-muted-foreground",
label: tooltip,
text: number,
};
}
/** The complete linked-PR control shared by the sidebar and composer footer. */
@@ -155,16 +200,9 @@ export function ThreadPullRequestBadgeControl({
onOpenStack: () => void;
onOpenPullRequest: (event: MouseEvent<HTMLAnchorElement>) => void;
}) {
const presentation = resolveThreadPullRequestBadgePresentation({ badge, number, url, status });
if (presentation === null) return null;
const isStack = badge?.kind === "stack";
const linkedCount = badge?.kind === "pull-request" && badge.others > 0 ? badge.others + 1 : null;
if (!isStack && (number === undefined || url === undefined)) return null;
const label = isStack
? `Stack of ${badge.layers} pull requests, ${badge.state}`
: `${status?.tooltip ?? `PR #${number}, status pending`}${
badge?.kind === "pull-request" && badge.others > 0
? `, and ${badge.others} more linked; overall ${badge.state}`
: ""
}`;
const className = cn(
variant === "ghost"
? buttonVariants({ variant: "ghost", size: "xs" })
@@ -172,14 +210,12 @@ export function ThreadPullRequestBadgeControl({
"text-xs tabular-nums",
variant === "ghost" &&
"font-normal text-xs! active:scale-100 [--control-icon-color:currentColor]",
badge !== null && (isStack || linkedCount !== null)
? PR_STATE_COLOR_CLASS[badge.state]
: (status?.colorClass ?? "text-muted-foreground"),
presentation.toneClassName,
);
const content = (
<>
<ThreadPullRequestBadgeIcon icon={badge?.kind ?? "pull-request"} />
{isStack ? badge.layers : linkedCount !== null ? `+${linkedCount}` : number}
<presentation.Icon aria-hidden className="size-3 shrink-0" />
{presentation.text}
</>
);
return (
@@ -189,7 +225,7 @@ export function ThreadPullRequestBadgeControl({
isStack ? (
<InlineButton
className={className}
aria-label={label}
aria-label={presentation.label}
onPointerDown={(event) => event.stopPropagation()}
onClick={(event) => {
event.preventDefault();
@@ -203,7 +239,7 @@ export function ThreadPullRequestBadgeControl({
target="_blank"
rel="noopener noreferrer"
className={className}
aria-label={label}
aria-label={presentation.label}
onPointerDown={(event) => event.stopPropagation()}
onClick={onOpenPullRequest}
/>
@@ -212,7 +248,7 @@ export function ThreadPullRequestBadgeControl({
>
{content}
</TooltipTrigger>
<TooltipPopup side="top">{label}</TooltipPopup>
<TooltipPopup side="top">{presentation.label}</TooltipPopup>
</Tooltip>
);
}
@@ -254,7 +290,7 @@ export function ThreadPullRequestsMiniList({
className={cn("size-3 shrink-0", presentation.toneClassName)}
/>
) : (
<GitPullRequestArrowIcon
<PullRequestGlyph.pullRequest
aria-hidden
className="size-3 shrink-0 stroke-muted-foreground"
/>
@@ -275,83 +311,24 @@ export function ThreadPullRequestsMiniList({
);
}
/** The ink each pull-request state wears in the sidebar, shared by the number and stack badges. */
const PR_STATE_COLOR_CLASS: Record<ThreadPullRequestBadge["state"], string> = {
open: "text-emerald-600 dark:text-emerald-300/90",
merged: "text-violet-600 dark:text-violet-300/90",
closed: "text-red-600 dark:text-red-300/90",
draft: "text-zinc-500 dark:text-zinc-400/80",
};
export function settledPrHoverColorClass(
state: NonNullable<ThreadPr>["state"],
isDraft = false,
): string {
switch (state) {
case "open":
if (isDraft) {
return "group-hover/sidebar-row:text-zinc-500 dark:group-hover/sidebar-row:text-zinc-400/80";
}
return "group-hover/sidebar-row:text-emerald-600 dark:group-hover/sidebar-row:text-emerald-300/90";
case "merged":
return "group-hover/sidebar-row:text-violet-600 dark:group-hover/sidebar-row:text-violet-300/90";
case "closed":
return "group-hover/sidebar-row:text-red-600 dark:group-hover/sidebar-row:text-red-300/90";
}
}
export function prStatusIndicator(
pr: ThreadPr,
provider: VcsStatusResult["sourceControlProvider"] | null | undefined,
): PrStatusIndicator | null {
function formatPrState(pr: NonNullable<ThreadPr>): string {
if (pr.state === "open" && pr.isDraft === true) return "Draft";
return pr.state.charAt(0).toUpperCase() + pr.state.slice(1);
}
function formatPrStatusLead(pr: NonNullable<ThreadPr>, changeRequestShortName: string): string {
return `${changeRequestShortName} #${pr.number} - ${formatPrState(pr)}`;
}
if (!pr) return null;
const presentation = resolveChangeRequestPresentation(provider);
const state = resolvePullRequestState({ state: pr.state, isDraft: pr.isDraft === true });
const tooltipLead = formatPrStatusLead(pr, presentation.shortName);
const tooltip = `${tooltipLead}: ${pr.title}`;
if (pr.state === "open") {
const isDraft = pr.isDraft === true;
return {
label: `${presentation.shortName} ${isDraft ? "draft" : "open"}`,
colorClass: isDraft
? "text-zinc-500 dark:text-zinc-400/80"
: "text-emerald-600 dark:text-emerald-300/90",
tooltip,
tooltipLead,
tooltipTitle: pr.title,
url: pr.url,
};
}
if (pr.state === "closed") {
return {
label: `${presentation.shortName} closed`,
colorClass: "text-red-600 dark:text-red-300/90",
tooltip,
tooltipLead,
tooltipTitle: pr.title,
url: pr.url,
};
}
if (pr.state === "merged") {
return {
label: `${presentation.shortName} merged`,
colorClass: "text-violet-600 dark:text-violet-300/90",
tooltip,
tooltipLead,
tooltipTitle: pr.title,
url: pr.url,
};
}
return null;
const tooltipLead = `${presentation.shortName} #${pr.number} - ${state.label}`;
return {
label: `${presentation.shortName} ${state.label.toLowerCase()}`,
colorClass: state.toneClassName,
Icon: state.Icon,
tooltip: `${tooltipLead}: ${pr.title}`,
tooltipLead,
tooltipTitle: pr.title,
url: pr.url,
};
}
export function ChangeRequestStatusIcon({
@@ -529,7 +506,7 @@ export function ThreadRowLeadingStatus({ thread }: { thread: SidebarThreadSummar
</Tooltip>
) : null}
{pendingLink ? (
<GitPullRequestArrowIcon
<PullRequestGlyph.pullRequest
className="size-3 text-muted-foreground"
aria-label={`PR #${pendingLink.number}, status pending`}
/>
@@ -112,7 +112,6 @@ import {
CircleAlertIcon,
DownloadIcon,
EyeIcon,
GitPullRequestIcon,
GlobeIcon,
HammerIcon,
MessageCircleIcon,
@@ -250,6 +249,7 @@ import {
formatReviewCommentFence,
type ReviewCommentContext,
} from "../../reviewCommentContext";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
// ---------------------------------------------------------------------------
// Context — shared state consumed by every row component via Context.
@@ -3326,7 +3326,7 @@ const userMessageContextPresentationRegistry = createContextPresentationRegistry
<UserMessageContextChip
icon={
isPullRequest ? (
<GitPullRequestIcon
<PullRequestGlyph.pullRequest
className={cn(
COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
CONTEXT_INLINE_CHIP_ICON_TONE_CLASS_NAMES["pull-request"],
@@ -3877,7 +3877,7 @@ function ToolActivityImageIcon(props: {
function WorkEntryIcon({ name, className }: { name: WorkEntryIconName; className: string }) {
switch (name) {
case "pull-request":
return <GitPullRequestIcon className={className} aria-hidden />;
return <PullRequestGlyph.pullRequest className={className} aria-hidden />;
case "bot":
return <BotIcon className={className} aria-hidden />;
case "brain":
@@ -3,7 +3,7 @@ import { ReadOnlySourcePreview } from "./files/AttachmentFilePreview";
import type { PreviewAnnotationPayload } from "@t3tools/contracts";
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
import { videoMimeType } from "@t3tools/shared/video";
import { GitPullRequestIcon, MessageCircleIcon, MousePointerClickIcon } from "lucide-react";
import { MessageCircleIcon, MousePointerClickIcon } from "lucide-react";
import { createContext, type MouseEvent, type ReactElement, type ReactNode, use } from "react";
import type { ComposerFileAttachment, ComposerImageAttachment } from "~/composerDraftStore";
@@ -14,6 +14,7 @@ import {
type AttachmentUploadState,
} from "~/lib/attachmentUploadState";
import { cn } from "~/lib/utils";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
import {
fileContextReference,
imageContextReference,
@@ -392,7 +393,7 @@ const composerContextPresentationRegistry = createContextPresentationRegistry<
<ContextChip
icon={
isPullRequest ? (
<GitPullRequestIcon
<PullRequestGlyph.pullRequest
className={cn(
COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
CONTEXT_INLINE_CHIP_ICON_TONE_CLASS_NAMES["pull-request"],
+5 -2
View File
@@ -1,5 +1,5 @@
import type { PullRequestContextMetadata } from "@t3tools/contracts";
import { CircleDashedIcon, FilmIcon, GitPullRequestIcon, ImageIcon } from "lucide-react";
import { CircleDashedIcon, FilmIcon, ImageIcon } from "lucide-react";
import {
useState,
type ComponentProps,
@@ -9,6 +9,7 @@ import {
} from "react";
import { cn } from "~/lib/utils";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
import { PierreEntryIcon } from "./chat/PierreEntryIcon";
import {
COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
@@ -134,7 +135,9 @@ export function PullRequestChip(props: {
data-markdown-copy={props.copyMarkdown}
onClick={(event) => props.onOpen(event, props.metadata.url)}
>
<GitPullRequestIcon className={cn(COMPOSER_INLINE_CHIP_ICON_CLASS_NAME, "size-3.5")} />
<PullRequestGlyph.pullRequest
className={cn(COMPOSER_INLINE_CHIP_ICON_CLASS_NAME, "size-3.5")}
/>
<span className={props.labelClassName}>{props.label}</span>
</Button>
}
@@ -1,11 +1,5 @@
import type { EnvironmentId, PullRequestDetailView, PullRequestRef } from "@t3tools/contracts";
import {
GitPullRequestClosedIcon,
MessageSquareIcon,
RotateCcwIcon,
SendIcon,
XIcon,
} from "lucide-react";
import { MessageSquareIcon, SendIcon, XIcon } from "lucide-react";
import { useRef, useState } from "react";
import { useAtomCommand } from "~/state/use-atom-command";
@@ -15,6 +9,7 @@ import { Button } from "../ui/button";
import { Popover, PopoverClose, PopoverPopup, PopoverTitle, PopoverTrigger } from "../ui/popover";
import { Textarea } from "../ui/textarea";
import { toastManager } from "../ui/toast";
import { PullRequestGlyph } from "./pullRequestIcons";
export function PullRequestCommentComposer({
environmentId,
@@ -146,9 +141,9 @@ export function PullRequestCommentComposer({
onClick={() => void submit(followUpAction)}
>
{followUpAction === "close" ? (
<GitPullRequestClosedIcon className="size-3.5" />
<PullRequestGlyph.closed className="size-3.5" />
) : (
<RotateCcwIcon className="size-3.5" />
<PullRequestGlyph.reopen className="size-3.5" />
)}
{submitting === followUpAction
? followUpAction === "close"
@@ -29,12 +29,7 @@ import {
FolderGit2Icon,
GitBranchIcon,
GitCommitHorizontalIcon,
GitMergeIcon,
GitPullRequestClosedIcon,
GitPullRequestDraftIcon,
GitPullRequestIcon,
HammerIcon,
LayersIcon,
MessageCircleQuestionIcon,
MessageSquareIcon,
LinkIcon,
@@ -176,6 +171,7 @@ import {
resolvePullRequestState,
summarizePullRequestChecks,
} from "./pullRequestPresentation";
import { PullRequestGlyph } from "./pullRequestIcons";
type DetailTab = "summary" | "timeline" | "code";
@@ -455,7 +451,7 @@ function PullRequestBaseFreshnessWarning({
disabled={pending}
onClick={() => onUpdate(method)}
>
<GitMergeIcon aria-hidden className="size-3" />
<PullRequestGlyph.merged aria-hidden className="size-3" />
{method === "rebase" ? "Update with rebase" : "Update branch"}
</Button>
))}
@@ -1803,7 +1799,7 @@ export function PullRequestDetailPanel({
role="img"
aria-label={armedAutoMergeLabel}
>
<GitMergeIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.merged aria-hidden className="size-3.5" />
<span className="@max-[30rem]/pr-header:hidden">{armedAutoMergeLabel}</span>
</Badge>
}
@@ -1828,7 +1824,7 @@ export function PullRequestDetailPanel({
handoff === "conflicts" ? "Preparing..." : "Resolve conflicts"
}
>
<TriangleAlertIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.conflicting aria-hidden className="size-3.5" />
<span className="@max-[30rem]/pr-header:hidden">
{handoff === "conflicts" ? "Preparing..." : "Resolve conflicts"}
</span>
@@ -1852,7 +1848,7 @@ export function PullRequestDetailPanel({
onClick={() => void perform("ready")}
aria-label="Ready for review"
>
<GitPullRequestIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.pullRequest aria-hidden className="size-3.5" />
<span className="@max-[30rem]/pr-header:hidden">Ready for review</span>
</Button>
</span>
@@ -1878,7 +1874,7 @@ export function PullRequestDetailPanel({
: pendingAutoMergeLabel
}
>
<GitMergeIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.merged aria-hidden className="size-3.5" />
<span className="@max-[30rem]/pr-header:hidden">
{pendingAction === "enable-auto-merge"
? "Enabling..."
@@ -1902,7 +1898,7 @@ export function PullRequestDetailPanel({
role="img"
aria-label={armedAutoMergeLabel}
>
<GitMergeIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.merged aria-hidden className="size-3.5" />
<span className="@max-[30rem]/pr-header:hidden">{armedAutoMergeLabel}</span>
</Badge>
}
@@ -1926,7 +1922,7 @@ export function PullRequestDetailPanel({
pendingAction === "merge" ? "Merging..." : selectedMergeMethodLabel
}
>
<GitMergeIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.merged aria-hidden className="size-3.5" />
<span className="@max-[30rem]/pr-header:hidden">
{pendingAction === "merge" ? "Merging..." : selectedMergeMethodLabel}
</span>
@@ -2031,9 +2027,9 @@ export function PullRequestDetailPanel({
onClick={() => void perform(detail.isDraft ? "ready" : "draft")}
>
{detail.isDraft ? (
<GitPullRequestIcon className="size-3.5" />
<PullRequestGlyph.pullRequest className="size-3.5" />
) : (
<GitPullRequestDraftIcon className="size-3.5" />
<PullRequestGlyph.draft className="size-3.5" />
)}
{detail.isDraft ? "Ready for review" : "Convert to draft"}
</MenuItem>
@@ -2043,7 +2039,7 @@ export function PullRequestDetailPanel({
disabled={actionPending}
onClick={() => setConfirmation({ open: true, action: "merge" })}
>
<GitMergeIcon className="size-3.5" />
<PullRequestGlyph.merged className="size-3.5" />
Merge now
</MenuItem>
) : null}
@@ -2055,7 +2051,7 @@ export function PullRequestDetailPanel({
disabled={actionPending}
onClick={() => void perform("disable-auto-merge")}
>
<GitMergeIcon className="size-3.5" />
<PullRequestGlyph.merged className="size-3.5" />
Disable auto-merge
</MenuItem>
) : showsAutoMerge ? (
@@ -2065,7 +2061,7 @@ export function PullRequestDetailPanel({
setConfirmation({ open: true, action: "enable-auto-merge" })
}
>
<GitMergeIcon className="size-3.5" />
<PullRequestGlyph.merged className="size-3.5" />
Enable auto-merge
</MenuItem>
) : null}
@@ -2100,7 +2096,7 @@ export function PullRequestDetailPanel({
{/* The radio item lays its children out as one block, so the
icon and the label need their own row to share a line. */}
<span className="flex min-w-0 items-center gap-2">
<GitMergeIcon className="size-3.5" />
<PullRequestGlyph.merged className="size-3.5" />
<span>{PULL_REQUEST_MERGE_METHOD_LABELS[method]}</span>
</span>
</MenuRadioItem>
@@ -2143,7 +2139,7 @@ export function PullRequestDetailPanel({
disabled={actionPending}
onClick={() => setConfirmation({ open: true, action: "close" })}
>
<GitPullRequestClosedIcon className="size-3.5" />
<PullRequestGlyph.closed className="size-3.5" />
Close pull request
</MenuItem>
</>
@@ -2151,7 +2147,7 @@ export function PullRequestDetailPanel({
<>
<MenuSeparator />
<MenuItem disabled={actionPending} onClick={() => void perform("reopen")}>
<GitPullRequestIcon className="size-3.5" />
<PullRequestGlyph.reopen className="size-3.5" />
Reopen pull request
</MenuItem>
</>
@@ -2220,7 +2216,7 @@ export function PullRequestDetailPanel({
render={
<span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1">
{isStackedPullRequest ? (
<LayersIcon
<PullRequestGlyph.stack
aria-label="Stacked pull request"
className="size-3 shrink-0"
/>
@@ -2404,7 +2400,7 @@ export function PullRequestDetailPanel({
render={
<span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1">
{isStackedPullRequest ? (
<LayersIcon
<PullRequestGlyph.stack
aria-label="Stacked pull request"
className="size-3 shrink-0"
/>
@@ -15,7 +15,6 @@ import {
CircleXIcon,
EyeOffIcon,
FolderGit2Icon,
GitPullRequestDraftIcon,
LayersIcon,
ListFilterIcon,
SearchIcon,
@@ -51,6 +50,7 @@ import {
type PullRequestLabelFacet,
} from "./pullRequestList.logic";
import { PullRequestActorAvatar } from "./pullRequestPresentation";
import { PullRequestGlyph } from "./pullRequestIcons";
export interface PullRequestFilterOption<Value extends string> {
readonly value: Value;
@@ -143,7 +143,7 @@ export const pullRequestProjectKey = (project: {
const DRAFT_OPTIONS = [
{ value: UNFILTERED_VALUE, label: "All", Icon: LayersIcon },
{ value: "only", label: "Drafts only", Icon: GitPullRequestDraftIcon },
{ value: "only", label: "Drafts only", Icon: PullRequestGlyph.draft },
{ value: "hide", label: "Hide drafts", Icon: EyeOffIcon },
] as const satisfies ReadonlyArray<PullRequestFilterOption<string>>;
@@ -12,6 +12,7 @@ import { pullRequestLabelColor, type EnvironmentPullRequestEntry } from "./pullR
import { openOnHostLabel, showPullRequestLinkContextMenu } from "./pullRequestLinkContextMenu";
import {
PullRequestActorLabel,
PullRequestConflictGlyph,
PullRequestDiffStat,
PullRequestMetaLine,
PullRequestApprovalGlyph,
@@ -112,12 +113,23 @@ function PullRequestRowImpl({
selected ? "bg-accent" : "hover:bg-accent/60",
)}
>
<PullRequestStateGlyph
state={entry.state}
isDraft={entry.isDraft}
mergeability={entry.mergeability}
baseBranch={entry.baseBranch}
/>
{/* The conflict warning rides the corner of the lifecycle glyph, over the arrow's
merge circle, so the leading slot stays one icon wide and titles line up whether or
not a row is blocked. The background fill cuts it out of the glyph beneath. */}
<span className="relative inline-flex shrink-0">
<PullRequestStateGlyph state={entry.state} isDraft={entry.isDraft} />
{/* The wrapper takes the offset, not the icon, so the tooltip trigger inside keeps the
badge's size and anchors the popup to it. */}
<span className="absolute -right-1 -bottom-1 inline-flex">
<PullRequestConflictGlyph
state={entry.state}
isDraft={entry.isDraft}
mergeability={entry.mergeability}
baseBranch={entry.baseBranch}
className="size-3 fill-background [stroke-width:2.5]"
/>
</span>
</span>
<span className="grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1.5">
<span className="col-start-1 row-start-1 block truncate text-sm font-medium text-foreground">
{entry.title}
@@ -6,7 +6,7 @@ import type {
PullRequestMergeMethod,
} from "@t3tools/contracts";
import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
import { GitMergeIcon, LayersIcon, RefreshCwIcon, TriangleAlertIcon } from "lucide-react";
import { RefreshCwIcon, TriangleAlertIcon } from "lucide-react";
import { useState } from "react";
import { useAtomCommand } from "~/state/use-atom-command";
import { pullRequestEnvironment } from "~/state/pullRequests";
@@ -25,6 +25,7 @@ import { toastManager } from "../ui/toast";
import { PullRequestStackLayers } from "./PullRequestStackLayers";
import { PullRequestStackHeader } from "./PullRequestStackHeader";
import { PullRequestStackLayerContent } from "./PullRequestStackLayerContent";
import { PullRequestGlyph } from "./pullRequestIcons";
export function PullRequestStackMenu({
stack,
@@ -133,7 +134,8 @@ export function PullRequestStackMenu({
/>
}
>
<LayersIcon aria-hidden className="size-3.5" /> {position}/{stack.layers.length}
<PullRequestGlyph.stack aria-hidden className="size-3.5" /> {position}/
{stack.layers.length}
{onRetry ? <TriangleAlertIcon aria-hidden className="size-3 text-warning" /> : null}
</MenuTrigger>
}
@@ -166,7 +168,7 @@ export function PullRequestStackMenu({
<MenuSeparator />
{canMerge ? (
<MenuItem disabled={mergeDisabled} onClick={() => setConfirmation("merge")}>
<GitMergeIcon aria-hidden />
<PullRequestGlyph.merged aria-hidden />
Merge stack ({mergeLayers.length})
</MenuItem>
) : null}
@@ -199,7 +201,7 @@ export function PullRequestStackMenu({
disabled={mergeDisabled}
onClick={() => setConfirmation("merge")}
>
<GitMergeIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.merged aria-hidden className="size-3.5" />
Merge stack
</Button>
</span>
@@ -1,11 +1,11 @@
import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
import type { EnvironmentId, PullRequestRef, PullRequestStackMembership } from "@t3tools/contracts";
import { LayersIcon } from "lucide-react";
import { useState } from "react";
import { usePullRequestStack } from "~/state/usePullRequestStack";
import { Menu, MenuTrigger, MenuPopup, MenuGroup, MenuGroupLabel, MenuItem } from "../ui/menu";
import { PullRequestStackLayers } from "./PullRequestStackLayers";
import { PullRequestStackHeader } from "./PullRequestStackHeader";
import { PullRequestGlyph } from "./pullRequestIcons";
/** Mounted only while the menu is open, so list rows do not each fetch a stack. */
function StackBody({
@@ -74,7 +74,7 @@ export function PullRequestStackPopover({
onClick={(event) => event.stopPropagation()}
onKeyDown={(event) => event.stopPropagation()}
>
<LayersIcon aria-hidden className="size-3" />
<PullRequestGlyph.stack aria-hidden className="size-3" />
{membership.position}/{membership.size}
</MenuTrigger>
}
@@ -1,7 +1,7 @@
import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import type { EnvironmentId, PullRequestRef, ScopedThreadRef, ThreadId } from "@t3tools/contracts";
import { CheckIcon, LinkIcon, MessageSquareIcon, UnlinkIcon } from "lucide-react";
import { CheckIcon, MessageSquareIcon } from "lucide-react";
import { useState } from "react";
import { threadPullRequestLinkMode } from "@t3tools/client-runtime/thread-pull-request-compatibility";
import { usePullRequestLinking } from "~/hooks/usePullRequestLinking";
@@ -18,6 +18,7 @@ import { Command, CommandInput, CommandItem, CommandList } from "../ui/command";
import { Dialog, DialogPopup, DialogTitle } from "../ui/dialog";
import { MenuItem } from "../ui/menu";
import { toastManager } from "../ui/toast";
import { PullRequestGlyph } from "./pullRequestIcons";
interface PullRequestThreadLinksProps {
environmentId: EnvironmentId;
@@ -144,9 +145,9 @@ function EnabledPullRequestThreadLinks({
}}
>
{linkedHere ? (
<UnlinkIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.unlink aria-hidden className="size-3.5" />
) : (
<LinkIcon aria-hidden className="size-3.5" />
<PullRequestGlyph.link aria-hidden className="size-3.5" />
)}
{linkedHere
? "Unlink from this thread"
@@ -11,9 +11,6 @@ import {
ExternalLinkIcon,
FileCode2Icon,
GitCommitHorizontalIcon,
GitMergeIcon,
GitPullRequestClosedIcon,
GitPullRequestIcon,
MessageSquareIcon,
PencilIcon,
} from "lucide-react";
@@ -51,6 +48,7 @@ import {
pullRequestReviewOutcomeStaleLabel,
pullRequestReviewOutcomeToneClassName,
} from "./pullRequestPresentation";
import { PullRequestGlyph } from "./pullRequestIcons";
/** What every comment on the timeline needs to react; only the subject differs between them. */
interface ReactionSurface {
@@ -419,16 +417,16 @@ function LifecycleEvent({ event }: { event: PullRequestTimelineEvent }) {
const presentation =
event.kind === "opened"
? {
icon: <GitPullRequestIcon className="size-3.5" />,
icon: <PullRequestGlyph.pullRequest className="size-3.5" />,
label: "Pull request opened",
}
: event.kind === "merged"
? {
icon: <GitMergeIcon className="size-3.5" />,
icon: <PullRequestGlyph.merged className="size-3.5" />,
label: "Pull request merged",
}
: {
icon: <GitPullRequestClosedIcon className="size-3.5" />,
icon: <PullRequestGlyph.closed className="size-3.5" />,
label: "Pull request closed",
};
@@ -629,7 +627,7 @@ export function PullRequestTimelineTab({
{events.length === 0 ? (
<div className="flex flex-col items-center justify-center py-16 text-center text-muted-foreground">
<GitPullRequestIcon className="mb-2 size-5" />
<PullRequestGlyph.pullRequest className="mb-2 size-5" />
<p className="text-xs">No activity yet.</p>
</div>
) : null}
@@ -1,5 +1,5 @@
import { RefreshIcon } from "~/components/ui/refresh-icon";
import { ExternalLinkIcon, GitPullRequestIcon } from "lucide-react";
import { ExternalLinkIcon } from "lucide-react";
import { Button } from "../ui/button";
import {
@@ -10,6 +10,7 @@ import {
EmptyMedia,
EmptyTitle,
} from "../ui/empty";
import { PullRequestGlyph } from "./pullRequestIcons";
export function PullRequestsUnavailableState({
title = "Could not load pull requests",
@@ -27,7 +28,7 @@ export function PullRequestsUnavailableState({
return (
<Empty className="min-h-0 justify-center-safe overflow-y-auto px-4 py-16 md:px-4 [&>*]:shrink-0">
<EmptyMedia variant="icon">
<GitPullRequestIcon />
<PullRequestGlyph.pullRequest />
</EmptyMedia>
<EmptyHeader>
<EmptyTitle>{title}</EmptyTitle>
@@ -3,13 +3,7 @@ import {
resolveThreadPullRequestChains,
visibleThreadPullRequests,
} from "@t3tools/shared/threadPullRequests";
import {
GitPullRequestArrow,
LayersIcon,
LinkIcon,
MoreHorizontalIcon,
PlusIcon,
} from "lucide-react";
import { ArrowUpRightIcon, LinkIcon, MoreHorizontalIcon, PlusIcon } from "lucide-react";
import { useCallback, useMemo } from "react";
import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";
@@ -28,11 +22,13 @@ import { openLinkPullRequestDialog } from "./LinkPullRequestDialog";
import { pullRequestListLines, type PullRequestListLine } from "./pullRequestListLines";
import {
PullRequestActorAvatar,
PullRequestConflictGlyph,
PullRequestDiffStat,
PullRequestApprovalGlyph,
PullRequestStateGlyph,
pullRequestChecksStatePresentation,
} from "./pullRequestPresentation";
import { PullRequestGlyph } from "./pullRequestIcons";
const SOURCE_LABELS: Record<ThreadPullRequestLink["source"], string> = {
manual: "Linked by you",
@@ -84,12 +80,20 @@ function LinkRow({
>
{depth > 0 ? <span aria-hidden className="-ml-2 h-6 w-px shrink-0 bg-border/70" /> : null}
{snapshot === null ? (
<GitPullRequestArrow
<PullRequestGlyph.pullRequest
aria-label="Waiting for host state"
className="size-4 shrink-0 text-muted-foreground"
/>
) : (
<PullRequestStateGlyph state={snapshot.state} isDraft={snapshot.isDraft} />
<span className="flex shrink-0 items-center gap-1">
<PullRequestStateGlyph state={snapshot.state} isDraft={snapshot.isDraft} />
<PullRequestConflictGlyph
state={snapshot.state}
isDraft={snapshot.isDraft}
baseBranch={snapshot.baseBranch}
{...(snapshot.mergeability ? { mergeability: snapshot.mergeability } : {})}
/>
</span>
)}
<a
href={link.url}
@@ -125,9 +129,6 @@ function LinkRow({
<span className="text-amber-600/90 dark:text-amber-400/80">Changes requested</span>
)
) : null}
{snapshot?.state === "open" && snapshot.mergeability === "conflicting" ? (
<span className="text-destructive">Conflicts</span>
) : null}
{snapshot?.checksState ? <ChecksGlyph state={snapshot.checksState} /> : null}
<PullRequestDiffStat
additions={snapshot?.additions ?? 0}
@@ -144,11 +145,7 @@ function LinkRow({
<span className="inline-flex shrink-0 items-center gap-0.5 text-foreground/70" />
}
>
{stack.kind === "native" ? (
<LayersIcon aria-hidden className="size-3" />
) : (
<GitPullRequestArrow aria-hidden className="size-3" />
)}
<PullRequestGlyph.stack aria-hidden className="size-3" />
{stack.size}
</TooltipTrigger>
<TooltipPopup>
@@ -190,9 +187,16 @@ function LinkRow({
}
/>
<MenuPopup align="end" side="bottom">
<MenuItem onClick={() => void writeTextToClipboard(link.url, "link")}>Copy link</MenuItem>
<MenuItem onClick={(event) => openPrLink(event, link.url, threadRef)}>Open</MenuItem>
<MenuItem onClick={() => void writeTextToClipboard(link.url, "link")}>
<LinkIcon className="size-3.5" />
Copy link
</MenuItem>
<MenuItem onClick={(event) => openPrLink(event, link.url, threadRef)}>
<ArrowUpRightIcon className="size-3.5" />
Open
</MenuItem>
<MenuItem onClick={() => onUnlink(link)}>
<PullRequestGlyph.unlink className="size-3.5" />
{link.source === "stack" ? "Dismiss from thread" : "Unlink from thread"}
</MenuItem>
</MenuPopup>
@@ -250,7 +254,7 @@ function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThread
if (links.length === 0) {
return (
<div className="flex h-full flex-col items-center justify-center gap-2 p-6 text-center">
<LinkIcon aria-hidden className="size-6 text-muted-foreground/60" />
<PullRequestGlyph.link aria-hidden className="size-6 text-muted-foreground/60" />
<p className="text-sm font-medium">No linked pull requests</p>
<p className="max-w-60 text-xs text-muted-foreground">
Pull requests the agent opens from this thread land here. Link one yourself from a URL or
@@ -0,0 +1,54 @@
import {
GitMergeIcon,
GitPullRequestArrowIcon,
GitPullRequestClosedIcon,
GitPullRequestDraftIcon,
LayersIcon,
Link2Icon,
Unlink2Icon,
TriangleAlertIcon,
} from "lucide-react";
import type { PullRequestState } from "@t3tools/contracts";
export const PullRequestGlyph = {
pullRequest: GitPullRequestArrowIcon,
reopen: GitPullRequestArrowIcon,
draft: GitPullRequestDraftIcon,
closed: GitPullRequestClosedIcon,
merged: GitMergeIcon,
conflicting: TriangleAlertIcon,
stack: LayersIcon,
link: Link2Icon,
unlink: Unlink2Icon,
} as const;
export type PullRequestGlyphIcon = (typeof PullRequestGlyph)[keyof typeof PullRequestGlyph];
export interface PullRequestStatePresentation {
readonly label: string;
readonly toneClassName: string;
readonly Icon: PullRequestGlyphIcon;
}
export const PULL_REQUEST_STATE_PRESENTATION = {
open: {
label: "Open",
toneClassName: "text-emerald-600 dark:text-emerald-300/90",
Icon: PullRequestGlyph.pullRequest,
},
draft: {
label: "Draft",
toneClassName: "text-zinc-500 dark:text-zinc-400/80",
Icon: PullRequestGlyph.draft,
},
closed: {
label: "Closed",
toneClassName: "text-red-600 dark:text-red-300/90",
Icon: PullRequestGlyph.closed,
},
merged: {
label: "Merged",
toneClassName: "text-violet-600 dark:text-violet-300/90",
Icon: PullRequestGlyph.merged,
},
} as const satisfies Record<PullRequestState | "draft", PullRequestStatePresentation>;
@@ -0,0 +1,139 @@
import { describe, expect, it } from "vite-plus/test";
import { resolvePullRequestConflict, resolvePullRequestState } from "./pullRequestPresentation";
import { PullRequestGlyph } from "./pullRequestIcons";
describe("resolvePullRequestState", () => {
it.each([
[
"open",
{ state: "open", isDraft: false },
PullRequestGlyph.pullRequest,
"Open",
"text-emerald-600 dark:text-emerald-300/90",
],
[
"draft",
{ state: "open", isDraft: true },
PullRequestGlyph.draft,
"Draft",
"text-zinc-500 dark:text-zinc-400/80",
],
[
"closed",
{ state: "closed", isDraft: false },
PullRequestGlyph.closed,
"Closed",
"text-red-600 dark:text-red-300/90",
],
[
"merged",
{ state: "merged", isDraft: false },
PullRequestGlyph.merged,
"Merged",
"text-violet-600 dark:text-violet-300/90",
],
] as const)(
"resolves the %s lifecycle presentation",
(_name, input, Icon, label, toneClassName) => {
expect(resolvePullRequestState(input)).toEqual({
Icon,
label,
toneClassName,
});
},
);
it("keeps a merged pull request merged when stale draft metadata is also present", () => {
expect(resolvePullRequestState({ state: "merged", isDraft: true })).toMatchObject({
Icon: PullRequestGlyph.merged,
label: "Merged",
});
});
it("keeps a closed pull request closed when stale draft metadata is also present", () => {
expect(resolvePullRequestState({ state: "closed", isDraft: true })).toMatchObject({
Icon: PullRequestGlyph.closed,
label: "Closed",
});
});
it("keeps lifecycle and conflict presentation independent for an open conflicting pull request", () => {
const input = {
state: "open" as const,
isDraft: false,
mergeability: "conflicting" as const,
baseBranch: "main",
};
expect(resolvePullRequestState(input)).toMatchObject({
Icon: PullRequestGlyph.pullRequest,
label: "Open",
});
expect(resolvePullRequestConflict(input)).toMatchObject({
Icon: PullRequestGlyph.conflicting,
label: "Conflicts with main",
toneClassName: "text-destructive",
});
});
});
describe("resolvePullRequestConflict", () => {
it.each([
["closed", { state: "closed", isDraft: false }],
["merged", { state: "merged", isDraft: false }],
["closed draft", { state: "closed", isDraft: true }],
["merged draft", { state: "merged", isDraft: true }],
["open draft", { state: "open", isDraft: true }],
] as const)("does not report a conflict for %s", (_name, input) => {
expect(
resolvePullRequestConflict({
...input,
mergeability: "conflicting",
baseBranch: "main",
}),
).toBeNull();
});
it.each([
["omitted", undefined],
["unknown", "unknown"],
["mergeable", "mergeable"],
] as const)("does not report an open conflict when mergeability is %s", (_name, mergeability) => {
const input = {
state: "open" as const,
isDraft: false,
...(mergeability === undefined ? {} : { mergeability }),
};
expect(resolvePullRequestConflict(input)).toBeNull();
});
it("reports a known conflict with its base branch", () => {
expect(
resolvePullRequestConflict({
state: "open",
isDraft: false,
mergeability: "conflicting",
baseBranch: "main",
}),
).toEqual({
Icon: PullRequestGlyph.conflicting,
label: "Conflicts with main",
toneClassName: "text-destructive",
});
});
it("reports a known conflict without inventing a base branch", () => {
expect(
resolvePullRequestConflict({
state: "open",
isDraft: false,
mergeability: "conflicting",
}),
).toEqual({
Icon: PullRequestGlyph.conflicting,
label: "Has conflicts",
toneClassName: "text-destructive",
});
});
});
@@ -12,11 +12,6 @@ import {
CircleDashedIcon,
CircleDotIcon,
CircleXIcon,
GitMergeIcon,
GitPullRequestClosedIcon,
GitPullRequestDraftIcon,
GitPullRequestIcon,
TriangleAlertIcon,
UserCheckIcon,
} from "lucide-react";
import { Children, isValidElement, type ReactNode } from "react";
@@ -26,12 +21,12 @@ import { cn } from "~/lib/utils";
import { Badge } from "../ui/badge";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import type { PullRequestReviewOutcome } from "./pullRequestDetail.logic";
interface StatePresentation {
readonly label: string;
readonly toneClassName: string;
readonly Icon: typeof GitPullRequestIcon;
}
import {
PULL_REQUEST_STATE_PRESENTATION,
PullRequestGlyph,
type PullRequestStatePresentation,
type PullRequestGlyphIcon,
} from "./pullRequestIcons";
export function PullRequestApprovalGlyph() {
return (
@@ -49,57 +44,69 @@ export function PullRequestApprovalGlyph() {
}
/**
* How a pull request's state reads on this page. Open, closed, merged, and draft use the same
* ink as the thread badge in `ThreadStatusIndicators`, so one pull request cannot look like two
* different things in two places.
* How a pull request's state reads anywhere it appears: the thread badge, the right-panel tab,
* the list, and the detail header all resolve through here so one pull request cannot look like
* two different things in two places.
*
* Draft outranks conflicts: a draft is not heading for a merge yet, so conflicts only surface
* once it is real work.
* Closed and merged take precedence over a stale draft flag.
*/
export function resolvePullRequestState(input: {
readonly state: PullRequestState;
readonly isDraft: boolean;
}): PullRequestStatePresentation {
const key = input.state === "open" && input.isDraft ? "draft" : input.state;
return PULL_REQUEST_STATE_PRESENTATION[key];
}
export interface PullRequestConflictPresentation {
readonly label: string;
readonly toneClassName: string;
readonly Icon: PullRequestGlyphIcon;
}
export function resolvePullRequestConflict(input: {
readonly state: PullRequestState;
readonly isDraft: boolean;
readonly mergeability?: PullRequestMergeability;
readonly baseBranch?: string;
}): StatePresentation {
if (input.state === "merged") {
return {
label: "Merged",
toneClassName: "text-violet-600 dark:text-violet-300/90",
Icon: GitMergeIcon,
};
}
if (input.state === "closed") {
return {
label: "Closed",
toneClassName: "text-red-600 dark:text-red-300/90",
Icon: GitPullRequestClosedIcon,
};
}
if (input.isDraft) {
return {
label: "Draft",
toneClassName: "text-zinc-500 dark:text-zinc-400/80",
Icon: GitPullRequestDraftIcon,
};
}
if (input.mergeability === "conflicting") {
return {
// "Has conflicts" leaves out the one thing a reader wants when the warning triangle catches
// their eye, so name the branch it collides with wherever the caller knows it.
label: input.baseBranch ? `Conflicts with ${input.baseBranch}` : "Has conflicts",
toneClassName: "text-destructive",
Icon: TriangleAlertIcon,
};
}): PullRequestConflictPresentation | null {
if (input.state !== "open" || input.isDraft || input.mergeability !== "conflicting") {
return null;
}
return {
label: "Open",
toneClassName: "text-emerald-600 dark:text-emerald-300/90",
Icon: GitPullRequestIcon,
label: input.baseBranch ? `Conflicts with ${input.baseBranch}` : "Has conflicts",
toneClassName: "text-destructive",
Icon: PullRequestGlyph.conflicting,
};
}
export function PullRequestStateGlyph({
state,
isDraft,
className,
}: {
state: PullRequestState;
isDraft: boolean;
className?: string;
}) {
const presentation = resolvePullRequestState({ state, isDraft });
return (
<Tooltip>
{/* The list row is itself a button, so the trigger stays a span: an interactive one would
nest a control inside that button and steal the row's click target. */}
<TooltipTrigger render={<span className="inline-flex shrink-0" />}>
<presentation.Icon
role="img"
aria-label={presentation.label}
className={cn("size-4 shrink-0", presentation.toneClassName, className)}
/>
</TooltipTrigger>
<TooltipPopup>{presentation.label}</TooltipPopup>
</Tooltip>
);
}
export function PullRequestConflictGlyph({
state,
isDraft,
mergeability,
@@ -112,16 +119,15 @@ export function PullRequestStateGlyph({
baseBranch?: string;
className?: string;
}) {
const presentation = resolvePullRequestState({
const presentation = resolvePullRequestConflict({
state,
isDraft,
...(mergeability ? { mergeability } : {}),
...(baseBranch ? { baseBranch } : {}),
...(mergeability === undefined ? {} : { mergeability }),
...(baseBranch === undefined ? {} : { baseBranch }),
});
if (presentation === null) return null;
return (
<Tooltip>
{/* The list row is itself a button, so the trigger stays a span: an interactive one would
nest a control inside that button and steal the row's click target. */}
<TooltipTrigger render={<span className="inline-flex shrink-0" />}>
<presentation.Icon
role="img"
@@ -1,5 +1,5 @@
import { RefreshIcon } from "~/components/ui/refresh-icon";
import { ChevronDownIcon, GitPullRequestIcon } from "lucide-react";
import { ChevronDownIcon } from "lucide-react";
import * as Duration from "effect/Duration";
import * as Option from "effect/Option";
import { useEffect, useState, type ReactNode } from "react";
@@ -67,6 +67,7 @@ import {
useSettingsSearchTargetId,
} from "./settingsLayout";
import { searchableSetting } from "./settingsSearch";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
const EMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult = {
versionControlSystems: [],
@@ -476,7 +477,7 @@ function EmptySourceControlDiscovery({
<SettingsSection id={searchableSetting("source-control").id} title="Server environment">
<Empty className="min-h-88">
<EmptyMedia variant="icon">
<GitPullRequestIcon />
<PullRequestGlyph.pullRequest />
</EmptyMedia>
<EmptyHeader>
<EmptyTitle>
@@ -1,9 +1,4 @@
import {
ArrowLeftIcon,
ChartNoAxesColumnIcon,
GitPullRequestIcon,
SettingsIcon,
} from "lucide-react";
import { ArrowLeftIcon, ChartNoAxesColumnIcon, SettingsIcon } from "lucide-react";
import type { ReactNode } from "react";
import { memo, useCallback } from "react";
import { Link, useCanGoBack, useLocation, useNavigate } from "@tanstack/react-router";
@@ -33,6 +28,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { readPullRequestListPreferences } from "../pullRequest/pullRequestListPreferences";
import { SidebarProviderUpdatePill } from "./SidebarProviderUpdatePill";
import { SidebarUpdateArchitectureWarning, SidebarUpdatePill } from "./SidebarUpdatePill";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
export const SidebarChromeHeader = memo(function SidebarChromeHeader({
isElectron,
@@ -205,7 +201,7 @@ export const SidebarUtilityMenu = memo(function SidebarUtilityMenu() {
/>
{pullRequestsSupported ? (
<SidebarUtilityItem
icon={<GitPullRequestIcon />}
icon={<PullRequestGlyph.pullRequest />}
label="Pull Requests"
onClick={handlePullRequestsClick}
/>
+4 -6
View File
@@ -21,9 +21,6 @@ import {
ChevronDownIcon,
ClockIcon,
EyeIcon,
GitMergeIcon,
GitPullRequestClosedIcon,
GitPullRequestIcon,
LayersIcon,
ListChecksIcon,
PenLineIcon,
@@ -150,6 +147,7 @@ import { useAtomCommand } from "../state/use-atom-command";
import { cn } from "~/lib/utils";
import { primaryServerKeybindingsAtom } from "~/state/server";
import { getSourceControlPresentationForKind } from "~/sourceControlPresentation";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
function getShortcutContext() {
return {
@@ -196,9 +194,9 @@ const INVOLVEMENT_TABS = [
const STATE_TABS = [
{ value: "all", label: "All", Icon: LayersIcon },
{ value: "open", label: "Open", Icon: GitPullRequestIcon },
{ value: "closed", label: "Closed", Icon: GitPullRequestClosedIcon },
{ value: "merged", label: "Merged", Icon: GitMergeIcon },
{ value: "open", label: "Open", Icon: PullRequestGlyph.pullRequest },
{ value: "closed", label: "Closed", Icon: PullRequestGlyph.closed },
{ value: "merged", label: "Merged", Icon: PullRequestGlyph.merged },
] as const satisfies ReadonlyArray<PullRequestFilterOption<PullRequestListState>>;
const SORT_OPTIONS = [
+3 -3
View File
@@ -1,4 +1,3 @@
import { GitPullRequestIcon } from "lucide-react";
import type { ElementType } from "react";
import type { SourceControlProviderInfo, SourceControlProviderKind } from "@t3tools/contracts";
export {
@@ -16,10 +15,11 @@ import {
import {
AzureDevOpsIcon,
BitbucketIcon,
ForgejoIcon,
GitHubIcon,
GitLabIcon,
ForgejoIcon,
} from "./components/Icons";
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
export interface SourceControlPresentation {
readonly providerName: string;
@@ -66,7 +66,7 @@ export function getSourceControlPresentation(
return {
providerName: provider?.name || presentation.providerName,
terminology: getChangeRequestTerminology(provider),
Icon: GitPullRequestIcon,
Icon: PullRequestGlyph.pullRequest,
};
}
}
+44 -15
View File
@@ -2,6 +2,43 @@ import "vite-plus/test/config";
import { defineConfig } from "vite-plus";
import * as NodeURL from "node:url";
/** Import restrictions every file keeps, including the one module exempt from the glyph rule. */
const RESTRICTED_IMPORT_PATHS = [
{
name: "@t3tools/client-runtime",
message:
"Import from an explicit @t3tools/client-runtime/* subpath. The package has no root export.",
},
{
name: "@pierre/diffs/react",
importNames: ["CodeView"],
message: "Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",
},
];
/** Lucide's pull-request glyphs, which only `pullRequestIcons.tsx` may name. */
const RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS = {
name: "lucide-react",
importNames: [
"GitMerge",
"GitMergeIcon",
"GitPullRequest",
"GitPullRequestIcon",
"GitPullRequestArrow",
"GitPullRequestArrowIcon",
"GitPullRequestClosed",
"GitPullRequestClosedIcon",
"GitPullRequestDraft",
"GitPullRequestDraftIcon",
"GitPullRequestCreate",
"GitPullRequestCreateIcon",
"GitPullRequestCreateArrow",
"GitPullRequestCreateArrowIcon",
],
message:
"Pick a glyph by meaning from PullRequestGlyph in apps/web/src/components/pullRequest/pullRequestIcons.tsx so every surface draws the same pull request the same way.",
};
export default defineConfig({
resolve: {
alias: {
@@ -103,21 +140,7 @@ export default defineConfig({
"typescript/unbound-method": "off",
"eslint/no-restricted-imports": [
"error",
{
paths: [
{
name: "@t3tools/client-runtime",
message:
"Import from an explicit @t3tools/client-runtime/* subpath. The package has no root export.",
},
{
name: "@pierre/diffs/react",
importNames: ["CodeView"],
message:
"Use StyledDiffCodeView so web diff surfaces share styling and virtualized geometry.",
},
],
},
{ paths: [...RESTRICTED_IMPORT_PATHS, RESTRICTED_PULL_REQUEST_GLYPH_IMPORTS] },
],
"t3code/no-global-process-runtime": "error",
"t3code/no-inline-schema-compile": "warn",
@@ -131,6 +154,12 @@ export default defineConfig({
files: ["packages/shared/src/hostProcess.ts"],
rules: { "t3code/no-global-process-runtime": "off" },
},
{
// The one module allowed to name lucide's pull-request glyphs; everything else picks
// from its vocabulary. The other import restrictions still apply here.
files: ["apps/web/src/components/pullRequest/pullRequestIcons.tsx"],
rules: { "eslint/no-restricted-imports": ["error", { paths: RESTRICTED_IMPORT_PATHS }] },
},
{
files: ["apps/mobile/src/**"],
rules: { "t3code/no-mobile-uniwind-theme-escape-hatches": "error" },