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

ThreadDetailsPanel.tsx

239 lines9.3 KB

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