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

ThreadDetailsPanel.tsx

226 lines8.9 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 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;
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 effectiveEnvModeOverride?: EnvMode;
57 activeThreadBranchOverride?: string | null;
58 onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
59 startFromOrigin: boolean;
60 onStartFromOriginChange: (startFromOrigin: boolean) => void;
61 onCheckoutPullRequestRequest?: (reference: string) => void;
62 onComposerFocusRequest: () => void;
63 onOpenChanges?: () => void;
64 versionMismatch: VersionMismatchIssue | null;
65 onDismissVersionMismatch: () => void;
66 onRunProjectScript: (script: ProjectScript) => void;
67 onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
68 onUpdateProjectScript: (
69 scriptId: string,
70 input: NewProjectScriptInput,
71 ) => Promise<ProjectScriptActionResult>;
72 onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
74​
75export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
76 const fileScripts = useT3ProjectFileScripts(
77 props.environmentId,
78 props.activeProjectScripts ? props.gitCwd : null,
79 );
80 const branchToolbarProps = {
81 showGitControls: props.isGitRepo,
82 environmentId: props.environmentId,
83 threadId: props.threadId,
84 ...(props.draftId ? { draftId: props.draftId } : {}),
85 onEnvModeChange: props.onEnvModeChange,
86 startFromOrigin: props.startFromOrigin,
87 onStartFromOriginChange: props.onStartFromOriginChange,
88 ...(props.effectiveEnvModeOverride
89 ? { effectiveEnvModeOverride: props.effectiveEnvModeOverride }
90 : {}),
91 ...(props.activeThreadBranchOverride !== undefined
92 ? { activeThreadBranchOverride: props.activeThreadBranchOverride }
93 : {}),
94 ...(props.onActiveThreadBranchOverrideChange
95 ? { onActiveThreadBranchOverrideChange: props.onActiveThreadBranchOverrideChange }
96 : {}),
97 envLocked: props.envLocked,
98 forceNewWorktree: props.forceNewWorktree ?? false,
99 onComposerFocusRequest: props.onComposerFocusRequest,
100 ...(props.onCheckoutPullRequestRequest
101 ? { onCheckoutPullRequestRequest: props.onCheckoutPullRequestRequest }
102 : {}),
103 };
104​
105 return (
106 <ThreadDetailsCard
107 threadRef={{ environmentId: props.environmentId, threadId: props.threadId }}
108 anchor={props.anchor}
109 handle={props.handle}
110 onPresentationChange={props.onPresentationChange}
111 >
112 {(density) => (
113 <>
114 <ThreadDetailsSection
115 headingId="thread-details-workspace-heading"
116 title="Workspace"
117 separated={false}
118 showHeading={density === "full"}
119 >
120 {props.versionMismatch ? (
121 <div className="mx-1 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
122 <AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
123 <div className="min-w-0 flex-1">
124 <p className="text-xs font-medium">Client and server versions differ</p>
125 <p className="mt-1 text-2xs leading-relaxed text-muted-foreground">
126 Client {props.versionMismatch.clientVersion} ·{" "}
127 {props.versionMismatch.serverLabel} {props.versionMismatch.serverVersion}
128 </p>
129 </div>
130 <Button
131 size="icon-xs"
132 variant="ghost"
133 aria-label="Dismiss version mismatch warning"
134 onClick={props.onDismissVersionMismatch}
135 >
136 <XIcon className="size-3.5" />
137 </Button>
138 </div>
139 ) : null}
140​
141 <div className="flex flex-col">
142 {density === "full" && props.availableEnvironments.length > 1 ? (
143 <BranchToolbarEnvironmentSelector
144 displayMode="panel"
145 autoEnvironmentLabel={props.autoEnvironmentLabel}
146 onAutoEnvironment={props.onAutoEnvironment}
147 envLocked={props.envLocked}
148 environmentId={props.environmentId}
149 availableEnvironments={props.availableEnvironments}
150 onEnvironmentChange={props.onEnvironmentChange}
151 />
152 ) : null}
153​
154 {density === "full" ? (
155 <BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
156 ) : null}
157​
158 {density !== "essential" && props.showOpenInPicker ? (
159 <OpenInPicker
160 environmentId={props.environmentId}
161 keybindings={props.keybindings}
162 availableEditors={props.availableEditors}
163 openInCwd={props.gitCwd}
164 displayMode="panel"
165 />
166 ) : null}
167​
168 {props.activeProjectScripts ? (
169 <ProjectScriptsControl
170 displayMode="panel"
171 scripts={props.activeProjectScripts}
172 fileScripts={fileScripts}
173 keybindings={props.keybindings}
174 preferredScriptId={props.preferredScriptId}
175 onRunScript={props.onRunProjectScript}
176 onAddScript={props.onAddProjectScript}
177 onUpdateScript={props.onUpdateProjectScript}
178 onDeleteScript={props.onDeleteProjectScript}
179 />
180 ) : null}
181 </div>
182 </ThreadDetailsSection>
183​
184 {props.gitCwd ? (
185 <ThreadDetailsSection
186 headingId="thread-details-version-control-heading"
187 title="Version Control"
188 showHeading={density === "full"}
189 separated={density === "full"}
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 compact={density !== "full"}
199 gitCwd={props.gitCwd}
200 activeThreadRef={{
201 environmentId: props.environmentId,
202 threadId: props.threadId,
203 }}
204 {...(props.draftId ? { draftId: props.draftId } : {})}
205 {...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
206 />
207 ) : null}
208 </div>
209 </ThreadDetailsSection>
210 ) : null}
211​
212 {density === "full" && !props.draftId ? (
213 <ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />
214 ) : null}
215​
216 {density === "full" && !props.draftId ? (
217 <ThreadRelationshipsPanel
218 environmentId={props.environmentId}
219 threadId={props.threadId}
220 />
221 ) : null}
222 </>
223 )}
224 </ThreadDetailsCard>
225 );