@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
tsx 88 lines 2.63 KB
Raw
1 import type { EnvironmentId, PullRequestRef } from "@t3tools/contracts";
2 import { T } from "gt-react";
3 import { useState } from "react";
4
5 import { pullRequestEnvironment } from "~/state/pullRequests";
6 import { useEnvironmentQuery } from "~/state/query";
7
8 import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
9 import { ChangeBreakdownGrid } from "./ChangeBreakdownGrid";
10 import { PullRequestDiffStat } from "./pullRequestPresentation";
11
12 /**
13 * The pull request's diff stat, with a hover split into code, tests, mocks, and generated files.
14 * In lists the split is read on first pointer or focus intent, so rows nobody hovers cost the
15 * host nothing. A view of one pull request passes `eager` so the split is ready before the hover.
16 */
17 export function PullRequestChangeBreakdownStat({
18 environmentId,
19 reference,
20 additions,
21 deletions,
22 className,
23 eager = false,
24 }: {
25 environmentId: EnvironmentId;
26 reference: PullRequestRef;
27 additions: number;
28 deletions: number;
29 className: string;
30 eager?: boolean;
31 }) {
32 const [requested, setRequested] = useState(eager);
33 const query = useEnvironmentQuery(
34 requested ? pullRequestEnvironment.changeBreakdown({ environmentId, input: reference }) : null,
35 );
36 const breakdown = query.data;
37 if (additions === 0 && deletions === 0) return null;
38 return (
39 <Tooltip>
40 <TooltipTrigger
41 onPointerEnter={() => setRequested(true)}
42 onFocus={() => setRequested(true)}
43 render={
44 <span className="inline-flex">
45 <PullRequestDiffStat
46 additions={additions}
47 deletions={deletions}
48 className={className}
49 />
50 </span>
51 }
52 />
53 {breakdown ? (
54 <TooltipPopup side="bottom">
55 <ChangeBreakdownGrid breakdown={breakdown} total={{ additions, deletions }} />
56 </TooltipPopup>
57 ) : query.isPending ? (
58 <TooltipPopup side="bottom">
59 <T>Loading breakdown</T>
60 </TooltipPopup>
61 ) : null}
62 </Tooltip>
63 );
64 }
65
66 /**
67 * The split shown inline, for surfaces that already sit behind a hover, such as the thread
68 * details card. It reads on mount, so it costs the host a request only once the card opens.
69 */
70 export function PullRequestChangeBreakdownRows({
71 environmentId,
72 reference,
73 className,
74 }: {
75 environmentId: EnvironmentId;
76 reference: PullRequestRef;
77 className: string;
78 }) {
79 const query = useEnvironmentQuery(
80 pullRequestEnvironment.changeBreakdown({ environmentId, input: reference }),
81 );
82 if (!query.data) return null;
83 return (
84 <div className={className}>
85 <ChangeBreakdownGrid breakdown={query.data} />
86 </div>
87 );
88 }