fix(web): simplify workspace card rows (#16823)
This commit is contained in:
1 parent
26285ab805
commit
7f3628e415
17 files changed
+376
-343
No files matched your search
@@ -13,7 +13,6 @@ import {
|
||||
resolveBranchToolbarPrBranch,
|
||||
resolveBranchToolbarValue,
|
||||
resolveLockedWorkspaceLabel,
|
||||
resolveWorkspaceDisplayName,
|
||||
resolveLocalCheckoutBranchMismatch,
|
||||
resolvePreviousWorktreeLabel,
|
||||
resolvePreviousWorktreeSeed,
|
||||
@@ -568,18 +567,6 @@ describe("resolveLockedWorkspaceLabel", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveWorkspaceDisplayName", () => {
|
||||
it("returns the final folder for POSIX and Windows paths", () => {
|
||||
expect(resolveWorkspaceDisplayName("/repo/.t3/worktrees/feature-a")).toBe("feature-a");
|
||||
expect(resolveWorkspaceDisplayName("C:\\code\\project\\feature-b\\")).toBe("feature-b");
|
||||
});
|
||||
|
||||
it("handles missing and root paths", () => {
|
||||
expect(resolveWorkspaceDisplayName(null)).toBeNull();
|
||||
expect(resolveWorkspaceDisplayName("/")).toBe("/");
|
||||
});
|
||||
});
|
||||
|
||||
describe("deriveLocalBranchNameFromRemoteRef", () => {
|
||||
it("strips the remote prefix from a remote ref", () => {
|
||||
expect(deriveLocalBranchNameFromRemoteRef("origin/feature/demo")).toBe("feature/demo");
|
||||
|
||||
@@ -118,13 +118,6 @@ export function resolveLockedWorkspaceLabel(
|
||||
return effectiveEnvMode === "worktree" ? resolveEnvModeLabel("worktree") : "Local checkout";
|
||||
}
|
||||
|
||||
export function resolveWorkspaceDisplayName(path: string | null): string | null {
|
||||
if (!path) return null;
|
||||
const normalizedPath = path.replace(/[\\/]+$/, "");
|
||||
if (normalizedPath.length === 0) return path;
|
||||
return normalizedPath.split(/[\\/]/).at(-1) ?? normalizedPath;
|
||||
}
|
||||
|
||||
export interface PreviousWorktreeSeed {
|
||||
branch: string | null;
|
||||
worktreePath: string;
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
|
||||
import { act } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { expect, it, vi } from "vite-plus/test";
|
||||
|
||||
const state = vi.hoisted(() => ({
|
||||
worktreePath: "/tmp/worktree" as string | null,
|
||||
showContextMenu: vi.fn().mockResolvedValue("copy-path"),
|
||||
writeTextToClipboard: vi.fn().mockResolvedValue(true),
|
||||
}));
|
||||
|
||||
vi.mock("../localApi", () => ({
|
||||
readLocalApi: () => ({ contextMenu: { show: state.showContextMenu } }),
|
||||
}));
|
||||
vi.mock("../hooks/useCopyToClipboard", () => ({
|
||||
writeTextToClipboard: state.writeTextToClipboard,
|
||||
}));
|
||||
vi.mock("./BranchToolbarBranchSelector", () => ({ BranchToolbarBranchSelector: () => null }));
|
||||
vi.mock("../composerDraftStore", () => ({
|
||||
useComposerDraftStore: (select: (store: unknown) => unknown) =>
|
||||
select({ getDraftThreadByRef: () => null, setDraftThreadContext: vi.fn() }),
|
||||
}));
|
||||
vi.mock("../state/entities", () => ({
|
||||
useThreadShell: () => ({
|
||||
environmentId: "local",
|
||||
projectId: "project",
|
||||
worktreePath: state.worktreePath,
|
||||
}),
|
||||
useProject: () => ({ workspaceRoot: "/tmp/project" }),
|
||||
useThreadShellsForProjectRefs: () => [],
|
||||
}));
|
||||
|
||||
import { BranchToolbar } from "./BranchToolbar";
|
||||
|
||||
it("keeps machine choices usable when the combined row's workspace is locked", async () => {
|
||||
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
||||
const container = document.createElement("div");
|
||||
document.body.append(container);
|
||||
const root = createRoot(container);
|
||||
const onEnvironmentChange = vi.fn();
|
||||
try {
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<BranchToolbar
|
||||
layout="panel"
|
||||
panelSection="workspace"
|
||||
environmentId={EnvironmentId.make("local")}
|
||||
threadId={ThreadId.make("thread")}
|
||||
showGitControls
|
||||
envMode="local"
|
||||
envLocked={false}
|
||||
startFromOrigin={false}
|
||||
onStartFromOriginChange={vi.fn()}
|
||||
onEnvModeChange={vi.fn()}
|
||||
onEnvironmentChange={onEnvironmentChange}
|
||||
availableEnvironments={["local", "remote"].map((id) => ({
|
||||
environmentId: EnvironmentId.make(id),
|
||||
projectId: ProjectId.make("project"),
|
||||
label: id,
|
||||
isPrimary: id === "local",
|
||||
machine: "server",
|
||||
}))}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
const trigger = container.querySelector("button")!;
|
||||
expect(trigger.textContent).toBe("local");
|
||||
expect(container.querySelectorAll("button")).toHaveLength(1);
|
||||
await act(async () => {
|
||||
trigger.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, ctrlKey: true }));
|
||||
});
|
||||
expect(document.querySelector('[role="menu"]')).toBeNull();
|
||||
await act(async () => trigger.click());
|
||||
const items = [...document.querySelectorAll<HTMLElement>('[role="menuitemradio"]')];
|
||||
expect(
|
||||
items.find((item) => item.textContent === "New worktree")?.getAttribute("aria-disabled"),
|
||||
).toBe("true");
|
||||
await act(async () => items.find((item) => item.textContent === "remote")!.click());
|
||||
expect(onEnvironmentChange).toHaveBeenCalledWith("remote");
|
||||
} finally {
|
||||
await act(async () => root.unmount());
|
||||
container.remove();
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
["local", null, "/tmp/project"],
|
||||
["worktree", null, null],
|
||||
["worktree", "/tmp/worktree", "/tmp/worktree"],
|
||||
] as const)(
|
||||
"copies only an existing workspace path with mode %s and worktree %s",
|
||||
async (envMode, worktreePath, copiedPath) => {
|
||||
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
||||
state.worktreePath = worktreePath;
|
||||
state.showContextMenu.mockClear();
|
||||
state.writeTextToClipboard.mockClear();
|
||||
const container = document.createElement("div");
|
||||
document.body.append(container);
|
||||
const root = createRoot(container);
|
||||
try {
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<BranchToolbar
|
||||
layout="panel"
|
||||
panelSection="workspace"
|
||||
environmentId={EnvironmentId.make("local")}
|
||||
threadId={ThreadId.make("thread")}
|
||||
showGitControls
|
||||
envMode={envMode}
|
||||
envLocked={false}
|
||||
startFromOrigin={false}
|
||||
onStartFromOriginChange={vi.fn()}
|
||||
onEnvModeChange={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
});
|
||||
const event = new MouseEvent("contextmenu", { bubbles: true, cancelable: true });
|
||||
await act(async () => {
|
||||
container.querySelector('[aria-label="Run context"]')!.dispatchEvent(event);
|
||||
});
|
||||
expect(event.defaultPrevented).toBe(copiedPath !== null);
|
||||
if (copiedPath === null) {
|
||||
expect(state.showContextMenu).not.toHaveBeenCalled();
|
||||
expect(state.writeTextToClipboard).not.toHaveBeenCalled();
|
||||
} else {
|
||||
expect(state.writeTextToClipboard).toHaveBeenCalledWith(copiedPath, "workspace path");
|
||||
}
|
||||
} finally {
|
||||
await act(async () => root.unmount());
|
||||
container.remove();
|
||||
state.worktreePath = "/tmp/worktree";
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -1,3 +1,6 @@
|
||||
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
|
||||
import { readLocalApi } from "../localApi";
|
||||
import { stackedThreadToast, toastManager } from "./ui/toast";
|
||||
import { ComposerContextLabel } from "./ComposerContextLabel";
|
||||
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
|
||||
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
|
||||
@@ -10,6 +13,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import {
|
||||
type Ref,
|
||||
type MouseEvent as ReactMouseEvent,
|
||||
memo,
|
||||
useImperativeHandle,
|
||||
useCallback,
|
||||
@@ -41,6 +45,11 @@ import {
|
||||
import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector";
|
||||
import { BranchToolbarEnvModeSelector } from "./BranchToolbarEnvModeSelector";
|
||||
import { PreviousWorktreeItemContent } from "./PreviousWorktreeItemContent";
|
||||
import { ThreadDetailsControl } from "./chat/ThreadDetailsControl";
|
||||
import {
|
||||
THREAD_DETAILS_PANEL_ICON_CLASS,
|
||||
THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS,
|
||||
} from "./chat/threadDetailsPanelStyles";
|
||||
import { ComposerControl } from "./chat/ComposerControl";
|
||||
import {
|
||||
Menu,
|
||||
@@ -93,7 +102,44 @@ interface BranchToolbarProps {
|
||||
contextStripVisible?: boolean;
|
||||
}
|
||||
|
||||
interface MobileRunContextSelectorProps {
|
||||
function showWorkspaceContextMenu(event: ReactMouseEvent, workspacePath: string) {
|
||||
const api = readLocalApi();
|
||||
if (!api) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
void api.contextMenu
|
||||
.show([{ id: "copy-path", label: "Copy full path", icon: "copy" }], {
|
||||
x: event.clientX,
|
||||
y: event.clientY,
|
||||
})
|
||||
.then((action) => {
|
||||
if (action !== "copy-path") return;
|
||||
void writeTextToClipboard(workspacePath, "workspace path").then(
|
||||
(didCopy) => {
|
||||
if (didCopy) {
|
||||
toastManager.add({
|
||||
type: "success",
|
||||
title: "Path copied",
|
||||
description: workspacePath,
|
||||
});
|
||||
}
|
||||
},
|
||||
(error: unknown) => {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to copy path",
|
||||
description: error instanceof Error ? error.message : "An error occurred.",
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
interface RunContextSelectorProps {
|
||||
displayMode?: "toolbar" | "panel";
|
||||
workspaceRoot?: string;
|
||||
forceNewWorktree: boolean;
|
||||
autoEnvironmentLabel?: string | undefined;
|
||||
onAutoEnvironment?: (() => void) | undefined;
|
||||
@@ -112,7 +158,9 @@ interface MobileRunContextSelectorProps {
|
||||
onUsePreviousWorktree: () => void;
|
||||
}
|
||||
|
||||
const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
const RunContextSelector = memo(function RunContextSelector({
|
||||
displayMode = "toolbar",
|
||||
workspaceRoot,
|
||||
forceNewWorktree,
|
||||
autoEnvironmentLabel,
|
||||
onAutoEnvironment,
|
||||
@@ -129,7 +177,7 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
previousWorktreeLabel,
|
||||
previousWorktreeBranch,
|
||||
onUsePreviousWorktree,
|
||||
}: MobileRunContextSelectorProps) {
|
||||
}: RunContextSelectorProps) {
|
||||
const composerFloatingLayerProps = useComposerMenuProps();
|
||||
const activeEnvironment = useMemo(
|
||||
() => availableEnvironments?.find((env) => env.environmentId === environmentId) ?? null,
|
||||
@@ -148,13 +196,35 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
: effectiveEnvMode === "worktree"
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: resolveCurrentWorkspaceLabel(activeWorktreePath);
|
||||
const isLocked = envLocked || envModeLocked;
|
||||
const isPanel = displayMode === "panel";
|
||||
const isLocked = envLocked || (envModeLocked && (!isPanel || !showEnvironmentPicker));
|
||||
const workspacePath =
|
||||
forceNewWorktree || (effectiveEnvMode === "worktree" && !activeWorktreePath)
|
||||
? null
|
||||
: (activeWorktreePath ?? workspaceRoot);
|
||||
const handleContextMenu = (event: ReactMouseEvent) => {
|
||||
if (isPanel && workspacePath) {
|
||||
showWorkspaceContextMenu(event, workspacePath);
|
||||
}
|
||||
};
|
||||
const workspaceIcon = (
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={<span className="inline-flex shrink-0" />}>
|
||||
<WorkspaceIcon className={cn("size-3 shrink-0", showEnvironmentIndicator && "mx-0!")} />
|
||||
<WorkspaceIcon
|
||||
className={
|
||||
isPanel
|
||||
? THREAD_DETAILS_PANEL_ICON_CLASS
|
||||
: cn("size-3 shrink-0", showEnvironmentIndicator && "mx-0!")
|
||||
}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>{workspaceLabel}</TooltipPopup>
|
||||
<TooltipPopup>
|
||||
{isPanel
|
||||
? forceNewWorktree
|
||||
? "Each model starts in its own worktree."
|
||||
: (workspacePath ?? workspaceLabel)
|
||||
: workspaceLabel}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
);
|
||||
const icon = showEnvironmentIndicator ? (
|
||||
@@ -164,11 +234,14 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={<span className="inline-flex shrink-0" />}>
|
||||
{autoEnvironmentLabel ? (
|
||||
<ScaleIcon className="size-3 shrink-0 mx-0!" aria-hidden="true" />
|
||||
<ScaleIcon
|
||||
className={isPanel ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3 shrink-0 mx-0!"}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : (
|
||||
<EnvironmentMachineIcon
|
||||
kind={activeEnvironment?.machine ?? "server"}
|
||||
className="size-3 shrink-0 mx-0!"
|
||||
className={isPanel ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3 shrink-0 mx-0!"}
|
||||
/>
|
||||
)}
|
||||
</TooltipTrigger>
|
||||
@@ -182,7 +255,7 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
const triggerContent = (
|
||||
<>
|
||||
{icon}
|
||||
<ComposerContextLabel>
|
||||
<ComposerContextLabel displayMode={displayMode}>
|
||||
{autoEnvironmentLabel ??
|
||||
(showEnvironmentIndicator ? (activeEnvironment?.label ?? "Run on") : workspaceLabel)}
|
||||
</ComposerContextLabel>
|
||||
@@ -192,7 +265,13 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
if (isLocked) {
|
||||
return (
|
||||
<span
|
||||
className="inline-flex h-7 min-w-0 max-w-[48%] flex-initial items-center justify-start gap-1 rounded-md border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6"
|
||||
className={cn(
|
||||
"inline-flex h-7 min-w-0 max-w-[48%] flex-initial items-center justify-start gap-1 rounded-md border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6",
|
||||
isPanel && "max-w-full",
|
||||
isPanel && THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS,
|
||||
)}
|
||||
onContextMenu={handleContextMenu}
|
||||
aria-label={isPanel ? "Run context" : undefined}
|
||||
data-composer-context-control
|
||||
>
|
||||
{triggerContent}
|
||||
@@ -203,8 +282,17 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
return (
|
||||
<Menu>
|
||||
<MenuTrigger
|
||||
render={<ComposerControl size="xs" />}
|
||||
className="min-w-0 max-w-[48%] flex-initial justify-start"
|
||||
render={isPanel ? <ThreadDetailsControl part="select" /> : <ComposerControl size="xs" />}
|
||||
className={isPanel ? undefined : "min-w-0 max-w-[48%] flex-initial justify-start"}
|
||||
onContextMenu={handleContextMenu}
|
||||
onMouseDownCapture={
|
||||
isPanel
|
||||
? (event) => {
|
||||
if (event.button !== 0 || event.ctrlKey) event.stopPropagation();
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
aria-label={isPanel ? "Run context" : undefined}
|
||||
data-composer-context-control
|
||||
data-composer-shortcut={[
|
||||
showEnvironmentPicker && !envLocked ? "composer.host" : "",
|
||||
@@ -212,13 +300,19 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
|
||||
].join(" ")}
|
||||
>
|
||||
{triggerContent}
|
||||
<ChevronDownIcon className="size-3 shrink-0 opacity-50" />
|
||||
{!isPanel ? <ChevronDownIcon className="size-3 shrink-0 opacity-50" /> : null}
|
||||
</MenuTrigger>
|
||||
<MenuPopup
|
||||
align="start"
|
||||
side="top"
|
||||
className={previousWorktreeLabel ? "w-[min(21rem,calc(100vw-2rem))]" : undefined}
|
||||
{...composerFloatingLayerProps}
|
||||
side={isPanel ? "bottom" : "top"}
|
||||
className={
|
||||
isPanel
|
||||
? "w-(--anchor-width)"
|
||||
: previousWorktreeLabel
|
||||
? "w-[min(21rem,calc(100vw-2rem))]"
|
||||
: undefined
|
||||
}
|
||||
{...(!isPanel ? composerFloatingLayerProps : {})}
|
||||
>
|
||||
{showEnvironmentPicker && availableEnvironments && onEnvironmentChange ? (
|
||||
<>
|
||||
@@ -618,13 +712,25 @@ export const BranchToolbar = memo(function BranchToolbar({
|
||||
return (
|
||||
<div className="flex w-full flex-col" data-thread-panel-run-context>
|
||||
{panelSection !== "branch" ? (
|
||||
<BranchToolbarEnvModeSelector
|
||||
<RunContextSelector
|
||||
displayMode="panel"
|
||||
envLocked={envModeLocked}
|
||||
workspaceRoot={activeProject.workspaceRoot}
|
||||
forceNewWorktree={forceNewWorktree}
|
||||
autoEnvironmentLabel={autoEnvironmentLabel}
|
||||
onAutoEnvironment={onAutoEnvironment}
|
||||
envLocked={envLocked}
|
||||
envModeLocked={envModeLocked}
|
||||
environmentId={environmentId}
|
||||
availableEnvironments={availableEnvironments}
|
||||
showEnvironmentPicker={showEnvironmentPicker}
|
||||
showEnvironmentIndicator={activeEnvironmentOption !== null}
|
||||
onEnvironmentChange={onEnvironmentChange}
|
||||
effectiveEnvMode={effectiveEnvMode}
|
||||
activeWorktreePath={activeWorktreePath}
|
||||
workspaceRoot={activeProject.workspaceRoot}
|
||||
onEnvModeChange={onEnvModeChange}
|
||||
previousWorktreeLabel={previousWorktreeLabel}
|
||||
previousWorktreeBranch={previousWorktreeSeed?.branch ?? null}
|
||||
onUsePreviousWorktree={onUsePreviousWorktree}
|
||||
/>
|
||||
) : null}
|
||||
{panelSection !== "workspace" ? (
|
||||
@@ -662,7 +768,7 @@ export const BranchToolbar = memo(function BranchToolbar({
|
||||
>
|
||||
{showGitControls ? (
|
||||
<div className="contents @3xl/composer-surface:hidden">
|
||||
<MobileRunContextSelector
|
||||
<RunContextSelector
|
||||
forceNewWorktree={forceNewWorktree}
|
||||
autoEnvironmentLabel={autoEnvironmentLabel}
|
||||
onAutoEnvironment={onAutoEnvironment}
|
||||
|
||||
@@ -42,10 +42,7 @@ import { threadEnvironment } from "../state/threads";
|
||||
import { useAtomCommand } from "../state/use-atom-command";
|
||||
import { vcsEnvironment } from "../state/vcs";
|
||||
import { cn } from "../lib/utils";
|
||||
import {
|
||||
THREAD_DETAILS_PANEL_CHEVRON_CLASS,
|
||||
THREAD_DETAILS_PANEL_ICON_CLASS,
|
||||
} from "./chat/threadDetailsPanelStyles";
|
||||
import { THREAD_DETAILS_PANEL_ICON_CLASS } from "./chat/threadDetailsPanelStyles";
|
||||
import { ThreadDetailsPrRows } from "./chat/ThreadDetailsPrRows";
|
||||
import { parsePullRequestReference } from "../pullRequestReference";
|
||||
import { getSourceControlPresentation } from "../sourceControlPresentation";
|
||||
@@ -784,13 +781,9 @@ export function BranchToolbarBranchSelector({
|
||||
<ComposerContextLabel displayMode={displayMode}>
|
||||
<MiddleTruncate value={triggerLabel} className="w-full" />
|
||||
</ComposerContextLabel>
|
||||
{displayMode === "panel" ? (
|
||||
<span data-slot="select-icon">
|
||||
<ChevronDownIcon className={THREAD_DETAILS_PANEL_CHEVRON_CLASS} />
|
||||
</span>
|
||||
) : (
|
||||
{displayMode !== "panel" ? (
|
||||
<ChevronDownIcon className="size-3 shrink-0 opacity-50" />
|
||||
)}
|
||||
) : null}
|
||||
</ComboboxTrigger>
|
||||
</span>
|
||||
{displayMode === "panel" && prNumber !== undefined && prUrl !== undefined ? (
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import { ThreadDetailsSelectControl } from "./chat/ThreadDetailsControl";
|
||||
import { ComposerSelectControl } from "./chat/ComposerControl";
|
||||
import { ComposerContextLabel } from "./ComposerContextLabel";
|
||||
import { FolderGit2Icon, FolderGitIcon, FolderIcon } from "lucide-react";
|
||||
import { memo, useMemo, type MouseEvent as ReactMouseEvent } from "react";
|
||||
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
|
||||
import { readLocalApi } from "../localApi";
|
||||
import { cn } from "../lib/utils";
|
||||
import {
|
||||
THREAD_DETAILS_PANEL_ICON_CLASS,
|
||||
THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS,
|
||||
} from "./chat/threadDetailsPanelStyles";
|
||||
|
||||
import {
|
||||
resolveCurrentWorkspaceLabel,
|
||||
resolveEnvModeLabel,
|
||||
resolveLockedWorkspaceLabel,
|
||||
resolveWorkspaceDisplayName,
|
||||
type EnvMode,
|
||||
} from "./BranchToolbar.logic";
|
||||
import { useComposerMenuProps } from "./chat/composerEventScope";
|
||||
@@ -28,7 +20,6 @@ import {
|
||||
SelectValue,
|
||||
} from "./ui/select";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
import { stackedThreadToast, toastManager } from "./ui/toast";
|
||||
|
||||
const PREVIOUS_WORKTREE_SELECT_VALUE = "previous-worktree";
|
||||
|
||||
@@ -37,9 +28,7 @@ interface BranchToolbarEnvModeSelectorProps {
|
||||
envLocked: boolean;
|
||||
effectiveEnvMode: EnvMode;
|
||||
activeWorktreePath: string | null;
|
||||
workspaceRoot?: string | null;
|
||||
onEnvModeChange: (mode: EnvMode) => void;
|
||||
displayMode?: "toolbar" | "panel";
|
||||
previousWorktreeLabel?: string | null;
|
||||
previousWorktreeBranch?: string | null;
|
||||
onUsePreviousWorktree?: () => void;
|
||||
@@ -50,72 +39,27 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
|
||||
envLocked,
|
||||
effectiveEnvMode,
|
||||
activeWorktreePath,
|
||||
workspaceRoot = null,
|
||||
onEnvModeChange,
|
||||
displayMode = "toolbar",
|
||||
previousWorktreeLabel,
|
||||
previousWorktreeBranch = null,
|
||||
onUsePreviousWorktree,
|
||||
}: BranchToolbarEnvModeSelectorProps) {
|
||||
const workspacePath = displayMode === "panel" ? (activeWorktreePath ?? workspaceRoot) : null;
|
||||
const workspaceDisplayName = resolveWorkspaceDisplayName(workspacePath);
|
||||
// The panel names the workspace kind only when it is not the project folder.
|
||||
const workspaceKind = activeWorktreePath ? "Worktree" : null;
|
||||
const lockedWorkspaceKind = forceNewWorktree ? "Worktree" : workspaceKind;
|
||||
const selectWorkspaceKind =
|
||||
effectiveEnvMode === "worktree" && !activeWorktreePath ? "Create" : workspaceKind;
|
||||
const composerFloatingLayerProps = useComposerMenuProps();
|
||||
const showPreviousWorktree = Boolean(previousWorktreeLabel && onUsePreviousWorktree);
|
||||
const envModeItems = useMemo(
|
||||
() => [
|
||||
{
|
||||
value: "local",
|
||||
label: workspaceDisplayName ?? resolveCurrentWorkspaceLabel(activeWorktreePath),
|
||||
label: resolveCurrentWorkspaceLabel(activeWorktreePath),
|
||||
},
|
||||
{ value: "worktree", label: resolveEnvModeLabel("worktree") },
|
||||
...(showPreviousWorktree && previousWorktreeLabel
|
||||
? [{ value: PREVIOUS_WORKTREE_SELECT_VALUE, label: previousWorktreeLabel }]
|
||||
: []),
|
||||
],
|
||||
[activeWorktreePath, previousWorktreeLabel, showPreviousWorktree, workspaceDisplayName],
|
||||
[activeWorktreePath, previousWorktreeLabel, showPreviousWorktree],
|
||||
);
|
||||
|
||||
const handleWorkspaceContextMenu = (event: ReactMouseEvent) => {
|
||||
if (!workspacePath || forceNewWorktree) return;
|
||||
const api = readLocalApi();
|
||||
if (!api) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
void api.contextMenu
|
||||
.show([{ id: "copy-path", label: "Copy full path", icon: "copy" }], {
|
||||
x: event.clientX,
|
||||
y: event.clientY,
|
||||
})
|
||||
.then((action) => {
|
||||
if (action !== "copy-path") return;
|
||||
void writeTextToClipboard(workspacePath, "workspace path").then(
|
||||
(didCopy) => {
|
||||
if (didCopy) {
|
||||
toastManager.add({
|
||||
type: "success",
|
||||
title: "Path copied",
|
||||
description: workspacePath,
|
||||
});
|
||||
}
|
||||
},
|
||||
(error: unknown) => {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to copy path",
|
||||
description: error instanceof Error ? error.message : "An error occurred.",
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const stopContextMenuMouseDown = (event: ReactMouseEvent) => {
|
||||
if (event.button !== 0 || event.ctrlKey) {
|
||||
event.stopPropagation();
|
||||
@@ -125,47 +69,31 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
|
||||
if (envLocked || forceNewWorktree) {
|
||||
const lockedRow = (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex h-7 min-w-0 items-center gap-1 border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6",
|
||||
displayMode === "panel" && THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS,
|
||||
)}
|
||||
className="inline-flex h-7 min-w-0 items-center gap-1 border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6"
|
||||
data-composer-context-control
|
||||
onContextMenu={handleWorkspaceContextMenu}
|
||||
>
|
||||
{activeWorktreePath ? (
|
||||
<FolderGitIcon
|
||||
className={displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3"}
|
||||
/>
|
||||
<FolderGitIcon className="size-3" />
|
||||
) : effectiveEnvMode === "worktree" ? (
|
||||
<FolderGit2Icon
|
||||
className={displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3"}
|
||||
/>
|
||||
<FolderGit2Icon className="size-3" />
|
||||
) : (
|
||||
<FolderIcon
|
||||
className={displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3"}
|
||||
/>
|
||||
<FolderIcon className="size-3" />
|
||||
)}
|
||||
<ComposerContextLabel displayMode={displayMode}>
|
||||
<ComposerContextLabel>
|
||||
{forceNewWorktree
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: (workspaceDisplayName ??
|
||||
resolveLockedWorkspaceLabel(activeWorktreePath, effectiveEnvMode))}
|
||||
: resolveLockedWorkspaceLabel(activeWorktreePath, effectiveEnvMode)}
|
||||
</ComposerContextLabel>
|
||||
{displayMode === "panel" && lockedWorkspaceKind ? (
|
||||
<span className="shrink-0 text-3xs font-normal text-muted-foreground/70">
|
||||
{lockedWorkspaceKind}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger render={lockedRow} />
|
||||
<TooltipPopup side={displayMode === "panel" ? "left" : undefined}>
|
||||
<TooltipPopup>
|
||||
{forceNewWorktree
|
||||
? "Each model starts in its own worktree."
|
||||
: (workspacePath ?? resolveLockedWorkspaceLabel(activeWorktreePath, effectiveEnvMode))}
|
||||
: resolveLockedWorkspaceLabel(activeWorktreePath, effectiveEnvMode)}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
);
|
||||
@@ -187,56 +115,37 @@ export const BranchToolbarEnvModeSelector = memo(function BranchToolbarEnvModeSe
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<ThreadDetailsSelectControl
|
||||
panel={displayMode === "panel"}
|
||||
<ComposerSelectControl
|
||||
size="xs"
|
||||
className="min-w-0 shrink"
|
||||
aria-label="Workspace"
|
||||
data-composer-shortcut="composer.workspace"
|
||||
data-composer-context-control
|
||||
onMouseDownCapture={stopContextMenuMouseDown}
|
||||
onContextMenu={handleWorkspaceContextMenu}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{effectiveEnvMode === "worktree" ? (
|
||||
<FolderGit2Icon
|
||||
className={displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3"}
|
||||
/>
|
||||
<FolderGit2Icon className="size-3" />
|
||||
) : activeWorktreePath ? (
|
||||
<FolderGitIcon
|
||||
className={displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3"}
|
||||
/>
|
||||
<FolderGitIcon className="size-3" />
|
||||
) : (
|
||||
<FolderIcon
|
||||
className={displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3"}
|
||||
/>
|
||||
<FolderIcon className="size-3" />
|
||||
)}
|
||||
<ComposerContextLabel displayMode={displayMode}>
|
||||
<ComposerContextLabel>
|
||||
<SelectValue />
|
||||
</ComposerContextLabel>
|
||||
{displayMode === "panel" && selectWorkspaceKind ? (
|
||||
<span className="shrink-0 text-3xs font-normal text-muted-foreground/70">
|
||||
{selectWorkspaceKind}
|
||||
</span>
|
||||
) : null}
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup side={displayMode === "panel" ? "left" : undefined}>
|
||||
{workspacePath ??
|
||||
(effectiveEnvMode === "worktree"
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: resolveCurrentWorkspaceLabel(activeWorktreePath))}
|
||||
<TooltipPopup>
|
||||
{effectiveEnvMode === "worktree"
|
||||
? resolveEnvModeLabel("worktree")
|
||||
: resolveCurrentWorkspaceLabel(activeWorktreePath)}
|
||||
</TooltipPopup>
|
||||
</Tooltip>
|
||||
<SelectPopup
|
||||
alignItemWithTrigger={false}
|
||||
{...(displayMode === "toolbar" ? composerFloatingLayerProps : {})}
|
||||
className={
|
||||
displayMode === "panel"
|
||||
? "w-(--anchor-width)"
|
||||
: showPreviousWorktree
|
||||
? "w-[min(21rem,calc(100vw-2rem))]"
|
||||
: undefined
|
||||
}
|
||||
{...composerFloatingLayerProps}
|
||||
className={showPreviousWorktree ? "w-[min(21rem,calc(100vw-2rem))]" : undefined}
|
||||
>
|
||||
<SelectGroup>
|
||||
<SelectGroupLabel>Workspace</SelectGroupLabel>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ThreadDetailsSelectControl } from "./chat/ThreadDetailsControl";
|
||||
import { ComposerSelectControl } from "./chat/ComposerControl";
|
||||
import { ComposerContextLabel } from "./ComposerContextLabel";
|
||||
import { Tooltip, TooltipTrigger, TooltipPopup } from "./ui/tooltip";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
@@ -6,11 +6,6 @@ import { ScaleIcon } from "lucide-react";
|
||||
import { memo, useMemo } from "react";
|
||||
|
||||
import type { EnvironmentOption } from "./BranchToolbar.logic";
|
||||
import { cn } from "../lib/utils";
|
||||
import {
|
||||
THREAD_DETAILS_PANEL_ICON_CLASS,
|
||||
THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS,
|
||||
} from "./chat/threadDetailsPanelStyles";
|
||||
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
|
||||
import { useComposerMenuProps } from "./chat/composerEventScope";
|
||||
import {
|
||||
@@ -29,7 +24,6 @@ interface BranchToolbarEnvironmentSelectorProps {
|
||||
environmentId: EnvironmentId;
|
||||
availableEnvironments: readonly EnvironmentOption[];
|
||||
onEnvironmentChange?: (environmentId: EnvironmentId) => void;
|
||||
displayMode?: "toolbar" | "panel";
|
||||
}
|
||||
|
||||
export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvironmentSelector({
|
||||
@@ -39,7 +33,6 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir
|
||||
environmentId,
|
||||
availableEnvironments,
|
||||
onEnvironmentChange,
|
||||
displayMode = "toolbar",
|
||||
}: BranchToolbarEnvironmentSelectorProps) {
|
||||
const composerFloatingLayerProps = useComposerMenuProps();
|
||||
const activeEnvironment = useMemo(() => {
|
||||
@@ -67,19 +60,14 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir
|
||||
if (envLocked || onEnvironmentChange === undefined) {
|
||||
const lockedRow = (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex h-7 min-w-0 max-w-full items-center gap-1 border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6",
|
||||
displayMode === "panel" && THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS,
|
||||
)}
|
||||
className="inline-flex h-7 min-w-0 max-w-full items-center gap-1 border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6"
|
||||
data-composer-context-control
|
||||
>
|
||||
<EnvironmentMachineIcon
|
||||
kind={activeEnvironment?.machine ?? "server"}
|
||||
className={displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3 shrink-0"}
|
||||
className="size-3 shrink-0"
|
||||
/>
|
||||
<ComposerContextLabel displayMode={displayMode}>
|
||||
{activeEnvironment?.label ?? "Run on"}
|
||||
</ComposerContextLabel>
|
||||
<ComposerContextLabel>{activeEnvironment?.label ?? "Run on"}</ComposerContextLabel>
|
||||
</span>
|
||||
);
|
||||
return (
|
||||
@@ -102,8 +90,8 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
<ThreadDetailsSelectControl
|
||||
panel={displayMode === "panel"}
|
||||
<ComposerSelectControl
|
||||
size="xs"
|
||||
className="min-w-0 max-w-full"
|
||||
aria-label="Run on"
|
||||
data-composer-shortcut="composer.host"
|
||||
@@ -112,35 +100,20 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir
|
||||
}
|
||||
>
|
||||
{autoEnvironmentLabel ? (
|
||||
<ScaleIcon
|
||||
className={
|
||||
displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3 shrink-0"
|
||||
}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<ScaleIcon className="size-3 shrink-0" aria-hidden="true" />
|
||||
) : (
|
||||
<EnvironmentMachineIcon
|
||||
kind={activeEnvironment?.machine ?? "server"}
|
||||
className={
|
||||
displayMode === "panel" ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3 shrink-0"
|
||||
}
|
||||
className="size-3 shrink-0"
|
||||
/>
|
||||
)}
|
||||
<ComposerContextLabel displayMode={displayMode}>
|
||||
<ComposerContextLabel>
|
||||
<SelectValue />
|
||||
</ComposerContextLabel>
|
||||
</TooltipTrigger>
|
||||
<TooltipPopup>{autoEnvironmentLabel ?? activeEnvironment?.label ?? "Run on"}</TooltipPopup>
|
||||
</Tooltip>
|
||||
<SelectPopup
|
||||
alignItemWithTrigger={false}
|
||||
{...(displayMode === "toolbar" ? composerFloatingLayerProps : {})}
|
||||
{...(displayMode === "panel"
|
||||
? {
|
||||
className: "w-(--anchor-width)",
|
||||
}
|
||||
: {})}
|
||||
>
|
||||
<SelectPopup alignItemWithTrigger={false} {...composerFloatingLayerProps}>
|
||||
<SelectGroup>
|
||||
<SelectGroupLabel>Run on</SelectGroupLabel>
|
||||
{onAutoEnvironment && (
|
||||
|
||||
@@ -3069,11 +3069,6 @@ export default function ChatView(props: ChatViewProps) {
|
||||
hasMultipleRegisteredEnvironments && activeThread
|
||||
? `${environmentById.get(activeThread.environmentId)?.label ?? serverConfig?.environment.label ?? activeThread.environmentId} server`
|
||||
: "server";
|
||||
const handleDismissVersionMismatch = useCallback(() => {
|
||||
if (!versionMismatchDismissKey) return;
|
||||
dismissVersionMismatch(versionMismatchDismissKey);
|
||||
setDismissedVersionMismatchKey(versionMismatchDismissKey);
|
||||
}, [setDismissedVersionMismatchKey, versionMismatchDismissKey]);
|
||||
const serverUpdateEnvironmentId = activeThread?.environmentId ?? null;
|
||||
const versionMismatchSelfUpdate = resolveServerSelfUpdateCapability(serverConfig);
|
||||
const versionMismatchInstallation = serverConfig?.environment.capabilities.serverInstallation;
|
||||
@@ -11078,15 +11073,6 @@ export default function ChatView(props: ChatViewProps) {
|
||||
: {}),
|
||||
onComposerFocusRequest: scheduleComposerFocus,
|
||||
...(isServerThread && isGitRepo ? { onOpenChanges: openChangesFromThreadPanel } : {}),
|
||||
versionMismatch:
|
||||
showVersionMismatchBanner && versionMismatch
|
||||
? {
|
||||
clientVersion: versionMismatch.clientVersion,
|
||||
serverVersion: versionMismatch.serverVersion,
|
||||
serverLabel: versionMismatchServerLabel,
|
||||
}
|
||||
: null,
|
||||
onDismissVersionMismatch: handleDismissVersionMismatch,
|
||||
onRunProjectScript: runProjectScript,
|
||||
onAddProjectScript: saveProjectScript,
|
||||
onUpdateProjectScript: updateProjectScript,
|
||||
@@ -11100,8 +11086,6 @@ export default function ChatView(props: ChatViewProps) {
|
||||
threadPanelPresentation,
|
||||
threadPanelPopoverHandle,
|
||||
threadPanelShortcutLabel: shortcutLabelForCommand(keybindings, "threadPanel.toggle"),
|
||||
threadPanelHasAttention:
|
||||
activeEnvironmentUnavailableState !== null || showVersionMismatchBanner,
|
||||
rightPanelAvailable: activeProject !== null,
|
||||
rightPanelOpen,
|
||||
rightPanelShortcutLabel: shortcutLabelForCommand(keybindings, "rightPanel.toggle"),
|
||||
|
||||
@@ -19,7 +19,6 @@ export interface PanelLayoutControlsProps {
|
||||
threadPanelPresentation: ThreadPanelPresentation;
|
||||
threadPanelPopoverHandle?: ReturnType<typeof PopoverCreateHandle>;
|
||||
threadPanelShortcutLabel: string | null;
|
||||
threadPanelHasAttention: boolean;
|
||||
rightPanelAvailable: boolean;
|
||||
rightPanelOpen: boolean;
|
||||
rightPanelShortcutLabel: string | null;
|
||||
@@ -40,7 +39,6 @@ export const PanelLayoutControls = memo(function PanelLayoutControls({
|
||||
threadPanelPresentation,
|
||||
threadPanelPopoverHandle,
|
||||
threadPanelShortcutLabel,
|
||||
threadPanelHasAttention,
|
||||
rightPanelAvailable,
|
||||
rightPanelOpen,
|
||||
rightPanelShortcutLabel,
|
||||
@@ -58,12 +56,6 @@ export const PanelLayoutControls = memo(function PanelLayoutControls({
|
||||
size="sm"
|
||||
>
|
||||
<SquareMenuIcon className="size-4" />
|
||||
{threadPanelHasAttention ? (
|
||||
<span
|
||||
className="absolute right-1 top-1 size-1.5 rounded-full bg-warning ring-2 ring-background"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : null}
|
||||
</Toggle>
|
||||
);
|
||||
const threadPanelTooltip = (trigger: ReactElement) => (
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
import { act } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { expect, it, vi } from "vite-plus/test";
|
||||
|
||||
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
|
||||
import { ThreadDetailsControl } from "./ThreadDetailsControl";
|
||||
|
||||
it("keeps the row label and one chevron when used as a menu trigger", async () => {
|
||||
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
||||
const container = document.createElement("div");
|
||||
document.body.append(container);
|
||||
const root = createRoot(container);
|
||||
try {
|
||||
await act(async () => {
|
||||
root.render(
|
||||
<Menu>
|
||||
<MenuTrigger render={<ThreadDetailsControl part="select" />}>
|
||||
Run on this machine
|
||||
</MenuTrigger>
|
||||
<MenuPopup>
|
||||
<MenuItem>New worktree</MenuItem>
|
||||
</MenuPopup>
|
||||
</Menu>,
|
||||
);
|
||||
});
|
||||
const trigger = container.querySelector("button")!;
|
||||
expect(trigger.textContent).toBe("Run on this machine");
|
||||
expect(trigger.querySelectorAll(".lucide-chevron-down")).toHaveLength(1);
|
||||
await act(async () => trigger.click());
|
||||
expect(document.querySelector('[role="menuitem"]')?.textContent).toBe("New worktree");
|
||||
} finally {
|
||||
await act(async () => root.unmount());
|
||||
container.remove();
|
||||
vi.unstubAllGlobals();
|
||||
}
|
||||
});
|
||||
@@ -1,17 +1,14 @@
|
||||
import { mergeProps } from "@base-ui/react/merge-props";
|
||||
import { Select as SelectPrimitive } from "@base-ui/react/select";
|
||||
import { useRender } from "@base-ui/react/use-render";
|
||||
import type { ComponentProps } from "react";
|
||||
|
||||
import { cn } from "~/lib/utils";
|
||||
import { Button } from "../ui/button";
|
||||
import { ComposerSelectControl } from "./ComposerControl";
|
||||
import {
|
||||
THREAD_DETAILS_PANEL_ROW_CLASS,
|
||||
THREAD_DETAILS_PANEL_SELECT_ROW_CLASS,
|
||||
THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS,
|
||||
THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
|
||||
THREAD_DETAILS_PANEL_LINK_SPLIT_PRIMARY_CLASS,
|
||||
THREAD_DETAILS_PANEL_ICON_ACTION_CLASS,
|
||||
THREAD_DETAILS_PANEL_META_ACTION_CLASS,
|
||||
THREAD_DETAILS_PANEL_CHEVRON_CLASS,
|
||||
@@ -20,11 +17,9 @@ import { ChevronDownIcon } from "lucide-react";
|
||||
|
||||
const parts = {
|
||||
row: THREAD_DETAILS_PANEL_ROW_CLASS,
|
||||
"group-row": `${THREAD_DETAILS_PANEL_ROW_CLASS} hover:!bg-transparent dark:hover:!bg-transparent`,
|
||||
select: THREAD_DETAILS_PANEL_SELECT_ROW_CLASS,
|
||||
primary: THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS,
|
||||
secondary: THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
|
||||
"link-primary": THREAD_DETAILS_PANEL_LINK_SPLIT_PRIMARY_CLASS,
|
||||
icon: THREAD_DETAILS_PANEL_ICON_ACTION_CLASS,
|
||||
meta: THREAD_DETAILS_PANEL_META_ACTION_CLASS,
|
||||
};
|
||||
@@ -36,6 +31,7 @@ export function ThreadDetailsControl({
|
||||
multiline = false,
|
||||
tone = "default",
|
||||
className,
|
||||
children,
|
||||
size = "default",
|
||||
variant = "default",
|
||||
render,
|
||||
@@ -64,6 +60,19 @@ export function ThreadDetailsControl({
|
||||
),
|
||||
},
|
||||
props,
|
||||
{
|
||||
children:
|
||||
part === "select" ? (
|
||||
<>
|
||||
{children}
|
||||
<span data-slot="select-icon">
|
||||
<ChevronDownIcon className={THREAD_DETAILS_PANEL_CHEVRON_CLASS} />
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
children
|
||||
),
|
||||
},
|
||||
),
|
||||
});
|
||||
if (!panel) {
|
||||
@@ -74,34 +83,10 @@ export function ThreadDetailsControl({
|
||||
size={multiline ? "sm-multiline" : size}
|
||||
variant={variant}
|
||||
className={className}
|
||||
/>
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
return control;
|
||||
}
|
||||
|
||||
export function ThreadDetailsSelectControl({
|
||||
panel,
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: Omit<SelectPrimitive.Trigger.Props, "className"> & { panel: boolean; className?: string }) {
|
||||
if (!panel) {
|
||||
return (
|
||||
<ComposerSelectControl {...props} size="xs" className={className}>
|
||||
{children}
|
||||
</ComposerSelectControl>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<SelectPrimitive.Trigger
|
||||
{...props}
|
||||
render={<ThreadDetailsControl part="select" className={className} />}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon data-slot="select-icon">
|
||||
<ChevronDownIcon className={THREAD_DETAILS_PANEL_CHEVRON_CLASS} />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
);
|
||||
}
|
||||
@@ -74,8 +74,6 @@ describe("ThreadDetailsPanel", () => {
|
||||
startFromOrigin: false,
|
||||
onStartFromOriginChange: vi.fn(),
|
||||
onComposerFocusRequest: vi.fn(),
|
||||
versionMismatch: null,
|
||||
onDismissVersionMismatch: vi.fn(),
|
||||
onRunProjectScript: vi.fn(),
|
||||
onAddProjectScript: vi.fn() as ThreadDetailsPanelProps["onAddProjectScript"],
|
||||
onUpdateProjectScript: vi.fn() as ThreadDetailsPanelProps["onUpdateProjectScript"],
|
||||
|
||||
@@ -5,23 +5,16 @@ import type {
|
||||
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 { 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";
|
||||
@@ -29,12 +22,6 @@ 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"
|
||||
@@ -66,8 +53,6 @@ export interface ThreadDetailsPanelProps extends Pick<
|
||||
onCheckoutPullRequestRequest?: (reference: string) => void;
|
||||
onComposerFocusRequest: () => void;
|
||||
onOpenChanges?: () => void;
|
||||
versionMismatch: VersionMismatchIssue | null;
|
||||
onDismissVersionMismatch: () => void;
|
||||
onRunProjectScript: (script: ProjectScript) => void;
|
||||
onAddProjectScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
|
||||
onUpdateProjectScript: (
|
||||
@@ -82,14 +67,6 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
|
||||
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,
|
||||
@@ -128,46 +105,19 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
|
||||
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"
|
||||
{density === "full" ? (
|
||||
<BranchToolbar
|
||||
layout="panel"
|
||||
panelSection="workspace"
|
||||
availableEnvironments={props.availableEnvironments}
|
||||
onEnvironmentChange={props.onEnvironmentChange}
|
||||
autoEnvironmentLabel={props.autoEnvironmentLabel}
|
||||
onAutoEnvironment={props.onAutoEnvironment}
|
||||
envLocked={props.envLocked}
|
||||
environmentId={props.environmentId}
|
||||
availableEnvironments={props.availableEnvironments}
|
||||
{...(canPickEnvironment
|
||||
? { onEnvironmentChange: props.onEnvironmentChange }
|
||||
: {})}
|
||||
{...branchToolbarProps}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{density === "full" ? (
|
||||
<BranchToolbar layout="panel" panelSection="workspace" {...branchToolbarProps} />
|
||||
) : null}
|
||||
|
||||
{density !== "essential" && props.showOpenInPicker ? (
|
||||
<OpenInPicker
|
||||
keybindings={props.keybindings}
|
||||
|
||||
@@ -75,7 +75,7 @@ import { Button } from "../ui/button";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import {
|
||||
THREAD_DETAILS_PANEL_ICON_CLASS,
|
||||
THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS,
|
||||
THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,
|
||||
THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
|
||||
} from "./threadDetailsPanelStyles";
|
||||
|
||||
@@ -383,7 +383,7 @@ export function ThreadDetailsPrRow({
|
||||
</Tooltip>
|
||||
) : null;
|
||||
|
||||
const openRow = (text: string, part: "row" | "link-primary") => (
|
||||
const openRow = (text: string, part: "row" | "primary") => (
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
render={
|
||||
@@ -450,8 +450,8 @@ export function ThreadDetailsPrRow({
|
||||
</div>
|
||||
</div>
|
||||
) : watching ? (
|
||||
<div className={THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS}>
|
||||
{openRow(label, "link-primary")}
|
||||
<div className={THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS}>
|
||||
{openRow(label, "primary")}
|
||||
<span aria-hidden="true" className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS} />
|
||||
{watchControl("secondary")}
|
||||
</div>
|
||||
|
||||
@@ -59,7 +59,7 @@ import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
|
||||
import { toastManager } from "../ui/toast";
|
||||
import {
|
||||
THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS,
|
||||
THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,
|
||||
THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS,
|
||||
THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
|
||||
} from "./threadDetailsPanelStyles";
|
||||
@@ -461,12 +461,9 @@ export function ThreadRelationshipsPanel(props: {
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<li
|
||||
key={threadId}
|
||||
className={`group relative flex h-8 items-center rounded-lg ${canStop ? THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS : ""}`}
|
||||
>
|
||||
<li key={threadId} className="group relative flex h-8 items-center rounded-lg">
|
||||
{isMergeTarget ? (
|
||||
<div className={THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS}>
|
||||
<div className={THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS}>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
delay={200}
|
||||
@@ -474,7 +471,7 @@ export function ThreadRelationshipsPanel(props: {
|
||||
<ThreadDetailsControl
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
part="link-primary"
|
||||
part="primary"
|
||||
aria-label={`${threadTitle} ${threadRelationshipStatusLabel(status)}`}
|
||||
disabled={node?.missing === true}
|
||||
onClick={() => openThread(threadId)}
|
||||
@@ -534,7 +531,7 @@ export function ThreadRelationshipsPanel(props: {
|
||||
variant="ghost"
|
||||
disabled={node?.missing === true}
|
||||
onClick={() => openThread(threadId)}
|
||||
part={canStop ? "group-row" : "row"}
|
||||
part="row"
|
||||
/>
|
||||
}
|
||||
>
|
||||
|
||||
@@ -6,29 +6,20 @@
|
||||
const THREAD_DETAILS_PANEL_RESTING_BUTTON_SURFACE_CLASS = "bg-transparent shadow-none";
|
||||
|
||||
const THREAD_DETAILS_PANEL_HOVER_SURFACE_CLASS =
|
||||
"hover:!bg-black/[0.055] data-pressed:!bg-black/[0.055] dark:hover:!bg-white/[0.075] dark:data-pressed:!bg-white/[0.075]";
|
||||
"hover:!bg-black/[0.035] data-pressed:!bg-black/[0.035] dark:hover:!bg-white/[0.08] dark:data-pressed:!bg-white/[0.08]";
|
||||
|
||||
const THREAD_DETAILS_PANEL_ROW_SURFACE_CLASS = `${THREAD_DETAILS_PANEL_RESTING_BUTTON_SURFACE_CLASS} ${THREAD_DETAILS_PANEL_HOVER_SURFACE_CLASS}`;
|
||||
const THREAD_DETAILS_PANEL_SPLIT_BUTTON_SURFACE_CLASS = `${THREAD_DETAILS_PANEL_ROW_SURFACE_CLASS} data-popup-open:!bg-black/[0.035] dark:data-popup-open:!bg-white/[0.08]`;
|
||||
const THREAD_DETAILS_PANEL_SPLIT_GROUP_SURFACE_CLASS = `${THREAD_DETAILS_PANEL_HOVER_SURFACE_CLASS} has-[[data-popup-open]]:bg-black/[0.035] dark:has-[[data-popup-open]]:bg-white/[0.08]`;
|
||||
|
||||
export const THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS = "gap-2.5 px-2.5 text-left";
|
||||
|
||||
// The row supplies the first tint; the hovered or open segment adds a second tint.
|
||||
const THREAD_DETAILS_PANEL_SPLIT_BUTTON_SURFACE_CLASS = `${THREAD_DETAILS_PANEL_ROW_SURFACE_CLASS} data-popup-open:!bg-black/[0.055] dark:data-popup-open:!bg-white/[0.075]`;
|
||||
|
||||
const THREAD_DETAILS_PANEL_CONTROL_CLASS = `h-8 min-w-0 rounded-lg border-transparent ${THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS} text-[13px] font-medium text-foreground/80`;
|
||||
const THREAD_DETAILS_PANEL_SPLIT_GROUP_SURFACE_CLASS = `${THREAD_DETAILS_PANEL_HOVER_SURFACE_CLASS} has-[[data-popup-open]]:bg-black/[0.055] dark:has-[[data-popup-open]]:bg-white/[0.075]`;
|
||||
|
||||
export const THREAD_DETAILS_PANEL_ROW_CLASS = `${THREAD_DETAILS_PANEL_CONTROL_CLASS} w-full justify-start ${THREAD_DETAILS_PANEL_ROW_SURFACE_CLASS}`;
|
||||
|
||||
export const THREAD_DETAILS_PANEL_SELECT_ROW_CLASS = `${THREAD_DETAILS_PANEL_ROW_CLASS} pe-0 [&_[data-slot=select-icon]]:-me-px [&_[data-slot=select-icon]]:relative [&_[data-slot=select-icon]]:flex [&_[data-slot=select-icon]]:h-full [&_[data-slot=select-icon]]:w-8 [&_[data-slot=select-icon]]:shrink-0 [&_[data-slot=select-icon]]:items-center [&_[data-slot=select-icon]]:justify-center [&_[data-slot=select-icon]]:before:absolute [&_[data-slot=select-icon]]:before:-left-px [&_[data-slot=select-icon]]:before:top-1/2 [&_[data-slot=select-icon]]:before:h-4 [&_[data-slot=select-icon]]:before:w-px [&_[data-slot=select-icon]]:before:-translate-y-1/2 [&_[data-slot=select-icon]]:before:bg-border/65 [&_[data-slot=select-icon]>svg]:me-0 [&_[data-slot=select-icon]>svg]:size-4 [&_[data-slot=select-icon]>svg]:text-muted-foreground [&_[data-slot=select-icon]>svg]:opacity-100`;
|
||||
|
||||
// No transition on the group: the halves are Buttons whose background snaps (their base only
|
||||
// transitions shadow), so an eased group tint would land frames later and the hover would
|
||||
// visibly commit in two steps.
|
||||
export const THREAD_DETAILS_PANEL_LINK_SPLIT_GROUP_CLASS = `group/thread-details-link flex w-full items-center rounded-lg ${THREAD_DETAILS_PANEL_SPLIT_GROUP_SURFACE_CLASS}`;
|
||||
|
||||
export const THREAD_DETAILS_PANEL_LINK_SPLIT_PRIMARY_CLASS = `${THREAD_DETAILS_PANEL_CONTROL_CLASS} flex-1 justify-start rounded-e-none ${THREAD_DETAILS_PANEL_SPLIT_BUTTON_SURFACE_CLASS}`;
|
||||
|
||||
export const THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS = `h-8 w-full min-w-0 justify-start rounded-lg border border-transparent ${THREAD_DETAILS_PANEL_ROW_CONTENT_CLASS} text-[13px] font-medium text-foreground/80 sm:h-8 sm:text-[13px]`;
|
||||
|
||||
export const THREAD_DETAILS_PANEL_ICON_CLASS = "size-4 shrink-0 text-muted-foreground";
|
||||
@@ -40,7 +31,7 @@ export const THREAD_DETAILS_PANEL_ICON_ACTION_CLASS = `size-6 justify-center rou
|
||||
/** A small text control on a row's second line, such as a pull request's checks or next action. */
|
||||
export const THREAD_DETAILS_PANEL_META_ACTION_CLASS = `h-6 gap-1 rounded-md border-transparent px-1.5 text-xs font-medium text-muted-foreground ${THREAD_DETAILS_PANEL_ROW_SURFACE_CLASS}`;
|
||||
|
||||
export const THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS = `group/thread-details-action flex w-full items-center rounded-lg ${THREAD_DETAILS_PANEL_SPLIT_GROUP_SURFACE_CLASS}`;
|
||||
export const THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS = `flex w-full items-center rounded-lg ${THREAD_DETAILS_PANEL_SPLIT_GROUP_SURFACE_CLASS}`;
|
||||
|
||||
export const THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS = `${THREAD_DETAILS_PANEL_CONTROL_CLASS} flex-1 justify-start rounded-e-none ${THREAD_DETAILS_PANEL_SPLIT_BUTTON_SURFACE_CLASS}`;
|
||||
|
||||
|
||||
@@ -1843,7 +1843,6 @@ function PullRequestsRouteView() {
|
||||
threadPanelOpen={false}
|
||||
threadPanelPresentation="inline"
|
||||
threadPanelShortcutLabel={null}
|
||||
threadPanelHasAttention={false}
|
||||
onToggleThreadPanel={() => undefined}
|
||||
rightPanelAvailable={rightPanelAvailable}
|
||||
rightPanelOpen={rightPanelState.isOpen}
|
||||
|
||||
Reference in new issue
Block a user