The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { PullRequestAction } from "@t3tools/contracts"; |
| 2 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; |
| 3 | import { T } from "gt-react"; |
| 4 | import { SearchIcon } from "lucide-react"; |
| 5 | import { PullRequestChangeBreakdownStat } from "./PullRequestChangeBreakdownStat"; |
| 6 | import { PullRequestStackPopover } from "./PullRequestStackPopover"; |
| 7 | import { |
| 8 | PullRequestSpeedActions, |
| 9 | type PullRequestSpeedActionResult, |
| 10 | } from "./PullRequestSpeedActions"; |
| 11 | import { memo, type RefCallback } from "react"; |
| 12 | |
| 13 | import { cn } from "~/lib/utils"; |
| 14 | import { getSourceControlPresentationForKind } from "~/sourceControlPresentation"; |
| 15 | |
| 16 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; |
| 17 | import { PullRequestChecksPopover } from "./PullRequestChecksPopover"; |
| 18 | import { pullRequestPanelReference } from "./usePullRequestDetail"; |
| 19 | import type { EnvironmentPullRequestEntry } from "./pullRequestList.logic"; |
| 20 | import { openOnHostLabel, showPullRequestLinkContextMenu } from "./pullRequestLinkContextMenu"; |
| 21 | import { |
| 22 | PULL_REQUEST_ROW_CLASS, |
| 23 | PULL_REQUEST_ROW_NUMBER_CLASS, |
| 24 | PullRequestRowAuthor, |
| 25 | PullRequestRowGlyph, |
| 26 | PullRequestRowLines, |
| 27 | } from "./PullRequestListRow"; |
| 28 | import { PullRequestLabelChip, PullRequestReviewDecisionGlyph } from "./pullRequestPresentation"; |
| 29 | |
| 30 | const LABEL_SLOTS = [ |
| 31 | { overflow: "@xl/pr-row-meta:hidden" }, |
| 32 | { overflow: "@3xl/pr-row-meta:hidden" }, |
| 33 | { overflow: "" }, |
| 34 | ] as const; |
| 35 | |
| 36 | function PullRequestRowLabels({ labels }: { labels: EnvironmentPullRequestEntry["labels"] }) { |
| 37 | if (labels.length === 0) return null; |
| 38 | return ( |
| 39 | <span className="flex min-w-0 items-center gap-1"> |
| 40 | {LABEL_SLOTS.map((slot, index) => { |
| 41 | const label = labels[index]; |
| 42 | if (!label) return null; |
| 43 | const remaining = labels.length - index - 1; |
| 44 | return ( |
| 45 | <PullRequestLabelChip |
| 46 | key={label.name} |
| 47 | label={label} |
| 48 | className={ |
| 49 | index === 0 |
| 50 | ? "" |
| 51 | : index === 1 |
| 52 | ? "hidden @xl/pr-row-meta:inline-flex" |
| 53 | : "hidden @3xl/pr-row-meta:inline-flex" |
| 54 | } |
| 55 | > |
| 56 | {remaining > 0 ? ( |
| 57 | <span className={cn("shrink-0", slot.overflow)}>+{remaining}</span> |
| 58 | ) : null} |
| 59 | </PullRequestLabelChip> |
| 60 | ); |
| 61 | })} |
| 62 | </span> |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | const PAGE_ROW_CLASS = "px-3 py-2.5"; |
| 67 | |
| 68 | export type PullRequestRowTarget = Pick< |
| 69 | EnvironmentPullRequestEntry, |
| 70 | "environmentId" | "projectId" | "host" | "repository" | "number" |
| 71 | >; |
| 72 | |
| 73 | function PullRequestRowImpl({ |
| 74 | entry, |
| 75 | selected, |
| 76 | showProjectTitle, |
| 77 | showProvider, |
| 78 | environmentLabel, |
| 79 | matchedElsewhere, |
| 80 | statsKey, |
| 81 | statsRef, |
| 82 | onSelect, |
| 83 | onIntent, |
| 84 | hostActions, |
| 85 | onActed, |
| 86 | closing = false, |
| 87 | sweeping = false, |
| 88 | onCloseSweepStart, |
| 89 | }: { |
| 90 | entry: EnvironmentPullRequestEntry; |
| 91 | selected: boolean; |
| 92 | showProjectTitle: boolean; |
| 93 | showProvider: boolean; |
| 94 | environmentLabel?: string; |
| 95 | matchedElsewhere?: boolean; |
| 96 | /** Visibility key for deferred line-count reads. */ |
| 97 | statsKey?: string; |
| 98 | statsRef?: RefCallback<HTMLDivElement>; |
| 99 | onSelect: (entry: PullRequestRowTarget) => void; |
| 100 | /** The row the pointer or focus rests on, or null when it leaves. */ |
| 101 | onIntent?: (entry: PullRequestRowTarget | null) => void; |
| 102 | hostActions: ReadonlySet<PullRequestAction>; |
| 103 | onActed: (result: PullRequestSpeedActionResult) => void; |
| 104 | closing?: boolean; |
| 105 | sweeping?: boolean; |
| 106 | onCloseSweepStart?: (entry: EnvironmentPullRequestEntry, event: PointerEvent) => void; |
| 107 | }) { |
| 108 | const { Icon, providerName, terminology } = getSourceControlPresentationForKind(entry.provider); |
| 109 | return ( |
| 110 | <div |
| 111 | ref={statsRef} |
| 112 | data-pull-request-stats-key={statsKey} |
| 113 | data-pull-request-key={statsKey} |
| 114 | className={cn( |
| 115 | "flex items-center rounded-md [content-visibility:auto] [contain-intrinsic-block-size:56.5px]", |
| 116 | selected ? "bg-accent" : "hover:bg-accent/60", |
| 117 | )} |
| 118 | > |
| 119 | <button |
| 120 | type="button" |
| 121 | aria-current={selected ? "true" : undefined} |
| 122 | onClick={() => onSelect(entry)} |
| 123 | onPointerEnter={() => onIntent?.(entry)} |
| 124 | onPointerLeave={(event) => { |
| 125 | if (event.currentTarget !== document.activeElement) onIntent?.(null); |
| 126 | }} |
| 127 | onFocus={() => onIntent?.(entry)} |
| 128 | onBlur={(event) => { |
| 129 | if (!event.currentTarget.matches(":hover")) onIntent?.(null); |
| 130 | }} |
| 131 | className={cn( |
| 132 | PULL_REQUEST_ROW_CLASS, |
| 133 | PAGE_ROW_CLASS, |
| 134 | "min-w-0 flex-1 cursor-pointer transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-ring", |
| 135 | )} |
| 136 | > |
| 137 | <PullRequestRowGlyph |
| 138 | state={entry.state} |
| 139 | isDraft={entry.isDraft} |
| 140 | mergeability={entry.mergeability} |
| 141 | baseBranch={entry.baseBranch} |
| 142 | className="mt-0.75 self-start" |
| 143 | /> |
| 144 | <PullRequestRowLines |
| 145 | number={ |
| 146 | <span |
| 147 | className={PULL_REQUEST_ROW_NUMBER_CLASS} |
| 148 | onContextMenu={(event) => { |
| 149 | event.preventDefault(); |
| 150 | event.stopPropagation(); |
| 151 | void showPullRequestLinkContextMenu({ |
| 152 | url: entry.url, |
| 153 | openLabel: openOnHostLabel(sourceControlClients.get(entry.provider)), |
| 154 | position: { x: event.clientX, y: event.clientY }, |
| 155 | }); |
| 156 | }} |
| 157 | > |
| 158 | #{entry.number} |
| 159 | </span> |
| 160 | } |
| 161 | title={entry.title} |
| 162 | signals={ |
| 163 | <> |
| 164 | {entry.checksState === undefined ? null : ( |
| 165 | <PullRequestChecksPopover |
| 166 | checksState={entry.checksState} |
| 167 | environmentId={entry.environmentId} |
| 168 | reference={{ |
| 169 | ...pullRequestPanelReference({ ...entry, host: entry.host.toLowerCase() }), |
| 170 | allowStale: false, |
| 171 | }} |
| 172 | /> |
| 173 | )} |
| 174 | {entry.reviewDecision === undefined ? null : ( |
| 175 | <PullRequestReviewDecisionGlyph decision={entry.reviewDecision} /> |
| 176 | )} |
| 177 | </> |
| 178 | } |
| 179 | status={ |
| 180 | <> |
| 181 | {entry.stack ? ( |
| 182 | <PullRequestStackPopover |
| 183 | environmentId={entry.environmentId} |
| 184 | reference={{ |
| 185 | projectId: entry.projectId, |
| 186 | host: entry.host, |
| 187 | repository: entry.repository, |
| 188 | number: entry.number, |
| 189 | }} |
| 190 | membership={entry.stack} |
| 191 | onSelect={(target) => |
| 192 | onSelect({ ...target, host: entry.host, environmentId: entry.environmentId }) |
| 193 | } |
| 194 | /> |
| 195 | ) : null} |
| 196 | <PullRequestChangeBreakdownStat |
| 197 | environmentId={entry.environmentId} |
| 198 | reference={{ |
| 199 | projectId: entry.projectId, |
| 200 | host: entry.host, |
| 201 | repository: entry.repository, |
| 202 | number: entry.number, |
| 203 | }} |
| 204 | additions={entry.additions} |
| 205 | deletions={entry.deletions} |
| 206 | className="font-mono" |
| 207 | /> |
| 208 | </> |
| 209 | } |
| 210 | metaClassName="@container/pr-row-meta" |
| 211 | meta={ |
| 212 | <> |
| 213 | {matchedElsewhere ? ( |
| 214 | <Tooltip> |
| 215 | <TooltipTrigger |
| 216 | render={ |
| 217 | <span className="flex min-w-6 items-center gap-1 overflow-hidden rounded-full border border-border/60 px-1 text-3xs" /> |
| 218 | } |
| 219 | > |
| 220 | <span className="sr-only"> |
| 221 | <T>matched in the description</T> |
| 222 | </span> |
| 223 | <SearchIcon aria-hidden className="size-3 shrink-0" /> |
| 224 | <span aria-hidden className="hidden truncate @xs/pr-row-meta:block"> |
| 225 | <T>matched in the description</T> |
| 226 | </span> |
| 227 | </TooltipTrigger> |
| 228 | <TooltipPopup side="top"> |
| 229 | <T>Matched in the description</T> |
| 230 | </TooltipPopup> |
| 231 | </Tooltip> |
| 232 | ) : null} |
| 233 | {showProvider ? ( |
| 234 | <Tooltip> |
| 235 | <TooltipTrigger render={<span className="inline-flex shrink-0" />}> |
| 236 | <Icon aria-label={providerName} className="size-3" /> |
| 237 | </TooltipTrigger> |
| 238 | <TooltipPopup>{providerName}</TooltipPopup> |
| 239 | </Tooltip> |
| 240 | ) : null} |
| 241 | <PullRequestRowAuthor |
| 242 | actor={entry.author} |
| 243 | className="min-w-3.5 max-w-40" |
| 244 | labelClassName="sr-only @xs/pr-row-meta:not-sr-only @xs/pr-row-meta:truncate" |
| 245 | /> |
| 246 | {showProjectTitle ? <span className="truncate">{entry.repository}</span> : null} |
| 247 | {environmentLabel ? ( |
| 248 | <span className="min-w-0 max-w-32 truncate">{environmentLabel}</span> |
| 249 | ) : null} |
| 250 | {entry.labels.length > 0 ? <PullRequestRowLabels labels={entry.labels} /> : null} |
| 251 | </> |
| 252 | } |
| 253 | updatedAt={entry.updatedAt} |
| 254 | /> |
| 255 | </button> |
| 256 | {hostActions.size > 0 ? ( |
| 257 | <PullRequestSpeedActions |
| 258 | entry={entry} |
| 259 | hostActions={hostActions} |
| 260 | terminology={terminology} |
| 261 | onActed={onActed} |
| 262 | closing={closing} |
| 263 | sweeping={sweeping} |
| 264 | {...(onCloseSweepStart ? { onCloseSweepStart } : {})} |
| 265 | /> |
| 266 | ) : null} |
| 267 | </div> |
| 268 | ); |
| 269 | } |
| 270 | |
| 271 | export const PullRequestRow = memo(PullRequestRowImpl); |