Skip to content
Merged
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
11 changes: 6 additions & 5 deletions packages/app/e2e/app/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ test("@smoke home hero prompt starts a session", async ({ page, project, assista

test("@smoke project home status panel can open the server picker dialog", async ({ page, project }) => {
await project.open()
const statusButton = page.getByRole("button", { name: "Right utility panel" }).first()
const rightPanel = page.locator("#right-panel")

await statusButton.click()
await expect(rightPanel).toHaveAttribute("aria-hidden", "false")
await rightPanel.getByRole("button", { name: "Manage servers" }).click()
const statusPanel = page.getByRole("complementary", { name: "Right utility panel" })
if (!(await statusPanel.isVisible())) {
await page.getByRole("button", { name: "Right utility panel" }).click()
}
await expect(statusPanel).toBeVisible()
await statusPanel.getByRole("button", { name: "Manage servers" }).click()

const dialog = page.getByRole("dialog")
await expect(dialog).toBeVisible()
Expand Down
13 changes: 4 additions & 9 deletions packages/app/e2e/files/file-tree.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test, expect } from "../fixtures"
import { withSession } from "../actions"
import { titlebarRightSelector } from "../selectors"

// Historical context: before the right-panel-polish PR (#52), the Review tab
// carried a sibling vertical file-tree pane (#file-tree-panel) that surfaced
Expand All @@ -14,16 +13,12 @@ test("@smoke review tab no longer renders the legacy file-tree sub-panel", async
await withSession(project.sdk, `e2e review layout smoke ${Date.now()}`, async (session) => {
await project.gotoSession(session.id)

const rightToggle = page.locator(`${titlebarRightSelector} button`).first()
const rightPanel = page.locator("#right-panel")
const shellTabList = rightPanel.getByRole("tablist").first()

await expect(rightToggle).toBeVisible()
await rightToggle.click()
await expect(rightPanel).toHaveAttribute("aria-hidden", "false")
const rightPanel = page.getByRole("complementary", { name: "Right utility panel" })
const shellTabList = rightPanel.getByRole("tablist")
await shellTabList.locator("button").last().click()
await page.getByRole("menuitem", { name: "Review" }).click()

const reviewTab = shellTabList.getByRole("tab", { name: "Review", exact: true })
await reviewTab.click()
await expect(reviewTab).toHaveAttribute("aria-selected", "true")

// The old vertical file-tree pane is gone by design.
Expand Down
3 changes: 1 addition & 2 deletions packages/app/src/components/dialog-select-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ export function DialogSelectFile(props: { mode?: DialogSelectFileMode; onOpenFil
const value = file.tab(path)
tabs().open(value)
file.load(path)
if (!view().sidePanel.opened()) view().sidePanel.open()
view().sidePanel.setTab("changes")
view().sidePanel.openTab("review")
view().sidePanel.explorer.setTab("all")
props.onOpenFile?.(path)
tabs().setActive(value)
Expand Down
5 changes: 1 addition & 4 deletions packages/app/src/components/prompt-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,14 @@ export const PromptInput: Component<PromptInputProps> = (props) => {
}

const wantsReview = item.commentOrigin === "review" || (item.commentOrigin !== "file" && commentInReview(item.path))
view().sidePanel.openTab("review")
if (wantsReview) {
if (!view().sidePanel.opened()) view().sidePanel.open()
view().sidePanel.setTab("changes")
view().sidePanel.explorer.setTab("changes")
tabs().setActive("review")
queueCommentFocus()
return
}

if (!view().sidePanel.opened()) view().sidePanel.open()
view().sidePanel.setTab("changes")
view().sidePanel.explorer.setTab("all")
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const tab = files.tab(item.path)
tabs().open(tab)
Expand Down
33 changes: 2 additions & 31 deletions packages/app/src/components/session-context-usage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,24 @@ import { Tooltip, type TooltipProps } from "@opencode-ai/ui/tooltip"
import { ProgressCircle } from "@opencode-ai/ui/progress-circle"
import { Button } from "@opencode-ai/ui/button"

import { useFile } from "@/context/file"
import { useLayout } from "@/context/layout"
import { useSync } from "@/context/sync"
import { useLanguage } from "@/context/language"
import { useProviders } from "@/hooks/use-providers"
import { getSessionContextMetrics } from "@/components/session/session-context-metrics"
import { useSessionLayout } from "@/pages/session/session-layout"
import { createSessionTabs } from "@/pages/session/helpers"

interface SessionContextUsageProps {
variant?: "button" | "indicator"
placement?: TooltipProps["placement"]
}

function openSessionContext(args: {
view: ReturnType<ReturnType<typeof useLayout>["view"]>
tabs: ReturnType<ReturnType<typeof useLayout>["tabs"]>
}) {
if (!args.view.sidePanel.opened()) args.view.sidePanel.open()
args.view.sidePanel.setTab("changes")
if (args.view.sidePanel.explorer.tab() !== "all") args.view.sidePanel.explorer.setTab("all")
args.tabs.open("context")
args.tabs.setActive("context")
}

export function SessionContextUsage(props: SessionContextUsageProps) {
const sync = useSync()
const file = useFile()
const layout = useLayout()
const language = useLanguage()
const providers = useProviders()
const { params, tabs, view } = useSessionLayout()
const { params, view } = useSessionLayout()

const variant = createMemo(() => props.variant ?? "button")
const tabState = createSessionTabs({
tabs,
pathFromTab: file.pathFromTab,
normalizeTab: (tab) => (tab.startsWith("file://") ? file.tab(tab) : tab),
})
const messages = createMemo(() => (params.id ? (sync.data.message[params.id] ?? []) : []))

const metrics = createMemo(() => getSessionContextMetrics(messages(), providers.all()))
Expand All @@ -55,15 +34,7 @@ export function SessionContextUsage(props: SessionContextUsageProps) {

const openContext = () => {
if (!params.id) return

if (tabState.activeTab() === "context") {
tabs().close("context")
return
}
openSessionContext({
view: view(),
tabs: tabs(),
})
view().sidePanel.toggleTab("context")
}

const circle = () => (
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/components/session/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { SessionHeader } from "./session-header"
export { SessionContextTab } from "./session-context-tab"
export { SortableTab, FileVisual } from "./session-sortable-tab"
export { ShellTab, SortableShellTab } from "./session-sortable-shell-tab"
export { SortableTerminalTab } from "./session-sortable-terminal-tab"
export { NewSessionView } from "./session-new-view"
68 changes: 68 additions & 0 deletions packages/app/src/components/session/session-sortable-shell-tab.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { JSX } from "solid-js"
import { createSortable } from "@thisbeyond/solid-dnd"
import { IconButton } from "@opencode-ai/ui/icon-button"
import { Tabs } from "@opencode-ai/ui/tabs"
import { Tooltip } from "@opencode-ai/ui/tooltip"
import { useLanguage } from "@/context/language"
import type { RightPanelTab } from "@/pages/session/right-panel-tabs"

export function ShellTab(props: {
value: RightPanelTab
label: string
closable: boolean
onClose: (tab: RightPanelTab) => void
children: JSX.Element
}): JSX.Element {
const language = useLanguage()
const close = () => {
if (!props.closable) return
props.onClose(props.value)
}

return (
<div class="h-full flex items-center">
<Tabs.Trigger
value={props.value}
class="shrink-0 h-7"
classes={{
button:
"h-7 min-h-7 inline-flex items-center whitespace-nowrap rounded-md text-12-medium text-text-weak gap-1.5 px-2.5",
}}
closeButton={
props.closable ? (
<Tooltip value={language.t("common.closeTab")} placement="bottom" gutter={10}>
<IconButton
icon="close-small"
variant="ghost"
class="h-5 w-5"
onClick={close}
aria-label={language.t("common.closeTab")}
/>
</Tooltip>
) : undefined
}
hideCloseButton
onMiddleClick={close}
aria-label={props.label}
>
{props.children}
</Tabs.Trigger>
</div>
)
}

export function SortableShellTab(props: {
value: RightPanelTab
label: string
closable: boolean
onClose: (tab: RightPanelTab) => void
children: JSX.Element
}): JSX.Element {
const sortable = createSortable(props.value)

return (
<div use:sortable class="h-full flex items-center" classList={{ "opacity-0": sortable.isActiveDraggable }}>
<ShellTab {...props} />
</div>
)
}
6 changes: 4 additions & 2 deletions packages/app/src/context/global-sync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { ProjectMeta } from "./global-sync/types"
import { SESSION_RECENT_LIMIT } from "./global-sync/types"
import { sanitizeProject } from "./global-sync/utils"
import { formatServerError } from "@/utils/server-errors"
import { queryOptions, skipToken, useQueryClient } from "@tanstack/solid-query"
import { queryOptions, useQueryClient } from "@tanstack/solid-query"

type GlobalStore = {
ready: boolean
Expand All @@ -42,8 +42,10 @@ type GlobalStore = {
reload: undefined | "pending" | "complete"
}

const inactiveQueryFn = async () => null

export const loadSessionsQuery = (directory: string) =>
queryOptions<null>({ queryKey: [directory, "loadSessions"], queryFn: skipToken })
queryOptions<null>({ queryKey: [directory, "loadSessions"], queryFn: inactiveQueryFn, enabled: false })

function createGlobalSync() {
const globalSDK = useGlobalSDK()
Expand Down
8 changes: 5 additions & 3 deletions packages/app/src/context/global-sync/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { reconcile, type SetStoreFunction, type Store } from "solid-js/store"
import type { State, VcsCache } from "./types"
import { cmp, normalizeAgentList, normalizeProviderList } from "./utils"
import { formatServerError } from "@/utils/server-errors"
import { QueryClient, queryOptions, skipToken } from "@tanstack/solid-query"
import { QueryClient, queryOptions } from "@tanstack/solid-query"
import { loadSessionsQuery } from "../global-sync"

type GlobalStore = {
Expand Down Expand Up @@ -180,11 +180,13 @@ function warmSessions(input: {
).then(() => undefined)
}

const inactiveQueryFn = async () => null

export const loadProvidersQuery = (directory: string | null) =>
queryOptions<null>({ queryKey: [directory, "providers"], queryFn: skipToken })
queryOptions<null>({ queryKey: [directory, "providers"], queryFn: inactiveQueryFn, enabled: false })

export const loadAgentsQuery = (directory: string | null) =>
queryOptions<null>({ queryKey: [directory, "agents"], queryFn: skipToken })
queryOptions<null>({ queryKey: [directory, "agents"], queryFn: inactiveQueryFn, enabled: false })

export async function bootstrapDirectory(input: {
directory: string
Expand Down
96 changes: 96 additions & 0 deletions packages/app/src/context/layout.shell-tabs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { describe, expect, test } from "bun:test"

import {
closeShellTab,
moveShellTab,
normalizeShellTabs,
openShellTab,
toggleShellTab,
} from "@/pages/session/right-panel-tabs"

describe("shell tab transitions", () => {
const base = normalizeShellTabs({ openShellTabs: ["status"], sidePanelTab: "status" })

test("openShellTab appends to end and sets active", () => {
expect(openShellTab(base, "files")).toEqual({ openShellTabs: ["status", "files"], sidePanelTab: "files" })
})

test("openShellTab on existing tab only sets active", () => {
const start = openShellTab(openShellTab(base, "files"), "review")
const next = openShellTab(start, "files")
expect(next.openShellTabs).toEqual(["status", "files", "review"])
expect(next.sidePanelTab).toBe("files")
})

test("closeShellTab status is no-op", () => {
expect(closeShellTab(base, "status")).toEqual(base)
})

test("closeShellTab on active falls back to left neighbor", () => {
const start = openShellTab(openShellTab(base, "files"), "review")
expect(closeShellTab(start, "review")).toEqual({ openShellTabs: ["status", "files"], sidePanelTab: "files" })
})

test("closeShellTab on active with no left neighbor falls back to status", () => {
const start = openShellTab(base, "files")
expect(closeShellTab(start, "files")).toEqual({ openShellTabs: ["status"], sidePanelTab: "status" })
})

test("closeShellTab on non-active preserves active", () => {
const start = openShellTab(openShellTab(base, "files"), "review")
expect(closeShellTab(start, "files")).toEqual({ openShellTabs: ["status", "review"], sidePanelTab: "review" })
})

test("toggleShellTab opens when not in list", () => {
const next = toggleShellTab(base, "files", true)
expect(next.closePanel).toBe(false)
expect(next.state).toEqual({ openShellTabs: ["status", "files"], sidePanelTab: "files" })
})

test("toggleShellTab on inactive in-list tab only activates", () => {
const start = openShellTab(openShellTab(base, "files"), "review")
const next = toggleShellTab(start, "files", true)
expect(next.closePanel).toBe(false)
expect(next.state.openShellTabs).toEqual(["status", "files", "review"])
expect(next.state.sidePanelTab).toBe("files")
})

test("toggleShellTab on active but panel closed activates", () => {
const start = openShellTab(base, "files")
const next = toggleShellTab(start, "files", false)
expect(next.closePanel).toBe(false)
expect(next.state.sidePanelTab).toBe("files")
})

test("toggleShellTab on active and panel open closes the panel without removing the tab", () => {
const start = openShellTab(base, "files")
const next = toggleShellTab(start, "files", true)
expect(next.closePanel).toBe(true)
expect(next.state.openShellTabs).toEqual(["status", "files"])
expect(next.state.sidePanelTab).toBe("files")
})

test("toggleShellTab status never closes", () => {
const next = toggleShellTab(base, "status", true)
expect(next.closePanel).toBe(false)
expect(next.state).toEqual(base)
})

test("moveShellTab reorders non-status tabs and keeps active", () => {
const start = openShellTab(openShellTab(openShellTab(base, "files"), "review"), "terminal")
expect(moveShellTab(start, "terminal", 1)).toEqual({
openShellTabs: ["status", "terminal", "files", "review"],
sidePanelTab: "terminal",
})
})

test("moveShellTab cannot move status", () => {
const start = openShellTab(base, "files")
expect(moveShellTab(start, "status", 1)).toEqual(start)
})

test("moveShellTab clamps negative indexes after the pinned status tab", () => {
const start = openShellTab(openShellTab(openShellTab(base, "files"), "review"), "terminal")
expect(moveShellTab(start, "review", -1).openShellTabs).toEqual(["status", "review", "files", "terminal"])
})
})
Loading
Loading