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