Skip to content

Commit 8a9d0e0

Browse files
authored
fix(web): thread search shows the same PR badge as the sidebar (#22627)
1 parent 733a303 commit 8a9d0e0

1 file changed

Lines changed: 57 additions & 56 deletions

File tree

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

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,13 @@ import { useProject } from "../state/entities";
2323
import {
2424
pullRequestListLines,
2525
resolveThreadCurrentPullRequestLink,
26+
resolveThreadPullRequestBadge,
2627
resolveThreadPullRequestChains,
2728
type ThreadPullRequestBadge,
2829
visibleThreadPullRequests,
2930
} from "@t3tools/shared/threadPullRequests";
3031
import { useRender } from "@base-ui/react/use-render";
31-
import {
32-
type ReactNode,
33-
type AnimationEvent,
34-
type MouseEvent,
35-
type ReactElement,
36-
type ComponentProps,
37-
} from "react";
32+
import { type ReactNode, type AnimationEvent, type MouseEvent, type ReactElement } from "react";
3833
import { cn } from "../lib/utils";
3934
import { revealThreadTerminal } from "../lib/revealThreadTerminal";
4035

@@ -1019,24 +1014,11 @@ export function ThreadRowTrailingStatus({ thread }: { thread: SidebarThreadSumma
10191014
);
10201015
}
10211016

1022-
function ThreadPullRequestNumber({
1023-
number,
1024-
className,
1025-
...props
1026-
}: ComponentProps<"span"> & { number: number }) {
1027-
return (
1028-
<span {...props} className={cn("shrink-0 text-xs tabular-nums", className)}>
1029-
#{number}
1030-
</span>
1031-
);
1032-
}
1033-
1034-
function settledPrHoverColorClass(state: NonNullable<ThreadPr>["state"], isDraft = false): string {
1017+
function settledPrHoverColorClass(state: ThreadPullRequestBadge["state"]): string {
10351018
switch (state) {
1019+
case "draft":
1020+
return "group-hover/sidebar-row:text-zinc-500 dark:group-hover/sidebar-row:text-zinc-400/80";
10361021
case "open":
1037-
if (isDraft) {
1038-
return "group-hover/sidebar-row:text-zinc-500 dark:group-hover/sidebar-row:text-zinc-400/80";
1039-
}
10401022
return "group-hover/sidebar-row:text-emerald-600 dark:group-hover/sidebar-row:text-emerald-300/90";
10411023
case "merged":
10421024
return "group-hover/sidebar-row:text-violet-600 dark:group-hover/sidebar-row:text-violet-300/90";
@@ -1045,6 +1027,7 @@ function settledPrHoverColorClass(state: NonNullable<ThreadPr>["state"], isDraft
10451027
}
10461028
}
10471029

1030+
// Search rows are already buttons, so this renders the sidebar badge's look without its controls.
10481031
export function ThreadSearchPullRequestNumber({
10491032
thread,
10501033
query,
@@ -1056,40 +1039,58 @@ export function ThreadSearchPullRequestNumber({
10561039
enabled?: boolean;
10571040
settled?: boolean;
10581041
}) {
1059-
const matchedLink = visibleThreadPullRequests(thread.pullRequests).find((pr) =>
1060-
pullRequestMatchesSearchQuery({ pullRequests: [pr] }, query),
1061-
);
1062-
const fallbackCandidates =
1063-
thread.pullRequests.length === 0
1064-
? [thread.linkedPullRequest, thread.branchPullRequest]
1065-
: [thread.branchPullRequest];
1066-
const legacyReference = matchedLink
1067-
? undefined
1068-
: fallbackCandidates.find(
1069-
(pr) => pr != null && pullRequestMatchesSearchQuery({ linkedPullRequest: pr }, query),
1070-
);
1071-
const legacyStatus = useLinkedThreadPullRequest(
1042+
const matched = pullRequestMatchesSearchQuery(thread, query);
1043+
const supportsMultiplePullRequests = useSupportsMultiplePullRequests(thread.environmentId);
1044+
const linked = useLinkedThreadPullRequest(
10721045
thread.environmentId,
1073-
legacyReference,
1074-
enabled,
1075-
undefined,
1076-
legacyReference,
1046+
thread.linkedPullRequest,
1047+
enabled && matched,
1048+
thread.pullRequests,
1049+
thread.branchPullRequest,
10771050
);
1078-
const reference = matchedLink ?? legacyReference;
1079-
const linked = matchedLink ? linkedPullRequestSnapshotStatus(matchedLink) : legacyStatus;
1080-
const status = prStatusIndicator(linked?.pr ?? null, linked?.sourceControlProvider);
1081-
return reference ? (
1082-
<ThreadPullRequestNumber
1083-
number={reference.number}
1084-
className={
1051+
if (!matched) return null;
1052+
const badge = supportsMultiplePullRequests
1053+
? resolveThreadPullRequestBadge(thread.pullRequests)
1054+
: null;
1055+
const current = supportsMultiplePullRequests
1056+
? resolveThreadCurrentPullRequestLink(thread.pullRequests)
1057+
: null;
1058+
const pr = linked?.pr ?? null;
1059+
// Stored references already carry a number, so the badge shows before PR details load.
1060+
const stored =
1061+
current ??
1062+
[thread.linkedPullRequest, thread.branchPullRequest].find(
1063+
(reference) =>
1064+
reference != null && pullRequestMatchesSearchQuery({ linkedPullRequest: reference }, query),
1065+
);
1066+
const presentation = resolveThreadPullRequestBadgePresentation({
1067+
badge,
1068+
number: pr?.number ?? stored?.number,
1069+
url: pr?.url ?? stored?.url,
1070+
status: prStatusIndicator(pr, linked?.sourceControlProvider),
1071+
});
1072+
if (presentation === null) return null;
1073+
const aggregate = badge !== null && (badge.kind === "stack" || badge.others > 0);
1074+
const state = aggregate
1075+
? badge.state
1076+
: pr === null
1077+
? null
1078+
: pr.state === "open" && pr.isDraft
1079+
? "draft"
1080+
: pr.state;
1081+
return (
1082+
<span
1083+
aria-label={presentation.label}
1084+
className={cn(
1085+
"inline-flex shrink-0 items-center gap-0.5 text-xs tabular-nums",
10851086
settled
1086-
? cn(
1087-
"text-secondary-label transition-colors",
1088-
linked?.pr && settledPrHoverColorClass(linked.pr.state, linked.pr.isDraft),
1089-
)
1090-
: (status?.colorClass ?? "text-secondary-label")
1091-
}
1092-
aria-label={status?.tooltip ?? `Pull request #${reference.number}`}
1093-
/>
1094-
) : null;
1087+
? cn("text-secondary-label transition-colors", state && settledPrHoverColorClass(state))
1088+
: presentation.toneClassName,
1089+
)}
1090+
>
1091+
{/* text-current opts out of the command palette's muted icon color. */}
1092+
<presentation.Icon aria-hidden className="size-3 shrink-0 text-current" />
1093+
<span>{presentation.text}</span>
1094+
</span>
1095+
);
10951096
}

0 commit comments

Comments
 (0)