Open History to see the last commit
1import type {
2 EditorId,
3 EnvironmentId,
4 ProjectScript,
5 ResolvedKeybindingsConfig,
6 ThreadId,
7} from "@t3tools/contracts";
8import { AlertTriangleIcon, XIcon } from "lucide-react";
9
10import type { DraftId } from "../../composerDraftStore";
11import { useT3ProjectFileScripts } from "../../hooks/useT3ProjectFileScripts";
12import type { EnvMode, EnvironmentOption } from "../BranchToolbar.logic";
13import { BranchToolbar } from "../BranchToolbar";
14import { BranchToolbarEnvironmentSelector } from "../BranchToolbarEnvironmentSelector";
15import GitActionsControl from "../GitActionsControl";
16import ProjectScriptsControl, {
17 type NewProjectScriptInput,
18 type ProjectScriptActionResult,
19} from "../ProjectScriptsControl";
20import { Button } from "../ui/button";
21import { ScrollArea } from "../ui/scroll-area";
22import { cn } from "../../lib/utils";
23import { OpenInPicker } from "./OpenInPicker";
24import { ThreadDetailsSection } from "./ThreadDetailsSection";
25import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";
26import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
27
28interface VersionMismatchIssue {
29 readonly clientVersion: string;
30 readonly serverVersion: string;
31 readonly serverLabel: string;
32}
33
34export interface ThreadDetailsPanelProps {
35 forceNewWorktree?: boolean;
36 mode: "inline" | "popover";
37 onClose?: () => void;
38 environmentId: EnvironmentId;
39 threadId: ThreadId;
40 draftId?: DraftId;
41 activeProjectName: string | undefined;
42 activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
43 preferredScriptId: string | null;
44 keybindings: ResolvedKeybindingsConfig;
45 availableEditors: ReadonlyArray<EditorId>;
46 showOpenInPicker: boolean;
47 gitCwd: string | null;
48 isGitRepo: boolean;
49 envLocked: boolean;
50 availableEnvironments: readonly EnvironmentOption[];
51 autoEnvironmentLabel?: string | undefined;
52 onAutoEnvironment?: (() => void) | undefined;
53 onEnvironmentChange: (environmentId: EnvironmentId) => void;
54 onEnvModeChange: (mode: EnvMode) => void;
55 effectiveEnvModeOverride?: EnvMode;
56 activeThreadBranchOverride?: string | null;
57 onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
58 startFromOrigin: boolean;
59 onStartFromOriginChange: (startFromOrigin: boolean) => void;
60 onCheckoutPullRequestRequest?: (reference: string) => void;
61 onComposerFocusRequest: () => void;
62 onOpenChanges?: () => void;
63 versionMismatch: VersionMismatchIssue | null;
64 onDismissVersionMismatch: () => void;
65 onRunProjectScript: (script: ProjectScript) => void;
66 onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
67 onUpdateProjectScript: (
68 scriptId: string,
69 input: NewProjectScriptInput,
70 ) => Promise<ProjectScriptActionResult>;
71 onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
72}
73
74export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
75 const fileScripts = useT3ProjectFileScripts(
76 props.environmentId,
77 props.activeProjectScripts ? props.gitCwd : null,
78 );
79 const branchToolbarProps = {
80 showGitControls: props.isGitRepo,
81 environmentId: props.environmentId,
82 threadId: props.threadId,
83 ...(props.draftId ? { draftId: props.draftId } : {}),
84 onEnvModeChange: props.onEnvModeChange,
85 startFromOrigin: props.startFromOrigin,
86 onStartFromOriginChange: props.onStartFromOriginChange,
87 ...(props.effectiveEnvModeOverride
88 ? { effectiveEnvModeOverride: props.effectiveEnvModeOverride }
89 : {}),
90 ...(props.activeThreadBranchOverride !== undefined
91 ? { activeThreadBranchOverride: props.activeThreadBranchOverride }
92 : {}),
93 ...(props.onActiveThreadBranchOverrideChange
94 ? { onActiveThreadBranchOverrideChange: props.onActiveThreadBranchOverrideChange }
95 : {}),
96 envLocked: props.envLocked,
97 forceNewWorktree: props.forceNewWorktree ?? false,
98 onComposerFocusRequest: props.onComposerFocusRequest,
99 ...(props.onCheckoutPullRequestRequest
100 ? { onCheckoutPullRequestRequest: props.onCheckoutPullRequestRequest }
101 : {}),
102 };
103
104 const card = (
105 <div
106 className={cn(
107 // A single-track grid, because a grid area is a definite containing block: the card's own
108 // height is "content, clamped by max-height", which percentages treat as indefinite — as
109 // a plain block (or even a flex column) every `h-full`/`max-h-full` down the chain
110 // resolved to nothing, the scroll area's viewport stayed at its content height, and the
111 // card's overflow-hidden clipped the content instead of scrolling it. `minmax(0,1fr)`
112 // still shrink-wraps short content while letting the clamp bite on tall content.
113 "dropdown-glass isolate contain-paint grid max-h-full grid-rows-[minmax(0,1fr)] overflow-hidden rounded-[20px]",
114 // The popup's real ceiling is what base-ui measured for it — the anchor's clipping
115 // ancestors, which is how an open terminal drawer shrinks it — less the popover
116 // viewport's own p-2. The dvh term is the fallback's fallback, from before.
117 props.mode === "popover" &&
118 "max-h-[min(calc(100dvh-6.5rem),calc(var(--available-height,100dvh)-1rem))]",
119 )}
120 data-thread-details-card
121 >
122 <ScrollArea scrollFade className="min-h-0">
123 <ThreadDetailsSection
124 headingId="thread-details-workspace-heading"
125 title="Workspace"
126 separated={false}
127 >
128 {props.versionMismatch ? (
129 <div className="mx-1 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
130 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
131 <div className="min-w-0 flex-1">
132 <p className="text-xs font-medium">Client and server versions differ</p>
133 <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">
134 Client {props.versionMismatch.clientVersion} · {props.versionMismatch.serverLabel}{" "}
135 {props.versionMismatch.serverVersion}
136 </p>
137 </div>
138 <Button
139 size="icon-xs"
140 variant="ghost"
141 aria-label="Dismiss version mismatch warning"
142 onClick={props.onDismissVersionMismatch}
143 >
144 <XIcon className="size-3.5" />
145 </Button>
146 </div>
147 ) : null}
148
149 <div className="flex flex-col">
150 {props.availableEnvironments.length > 1 ? (
151 <BranchToolbarEnvironmentSelector
152 displayMode="panel"
153 autoEnvironmentLabel={props.autoEnvironmentLabel}
154 onAutoEnvironment={props.onAutoEnvironment}
155 envLocked={props.envLocked}
156 environmentId={props.environmentId}
157 availableEnvironments={props.availableEnvironments}
158 onEnvironmentChange={props.onEnvironmentChange}
159 />
160 ) : null}
161
162 <BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
163
164 {props.showOpenInPicker ? (
165 <OpenInPicker
166 environmentId={props.environmentId}
167 keybindings={props.keybindings}
168 availableEditors={props.availableEditors}
169 openInCwd={props.gitCwd}
170 displayMode="panel"
171 />
172 ) : null}
173
174 {props.activeProjectScripts ? (
175 <ProjectScriptsControl
176 displayMode="panel"
177 scripts={props.activeProjectScripts}
178 fileScripts={fileScripts}
179 keybindings={props.keybindings}
180 preferredScriptId={props.preferredScriptId}
181 onRunScript={props.onRunProjectScript}
182 onAddScript={props.onAddProjectScript}
183 onUpdateScript={props.onUpdateProjectScript}
184 onDeleteScript={props.onDeleteProjectScript}
185 />
186 ) : null}
187 </div>
188 </ThreadDetailsSection>
189
190 {props.gitCwd ? (
191 <ThreadDetailsSection
192 headingId="thread-details-version-control-heading"
193 title="Version Control"
194 >
195 <div className="flex flex-col">
196 {props.isGitRepo ? (
197 <BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />
198 ) : null}
199 {props.activeProjectName ? (
200 <GitActionsControl
201 displayMode="panel"
202 gitCwd={props.gitCwd}
203 activeThreadRef={{ environmentId: props.environmentId, threadId: props.threadId }}
204 {...(props.draftId ? { draftId: props.draftId } : {})}
205 {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
206 />
207 ) : null}
208 </div>
209 </ThreadDetailsSection>
210 ) : null}
211
212 {!props.draftId ? (
213 <ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />
214 ) : null}
215
216 {!props.draftId ? (
217 <ThreadRelationshipsPanel environmentId={props.environmentId} threadId={props.threadId} />
218 ) : null}
219 </ScrollArea>
220 </div>
221 );
222
223 if (props.mode === "popover") {
224 return <div data-thread-details-panel="popover">{card}</div>;
225 }
226
227 return (
228 <aside
229 aria-label="Thread details"
230 className="absolute inset-y-0 right-[var(--app-scrollbar-width)] z-20 w-[var(--thread-details-panel-width)] p-3"
231 data-thread-details-panel="inline"
232 >
233 {card}
234 </aside>
235 );
236}