Files
t3code/apps/web/src/components/chat/ThreadDetailsPanel.tsx
T
Theo BrowneandClaude Opus 5.5 429c625a85 fix(web): workspace card docks beside chat when the window is narrow (#14992)
Chat stays centered while the workspace card fits beside it with 32px to spare. When it does not fit, chat moves left only as far as needed, narrows only after it reaches the left padding, and the card becomes a popover below a 640px chat. The card is lighter: 280px wide, 32px rows, no section labels, no "Project folder" hint.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2026-10-03 13:31:44 -07:00

240 lines
9.3 KiB
TypeScript

import type {
EditorId,
EnvironmentId,
ProjectScript,
ResolvedKeybindingsConfig,
ThreadId,
} from "@t3tools/contracts";
import { AlertTriangleIcon, XIcon } from "lucide-react";
import type { DraftId } from "../../composerDraftStore";
import { useT3ProjectFileScripts } from "../../hooks/useT3ProjectFileScripts";
import {
shouldShowEnvironmentIndicator,
type EnvMode,
type EnvironmentOption,
} from "../BranchToolbar.logic";
import { BranchToolbar } from "../BranchToolbar";
import { BranchToolbarEnvironmentSelector } from "../BranchToolbarEnvironmentSelector";
import GitActionsControl from "../GitActionsControl";
import ProjectScriptsControl, {
type NewProjectScriptInput,
type ProjectScriptActionResult,
} from "../ProjectScriptsControl";
import { Button } from "../ui/button";
import type { ComponentProps } from "react";
import { ThreadDetailsCard } from "./ThreadDetailsCard";
import { OpenInPicker } from "./OpenInPicker";
import { ThreadDetailsSection } from "./ThreadDetailsSection";
import { ThreadAutomationsPanel } from "./ThreadAutomationsPanel";
import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
interface VersionMismatchIssue {
readonly clientVersion: string;
readonly serverVersion: string;
readonly serverLabel: string;
}
export interface ThreadDetailsPanelProps extends Pick<
ComponentProps<typeof ThreadDetailsCard>,
"anchor" | "handle" | "onPresentationChange"
> {
forceNewWorktree?: boolean;
environmentId: EnvironmentId;
threadId: ThreadId;
draftId?: DraftId;
activeProjectName: string | undefined;
activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
preferredScriptId: string | null;
keybindings: ResolvedKeybindingsConfig;
availableEditors: ReadonlyArray<EditorId>;
showOpenInPicker: boolean;
gitCwd: string | null;
isGitRepo: boolean;
envLocked: boolean;
availableEnvironments: readonly EnvironmentOption[];
autoEnvironmentLabel?: string | undefined;
onAutoEnvironment?: (() => void) | undefined;
onEnvironmentChange: (environmentId: EnvironmentId) => void;
onEnvModeChange: (mode: EnvMode) => void;
/** The thread's env mode as ChatView resolves it. */
envMode: EnvMode;
activeThreadBranchOverride?: string | null;
onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
startFromOrigin: boolean;
onStartFromOriginChange: (startFromOrigin: boolean) => void;
onCheckoutPullRequestRequest?: (reference: string) => void;
onComposerFocusRequest: () => void;
onOpenChanges?: () => void;
versionMismatch: VersionMismatchIssue | null;
onDismissVersionMismatch: () => void;
onRunProjectScript: (script: ProjectScript) => void;
onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
onUpdateProjectScript: (
scriptId: string,
input: NewProjectScriptInput,
) => Promise<ProjectScriptActionResult>;
onDeleteProjectScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
}
export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
const fileScripts = useT3ProjectFileScripts(
props.environmentId,
props.activeProjectScripts ? props.gitCwd : null,
);
// Same rule as the composer strip: a lone remote machine still gets a row,
// shown as a static label because there is nothing to pick.
const canPickEnvironment = props.availableEnvironments.length > 1;
const showEnvironment = shouldShowEnvironmentIndicator({
activeEnvironment:
props.availableEnvironments.find((env) => env.environmentId === props.environmentId) ?? null,
canPickEnvironment,
});
const branchToolbarProps = {
showGitControls: props.isGitRepo,
environmentId: props.environmentId,
threadId: props.threadId,
...(props.draftId ? { draftId: props.draftId } : {}),
onEnvModeChange: props.onEnvModeChange,
startFromOrigin: props.startFromOrigin,
onStartFromOriginChange: props.onStartFromOriginChange,
envMode: props.envMode,
...(props.activeThreadBranchOverride !== undefined
? { activeThreadBranchOverride: props.activeThreadBranchOverride }
: {}),
...(props.onActiveThreadBranchOverrideChange
? { onActiveThreadBranchOverrideChange: props.onActiveThreadBranchOverrideChange }
: {}),
envLocked: props.envLocked,
forceNewWorktree: props.forceNewWorktree ?? false,
onComposerFocusRequest: props.onComposerFocusRequest,
...(props.onCheckoutPullRequestRequest
? { onCheckoutPullRequestRequest: props.onCheckoutPullRequestRequest }
: {}),
};
return (
<ThreadDetailsCard
threadRef={{ environmentId: props.environmentId, threadId: props.threadId }}
anchor={props.anchor}
handle={props.handle}
onPresentationChange={props.onPresentationChange}
>
{(density) => (
<>
<ThreadDetailsSection
headingId="thread-details-workspace-heading"
title="Workspace"
separated={false}
showHeading={false}
>
{props.versionMismatch ? (
<div className="mx-1 mb-2 flex gap-2 rounded-xl border border-warning/30 bg-warning/6 p-3">
<AlertTriangleIcon className="mt-0.5 size-3.5 shrink-0 text-warning" />
<div className="min-w-0 flex-1">
<p className="text-xs font-medium">Client and server versions differ</p>
<p className="mt-1 text-2xs leading-relaxed text-muted-foreground">
Client {props.versionMismatch.clientVersion} ·{" "}
{props.versionMismatch.serverLabel} {props.versionMismatch.serverVersion}
</p>
</div>
<Button
size="icon-xs"
variant="ghost"
aria-label="Dismiss version mismatch warning"
onClick={props.onDismissVersionMismatch}
>
<XIcon className="size-3.5" />
</Button>
</div>
) : null}
<div className="flex flex-col">
{density === "full" && showEnvironment ? (
<BranchToolbarEnvironmentSelector
displayMode="panel"
autoEnvironmentLabel={props.autoEnvironmentLabel}
onAutoEnvironment={props.onAutoEnvironment}
envLocked={props.envLocked}
environmentId={props.environmentId}
availableEnvironments={props.availableEnvironments}
{...(canPickEnvironment
? { onEnvironmentChange: props.onEnvironmentChange }
: {})}
/>
) : null}
{density === "full" ? (
<BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
) : null}
{density !== "essential" && props.showOpenInPicker ? (
<OpenInPicker
environmentId={props.environmentId}
keybindings={props.keybindings}
availableEditors={props.availableEditors}
openInCwd={props.gitCwd}
displayMode="panel"
/>
) : null}
{props.activeProjectScripts ? (
<ProjectScriptsControl
displayMode="panel"
scripts={props.activeProjectScripts}
fileScripts={fileScripts}
keybindings={props.keybindings}
preferredScriptId={props.preferredScriptId}
onRunScript={props.onRunProjectScript}
onAddScript={props.onAddProjectScript}
onUpdateScript={props.onUpdateProjectScript}
onDeleteScript={props.onDeleteProjectScript}
/>
) : null}
</div>
</ThreadDetailsSection>
{props.gitCwd ? (
<ThreadDetailsSection
headingId="thread-details-version-control-heading"
title="Version Control"
showHeading={false}
separated={density === "full"}
>
<div className="flex flex-col">
{props.isGitRepo ? (
<BranchToolbar layout="panel" panelSection="branch" {...branchToolbarProps} />
) : null}
{props.activeProjectName ? (
<GitActionsControl
displayMode="panel"
compact={density !== "full"}
gitCwd={props.gitCwd}
activeThreadRef={{
environmentId: props.environmentId,
threadId: props.threadId,
}}
{...(props.draftId ? { draftId: props.draftId } : {})}
{...(props.onOpenChanges ? { onOpenChanges: props.onOpenChanges } : {})}
/>
) : null}
</div>
</ThreadDetailsSection>
) : null}
{density === "full" && !props.draftId ? (
<ThreadAutomationsPanel environmentId={props.environmentId} threadId={props.threadId} />
) : null}
{density === "full" && !props.draftId ? (
<ThreadRelationshipsPanel
environmentId={props.environmentId}
threadId={props.threadId}
/>
) : null}
</>
)}
</ThreadDetailsCard>
);
}