Skip to content

Commit e8ca3a8

Browse files
authored
refactor(web): centralize pull request icon state presentation (pingdotgg#11144)
1 parent f45c6b4 commit e8ca3a8

26 files changed

Lines changed: 628 additions & 307 deletions

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
FileSearchIcon,
4747
FolderIcon,
4848
FolderPlusIcon,
49-
GitPullRequestArrowIcon,
5049
LinkIcon,
5150
MessageSquareIcon,
5251
PaletteIcon,
@@ -181,6 +180,7 @@ import {
181180
buildSidebarProjectSnapshots,
182181
} from "../sidebarProjectGrouping";
183182
import type { Project } from "../types";
183+
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
184184

185185
const EMPTY_BROWSE_ENTRIES: FilesystemBrowseResult["entries"] = [];
186186

@@ -1712,7 +1712,7 @@ function OpenCommandPaletteDialog(props: {
17121712
value: "action:link-pull-request",
17131713
searchTerms: ["link", "pull request", "pr", "attach", "stack"],
17141714
title: "Link pull request to thread",
1715-
icon: <GitPullRequestArrowIcon className={ITEM_ICON_CLASS} />,
1715+
icon: <PullRequestGlyph.link className={ITEM_ICON_CLASS} />,
17161716
run: async () => {
17171717
openLinkPullRequestDialog(threadRef);
17181718
},
@@ -1724,7 +1724,7 @@ function OpenCommandPaletteDialog(props: {
17241724
searchTerms: ["pull requests", "linked", "stack", "prs"],
17251725
title: "Show linked pull requests",
17261726
disabled: visibleThreadPullRequests(activeThread.pullRequests).length === 0,
1727-
icon: <GitPullRequestArrowIcon className={ITEM_ICON_CLASS} />,
1727+
icon: <PullRequestGlyph.link className={ITEM_ICON_CLASS} />,
17281728
run: async () => {
17291729
useRightPanelStore.getState().open(threadRef, "pull-requests");
17301730
},

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useSupportsMultiplePullRequests } from "~/hooks/useSupportsMultiplePullRequests";
2-
import { GitPullRequestIcon } from "lucide-react";
32
import { resolveThreadCurrentPullRequestLink } from "@t3tools/shared/threadPullRequests";
43
import { Spinner } from "~/components/ui/spinner";
54
import {
@@ -214,6 +213,7 @@ import {
214213
type SidebarProjectGroupMember,
215214
type SidebarProjectSnapshot,
216215
} from "../sidebarProjectGrouping";
216+
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
217217
const SIDEBAR_SORT_LABELS: Record<SidebarProjectSortOrder, string> = {
218218
updated_at: "Last user message",
219219
created_at: "Created at",
@@ -757,7 +757,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
757757
className="text-muted-foreground"
758758
aria-label={`PR #${currentLinkedPr.number}, status pending`}
759759
>
760-
<GitPullRequestIcon className="size-3" />
760+
<PullRequestGlyph.pullRequest className="size-3" />
761761
</a>
762762
) : null}
763763
{threadStatus && <ThreadStatusLabel status={threadStatus} />}

‎apps/web/src/components/RightPanelTabs.tsx‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import {
2121
ChevronRight,
2222
FileDiff,
2323
Files,
24-
GitPullRequest,
25-
GitPullRequestArrow,
2624
Globe2,
2725
Plus,
2826
TerminalSquare,
@@ -73,6 +71,7 @@ import { FaviconImage } from "./preview/PreviewFaviconIcon";
7371
import { previewBridge } from "./preview/previewBridge";
7472
import { PierreEntryIcon } from "./chat/PierreEntryIcon";
7573
import { resolvePullRequestState } from "./pullRequest/pullRequestPresentation";
74+
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
7675

7776
interface RightPanelTabsProps {
7877
mode: PreviewPanelMode;
@@ -373,7 +372,7 @@ function RightPanelEmptyState(props: {
373372
},
374373
{
375374
label: "Pull request",
376-
icon: GitPullRequest,
375+
icon: PullRequestGlyph.pullRequest,
377376
shortcut: "P",
378377
available: props.pullRequestAvailable,
379378
disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequest,
@@ -382,7 +381,7 @@ function RightPanelEmptyState(props: {
382381
},
383382
{
384383
label: "Linked pull requests",
385-
icon: GitPullRequestArrow,
384+
icon: PullRequestGlyph.link,
386385
shortcut: "L",
387386
available: props.pullRequestsAvailable,
388387
disabledReason: SURFACE_UNAVAILABLE_HINTS.pullRequests,
@@ -712,7 +711,7 @@ function SurfaceIcon({
712711
/>
713712
);
714713
case "pull-requests":
715-
return <GitPullRequestArrow className="size-3 shrink-0" />;
714+
return <PullRequestGlyph.link className="size-3 shrink-0" />;
716715
case "agents":
717716
return <Bot className="size-3 shrink-0" />;
718717
case "device":
@@ -801,16 +800,17 @@ function PullRequestSurfaceIcon({
801800
},
802801
}),
803802
).data;
804-
// Only state and draft reach the tab. A list seed cannot know mergeability, so feeding the
805-
// full detail would flip an open tab to the conflict glyph the moment its read lands.
803+
// The compact tab intentionally shows lifecycle and draft state only. Conflict warnings have
804+
// their own presentation on surfaces that have mergeability, while this tab stays stable as
805+
// detail data arrives.
806806
const status =
807807
linkedSnapshot !== null
808808
? linkedSnapshot
809809
: detail === null
810810
? (seed ?? null)
811811
: { state: detail.state, isDraft: detail.isDraft };
812812
if (status === null) {
813-
return <GitPullRequest className="size-3 shrink-0 text-muted-foreground" />;
813+
return <PullRequestGlyph.pullRequest className="size-3 shrink-0 text-muted-foreground" />;
814814
}
815815
const presentation = resolvePullRequestState({ state: status.state, isDraft: status.isDraft });
816816
return <presentation.Icon className={cn("size-3 shrink-0", presentation.toneClassName)} />;
@@ -895,15 +895,15 @@ export function RightPanelTabs(props: RightPanelTabsProps) {
895895
},
896896
{
897897
label: "Pull request",
898-
icon: GitPullRequest,
898+
icon: PullRequestGlyph.pullRequest,
899899
shortcut: "P",
900900
available: props.pullRequestAvailable,
901901
disabledReason: SURFACE_DISABLED_REASONS.pullRequest,
902902
onClick: props.onAddPullRequest,
903903
},
904904
{
905905
label: "Linked pull requests",
906-
icon: GitPullRequestArrow,
906+
icon: PullRequestGlyph.link,
907907
shortcut: "L",
908908
available: props.pullRequestsAvailable,
909909
disabledReason: SURFACE_DISABLED_REASONS.pullRequests,

‎apps/web/src/components/ThreadStatusIndicators.test.ts‎

Lines changed: 130 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import { ProjectId, type PullRequestSummary, type VcsStatusResult } from "@t3tools/contracts";
22
import { describe, expect, it } from "@effect/vitest";
3-
import {
4-
GitMergeIcon,
5-
GitPullRequestClosedIcon,
6-
GitPullRequestDraftIcon,
7-
GitPullRequestIcon,
8-
} from "lucide-react";
93

104
import {
115
ChangeRequestStatusIcon,
126
prStatusIndicator,
13-
settledPrHoverColorClass,
7+
resolveThreadPullRequestBadgePresentation,
148
} from "./ThreadStatusIndicators";
159
import { newestPullRequestSummary } from "../state/pullRequests";
10+
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
1611

1712
describe("ChangeRequestStatusIcon", () => {
1813
it.each([
19-
["open", "open", false, GitPullRequestIcon],
20-
["draft", "open", true, GitPullRequestDraftIcon],
21-
["closed", "closed", false, GitPullRequestClosedIcon],
22-
["merged", "merged", false, GitMergeIcon],
14+
["open", "open", false, PullRequestGlyph.pullRequest],
15+
["draft", "open", true, PullRequestGlyph.draft],
16+
["closed", "closed", false, PullRequestGlyph.closed],
17+
["merged", "merged", false, PullRequestGlyph.merged],
2318
] as const)("uses the %s pull request glyph", (_label, state, isDraft, expectedIcon) => {
2419
expect(ChangeRequestStatusIcon({ state, isDraft }).type).toBe(expectedIcon);
2520
});
@@ -119,18 +114,131 @@ describe("prStatusIndicator", () => {
119114
});
120115
});
121116

122-
describe("settledPrHoverColorClass", () => {
123-
it.each([
124-
["open", "text-emerald-600"],
125-
["merged", "text-violet-600"],
126-
["closed", "text-red-600"],
127-
] as const)("restores the %s pull request color on row hover", (state, colorClass) => {
128-
expect(settledPrHoverColorClass(state)).toContain(`group-hover/sidebar-row:${colorClass}`);
117+
describe("resolveThreadPullRequestBadgePresentation", () => {
118+
const url = "https://github.com/pingdotgg/t3code/pull/42";
119+
120+
it("returns the pending pull-request badge when no snapshot is available", () => {
121+
expect(
122+
resolveThreadPullRequestBadgePresentation({
123+
badge: null,
124+
number: 42,
125+
url,
126+
status: null,
127+
}),
128+
).toEqual({
129+
Icon: PullRequestGlyph.pullRequest,
130+
toneClassName: "text-muted-foreground",
131+
label: "PR #42, status pending",
132+
text: 42,
133+
});
129134
});
130135

131-
it("keeps draft pull requests gray on row hover", () => {
132-
expect(settledPrHoverColorClass("open", true)).toContain(
133-
"group-hover/sidebar-row:text-zinc-500",
134-
);
136+
it.each([
137+
[
138+
"open",
139+
{ state: "open", isDraft: false },
140+
PullRequestGlyph.pullRequest,
141+
"text-emerald-600 dark:text-emerald-300/90",
142+
"PR #42 - Open: PR branch",
143+
],
144+
[
145+
"draft",
146+
{ state: "open", isDraft: true },
147+
PullRequestGlyph.draft,
148+
"text-zinc-500 dark:text-zinc-400/80",
149+
"PR #42 - Draft: PR branch",
150+
],
151+
[
152+
"closed",
153+
{ state: "closed", isDraft: false },
154+
PullRequestGlyph.closed,
155+
"text-red-600 dark:text-red-300/90",
156+
"PR #42 - Closed: PR branch",
157+
],
158+
[
159+
"merged",
160+
{ state: "merged", isDraft: false },
161+
PullRequestGlyph.merged,
162+
"text-violet-600 dark:text-violet-300/90",
163+
"PR #42 - Merged: PR branch",
164+
],
165+
] as const)(
166+
"keeps the %s state for one linked pull request",
167+
(_state, prOverrides, expectedIcon, expectedToneClassName, expectedLabel) => {
168+
const fixture = status().pr;
169+
if (!fixture) throw new Error("Expected pull request fixture");
170+
const prStatus = prStatusIndicator({ ...fixture, ...prOverrides }, undefined);
171+
if (!prStatus) throw new Error("Expected pull request status");
172+
173+
expect(
174+
resolveThreadPullRequestBadgePresentation({
175+
badge: { kind: "pull-request", others: 0, state: "open" },
176+
number: fixture.number,
177+
url: fixture.url,
178+
status: prStatus,
179+
}),
180+
).toEqual({
181+
Icon: expectedIcon,
182+
toneClassName: expectedToneClassName,
183+
label: expectedLabel,
184+
text: fixture.number,
185+
});
186+
},
187+
);
188+
189+
it.each([
190+
["open", "text-emerald-600 dark:text-emerald-300/90"],
191+
["draft", "text-zinc-500 dark:text-zinc-400/80"],
192+
["merged", "text-violet-600 dark:text-violet-300/90"],
193+
] as const)(
194+
"uses a layers badge with the %s stack tone without a link identity",
195+
(state, expectedToneClassName) => {
196+
expect(
197+
resolveThreadPullRequestBadgePresentation({
198+
badge: { kind: "stack", layers: 3, state },
199+
status: null,
200+
}),
201+
).toEqual({
202+
Icon: PullRequestGlyph.stack,
203+
toneClassName: expectedToneClassName,
204+
label: `Stack of 3 pull requests, ${state}`,
205+
text: 3,
206+
});
207+
},
208+
);
209+
210+
it.each([
211+
["open", PullRequestGlyph.pullRequest, "text-emerald-600 dark:text-emerald-300/90"],
212+
["draft", PullRequestGlyph.draft, "text-zinc-500 dark:text-zinc-400/80"],
213+
["merged", PullRequestGlyph.merged, "text-violet-600 dark:text-violet-300/90"],
214+
] as const)(
215+
"draws the count of unrelated linked pull requests with their %s aggregate state",
216+
(state, expectedIcon, expectedToneClassName) => {
217+
const fixture = status().pr;
218+
if (!fixture) throw new Error("Expected pull request fixture");
219+
const closedStatus = prStatusIndicator(
220+
{ ...fixture, state: "closed", isDraft: false },
221+
undefined,
222+
);
223+
if (!closedStatus) throw new Error("Expected pull request status");
224+
225+
expect(
226+
resolveThreadPullRequestBadgePresentation({
227+
badge: { kind: "pull-request", others: 2, state },
228+
number: fixture.number,
229+
url: fixture.url,
230+
status: closedStatus,
231+
}),
232+
).toEqual({
233+
Icon: expectedIcon,
234+
toneClassName: expectedToneClassName,
235+
label: `PR #42 - Closed: PR branch, and 2 more linked; overall ${state}`,
236+
text: "+3",
237+
});
238+
},
239+
);
240+
241+
it("omits the control when neither a stack nor a linked identity can be shown", () => {
242+
expect(resolveThreadPullRequestBadgePresentation({ badge: null, status: null })).toBeNull();
135243
});
136244
});

0 commit comments

Comments
 (0)