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 type { ComponentProps } from "react";
22import { ThreadDetailsCard } from "./ThreadDetailsCard";
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 extends Pick<
35 ComponentProps<typeof ThreadDetailsCard>,
36 "anchor" | "handle" | "onPresentationChange"
37> {
38 forceNewWorktree?: boolean;
39 environmentId: EnvironmentId;
40 threadId: ThreadId;
41 draftId?: DraftId;
42 activeProjectName: string | undefined;
43 activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
44 preferredScriptId: string | null;
45 keybindings: ResolvedKeybindingsConfig;
46 availableEditors: ReadonlyArray<EditorId>;
47 showOpenInPicker: boolean;
48 gitCwd: string | null;
49 isGitRepo: boolean;
50 envLocked: boolean;
51 availableEnvironments: readonly EnvironmentOption[];
52 autoEnvironmentLabel?: string | undefined;
53 onAutoEnvironment?: (() => void) | undefined;
54 onEnvironmentChange: (environmentId: EnvironmentId) => void;
55 onEnvModeChange: (mode: EnvMode) => void;
56 /** The thread's env mode as ChatView resolves it. */
57 envMode: EnvMode;
58 activeThreadBranchOverride?: string | null;
59 onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
60 startFromOrigin: boolean;
61 onStartFromOriginChange: (startFromOrigin: boolean) => void;
62 onCheckoutPullRequestRequest?: (reference: string) => void;
63 onComposerFocusRequest: () => void;
64 onOpenChanges?: () => void;
65 versionMismatch: VersionMismatchIssue | null;
66 onDismissVersionMismatch: () => void;
67 onRunProjectScript: (script: ProjectScript) => void;
68 onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
69 onUpdateProjectScript: (
70 scriptId: string,
71 input: NewProjectScriptInput,
72 ) => Promise<ProjectScriptActionResult>;
73 onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
74}
75
76export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
77 const fileScripts = useT3ProjectFileScripts(
78 props.environmentId,
79 props.activeProjectScripts ? props.gitCwd : null,
80 );
81 const branchToolbarProps = {
82 showGitControls: props.isGitRepo,
83 environmentId: props.environmentId,
84 threadId: props.threadId,
85 ...(props.draftId ? { draftId: props.draftId } : {}),
86 onEnvModeChange: props.onEnvModeChange,
87 startFromOrigin: props.startFromOrigin,
88 onStartFromOriginChange: props.onStartFromOriginChange,
89 envMode: props.envMode,
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 return (
105 <ThreadDetailsCard
106 threadRef={{ environmentId: props.environmentId, threadId: props.threadId }}
107 anchor={props.anchor}
108 handle={props.handle}
109 onPresentationChange={props.onPresentationChange}
110 >
111 {(density) => (
112 <>
113 <ThreadDetailsSection
114 headingId="thread-details-workspace-heading"
115 title="Workspace"
116 separated={false}
117 showHeading={density === "full"}
118 >
119 {props.versionMismatch ? (
120 <div className="mx-1 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
121 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
122 <div className="min-w-0 flex-1">
123 <p className="text-xs font-medium">Client and server versions differ</p>
124 <p className="mt-1 text-2xs leading-relaxed text-muted-foreground">
125 Client {props.versionMismatch.clientVersion} ·{" "}
126 {props.versionMismatch.serverLabel} {props.versionMismatch.serverVersion}
127 </p>
128 </div>
129 <Button
130 size="icon-xs"
131 variant="ghost"
132 aria-label="Dismiss version mismatch warning"
133 onClick={props.onDismissVersionMismatch}
134 >
135 <XIcon className="size-3.5" />
136 </Button>
137 </div>
138 ) : null}
139
140 <div className="flex flex-col">
141 {density === "full" && props.availableEnvironments.length > 1 ? (
142 <BranchToolbarEnvironmentSelector
143 displayMode="panel"
144 autoEnvironmentLabel={props.autoEnvironmentLabel}
145 onAutoEnvironment={props.onAutoEnvironment}
146 envLocked={props.envLocked}
147 environmentId={props.environmentId}
148 availableEnvironments={props.availableEnvironments}
149 onEnvironmentChange={props.onEnvironmentChange}
150 />
151 ) : null}
152
153 {density === "full" ? (
154 <BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
155 ) : null}
156
157 {density !== "essential" && props.showOpenInPicker ? (
158 <OpenInPicker
159 environmentId={props.environmentId}
160 keybindings={props.keybindings}
161 availableEditors={props.availableEditors}
162 openInCwd={props.gitCwd}
163 displayMode="panel"
164 />
165 ) : null}
166
167 {props.activeProjectScripts ? (
168 <ProjectScriptsControl
169 displayMode="panel"
170 scripts={props.activeProjectScripts}
171 fileScripts={fileScripts}
172 keybindings={props.keybindings}
173 preferredScriptId={props.preferredScriptId}
174 onRunScript={props.onRunProjectScript}
175 onAddScript={props.onAddProjectScript}
176 onUpdateScript={props.onUpdateProjectScript}
177 onDeleteScript={props.onDeleteProjectScript}
178 />
179 ) : null}
180 </div>
181 </ThreadDetailsSection>
182
183 {props.gitCwd ? (
184 <ThreadDetailsSection
185 headingId="thread-details-version-control-heading"
186 title="Version Control"
187 showHeading={density === "full"}
188 separated={density === "full"}
189 >
190 <div className="flex flex-col">
191 {props.isGitRepo ? (
192 <BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />
193 ) : null}
194 {props.activeProjectName ? (
195 <GitActionsControl
196 displayMode="panel"
197 compact={density !== "full"}
198 gitCwd={props.gitCwd}
199 activeThreadRef={{
200 environmentId: props.environmentId,
201 threadId: props.threadId,
202 }}
203 {...(props.draftId ? { draftId: props.draftId } : {})}
204 {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
205 />
206 ) : null}
207 </div>
208 </ThreadDetailsSection>
209 ) : null}
210
211 {density === "full" && !props.draftId ? (
212 <ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />
213 ) : null}
214
215 {density === "full" && !props.draftId ? (
216 <ThreadRelationshipsPanel
217 environmentId={props.environmentId}
218 threadId={props.threadId}
219 />
220 ) : null}
221 </>
222 )}
223 </ThreadDetailsCard>
224 );
225}