Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/app/workspace/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ function resolvePanelSizeRange(
}

function WorkspaceContent({ children }: { children: React.ReactNode }) {
const { mode, setActivePane, filesMaximized } = useWorkspaceContext()
const { mode, layoutMode, setActivePane, filesMaximized } =
useWorkspaceContext()
const panelGroupRef = useRef<ImperativePanelGroupHandle | null>(null)
const fusionLayoutRef = useRef<[number, number]>(DEFAULT_FUSION_LAYOUT)
const desiredLayoutRef = useRef<[number, number]>(DEFAULT_FUSION_LAYOUT)
Expand Down Expand Up @@ -160,10 +161,10 @@ function WorkspaceContent({ children }: { children: React.ReactNode }) {
}, [])

useEffect(() => {
if (mode === "fusion") {
if (mode === "fusion" && layoutMode === "fusion") {
applyLayout(fusionLayoutRef.current)
}
}, [applyLayout, mode])
}, [applyLayout, mode, layoutMode])

const handleLayout = useCallback(
(layout: number[]) => {
Expand All @@ -187,6 +188,10 @@ function WorkspaceContent({ children }: { children: React.ReactNode }) {
[applyLayout, mode]
)

if (layoutMode === "files" && mode === "fusion") {
return <SinglePaneWorkspaceContent>{children}</SinglePaneWorkspaceContent>
}

return (
<div className="relative h-full min-h-0 overflow-hidden">
<ResizablePanelGroup
Expand Down Expand Up @@ -289,6 +294,8 @@ function MobileWorkspaceContent({ children }: { children: React.ReactNode }) {
)
}

const SinglePaneWorkspaceContent = MobileWorkspaceContent

function MobileFolderWorkspaceShell({
children,
}: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/files/file-workspace-tab-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function FileWorkspaceTabBar() {
const t = useTranslations("Folder.fileWorkspace")
const {
mode,
layoutMode,
activePane,
fileTabs,
activeFileTabId,
Expand Down Expand Up @@ -217,7 +218,7 @@ export function FileWorkspaceTabBar() {
<ExternalLink className="h-4 w-4" />
</button>
)}
{!isMobile && mode === "fusion" && (
{!isMobile && mode === "fusion" && layoutMode === "fusion" && (
<button
type="button"
onClick={toggleFilesMaximized}
Expand Down
135 changes: 135 additions & 0 deletions src/components/settings/general-settings.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { fireEvent, render, screen, within } from "@testing-library/react"
import { NextIntlClientProvider } from "next-intl"
import { beforeEach, describe, expect, it, vi } from "vitest"

vi.mock("@/lib/api", () => ({
getAvailableTerminalShells: vi.fn(),
getSystemRenderingSettings: vi.fn(),
getSystemTerminalSettings: vi.fn(),
probeTerminalShellPath: vi.fn(),
updateSystemRenderingSettings: vi.fn(),
updateSystemTerminalSettings: vi.fn(),
}))

vi.mock("@/hooks/use-platform", () => ({
usePlatform: () => ({
platform: "linux",
isMac: false,
isWindows: false,
isLinux: true,
}),
}))

vi.mock("@/lib/platform", () => ({
isDesktop: () => false,
}))

vi.mock("@/lib/transport", () => ({
getActiveRemoteConnectionId: () => null,
}))

vi.mock("@/lib/updater", () => ({
relaunchApp: vi.fn(),
}))

vi.mock("sonner", () => ({
toast: {
success: vi.fn(),
error: vi.fn(),
},
}))

vi.mock("@/components/settings/delegation-settings", () => ({
DelegationSettingsSection: () => <div data-testid="delegation-settings" />,
}))

vi.mock("@/components/ui/select", () => ({
Select: ({
children,
onValueChange,
value,
}: {
children: React.ReactNode
onValueChange?: (value: string) => void
value?: string
}) => (
<select
value={value}
onChange={(event) => onValueChange?.(event.target.value)}
>
{children}
</select>
),
SelectTrigger: () => null,
SelectValue: () => null,
SelectContent: ({ children }: { children: React.ReactNode }) => children,
SelectItem: ({ value }: { children: React.ReactNode; value: string }) => (
<option value={value}>{value}</option>
),
}))

import enMessages from "@/i18n/messages/en.json"
import {
getAvailableTerminalShells,
getSystemTerminalSettings,
} from "@/lib/api"
import { GeneralSettings } from "./general-settings"

const mockGetAvailableTerminalShells = vi.mocked(getAvailableTerminalShells)
const mockGetSystemTerminalSettings = vi.mocked(getSystemTerminalSettings)

function renderWithIntl() {
return render(
<NextIntlClientProvider locale="en" messages={enMessages}>
<GeneralSettings />
</NextIntlClientProvider>
)
}

beforeEach(() => {
localStorage.clear()
mockGetAvailableTerminalShells.mockReset()
mockGetSystemTerminalSettings.mockReset()

mockGetSystemTerminalSettings.mockResolvedValue({
default_shell: null,
})
mockGetAvailableTerminalShells.mockResolvedValue({
options: [
{
id: "system",
label_key: "terminalSystemDefault",
value: null,
exists: true,
accepts_custom_path: false,
},
],
resolved_shell: "/bin/sh",
})
})

describe("GeneralSettings", () => {
it("renders without WorkspaceProvider and persists workspace layout changes", async () => {
localStorage.setItem("workspace:layout-mode", "files")

renderWithIntl()

const heading = await screen.findByRole("heading", {
name: "Workspace Layout",
})
const section = heading.closest("section")

expect(section).not.toBeNull()

const layoutSelect = within(section as HTMLElement).getByDisplayValue(
"files"
)

fireEvent.change(layoutSelect, { target: { value: "fusion" } })

expect(localStorage.getItem("workspace:layout-mode")).toBe("fusion")
expect(within(section as HTMLElement).getByDisplayValue("fusion")).toBe(
layoutSelect
)
})
})
59 changes: 58 additions & 1 deletion src/components/settings/general-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"use client"

import { useCallback, useEffect, useState } from "react"
import { Loader2, MonitorCog, RefreshCw, SquareTerminal } from "lucide-react"
import {
Columns2,
Loader2,
MonitorCog,
RefreshCw,
SquareTerminal,
} from "lucide-react"
import { useTranslations } from "next-intl"
import { toast } from "sonner"

Expand All @@ -26,6 +32,11 @@ import {
import { isDesktop } from "@/lib/platform"
import { getActiveRemoteConnectionId } from "@/lib/transport"
import type { AvailableTerminalShells, TerminalShellOption } from "@/lib/types"
import {
loadLayoutMode,
saveLayoutMode,
type WorkspaceLayoutMode,
} from "@/lib/workspace-layout-mode-storage"
import { usePlatform } from "@/hooks/use-platform"
import { relaunchApp } from "@/lib/updater"
import { toErrorMessage } from "@/lib/app-error"
Expand Down Expand Up @@ -61,6 +72,8 @@ export function GeneralSettings() {
// for that single call site rather than casting at every use.
const tDynamic = t as unknown as (key: string) => string
const { isWindows } = usePlatform()
const [layoutMode, setLayoutMode] =
useState<WorkspaceLayoutMode>(loadLayoutMode)

// Rendering settings are a local Tauri preference (preferences.json). They
// are only meaningful when the active transport is the local Tauri shell —
Expand Down Expand Up @@ -234,6 +247,11 @@ export function GeneralSettings() {
}
}, [t])

const onLayoutModeChange = useCallback((nextMode: WorkspaceLayoutMode) => {
saveLayoutMode(nextMode)
setLayoutMode(nextMode)
}, [])

if (loading) {
return (
<div className="h-full flex items-center justify-center text-sm text-muted-foreground gap-2">
Expand All @@ -259,6 +277,45 @@ export function GeneralSettings() {
</div>
)}

<section className="rounded-xl border bg-card p-4 space-y-4">
<div className="flex items-center gap-2">
<Columns2 className="h-4 w-4 text-muted-foreground" />
<h2 className="text-sm font-semibold">
{t("workspaceLayoutTitle")}
</h2>
</div>

<p className="text-xs text-muted-foreground leading-5">
{t("workspaceLayoutDescription")}
</p>

<div className="space-y-2">
<Select value={layoutMode} onValueChange={onLayoutModeChange}>
<SelectTrigger className="w-full text-left sm:w-64">
<SelectValue className="justify-start text-left" />
</SelectTrigger>
<SelectContent align="start">
<SelectItem value="fusion">
<div className="flex flex-col items-start text-left">
<span>{t("workspaceLayoutFusion")}</span>
<span className="text-left text-[10px] text-muted-foreground">
{t("workspaceLayoutFusionHint")}
</span>
</div>
</SelectItem>
<SelectItem value="files">
<div className="flex flex-col items-start text-left">
<span>{t("workspaceLayoutFiles")}</span>
<span className="text-left text-[10px] text-muted-foreground">
{t("workspaceLayoutFilesHint")}
</span>
</div>
</SelectItem>
</SelectContent>
</Select>
</div>
</section>

<section className="rounded-xl border bg-card p-4 space-y-4">
<div className="flex items-center gap-2">
<SquareTerminal className="h-4 w-4 text-muted-foreground" />
Expand Down
20 changes: 20 additions & 0 deletions src/contexts/workspace-context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const mockedApi = api as unknown as {
function WorkspaceProbe() {
const {
mode,
layoutMode,
activePane,
fileTabs,
activeFileTabId,
Expand All @@ -53,6 +54,7 @@ function WorkspaceProbe() {
return (
<div>
<output data-testid="mode">{mode}</output>
<output data-testid="layout-mode">{layoutMode}</output>
<output data-testid="file-tab-count">{fileTabs.length}</output>
<output data-testid="active-pane">{activePane}</output>
<output data-testid="files-maximized">{String(filesMaximized)}</output>
Expand Down Expand Up @@ -127,6 +129,24 @@ describe("WorkspaceProvider mode", () => {
expect(screen.getByTestId("mode")).toHaveTextContent("conversation")
expect(screen.getByTestId("file-tab-count")).toHaveTextContent("0")
})

it("syncs layoutMode from storage events fired by another window", () => {
renderWorkspace()

expect(screen.getByTestId("layout-mode")).toHaveTextContent("fusion")

act(() => {
localStorage.setItem("workspace:layout-mode", "files")
window.dispatchEvent(
new StorageEvent("storage", {
key: "workspace:layout-mode",
newValue: "files",
})
)
})

expect(screen.getByTestId("layout-mode")).toHaveTextContent("files")
})
})

describe("WorkspaceProvider files-maximized", () => {
Expand Down
Loading
Loading