diff --git a/frontend/src/components/navigation/DesktopSidebar.test.tsx b/frontend/src/components/navigation/DesktopSidebar.test.tsx index 2543ff95..75c16f16 100644 --- a/frontend/src/components/navigation/DesktopSidebar.test.tsx +++ b/frontend/src/components/navigation/DesktopSidebar.test.tsx @@ -1,6 +1,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { render, screen, fireEvent } from '@testing-library/react' import { MemoryRouter, useLocation } from 'react-router-dom' +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { DesktopSidebar } from './DesktopSidebar' import * as useDesktopModule from '@/hooks/useDesktop' import * as useSidebarCollapsedModule from '@/hooks/useSidebarCollapsed' @@ -18,6 +19,23 @@ function LocationDisplay() { return
{location.pathname}{location.search}
} +function createWrapper(initialEntries?: string[]) { + const queryClient = new QueryClient({ + defaultOptions: { + queries: { + retry: false, + }, + }, + }) + return ({ children }: { children: React.ReactNode }) => ( + + + {children} + + + ) +} + describe('DesktopSidebar', () => { beforeEach(() => { vi.clearAllMocks() @@ -90,11 +108,7 @@ describe('DesktopSidebar', () => { logout: vi.fn(), } as any) - render( - - - - ) + render(, { wrapper: createWrapper(['/']) }) expect(screen.getByText('New Repo')).toBeInTheDocument() expect(screen.getByText('Assistant')).toBeInTheDocument() @@ -110,17 +124,13 @@ describe('DesktopSidebar', () => { logout: vi.fn(), } as any) - render( - - - - ) + render(, { wrapper: createWrapper(['/repos/5']) }) expect(screen.getByText('New Session')).toBeInTheDocument() expect(screen.getByText('Assistant')).toBeInTheDocument() }) - it('renders primary CTA for session detail', () => { + it('renders primary CTAs for session detail', () => { vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true) vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()]) vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false }) @@ -130,12 +140,9 @@ describe('DesktopSidebar', () => { logout: vi.fn(), } as any) - render( - - - - ) + render(, { wrapper: createWrapper(['/repos/5/sessions/abc']) }) + expect(screen.getByText('New Session')).toBeInTheDocument() expect(screen.getByText('Assistant')).toBeInTheDocument() }) @@ -149,11 +156,7 @@ describe('DesktopSidebar', () => { logout: vi.fn(), } as any) - render( - - - - ) + render(, { wrapper: createWrapper(['/schedules']) }) expect(screen.getByText('New Schedule')).toBeInTheDocument() expect(screen.getByText('Assistant')).toBeInTheDocument() @@ -170,11 +173,7 @@ describe('DesktopSidebar', () => { logout: vi.fn(), } as any) - render( - - - - ) + render(, { wrapper: createWrapper(['/repos/5']) }) fireEvent.click(screen.getByText('New Session')) @@ -197,10 +196,11 @@ describe('DesktopSidebar', () => { } as any) render( - + <> - + , + { wrapper: createWrapper(['/repos/5/sessions/abc?assistant=1']) } ) fireEvent.click(screen.getByText('Files')) @@ -219,10 +219,11 @@ describe('DesktopSidebar', () => { } as any) render( - + <> - + , + { wrapper: createWrapper(['/?dialog=files']) } ) fireEvent.click(screen.getByText('Settings')) diff --git a/frontend/src/components/navigation/DesktopSidebar.tsx b/frontend/src/components/navigation/DesktopSidebar.tsx index 1e68917a..dff96f5c 100644 --- a/frontend/src/components/navigation/DesktopSidebar.tsx +++ b/frontend/src/components/navigation/DesktopSidebar.tsx @@ -1,21 +1,24 @@ +import { useState } from 'react' import { useLocation, useNavigate } from 'react-router-dom' import { useDesktop } from '@/hooks/useDesktop' import { useSidebarCollapsed } from '@/hooks/useSidebarCollapsed' import { useMemoryPluginStatus } from '@/hooks/useMemoryPluginStatus' import { useAuth } from '@/hooks/useAuth' -import { buildNavModel } from '@/components/navigation/moreDrawerItems' +import { buildNavModel, type MoreDrawerItem, type NavPrimaryCta } from '@/components/navigation/moreDrawerItems' +import { RepoQuickSwitchSheet } from '@/components/navigation/RepoQuickSwitchSheet' import { Sidebar, SidebarSection, SidebarItem, SidebarCollapseToggle, } from '@/components/ui/sidebar' -import { LayoutGrid } from 'lucide-react' +import { FolderGit2 } from 'lucide-react' export function DesktopSidebar() { const location = useLocation() const navigate = useNavigate() const [collapsed, toggle] = useSidebarCollapsed() + const [repoSwitcherOpen, setRepoSwitcherOpen] = useState(false) const { memoryPluginEnabled } = useMemoryPluginStatus() const { isAuthenticated, isLoading, logout } = useAuth() @@ -31,7 +34,7 @@ export function DesktopSidebar() { const { primary, items } = buildNavModel(location.pathname, { memoryPluginEnabled }) - const handlePrimaryClick = (item: (typeof primary)[number]) => { + const handlePrimaryClick = (item: NavPrimaryCta) => { if (item.to) { navigate(item.to) } else if (item.onSelect) { @@ -43,7 +46,7 @@ export function DesktopSidebar() { } } - const handleItemClick = (item: (typeof items)[number]) => { + const handleItemClick = (item: MoreDrawerItem) => { if (item.to) { navigate(item.to) } else if (item.dialog) { @@ -58,54 +61,63 @@ export function DesktopSidebar() { params.set('settings', 'open') params.set('tab', 'account') navigate({ search: params.toString() }, { replace: true }) + } else if (item.key === 'repos') { + setRepoSwitcherOpen(true) } } - return ( - -
- {!collapsed && ( - OpenCode - )} - {collapsed && ( -
- -
- )} -
+ const navItems: MoreDrawerItem[] = [ + { key: 'repos', label: 'Repos', icon: FolderGit2 }, + ...items, + ] - {primary.length > 0 && ( - - {primary.map((item) => ( + return ( + <> + + + {primary.length > 0 && ( + + {primary.map((item: NavPrimaryCta) => ( + handlePrimaryClick(item)} + asPrimary + variant={item.variant} + /> + ))} + + )} + +
+ {!collapsed && ( +
+ Navigation +
+ )} + +
+ +
+ {navItems.map((item: MoreDrawerItem) => ( handlePrimaryClick(item)} - asPrimary - variant={item.variant} + onClick={() => handleItemClick(item)} + danger={item.danger} /> ))} - - )} +
+
- - {items.map((item) => ( - handleItemClick(item)} - danger={item.danger} - /> - ))} - - -
- -
-
+ setRepoSwitcherOpen(false)} + /> + ) } diff --git a/frontend/src/components/navigation/RepoQuickSwitchSheet.test.tsx b/frontend/src/components/navigation/RepoQuickSwitchSheet.test.tsx index 8d927090..da008ae0 100644 --- a/frontend/src/components/navigation/RepoQuickSwitchSheet.test.tsx +++ b/frontend/src/components/navigation/RepoQuickSwitchSheet.test.tsx @@ -98,7 +98,7 @@ describe('RepoQuickSwitchSheet', () => { }) }) - it('navigates on repo click without calling onClose', async () => { + it('navigates on repo click and closes sheet', async () => { vi.mocked(listRepos).mockResolvedValue([ { id: 1, @@ -120,7 +120,7 @@ describe('RepoQuickSwitchSheet', () => { expect(screen.getByText('repo1')).toBeInTheDocument() }) fireEvent.click(screen.getByText('repo1')) - expect(handleClose).not.toHaveBeenCalled() + expect(handleClose).toHaveBeenCalled() }) it('navigates directly to assistant when mobileTabAction is assistant', async () => { @@ -162,6 +162,6 @@ describe('RepoQuickSwitchSheet', () => { fireEvent.click(screen.getByText('repo1')) expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/assistant') - expect(handleClose).not.toHaveBeenCalled() + expect(handleClose).toHaveBeenCalled() }) }) diff --git a/frontend/src/components/navigation/RepoQuickSwitchSheet.tsx b/frontend/src/components/navigation/RepoQuickSwitchSheet.tsx index 2aa513d6..da7f9afe 100644 --- a/frontend/src/components/navigation/RepoQuickSwitchSheet.tsx +++ b/frontend/src/components/navigation/RepoQuickSwitchSheet.tsx @@ -47,10 +47,12 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr const pendingAction = new URLSearchParams(location.search).get('mobileTabAction') if (pendingAction === 'assistant') { navigate(`/repos/${id}/assistant`) + onClose() return } navigate(`/repos/${id}`, { replace: true }) + onClose() } return ( diff --git a/frontend/src/components/navigation/moreDrawerItems.test.ts b/frontend/src/components/navigation/moreDrawerItems.test.ts index 093ec498..8df2c176 100644 --- a/frontend/src/components/navigation/moreDrawerItems.test.ts +++ b/frontend/src/components/navigation/moreDrawerItems.test.ts @@ -128,12 +128,15 @@ describe('buildNavModel', () => { expect(model.primary[1].to).toBe('/repos/5/assistant') }) - it('returns assistant-only primary CTA for session detail', () => { + it('returns new-session and assistant primary CTAs for session detail', () => { const model = buildNavModel('/repos/5/sessions/abc') - expect(model.primary).toHaveLength(1) - expect(model.primary[0].key).toBe('assistant') - expect(model.primary[0].to).toBe('/repos/5/assistant') + expect(model.primary).toHaveLength(2) + expect(model.primary[0].key).toBe('new-session') + expect(model.primary[0].onSelect).toBe('new-session') expect(model.primary[0].variant).toBe('primary') + expect(model.primary[1].key).toBe('assistant') + expect(model.primary[1].to).toBe('/repos/5/assistant') + expect(model.primary[1].variant).toBe('secondary') }) it('returns assistant primary CTA for assistant workspace', () => { diff --git a/frontend/src/components/navigation/moreDrawerItems.ts b/frontend/src/components/navigation/moreDrawerItems.ts index 2f90d67e..acb96121 100644 --- a/frontend/src/components/navigation/moreDrawerItems.ts +++ b/frontend/src/components/navigation/moreDrawerItems.ts @@ -96,7 +96,8 @@ export function buildNavModel(pathname: string, options: BuildNavOptions = {}): return { primary: [ - getAssistantNavItem(pathname, 'primary'), + { key: 'new-session', label: 'New Session', icon: SquarePlus, onSelect: 'new-session', variant: 'primary' }, + getAssistantNavItem(pathname), ], items, } diff --git a/frontend/src/components/ui/sidebar.tsx b/frontend/src/components/ui/sidebar.tsx index 59e0c0d2..d82e1a7e 100644 --- a/frontend/src/components/ui/sidebar.tsx +++ b/frontend/src/components/ui/sidebar.tsx @@ -1,7 +1,6 @@ import type { LucideIcon } from 'lucide-react' -import { ChevronLeft, ChevronRight } from 'lucide-react' +import { PanelLeft, PanelLeftClose } from 'lucide-react' import { cn } from '@/lib/utils' -import { Button } from '@/components/ui/button' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' export interface SidebarProps { @@ -122,15 +121,18 @@ export interface SidebarCollapseToggleProps { export function SidebarCollapseToggle({ collapsed, onToggle }: SidebarCollapseToggleProps) { return ( - + {collapsed ? : } + ) } diff --git a/frontend/src/components/ui/tooltip.tsx b/frontend/src/components/ui/tooltip.tsx index bfec7899..dfcd73f0 100644 --- a/frontend/src/components/ui/tooltip.tsx +++ b/frontend/src/components/ui/tooltip.tsx @@ -12,15 +12,17 @@ const TooltipContent = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, sideOffset = 4, ...props }, ref) => ( - + + + )) TooltipContent.displayName = TooltipPrimitive.Content.displayName diff --git a/frontend/src/pages/SessionDetail.tsx b/frontend/src/pages/SessionDetail.tsx index a690695a..a6dfc063 100644 --- a/frontend/src/pages/SessionDetail.tsx +++ b/frontend/src/pages/SessionDetail.tsx @@ -48,6 +48,7 @@ import { PendingActionsGroup } from "@/components/notifications/PendingActionsGr import { SourceControlPanel } from "@/components/source-control"; import { SessionTodoDisplay } from "@/components/message/SessionTodoDisplay"; import { useDialogParam } from "@/hooks/useDialogParam"; +import { useSidebarAction } from "@/hooks/useSidebarAction"; import { SessionMoreButton } from "@/components/navigation/SessionMoreButton"; const compareMessageIds = (id1: string, id2: string): number => { @@ -227,6 +228,10 @@ export function SessionDetail() { } }, [createSession, navigate, repoId, sessionRouteSuffix]); + useSidebarAction('new-session', () => { + handleNewSession(); + }); + const handleCompact = useCallback(async () => { if (!opcodeUrl || !sessionId) return; if (!model?.providerID || !model?.modelID) {