Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadDetailsPanel.tsx

278 lines10.8 KB

1import type {
2 EditorId,
3 EnvironmentId,
4 ProjectScript,
5 ResolvedKeybindingsConfig,
6 ThreadId,
7} from "@t3tools/contracts";
8import type { EnvironmentConnectionPresentation } from "@t3tools/client-runtime/connection";
9import { AlertTriangleIcon, XIcon } from "lucide-react";
10​
11import type { DraftId } from "../../composerDraftStore";
12import { useT3ProjectFileScripts } from "../../hooks/useT3ProjectFileScripts";
13import type { EnvMode, EnvironmentOption } from "../BranchToolbar.logic";
14import { BranchToolbar } from "../BranchToolbar";
15import { BranchToolbarEnvironmentSelector } from "../BranchToolbarEnvironmentSelector";
16import GitActionsControl from "../GitActionsControl";
17import ProjectScriptsControl, {
18 type NewProjectScriptInput,
19 type ProjectScriptActionResult,
20} from "../ProjectScriptsControl";
21import { Button } from "../ui/button";
22import { cn } from "../../lib/utils";
23import { OpenInPicker } from "./OpenInPicker";
24import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";
25import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
26​
27interface VersionMismatchIssue {
28 readonly clientVersion: string;
29 readonly serverVersion: string;
30 readonly serverLabel: string;
32​
33export interface ThreadDetailsPanelProps {
34 mode: "inline" | "popover";
35 onClose?: () => void;
36 environmentId: EnvironmentId;
37 environmentConnection: EnvironmentConnectionPresentation | null;
38 threadId: ThreadId;
39 draftId?: DraftId;
40 activeProjectName: string | undefined;
41 activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
42 preferredScriptId: string | null;
43 keybindings: ResolvedKeybindingsConfig;
44 availableEditors: ReadonlyArray<EditorId>;
45 showOpenInPicker: boolean;
46 gitCwd: string | null;
47 isGitRepo: boolean;
48 envLocked: boolean;
49 availableEnvironments: readonly EnvironmentOption[];
50 onEnvironmentChange: (environmentId: EnvironmentId) => void;
51 onEnvModeChange: (mode: EnvMode) => void;
52 effectiveEnvModeOverride?: EnvMode;
53 activeThreadBranchOverride?: string | null;
54 onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
55 startFromOrigin: boolean;
56 onStartFromOriginChange: (startFromOrigin: boolean) => void;
57 onCheckoutPullRequestRequest?: (reference: string) => void;
58 onComposerFocusRequest: () => void;
59 onOpenChanges?: () => void;
60 onReconnectEnvironment: () => void;
61 onOpenConnectionSettings: () => void;
62 versionMismatch: VersionMismatchIssue | null;
63 onDismissVersionMismatch: () => void;
64 onRunProjectScript: (script: ProjectScript) => void;
65 onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
66 onUpdateProjectScript: (
67 scriptId: string,
68 input: NewProjectScriptInput,
69 ) => Promise<ProjectScriptActionResult>;
70 onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
72​
73export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
74 const fileScripts = useT3ProjectFileScripts(
75 props.environmentId,
76 props.activeProjectScripts ? props.gitCwd : null,
77 );
78 const connectionIssue =
79 props.environmentConnection !== null &&
80 props.environmentConnection.phase !== "connected" &&
81 props.environmentConnection.phase !== "available";
82 const isReconnecting =
83 props.environmentConnection?.phase === "connecting" ||
84 props.environmentConnection?.phase === "reconnecting";
85 const branchToolbarProps = {
86 showGitControls: props.isGitRepo,
87 environmentId: props.environmentId,
88 threadId: props.threadId,
89 ...(props.draftId ? { draftId: props.draftId } : {}),
90 onEnvModeChange: props.onEnvModeChange,
91 startFromOrigin: props.startFromOrigin,
92 onStartFromOriginChange: props.onStartFromOriginChange,
93 ...(props.effectiveEnvModeOverride
94 ? { effectiveEnvModeOverride: props.effectiveEnvModeOverride }
95 : {}),
96 ...(props.activeThreadBranchOverride !== undefined
97 ? { activeThreadBranchOverride: props.activeThreadBranchOverride }
98 : {}),
99 ...(props.onActiveThreadBranchOverrideChange
100 ? { onActiveThreadBranchOverrideChange: props.onActiveThreadBranchOverrideChange }
101 : {}),
102 envLocked: props.envLocked,
103 onComposerFocusRequest: props.onComposerFocusRequest,
104 ...(props.onCheckoutPullRequestRequest
105 ? { onCheckoutPullRequestRequest: props.onCheckoutPullRequestRequest }
106 : {}),
107 };
108​
109 const card = (
110 <div
111 className={cn(
112 "dropdown-glass isolate contain-paint overflow-hidden rounded-[20px]",
113 props.mode === "inline" ? "max-h-full" : "max-h-[calc(100dvh-6.5rem)]",
114 )}
115 data-thread-details-card
116 >
117 <div
118 className={cn(
119 "overflow-x-hidden overflow-y-auto overscroll-contain [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
120 props.mode === "inline" ? "max-h-full" : "max-h-[calc(100dvh-6.5rem)]",
121 )}
122 >
123 <section aria-labelledby="thread-details-workspace-heading">
124 <div className="flex min-h-10 items-center justify-between gap-3 px-3.5 pb-1 pt-3">
125 <h3
126 id="thread-details-workspace-heading"
127 className="text-[11px] font-medium text-muted-foreground"
128 >
129 Workspace
130 </h3>
131 </div>
132​
133 {connectionIssue ? (
134 <div className="mx-3 mb-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
135 <div className="flex gap-2">
136 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
137 <div className="min-w-0 flex-1">
138 <p className="text-xs font-medium">Environment unavailable</p>
139 <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">
140 {props.environmentConnection?.error ??
141 "Reconnect this environment before sending messages or running actions."}
142 </p>
143 <div className="mt-2 flex items-center gap-1.5">
144 <Button
145 size="xs"
146 disabled={isReconnecting}
147 onClick={props.onReconnectEnvironment}
148 >
149 {isReconnecting ? "Reconnecting..." : "Reconnect"}
150 </Button>
151 <Button size="xs" variant="ghost" onClick={props.onOpenConnectionSettings}>
152 Connections
153 </Button>
154 </div>
155 </div>
156 </div>
157 </div>
158 ) : null}
159​
160 {props.versionMismatch ? (
161 <div className="mx-3 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
162 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
163 <div className="min-w-0 flex-1">
164 <p className="text-xs font-medium">Client and server versions differ</p>
165 <p className="mt-1 text-[11px] leading-relaxed text-muted-foreground">
166 Client {props.versionMismatch.clientVersion} · {props.versionMismatch.serverLabel}{" "}
167 {props.versionMismatch.serverVersion}
168 </p>
169 </div>
170 <Button
171 size="icon-xs"
172 variant="ghost"
173 aria-label="Dismiss version mismatch warning"
174 onClick={props.onDismissVersionMismatch}
175 >
176 <XIcon className="size-3.5" />
177 </Button>
178 </div>
179 ) : null}
180​
181 <div className="flex flex-col px-2 pb-2.5">
182 {props.availableEnvironments.length > 1 ? (
183 <BranchToolbarEnvironmentSelector
184 displayMode="panel"
185 envLocked={props.envLocked}
186 environmentId={props.environmentId}
187 availableEnvironments={props.availableEnvironments}
188 onEnvironmentChange={props.onEnvironmentChange}
189 />
190 ) : null}
191​
192 <BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
193​
194 {props.showOpenInPicker ? (
195 <OpenInPicker
196 environmentId={props.environmentId}
197 keybindings={props.keybindings}
198 availableEditors={props.availableEditors}
199 openInCwd={props.gitCwd}
200 displayMode="panel"
201 />
202 ) : null}
203​
204 {props.activeProjectScripts ? (
205 <ProjectScriptsControl
206 displayMode="panel"
207 scripts={props.activeProjectScripts}
208 fileScripts={fileScripts}
209 keybindings={props.keybindings}
210 preferredScriptId={props.preferredScriptId}
211 onRunScript={props.onRunProjectScript}
212 onAddScript={props.onAddProjectScript}
213 onUpdateScript={props.onUpdateProjectScript}
214 onDeleteScript={props.onDeleteProjectScript}
215 />
216 ) : null}
217 </div>
218 </section>
219​
220 {props.gitCwd ? (
221 <section
222 aria-labelledby="thread-details-version-control-heading"
223 className="border-t border-border/65"
224 >
225 <div className="px-3.5 pb-1 pt-3">
226 <h3
227 id="thread-details-version-control-heading"
228 className="text-[11px] font-medium text-muted-foreground"
229 >
230 Version Control
231 </h3>
232 </div>
233 <div className="flex flex-col px-2 pb-2.5">
234 {props.isGitRepo ? (
235 <BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />
236 ) : null}
237 {props.activeProjectName ? (
238 <GitActionsControl
239 displayMode="panel"
240 gitCwd={props.gitCwd}
241 activeThreadRef={{ environmentId: props.environmentId, threadId: props.threadId }}
242 {...(props.draftId ? { draftId: props.draftId } : {})}
243 {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
244 />
245 ) : null}
246 </div>
247 </section>
248 ) : null}
249​
250 {!props.draftId ? (
251 <ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />
252 ) : null}
253​
254 {!props.draftId ? (
255 <ThreadRelationshipsPanel environmentId={props.environmentId} threadId={props.threadId} />
256 ) : null}
257 </div>
258 </div>
259 );
260​
261 if (props.mode === "popover") {
262 return (
263 <div className="max-h-[calc(100dvh-6.5rem)]" data-thread-details-panel="popover">
264 {card}
265 </div>
266 );
267 }
268​
269 return (
270 <aside
271 aria-label="Thread details"
272 className="absolute inset-y-0 right-[var(--app-scrollbar-width)] z-20 w-[var(--thread-details-panel-width)] p-3"
273 data-thread-details-panel="inline"
274 >
275 {card}
276 </aside>
277 );