mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
feat(frontend): replace the repos sheet with a sessions picker sheet
The mobile tab bar's Repos sheet becomes a Sessions sheet with Activity, Sessions and Projects tabs, matching the mobile app. The picker body is shared with the desktop session dialog, the scope toggles by tapping the selected Sessions tab, and the header adds new-session, add-repo and server controls. The collapsed desktop sidebar opens the session dialog instead of the old sheet.
This commit is contained in:
1 parent
2e31cb45ba
commit
578a2211ba
25 files changed
+1131
-1493
No files matched your search
@@ -11,6 +11,9 @@ import * as useAuthModule from '@/hooks/useAuth'
|
||||
vi.mock('@/hooks/useDesktop')
|
||||
vi.mock('@/hooks/useSidebarCollapsed')
|
||||
vi.mock('@/hooks/useAuth')
|
||||
vi.mock('@/api/repos', () => ({
|
||||
listRepos: vi.fn().mockResolvedValue([]),
|
||||
}))
|
||||
vi.mock('@/hooks/useOpenCodeServers', () => ({
|
||||
useOpenCodeServers: () => ({ servers: [], isLoading: false }),
|
||||
useOpenCodeServerStatuses: () => ({ statuses: [], statusById: {}, isLoading: false }),
|
||||
@@ -18,6 +21,10 @@ vi.mock('@/hooks/useOpenCodeServers', () => ({
|
||||
vi.mock('@/components/navigation/DesktopSessionTree', () => ({
|
||||
DesktopSessionTree: () => <div data-testid="session-tree" />,
|
||||
}))
|
||||
vi.mock('@/components/session/SessionPickerDialog', () => ({
|
||||
SessionPickerDialog: ({ open }: { open: boolean }) =>
|
||||
open ? <div data-testid="sessions-picker-dialog" /> : null,
|
||||
}))
|
||||
|
||||
function LocationDisplay() {
|
||||
const location = useLocation()
|
||||
@@ -166,7 +173,7 @@ describe('DesktopSidebar', () => {
|
||||
for (const label of ['Home', 'Settings', 'Logout']) {
|
||||
expect(screen.getByText(label)).toBeInTheDocument()
|
||||
}
|
||||
for (const label of ['Menu', 'Repos', 'Files', 'MCP', 'Skills', 'Schedules', 'All Schedules', 'Source Control', 'Terminal', 'Walkthrough', 'Preview']) {
|
||||
for (const label of ['Menu', 'Files', 'MCP', 'Skills', 'Schedules', 'All Schedules', 'Source Control', 'Terminal', 'Walkthrough', 'Preview']) {
|
||||
expect(screen.queryByText(label)).toBeNull()
|
||||
}
|
||||
})
|
||||
@@ -263,7 +270,7 @@ describe('DesktopSidebar', () => {
|
||||
|
||||
expect(screen.queryByRole('button', { name: /Switch server/ })).toBeNull()
|
||||
})
|
||||
it('renders home, repos and account items and no session tree when collapsed', () => {
|
||||
it('renders home, sessions and account items and no session tree when collapsed', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([true, vi.fn()])
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
@@ -276,8 +283,26 @@ describe('DesktopSidebar', () => {
|
||||
|
||||
expect(screen.queryByTestId('session-tree')).toBeNull()
|
||||
expect(screen.getByText('Home')).toBeInTheDocument()
|
||||
expect(screen.getByText('Repos')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sessions')).toBeInTheDocument()
|
||||
expect(screen.getByText('Settings')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Files')).toBeNull()
|
||||
})
|
||||
|
||||
it('opens the sessions picker dialog from the collapsed Sessions item', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([true, vi.fn()])
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(<DesktopSidebar />, { wrapper: createWrapper(['/repos/5']) })
|
||||
|
||||
expect(screen.queryByTestId('sessions-picker-dialog')).toBeNull()
|
||||
|
||||
fireEvent.click(screen.getByText('Sessions'))
|
||||
|
||||
expect(screen.getByTestId('sessions-picker-dialog')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -6,8 +6,9 @@ import { useSidebarWidth } from '@/hooks/useSidebarWidth'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { useOpenNavItem } from '@/hooks/useOpenNavItem'
|
||||
import { useSessionPickerRouteScope } from '@/hooks/useSessionPickerRouteScope'
|
||||
import { buildNavModel, type MoreDrawerItem, type NavPrimaryCta } from '@/components/navigation/moreDrawerItems'
|
||||
import { RepoQuickSwitchSheet } from '@/components/navigation/RepoQuickSwitchSheet'
|
||||
import { SessionPickerDialog } from '@/components/session/SessionPickerDialog'
|
||||
import { DesktopSessionTree } from '@/components/navigation/DesktopSessionTree'
|
||||
import { LinkedServersNav } from '@/components/navigation/LinkedServersNav'
|
||||
import {
|
||||
@@ -15,10 +16,48 @@ import {
|
||||
SidebarSection,
|
||||
SidebarItem,
|
||||
} from '@/components/ui/sidebar'
|
||||
import { FolderGit2 } from 'lucide-react'
|
||||
import { getRepoPath, getServerSessionPath, getSessionPath } from '@/lib/navigation'
|
||||
import { List } from 'lucide-react'
|
||||
|
||||
const FOOTER_ITEM_KEYS = new Set(['home', 'settings', 'logout'])
|
||||
|
||||
function DesktopSessionsPicker({ onDismiss }: { onDismiss: () => void }) {
|
||||
const navigate = useNavigate()
|
||||
const { currentRepo, activeSessionID, remote } = useSessionPickerRouteScope(true)
|
||||
|
||||
return (
|
||||
<SessionPickerDialog
|
||||
open
|
||||
onOpenChange={(nextOpen) => {
|
||||
if (!nextOpen) onDismiss()
|
||||
}}
|
||||
currentRepo={currentRepo}
|
||||
activeSessionID={activeSessionID}
|
||||
remote={remote}
|
||||
onSelectSession={(session, sessionRepo) => {
|
||||
navigate(getSessionPath(sessionRepo.id, session.id))
|
||||
onDismiss()
|
||||
}}
|
||||
onSelectRemoteSession={(session, serverId) => {
|
||||
navigate(getServerSessionPath(serverId, session.id))
|
||||
onDismiss()
|
||||
}}
|
||||
onDeleteActiveSession={() => {
|
||||
onDismiss()
|
||||
if (currentRepo) navigate(getRepoPath(currentRepo.id))
|
||||
}}
|
||||
onSelectRepo={(selectedRepo) => {
|
||||
navigate(getRepoPath(selectedRepo.id))
|
||||
onDismiss()
|
||||
}}
|
||||
onNavigate={(path) => {
|
||||
navigate(path)
|
||||
onDismiss()
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function DesktopSidebar() {
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
@@ -26,7 +65,7 @@ export function DesktopSidebar() {
|
||||
const openNavItem = useOpenNavItem()
|
||||
const [collapsed, toggle] = useSidebarCollapsed()
|
||||
const [sidebarWidth, setSidebarWidth] = useSidebarWidth()
|
||||
const [repoSwitcherOpen, setRepoSwitcherOpen] = useState(false)
|
||||
const [sessionsOpen, setSessionsOpen] = useState(false)
|
||||
const { isAuthenticated, isLoading, logout } = useAuth()
|
||||
|
||||
const isDesktop = useDesktop()
|
||||
@@ -51,15 +90,15 @@ export function DesktopSidebar() {
|
||||
p.set('settingsTab', 'account')
|
||||
p.delete('mobileTab')
|
||||
}, 'push')
|
||||
} else if (item.key === 'repos') {
|
||||
setRepoSwitcherOpen(true)
|
||||
} else if (item.key === 'sessions') {
|
||||
setSessionsOpen(true)
|
||||
}
|
||||
}
|
||||
|
||||
const footerItems = items.filter((item) => FOOTER_ITEM_KEYS.has(item.key))
|
||||
const collapsedItems: MoreDrawerItem[] = [
|
||||
footerItems[0],
|
||||
{ key: 'repos', label: 'Repos', icon: FolderGit2 },
|
||||
{ key: 'sessions', label: 'Sessions', icon: List },
|
||||
...footerItems.slice(1),
|
||||
]
|
||||
|
||||
@@ -133,10 +172,7 @@ export function DesktopSidebar() {
|
||||
)}
|
||||
</Sidebar>
|
||||
|
||||
<RepoQuickSwitchSheet
|
||||
isOpen={repoSwitcherOpen}
|
||||
onClose={() => setRepoSwitcherOpen(false)}
|
||||
/>
|
||||
{sessionsOpen && <DesktopSessionsPicker onDismiss={() => setSessionsOpen(false)} />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ function SidebarServerRouteSync() {
|
||||
return null
|
||||
}
|
||||
|
||||
function renderNav(pathname = '/', variant?: 'sidebar' | 'rail' | 'sheet') {
|
||||
function renderNav(pathname = '/', variant?: 'sidebar' | 'rail') {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[pathname]}>
|
||||
<SidebarServerRouteSync />
|
||||
@@ -253,18 +253,4 @@ describe('LinkedServersNav', () => {
|
||||
|
||||
expect(screen.queryByRole('button', { name: /Switch server/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders a thin trigger row in the sheet variant', async () => {
|
||||
const user = userEvent.setup()
|
||||
setServers([kitchen])
|
||||
|
||||
renderNav('/', 'sheet')
|
||||
|
||||
expect(screen.queryByRole('heading', { name: 'Servers' })).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: triggerName('OC Manager') }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Kitchen/ }))
|
||||
|
||||
expect(await screen.findByRole('button', { name: triggerName('Kitchen') })).toBeInTheDocument()
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/')
|
||||
})
|
||||
})
|
||||
@@ -20,10 +20,10 @@ import { cn } from '@/lib/utils'
|
||||
|
||||
const LOCAL_SERVER_LABEL = 'OC Manager'
|
||||
|
||||
export type LinkedServersVariant = 'sidebar' | 'rail' | 'sheet' | 'header'
|
||||
export type LinkedServersVariant = 'sidebar' | 'rail' | 'header'
|
||||
|
||||
interface LinkedServersNavProps {
|
||||
/** `sidebar` renders the full-width trigger row, `rail` the collapsed icon button, `sheet` the mobile sheet row, `header` a compact page-header trigger. */
|
||||
/** `sidebar` renders the full-width trigger row, `rail` the collapsed icon button, `header` a compact page-header trigger. */
|
||||
variant?: LinkedServersVariant
|
||||
}
|
||||
|
||||
@@ -220,7 +220,7 @@ export function LinkedServersNav({ variant = 'sidebar' }: LinkedServersNavProps)
|
||||
'focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
||||
isRail && 'mx-auto h-9 w-9 justify-center',
|
||||
variant === 'header' && 'h-8 min-w-0 max-w-[45vw] gap-2 px-2 sm:max-w-xs',
|
||||
(variant === 'sidebar' || variant === 'sheet') && 'h-9 w-full gap-2 px-2',
|
||||
variant === 'sidebar' && 'h-9 w-full gap-2 px-2',
|
||||
)}
|
||||
>
|
||||
<span className="relative flex shrink-0">
|
||||
|
||||
@@ -8,9 +8,9 @@ vi.mock('@/components/file-browser/FileBrowserSheet', () => ({
|
||||
FileBrowserSheet: ({ isOpen, basePath, repoName }: { isOpen: boolean; basePath: string; repoName: string }) =>
|
||||
isOpen ? <div data-testid="file-browser-sheet" data-base-path={basePath} data-repo-name={repoName}>FileBrowserSheet</div> : null,
|
||||
}))
|
||||
vi.mock('@/components/navigation/RepoQuickSwitchSheet', () => ({
|
||||
RepoQuickSwitchSheet: ({ isOpen }: { isOpen: boolean }) =>
|
||||
isOpen ? <div data-testid="repo-quick-switch-sheet">RepoQuickSwitchSheet</div> : null,
|
||||
vi.mock('@/components/session/SessionPickerSheet', () => ({
|
||||
SessionPickerSheet: ({ isOpen }: { isOpen: boolean }) =>
|
||||
isOpen ? <div data-testid="session-picker-sheet">SessionPickerSheet</div> : null,
|
||||
}))
|
||||
vi.mock('@/components/navigation/NotificationsSheet', () => ({
|
||||
NotificationsSheet: ({ isOpen }: { isOpen: boolean }) =>
|
||||
@@ -58,18 +58,18 @@ describe('MobileSheetHost', () => {
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders RepoQuickSwitchSheet when mobileTab=repos', () => {
|
||||
it('renders SessionPickerSheet when mobileTab=sessions', () => {
|
||||
vi.mocked(useMobileTabBar).mockReturnValue({
|
||||
openSheet: 'repos',
|
||||
openSheet: 'sessions',
|
||||
open: vi.fn(),
|
||||
close: vi.fn(),
|
||||
})
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/?mobileTab=repos']}>
|
||||
<MemoryRouter initialEntries={['/?mobileTab=sessions']}>
|
||||
<MobileSheetHost />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
expect(screen.getByTestId('repo-quick-switch-sheet')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('session-picker-sheet')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders FileBrowserSheet with correct props when mobileTab=files', () => {
|
||||
@@ -134,15 +134,15 @@ describe('MobileSheetHost', () => {
|
||||
it('closes sheet when onClose is called', () => {
|
||||
const mockClose = vi.fn()
|
||||
vi.mocked(useMobileTabBar).mockReturnValue({
|
||||
openSheet: 'repos',
|
||||
openSheet: 'sessions',
|
||||
open: vi.fn(),
|
||||
close: mockClose,
|
||||
})
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/?mobileTab=repos']}>
|
||||
<MemoryRouter initialEntries={['/?mobileTab=sessions']}>
|
||||
<MobileSheetHost />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
expect(screen.getByTestId('repo-quick-switch-sheet')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('session-picker-sheet')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
|
||||
import { RepoQuickSwitchSheet } from '@/components/navigation/RepoQuickSwitchSheet'
|
||||
import { SessionPickerSheet } from '@/components/session/SessionPickerSheet'
|
||||
import { NotificationsSheet } from '@/components/navigation/NotificationsSheet'
|
||||
import { MoreDrawer } from '@/components/navigation/MoreDrawer'
|
||||
import { isLocalOpenCodeServer, useRouteOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
||||
@@ -15,7 +15,7 @@ export function MobileSheetHost() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<RepoQuickSwitchSheet isOpen={openSheet === 'repos'} onClose={close} />
|
||||
<SessionPickerSheet isOpen={openSheet === 'sessions'} onClose={close} />
|
||||
{openSheet === 'files' && !isRemoteRoute && (
|
||||
<FileBrowserSheet
|
||||
isOpen
|
||||
|
||||
@@ -70,11 +70,11 @@ describe('MobileTabBar', () => {
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
expect(screen.getByText('Repos')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sessions')).toBeInTheDocument()
|
||||
expect(screen.getByText('Git')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Schedules')).not.toBeInTheDocument()
|
||||
const labels = screen.getAllByRole('button').map((button) => button.textContent)
|
||||
expect(labels).toEqual(['Repos', 'Files', 'Git', 'Assistant', 'More'])
|
||||
expect(labels).toEqual(['Sessions', 'Files', 'Git', 'Assistant', 'More'])
|
||||
})
|
||||
|
||||
it('opens the source control dialog when Git is clicked on repo detail path', async () => {
|
||||
@@ -109,7 +109,7 @@ describe('MobileTabBar', () => {
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
expect(screen.getByText('Repos')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sessions')).toBeInTheDocument()
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
expect(screen.getByText('Schedules')).toBeInTheDocument()
|
||||
})
|
||||
@@ -226,7 +226,7 @@ describe('MobileTabBar', () => {
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
const labels = screen.getAllByRole('button').map((button) => button.textContent)
|
||||
expect(labels).toEqual(['Repos', 'Git', 'Assistant', 'More'])
|
||||
expect(labels).toEqual(['Sessions', 'Git', 'Assistant', 'More'])
|
||||
expect(screen.queryByText('Files')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Schedules')).not.toBeInTheDocument()
|
||||
})
|
||||
@@ -255,7 +255,7 @@ describe('MobileTabBar', () => {
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('dialog=sourceControl')
|
||||
})
|
||||
|
||||
it('opens the repos sheet from the Repos tab on a linked server project page', async () => {
|
||||
it('opens the sessions sheet from the Sessions tab on a linked server project page', async () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
const user = userEvent.setup()
|
||||
@@ -273,8 +273,8 @@ describe('MobileTabBar', () => {
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Repos' }))
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('mobileTab=repos')
|
||||
await user.click(screen.getByRole('button', { name: 'Sessions' }))
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('mobileTab=sessions')
|
||||
})
|
||||
|
||||
it('does not render tab bar on a linked server session path', () => {
|
||||
@@ -316,7 +316,7 @@ describe('MobileTabBar', () => {
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
expect(screen.getByText('Repos')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sessions')).toBeInTheDocument()
|
||||
expect(screen.getByText('Files')).toBeInTheDocument()
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
expect(screen.getByText('Schedules')).toBeInTheDocument()
|
||||
@@ -336,7 +336,7 @@ describe('MobileTabBar', () => {
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
const labels = screen.getAllByRole('button').map((button) => button.textContent)
|
||||
expect(labels).toEqual(['Repos', 'Assistant', 'Schedules', 'More'])
|
||||
expect(labels).toEqual(['Sessions', 'Assistant', 'Schedules', 'More'])
|
||||
expect(screen.queryByText('Files')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -350,11 +350,11 @@ describe('MobileTabBar', () => {
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
expect(screen.getByText('Repos')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sessions')).toBeInTheDocument()
|
||||
expect(screen.getByText('Schedules')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('Repos tab is active when pathname is / and no sheet is open', () => {
|
||||
it('Sessions tab is active when pathname is / and no sheet is open', () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
render(
|
||||
@@ -364,24 +364,24 @@ describe('MobileTabBar', () => {
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
const reposButton = screen.getByText('Repos').closest('button')
|
||||
expect(reposButton).toHaveClass('text-primary')
|
||||
expect(reposButton).toHaveClass('border-primary')
|
||||
const sessionsButton = screen.getByText('Sessions').closest('button')
|
||||
expect(sessionsButton).toHaveClass('text-primary')
|
||||
expect(sessionsButton).toHaveClass('border-primary')
|
||||
})
|
||||
|
||||
it('Repos tab is active when openSheet is repos regardless of pathname', () => {
|
||||
it('Sessions tab is active when openSheet is sessions regardless of pathname', () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={['/repos/123?mobileTab=repos']}>
|
||||
<MemoryRouter initialEntries={['/repos/123?mobileTab=sessions']}>
|
||||
<MobileTabBar />
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
const reposButton = screen.getByText('Repos').closest('button')
|
||||
expect(reposButton).toHaveClass('text-primary')
|
||||
expect(reposButton).toHaveClass('border-primary')
|
||||
const sessionsButton = screen.getByText('Sessions').closest('button')
|
||||
expect(sessionsButton).toHaveClass('text-primary')
|
||||
expect(sessionsButton).toHaveClass('border-primary')
|
||||
})
|
||||
|
||||
it('maintains stable callbacks when search changes but mobileTab does not', () => {
|
||||
@@ -396,8 +396,8 @@ describe('MobileTabBar', () => {
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
const firstReposButton = screen.getByText('Repos').closest('button')
|
||||
expect(firstReposButton).toBeInTheDocument()
|
||||
const firstSessionsButton = screen.getByText('Sessions').closest('button')
|
||||
expect(firstSessionsButton).toBeInTheDocument()
|
||||
|
||||
rerender(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
@@ -407,8 +407,8 @@ describe('MobileTabBar', () => {
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
const secondReposButton = screen.getByText('Repos').closest('button')
|
||||
expect(secondReposButton).toBeInTheDocument()
|
||||
const secondSessionsButton = screen.getByText('Sessions').closest('button')
|
||||
expect(secondSessionsButton).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render tab bar on SessionDetail path /repos/:id/sessions/:sid', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { memo, useMemo } from 'react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { FolderGit2, FolderOpen, CalendarClock, Menu, Info, History, Bot, GitCommitHorizontal } from 'lucide-react'
|
||||
import { List, FolderOpen, CalendarClock, Menu, Info, History, Bot, GitCommitHorizontal } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
||||
@@ -112,11 +112,11 @@ function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideR
|
||||
|
||||
return [
|
||||
{
|
||||
key: 'repos',
|
||||
label: 'Repos',
|
||||
icon: FolderGit2,
|
||||
onClick: () => open('repos'),
|
||||
active: openSheet === 'repos' || (pathname === '/' && !openSheet),
|
||||
key: 'sessions',
|
||||
label: 'Sessions',
|
||||
icon: List,
|
||||
onClick: () => open('sessions'),
|
||||
active: openSheet === 'sessions' || (pathname === '/' && !openSheet),
|
||||
},
|
||||
...(showsFiles
|
||||
? [{
|
||||
|
||||
@@ -323,28 +323,28 @@ describe('MoreDrawer', () => {
|
||||
expect(navigateMock).toHaveBeenCalledWith('/repos/1/schedules?returnTo=%2Frepos%2F1%2Fsessions%2Fsession-1%3Fassistant%3D1')
|
||||
})
|
||||
|
||||
it('swaps the menu for the Repos sheet from a session', () => {
|
||||
it('swaps the menu for the Sessions sheet from a session', () => {
|
||||
const navigateMock = vi.fn()
|
||||
vi.mocked(useNavigate).mockReturnValue(navigateMock)
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1?mobileTab=more', routePath: '/repos/:id/sessions/:sessionId' })
|
||||
|
||||
fireEvent.click(screen.getByText('Repos'))
|
||||
fireEvent.click(screen.getByText('Sessions'))
|
||||
|
||||
expect(navigateMock).toHaveBeenCalledWith(
|
||||
{ search: 'mobileTab=repos' },
|
||||
{ search: 'mobileTab=sessions' },
|
||||
{ state: { urlParamHistory: { previousSearch: '?mobileTab=more' } } },
|
||||
)
|
||||
})
|
||||
|
||||
it('keeps Home and hides the Repos row outside a session', () => {
|
||||
it('keeps Home and hides the Sessions row outside a session', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
renderMoreDrawer({ initialEntry: '/repos/1', routePath: '/repos/:id' })
|
||||
|
||||
expect(screen.getByText('Home')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Repos')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Sessions')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('offers the Assistant from a repo session', () => {
|
||||
@@ -420,7 +420,7 @@ describe('MoreDrawer', () => {
|
||||
expect(screen.getByText('Logout')).toBeInTheDocument()
|
||||
expect(screen.getByText('Terminal')).toBeInTheDocument()
|
||||
expect(screen.getByRole('heading', { name: 'Activity' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Repos')).toBeInTheDocument()
|
||||
expect(screen.getByText('Sessions')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Files')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Source Control')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Preview')).not.toBeInTheDocument()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNavigate, useLocation, useParams } from 'react-router-dom'
|
||||
import { useRef, useEffect, type ReactNode } from 'react'
|
||||
import { ChevronRight, FolderGit2, X, GitBranch, type LucideIcon } from 'lucide-react'
|
||||
import { ChevronRight, List, X, GitBranch, type LucideIcon } from 'lucide-react'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
@@ -211,7 +211,7 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
)}
|
||||
<MenuSection>
|
||||
{(isSessionDetail || isRemoteSessionDetail) && (
|
||||
<MenuRow icon={FolderGit2} label="Repos" onClick={() => openMobileSheet('repos')} trailing />
|
||||
<MenuRow icon={List} label="Sessions" onClick={() => openMobileSheet('sessions')} trailing />
|
||||
)}
|
||||
{assistantCta?.to && (
|
||||
<MenuRow icon={assistantCta.icon} label={assistantCta.label} onClick={() => navigate(assistantCta.to!)} />
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,159 +0,0 @@
|
||||
import { useState, useMemo } from 'react'
|
||||
import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
|
||||
import { FINE_POINTER_MEDIA_QUERY, useMediaQuery } from '@/hooks/useMediaQuery'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { BottomSheet, BottomSheetHeader, BottomSheetContent } from '@/components/ui/bottom-sheet'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { CompactActivityList } from '@/components/activity/CompactActivityList'
|
||||
import { getRepoDisplayName } from '@/lib/utils'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { FolderGit2, Plus } from 'lucide-react'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { getAssistantPath, getRepoPath, getSessionPath } from '@/lib/navigation'
|
||||
import { NewSessionButton, RepoSessionNavList, SearchClearButton } from '@/components/navigation/RepoSessionNav'
|
||||
import { LinkedServersNav } from '@/components/navigation/LinkedServersNav'
|
||||
import { RemoteProjectNavList } from '@/components/navigation/RemoteProjectNav'
|
||||
import { getActiveRepoId } from '@/components/navigation/sidebar-session-tree'
|
||||
import { useNavigableRepos } from '@/hooks/useSidebarRepoGroups'
|
||||
import { useSidebarServerSelection } from '@/hooks/useSidebarServerSelection'
|
||||
|
||||
interface RepoQuickSwitchSheetProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetProps) {
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const { searchParams } = useUrlParams()
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false)
|
||||
const [selectedServerId] = useSidebarServerSelection()
|
||||
const isRemote = selectedServerId !== LOCAL_OPENCODE_SERVER_ID
|
||||
const activeRepoId = getActiveRepoId(location.pathname)
|
||||
const hasFinePointer = useMediaQuery(FINE_POINTER_MEDIA_QUERY)
|
||||
|
||||
const { repos, isLoading, refetch } = useNavigableRepos(isOpen)
|
||||
|
||||
useRefreshOnOpen(isOpen, refetch)
|
||||
|
||||
const filteredRepos = useMemo(() => {
|
||||
if (!searchQuery.trim()) return repos
|
||||
const query = searchQuery.toLowerCase()
|
||||
return repos.filter((repo) =>
|
||||
getRepoDisplayName(repo).toLowerCase().includes(query)
|
||||
)
|
||||
}, [repos, searchQuery])
|
||||
|
||||
const isUrlControlledSheet = searchParams.get('mobileTab') === 'repos'
|
||||
|
||||
const navigateAndClose = (path: string, options?: { replace?: boolean }) => {
|
||||
navigate(path, options)
|
||||
if (!isUrlControlledSheet) {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
||||
const handleClick = (id: number) => {
|
||||
if (searchParams.get('mobileTabAction') === 'assistant') {
|
||||
navigateAndClose(getAssistantPath(), { replace: true })
|
||||
return
|
||||
}
|
||||
|
||||
if (id === activeRepoId) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
|
||||
navigateAndClose(getRepoPath(id), { replace: true })
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<BottomSheet isOpen={isOpen} onClose={onClose} heightClass="h-[70dvh]" ariaLabel="Switch repo">
|
||||
<BottomSheetHeader className="border-b-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Input
|
||||
type="text"
|
||||
placeholder={isRemote ? 'Search projects...' : 'Search repos...'}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
autoFocus={hasFinePointer}
|
||||
className="pr-9"
|
||||
autoComplete="off"
|
||||
name="repo-quick-switch"
|
||||
/>
|
||||
{searchQuery.length > 0 && <SearchClearButton onClear={() => setSearchQuery('')} />}
|
||||
</div>
|
||||
{!isRemote && (
|
||||
<Button
|
||||
type="button"
|
||||
size="lg"
|
||||
onClick={() => {
|
||||
onClose()
|
||||
setAddRepoOpen(true)
|
||||
}}
|
||||
className="flex-shrink-0"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">Repo</span>
|
||||
<span className="sr-only">Add repository</span>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</BottomSheetHeader>
|
||||
<BottomSheetContent className="flex flex-col px-0 pt-0 gap-0">
|
||||
{isOpen && (
|
||||
<div className="px-2 pt-1">
|
||||
<LinkedServersNav variant="sheet" />
|
||||
</div>
|
||||
)}
|
||||
{isOpen && !searchQuery.trim() && (
|
||||
<CompactActivityList onNavigate={(path) => navigateAndClose(path)} />
|
||||
)}
|
||||
{isRemote ? (
|
||||
<RemoteProjectNavList
|
||||
serverId={selectedServerId}
|
||||
isVisible={isOpen}
|
||||
search={searchQuery}
|
||||
onOpenProject={(path) => navigateAndClose(path, { replace: true })}
|
||||
onSelectSession={(path) => navigateAndClose(path)}
|
||||
/>
|
||||
) : isLoading ? (
|
||||
<div className="flex flex-col gap-2 px-4 pt-3">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<div key={i} className="h-14 rounded-lg bg-muted animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
) : filteredRepos.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center px-4 pt-3 pb-12 text-muted-foreground">
|
||||
<FolderGit2 className="h-12 w-12 mb-3 opacity-50" />
|
||||
<p className="text-sm">No repos found</p>
|
||||
</div>
|
||||
) : (
|
||||
<RepoSessionNavList
|
||||
repos={filteredRepos}
|
||||
activeRepoId={activeRepoId}
|
||||
isVisible={isOpen}
|
||||
onOpenRepo={handleClick}
|
||||
onSelectSession={(path) => navigateAndClose(path)}
|
||||
renderActions={(repo) => (
|
||||
<NewSessionButton
|
||||
directory={repo.fullPath}
|
||||
label={getRepoDisplayName(repo)}
|
||||
sessionPath={(sessionId) => getSessionPath(repo.id, sessionId)}
|
||||
onOpenSession={(path) => navigateAndClose(path)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<div aria-hidden="true" className="h-16 shrink-0" />
|
||||
</BottomSheetContent>
|
||||
</BottomSheet>
|
||||
<AddRepoDialog open={addRepoOpen} onOpenChange={setAddRepoOpen} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import { useEffect, useId, useMemo, useState } from 'react'
|
||||
import type { Repo } from '@/api/types'
|
||||
import { useNavigableRepos } from '@/hooks/useSidebarRepoGroups'
|
||||
import { NewSessionButton } from '@/components/navigation/RepoSessionNav'
|
||||
import { isRepoReady } from '@/components/navigation/sidebar-session-tree'
|
||||
import { getSessionPath } from '@/lib/navigation'
|
||||
import { cn, getRepoBranchLabel, getRepoDisplayName } from '@/lib/utils'
|
||||
import {
|
||||
PickerSearchBar,
|
||||
@@ -13,8 +16,10 @@ interface ProjectPickerContentProps {
|
||||
open: boolean
|
||||
currentRepo: Repo | undefined
|
||||
onSelectRepo: (repo: Repo) => void
|
||||
onNavigate: (path: string) => void
|
||||
switchHint: string
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
searchTrailing?: React.ReactNode
|
||||
}
|
||||
|
||||
interface ProjectPickerRow {
|
||||
@@ -26,8 +31,10 @@ export function ProjectPickerContent({
|
||||
open,
|
||||
currentRepo,
|
||||
onSelectRepo,
|
||||
onNavigate,
|
||||
switchHint,
|
||||
searchInputRef,
|
||||
searchTrailing,
|
||||
}: ProjectPickerContentProps) {
|
||||
const { repos, isLoading } = useNavigableRepos()
|
||||
const listId = useId()
|
||||
@@ -89,6 +96,7 @@ export function ProjectPickerContent({
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
placeholder="Search projects..."
|
||||
name="project-picker-search"
|
||||
trailing={searchTrailing}
|
||||
/>
|
||||
|
||||
<div
|
||||
@@ -149,6 +157,16 @@ export function ProjectPickerContent({
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{isRepoReady(repo) ? (
|
||||
<NewSessionButton
|
||||
directory={repo.fullPath}
|
||||
label={getRepoDisplayName(repo)}
|
||||
sessionPath={(sessionId) => getSessionPath(repo.id, sessionId)}
|
||||
onOpenSession={onNavigate}
|
||||
/>
|
||||
) : (
|
||||
<span className="shrink-0 pr-2 text-xs text-muted-foreground">Not ready</span>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
@@ -24,6 +24,7 @@ const mocks = vi.hoisted(() => ({
|
||||
fetchNextPage: vi.fn(),
|
||||
deleteSessionMock: vi.fn(),
|
||||
deletedSessionServerId: null as string | null,
|
||||
createSessionDirectories: [] as string[],
|
||||
togglePinMock: vi.fn(),
|
||||
getOpenCodeLocation: vi.fn(),
|
||||
sessionPins: [] as Array<{ sessionId: string; directory: string; pinnedAt: number }>,
|
||||
@@ -44,6 +45,12 @@ vi.mock('@/hooks/useSettings', () => ({
|
||||
useSettings: () => ({ preferences: mocks.preferences }),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/repos', () => ({
|
||||
listRepos: vi.fn().mockResolvedValue([]),
|
||||
createRepo: vi.fn(),
|
||||
discoverRepos: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/opencode', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/api/opencode')>()
|
||||
return { ...actual, getOpenCodeLocation: mocks.getOpenCodeLocation }
|
||||
@@ -87,6 +94,13 @@ vi.mock('@/hooks/useOpenCode', async (importOriginal) => {
|
||||
isPending: false,
|
||||
}
|
||||
},
|
||||
useCreateSession: (directory: string, onSuccess?: (session: { id: string }) => void) => ({
|
||||
mutate: () => {
|
||||
mocks.createSessionDirectories.push(directory)
|
||||
onSuccess?.({ id: 'ses_new' })
|
||||
},
|
||||
isPending: false,
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -202,7 +216,7 @@ const openProjectsTab = () => {
|
||||
}
|
||||
|
||||
const openActiveTab = () => {
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Active' }))
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Activity' }))
|
||||
}
|
||||
|
||||
describe('SessionPickerDialog', () => {
|
||||
@@ -212,6 +226,7 @@ describe('SessionPickerDialog', () => {
|
||||
localStorage.clear()
|
||||
mocks.deleteSessionMock.mockResolvedValue(undefined)
|
||||
mocks.deletedSessionServerId = null
|
||||
mocks.createSessionDirectories.length = 0
|
||||
mocks.locationData = {
|
||||
directory: '/w/a',
|
||||
project: { id: 'global', directory: '/w/a', canonical: '/w/a' },
|
||||
@@ -305,6 +320,7 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
expect(mocks.lastDirectories).toEqual(['/w/a'])
|
||||
expect(mocks.lastAllDirectories).toBe(false)
|
||||
expect(screen.getByRole('tab', { name: 'This project' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Alpha session')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Beta session')).not.toBeInTheDocument()
|
||||
|
||||
@@ -313,6 +329,7 @@ describe('SessionPickerDialog', () => {
|
||||
expect(mocks.lastDirectories).toEqual(['/w/a', '/w/b'])
|
||||
expect(mocks.lastAllDirectories).toBe(true)
|
||||
expect(localStorage.getItem('oc:session-picker:all-projects')).toBe('true')
|
||||
expect(screen.getByRole('tab', { name: 'All sessions' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Beta session')).toBeInTheDocument()
|
||||
expect(screen.getByText('alpha')).toBeInTheDocument()
|
||||
expect(screen.getByText('beta')).toBeInTheDocument()
|
||||
@@ -321,6 +338,97 @@ describe('SessionPickerDialog', () => {
|
||||
expect(mocks.lastDirectories).toEqual(['/w/a'])
|
||||
expect(mocks.lastAllDirectories).toBe(false)
|
||||
expect(localStorage.getItem('oc:session-picker:all-projects')).toBe('false')
|
||||
expect(screen.getByRole('tab', { name: 'This project' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('toggles the scope when the selected sessions tab is clicked again', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
await user.click(screen.getByRole('tab', { name: 'This project' }))
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'All sessions', selected: true })).toBeInTheDocument()
|
||||
expect(localStorage.getItem('oc:session-picker:all-projects')).toBe('true')
|
||||
|
||||
await user.click(screen.getByRole('tab', { name: 'All sessions' }))
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'This project', selected: true })).toBeInTheDocument()
|
||||
expect(localStorage.getItem('oc:session-picker:all-projects')).toBe('false')
|
||||
})
|
||||
|
||||
it('selects the sessions tab without toggling the scope when it was not selected', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
await user.click(screen.getByRole('tab', { name: 'Activity' }))
|
||||
await user.click(screen.getByRole('tab', { name: 'This project' }))
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'This project', selected: true })).toBeInTheDocument()
|
||||
expect(localStorage.getItem('oc:session-picker:all-projects')).toBeNull()
|
||||
})
|
||||
|
||||
it('toggles the scope with Enter on the focused selected sessions tab', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
act(() => {
|
||||
screen.getByRole('tab', { name: 'This project' }).focus()
|
||||
})
|
||||
await user.keyboard('{Enter}')
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'All sessions', selected: true })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('labels the sessions tab Sessions and lists every project without a current repo', () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
session('ses_b', 'Beta session', '/w/b', 1000),
|
||||
]
|
||||
|
||||
renderPicker({ currentRepo: undefined })
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'Sessions', selected: true })).toBeInTheDocument()
|
||||
expect(mocks.lastDirectories).toEqual(['/w/a', '/w/b'])
|
||||
expect(mocks.lastAllDirectories).toBe(true)
|
||||
expect(screen.getByText('Beta session')).toBeInTheDocument()
|
||||
expect(localStorage.getItem('oc:session-picker:all-projects')).toBeNull()
|
||||
})
|
||||
|
||||
it('starts a new session in the current repo from the sessions tab header action', () => {
|
||||
const onNavigate = vi.fn()
|
||||
renderPicker({ onNavigate })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'New session in alpha' }))
|
||||
|
||||
expect(mocks.createSessionDirectories).toEqual(['/w/a'])
|
||||
expect(onNavigate).toHaveBeenCalledWith('/repos/1/sessions/ses_new')
|
||||
})
|
||||
|
||||
it('opens the add repository dialog from the projects tab header action', async () => {
|
||||
renderPicker()
|
||||
|
||||
openProjectsTab()
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Add repository' }))
|
||||
|
||||
expect(await screen.findByRole('dialog', { name: 'Add Repository' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('starts a new session in a project row and marks a repo that is not ready', async () => {
|
||||
const onNavigate = vi.fn()
|
||||
mocks.repos = [
|
||||
repo(1, 'alpha', '/w/a'),
|
||||
{ ...repo(2, 'beta', '/w/b'), cloneStatus: 'cloning' },
|
||||
]
|
||||
renderPicker({ onNavigate })
|
||||
|
||||
openProjectsTab()
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'New session in alpha' }))
|
||||
|
||||
expect(mocks.createSessionDirectories).toEqual(['/w/a'])
|
||||
expect(onNavigate).toHaveBeenCalledWith('/repos/1/sessions/ses_new')
|
||||
expect(screen.queryByRole('button', { name: 'New session in beta' })).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Not ready')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('lists project sessions across worktrees and labels them with the folder name', async () => {
|
||||
@@ -556,11 +664,11 @@ describe('SessionPickerDialog', () => {
|
||||
expect(screen.getByRole('option', { name: /Active session/ })).toHaveAttribute('aria-selected', 'true')
|
||||
})
|
||||
|
||||
it('renders an Active/Sessions/Projects tab switcher and defaults to the sessions tab', () => {
|
||||
it('renders an Activity/Sessions/Projects tab switcher and defaults to the sessions tab', () => {
|
||||
renderPicker()
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'Sessions' })).toHaveAttribute('aria-selected', 'true')
|
||||
expect(screen.getByRole('tab', { name: 'Active' })).toHaveAttribute('aria-selected', 'false')
|
||||
expect(screen.getByRole('tab', { name: 'This project' })).toHaveAttribute('aria-selected', 'true')
|
||||
expect(screen.getByRole('tab', { name: 'Activity' })).toHaveAttribute('aria-selected', 'false')
|
||||
expect(screen.getByRole('tab', { name: 'Projects' })).toHaveAttribute('aria-selected', 'false')
|
||||
expect(combobox()).toHaveAttribute('placeholder', 'Search sessions...')
|
||||
})
|
||||
@@ -568,7 +676,7 @@ describe('SessionPickerDialog', () => {
|
||||
it('exposes a tabpanel labelled by the active tab and swaps panels on tab switch', async () => {
|
||||
renderPicker()
|
||||
|
||||
const sessionsPanel = screen.getByRole('tabpanel', { name: 'Sessions' })
|
||||
const sessionsPanel = screen.getByRole('tabpanel', { name: 'This project' })
|
||||
expect(sessionsPanel).toHaveAttribute('data-state', 'active')
|
||||
expect(screen.queryByRole('tabpanel', { name: 'Projects' })).not.toBeInTheDocument()
|
||||
|
||||
@@ -576,7 +684,7 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
const projectsPanel = await screen.findByRole('tabpanel', { name: 'Projects' })
|
||||
expect(projectsPanel).toHaveAttribute('data-state', 'active')
|
||||
expect(screen.queryByRole('tabpanel', { name: 'Sessions' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('tabpanel', { name: 'This project' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('focuses the projects search input after clicking the Projects tab and filters on typing', async () => {
|
||||
@@ -713,19 +821,19 @@ describe('SessionPickerDialog', () => {
|
||||
expect(screen.getByText('No projects found')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('cycles Active, Sessions and Projects with the default Ctrl+S binding', async () => {
|
||||
it('cycles Activity, Sessions and Projects with the default Ctrl+S binding', async () => {
|
||||
renderPicker()
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'Sessions', selected: true })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'This project', selected: true })).toBeInTheDocument()
|
||||
|
||||
fireEvent.keyDown(combobox(), { key: 's', ctrlKey: true })
|
||||
expect(await screen.findByRole('tab', { name: 'Projects', selected: true })).toBeInTheDocument()
|
||||
|
||||
fireEvent.keyDown(combobox(), { key: 's', ctrlKey: true })
|
||||
expect(await screen.findByRole('tab', { name: 'Active', selected: true })).toBeInTheDocument()
|
||||
expect(await screen.findByRole('tab', { name: 'Activity', selected: true })).toBeInTheDocument()
|
||||
|
||||
fireEvent.keyDown(combobox(), { key: 's', ctrlKey: true })
|
||||
expect(await screen.findByRole('tab', { name: 'Sessions', selected: true })).toBeInTheDocument()
|
||||
expect(await screen.findByRole('tab', { name: 'This project', selected: true })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('honors a configured switch binding and shows it in the footer', async () => {
|
||||
@@ -756,7 +864,7 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
fireEvent.keyDown(combobox(), { key: 'o', ctrlKey: true })
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'Sessions', selected: true })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'This project', selected: true })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('resets to the sessions tab when the dialog reopens', async () => {
|
||||
@@ -787,7 +895,7 @@ describe('SessionPickerDialog', () => {
|
||||
fireEvent.click(screen.getByText('open-picker'))
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('tab', { name: 'Sessions' })).toHaveAttribute('aria-selected', 'true'),
|
||||
expect(screen.getByRole('tab', { name: 'This project' })).toHaveAttribute('aria-selected', 'true'),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -918,7 +1026,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('tab', { name: 'Projects' })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Active' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Activity' })).toBeInTheDocument()
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Remote session/ })
|
||||
expect(row).toHaveTextContent('Kitchen')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { memo, useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { format, startOfDay } from 'date-fns'
|
||||
import { MoreHorizontal, Pin, PinOff } from 'lucide-react'
|
||||
import { ChevronsUpDown, MoreHorizontal, Pin, PinOff, Plus } from 'lucide-react'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import { getOpenCodeLocation } from '@/api/opencode'
|
||||
import { OpenCodeServerProvider, useOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
||||
@@ -20,6 +20,9 @@ import { SessionStatusIndicator } from '@/components/ui/session-status-indicator
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { DeleteSessionDialog } from '@/components/session/DeleteSessionDialog'
|
||||
import { ProjectPickerContent } from '@/components/session/ProjectPickerContent'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { NewSessionButton } from '@/components/navigation/RepoSessionNav'
|
||||
import { RemoteProjectNavList } from '@/components/navigation/RemoteProjectNav'
|
||||
import {
|
||||
PickerSearchBar,
|
||||
optionId,
|
||||
@@ -27,7 +30,7 @@ import {
|
||||
usePickerKeyNav,
|
||||
} from '@/components/session/usePickerKeyboardNav'
|
||||
import { partitionSessions } from '@/components/session/session-partition'
|
||||
import { buildRepoByDirectory } from '@/components/navigation/sidebar-session-tree'
|
||||
import { buildRepoByDirectory, isRepoReady } from '@/components/navigation/sidebar-session-tree'
|
||||
import { useDeleteSession } from '@/hooks/useOpenCode'
|
||||
import { useActiveWork, useActivityWindowMinutes } from '@/hooks/useActiveWork'
|
||||
import { useSessionSearch } from '@/hooks/useSessionSearch'
|
||||
@@ -38,6 +41,7 @@ import { useSessionStatusForSession } from '@/stores/sessionStatusStore'
|
||||
import { useShortcutActions } from '@/contexts/KeyboardShortcutsContext'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { buildPinnedSessionKeys, getSessionKey } from '@/lib/sessionKey'
|
||||
import { getSessionPath } from '@/lib/navigation'
|
||||
import { formatShortcutLabel, resolveShortcutBindings } from '@/lib/keyboardShortcuts'
|
||||
import { cn, formatShortRelativeTime, getRepoDisplayName } from '@/lib/utils'
|
||||
import { FINE_POINTER_MEDIA_QUERY, useMediaQuery } from '@/hooks/useMediaQuery'
|
||||
@@ -52,7 +56,7 @@ const SESSION_PICKER_TABS: SessionPickerTab[] = ['active', 'sessions', 'projects
|
||||
const REMOTE_SESSION_PICKER_TABS: SessionPickerTab[] = ['active', 'sessions']
|
||||
|
||||
const SESSION_PICKER_TAB_LABELS: Record<SessionPickerTab, string> = {
|
||||
active: 'Active',
|
||||
active: 'Activity',
|
||||
sessions: 'Sessions',
|
||||
projects: 'Projects',
|
||||
}
|
||||
@@ -62,6 +66,11 @@ function nextSessionPickerTab(tab: SessionPickerTab, tabs: SessionPickerTab[]):
|
||||
return tabs[(index + 1) % tabs.length]
|
||||
}
|
||||
|
||||
function sessionsTabLabel(scopeEnabled: boolean, allProjects: boolean): string {
|
||||
if (!scopeEnabled) return SESSION_PICKER_TAB_LABELS.sessions
|
||||
return allProjects ? 'All sessions' : 'This project'
|
||||
}
|
||||
|
||||
interface RemotePickerScope {
|
||||
serverId: string
|
||||
serverName?: string
|
||||
@@ -77,6 +86,8 @@ interface SessionPickerDialogProps {
|
||||
onSelectRemoteSession?: (session: Session, serverId: string) => void
|
||||
onDeleteActiveSession: () => void
|
||||
onSelectRepo: (repo: Repo) => void
|
||||
/** Navigates to a path the panel produced, such as a new session created from the header action. */
|
||||
onNavigate: (path: string) => void
|
||||
/** Set on a linked-server route to list that server's sessions instead of Manager repos. */
|
||||
remote?: RemotePickerScope
|
||||
}
|
||||
@@ -556,9 +567,12 @@ interface SessionPickerContentProps {
|
||||
onSelectSession: (session: Session, repo: Repo) => void
|
||||
onSelectRemoteSession?: (session: Session, serverId: string) => void
|
||||
onDeleteActiveSession: () => void
|
||||
allProjects: boolean
|
||||
scopeEnabled: boolean
|
||||
onToggleAllProjects: () => void
|
||||
switchHint: string
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
hasFinePointer: boolean
|
||||
searchTrailing?: React.ReactNode
|
||||
}
|
||||
|
||||
function SessionPickerContent({
|
||||
@@ -568,11 +582,13 @@ function SessionPickerContent({
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
allProjects,
|
||||
scopeEnabled,
|
||||
onToggleAllProjects,
|
||||
switchHint,
|
||||
searchInputRef,
|
||||
hasFinePointer,
|
||||
searchTrailing,
|
||||
}: SessionPickerContentProps) {
|
||||
const [allProjects, toggleAllProjects] = usePersistentBoolean(ALL_PROJECTS_STORAGE_KEY, false)
|
||||
const { repos } = useNavigableRepos()
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
const listId = useId()
|
||||
@@ -696,7 +712,7 @@ function SessionPickerContent({
|
||||
moveCursor,
|
||||
onOpenRow: openRow,
|
||||
onDeleteRow: deleteRow,
|
||||
onToggleAllProjects: toggleAllProjects,
|
||||
onToggleAllProjects,
|
||||
})
|
||||
|
||||
const handleListScroll = useCallback(
|
||||
@@ -739,23 +755,7 @@ function SessionPickerContent({
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
placeholder="Search sessions..."
|
||||
name="session-picker-search"
|
||||
trailing={
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
aria-pressed={allProjects}
|
||||
onClick={toggleAllProjects}
|
||||
className="h-9 shrink-0"
|
||||
>
|
||||
{allProjects ? 'All projects' : 'This project'}
|
||||
{hasFinePointer && (
|
||||
<kbd className="ml-1 rounded border border-border bg-muted px-1 text-[10px] text-muted-foreground">
|
||||
Ctrl+A
|
||||
</kbd>
|
||||
)}
|
||||
</Button>
|
||||
}
|
||||
trailing={searchTrailing}
|
||||
/>
|
||||
|
||||
<SessionPickerList
|
||||
@@ -809,7 +809,8 @@ function SessionPickerContent({
|
||||
</SessionPickerList>
|
||||
|
||||
<div className="mt-2 shrink-0 px-4 text-xs text-muted-foreground pointer-coarse:hidden sm:px-0">
|
||||
↑↓ move · Enter open · Ctrl+D delete · Ctrl+A {allProjects ? 'this project' : 'all projects'}
|
||||
↑↓ move · Enter open · Ctrl+D delete
|
||||
{scopeEnabled ? ` · Ctrl+A ${allProjects ? 'this project' : 'all sessions'}` : ''}
|
||||
{switchHint ? ` · ${switchHint} projects` : ''}
|
||||
</div>
|
||||
</div>
|
||||
@@ -827,6 +828,7 @@ interface ActivePickerContentProps {
|
||||
onDeleteActiveSession: () => void
|
||||
switchHint: string
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
searchTrailing?: React.ReactNode
|
||||
}
|
||||
|
||||
function ActivePickerContent({
|
||||
@@ -837,6 +839,7 @@ function ActivePickerContent({
|
||||
onDeleteActiveSession,
|
||||
switchHint,
|
||||
searchInputRef,
|
||||
searchTrailing,
|
||||
}: ActivePickerContentProps) {
|
||||
const windowMinutes = useActivityWindowMinutes()
|
||||
const { groups, isLoading, isError } = useActiveWork(windowMinutes * MS_PER_MINUTE)
|
||||
@@ -950,6 +953,7 @@ function ActivePickerContent({
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
placeholder="Search sessions..."
|
||||
name="active-picker-search"
|
||||
trailing={searchTrailing}
|
||||
/>
|
||||
|
||||
<SessionPickerList
|
||||
@@ -993,6 +997,7 @@ interface RemoteSessionPickerContentProps {
|
||||
onSelectSession: (session: Session) => void
|
||||
switchHint: string
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
searchTrailing?: React.ReactNode
|
||||
}
|
||||
|
||||
function RemoteSessionPickerContent({
|
||||
@@ -1003,6 +1008,7 @@ function RemoteSessionPickerContent({
|
||||
onSelectSession,
|
||||
switchHint,
|
||||
searchInputRef,
|
||||
searchTrailing,
|
||||
}: RemoteSessionPickerContentProps) {
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
const listId = useId()
|
||||
@@ -1019,7 +1025,9 @@ function RemoteSessionPickerContent({
|
||||
isFetchingNextPage,
|
||||
isFetchNextPageError,
|
||||
canFetchNextPage,
|
||||
} = useSessionSearch(projectDirectory ? [projectDirectory] : [])
|
||||
} = useSessionSearch(projectDirectory ? [projectDirectory] : [], {
|
||||
allDirectories: projectDirectory === undefined,
|
||||
})
|
||||
|
||||
const sections = useMemo(
|
||||
() => buildSections(filteredSessions, EMPTY_PINNED_KEYS, getSessionKey),
|
||||
@@ -1085,6 +1093,7 @@ function RemoteSessionPickerContent({
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
placeholder="Search sessions..."
|
||||
name="remote-session-picker-search"
|
||||
trailing={searchTrailing}
|
||||
/>
|
||||
|
||||
<SessionPickerList
|
||||
@@ -1146,22 +1155,99 @@ function RemoteSessionPickerContent({
|
||||
)
|
||||
}
|
||||
|
||||
export function SessionPickerDialog({
|
||||
interface RemoteProjectPickerContentProps {
|
||||
serverId: string
|
||||
open: boolean
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
searchTrailing?: React.ReactNode
|
||||
onOpenProject: (path: string) => void
|
||||
onSelectSession: (path: string) => void
|
||||
}
|
||||
|
||||
function RemoteProjectPickerContent({
|
||||
serverId,
|
||||
open,
|
||||
searchInputRef,
|
||||
searchTrailing,
|
||||
onOpenProject,
|
||||
onSelectSession,
|
||||
}: RemoteProjectPickerContentProps) {
|
||||
const listId = useId()
|
||||
const [query, setQuery] = useState('')
|
||||
|
||||
return (
|
||||
<div className="mt-4 flex min-h-0 flex-1 flex-col">
|
||||
<PickerSearchBar
|
||||
inputRef={searchInputRef}
|
||||
listId={listId}
|
||||
open={open}
|
||||
activeDescendantId={undefined}
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
onKeyDown={() => undefined}
|
||||
placeholder="Search projects..."
|
||||
name="remote-project-picker-search"
|
||||
trailing={searchTrailing}
|
||||
/>
|
||||
|
||||
<div className="mt-3 min-h-0 flex-1 overflow-y-auto rounded-md">
|
||||
<RemoteProjectNavList
|
||||
serverId={serverId}
|
||||
isVisible={open}
|
||||
search={query}
|
||||
onOpenProject={onOpenProject}
|
||||
onSelectSession={onSelectSession}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export interface SessionPickerPanelProps {
|
||||
open: boolean
|
||||
currentRepo: Repo | undefined
|
||||
activeSessionID?: string
|
||||
onSelectSession: (session: Session, repo: Repo) => void
|
||||
onSelectRemoteSession?: (session: Session, serverId: string) => void
|
||||
onDeleteActiveSession: () => void
|
||||
onSelectRepo: (repo: Repo) => void
|
||||
onNavigate: (path: string) => void
|
||||
/** Set on a linked-server route to list that server's sessions instead of Manager repos. */
|
||||
remote?: RemotePickerScope
|
||||
/** Lists the linked server's projects on a Projects tab; the desktop dialog leaves it off. */
|
||||
remoteProjects?: boolean
|
||||
/** Extra controls rendered at the trailing end of every tab's search bar. */
|
||||
searchTrailing?: React.ReactNode
|
||||
/** Hands the add-repository action to the host, which renders the dialog above its own surface. */
|
||||
onAddRepo?: () => void
|
||||
/** Renders the dialog title element, which only a Radix Dialog can host. */
|
||||
renderTitle?: (label: string) => React.ReactNode
|
||||
}
|
||||
|
||||
/** The tab strip, search bars, lists and header actions shared by the picker dialog and sheet. */
|
||||
export function SessionPickerPanel({
|
||||
open,
|
||||
onOpenChange,
|
||||
currentRepo,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
onSelectRepo,
|
||||
onNavigate,
|
||||
remote,
|
||||
}: SessionPickerDialogProps) {
|
||||
remoteProjects = false,
|
||||
searchTrailing,
|
||||
onAddRepo,
|
||||
renderTitle,
|
||||
}: SessionPickerPanelProps) {
|
||||
const searchInputRef = useRef<HTMLInputElement>(null)
|
||||
const activeSearchInputRef = useRef<HTMLInputElement>(null)
|
||||
const projectSearchInputRef = useRef<HTMLInputElement>(null)
|
||||
const focusSearchAfterSwitchRef = useRef(false)
|
||||
const scopePressRef = useRef(false)
|
||||
const hasFinePointer = useMediaQuery(FINE_POINTER_MEDIA_QUERY)
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false)
|
||||
const [allProjectsPreference, toggleAllProjects] = usePersistentBoolean(ALL_PROJECTS_STORAGE_KEY, false)
|
||||
const { preferences } = useSettings()
|
||||
const switchHint = useMemo(
|
||||
() => {
|
||||
@@ -1175,7 +1261,7 @@ export function SessionPickerDialog({
|
||||
[preferences],
|
||||
)
|
||||
const isRemote = remote !== undefined
|
||||
const pickerTabs = isRemote ? REMOTE_SESSION_PICKER_TABS : SESSION_PICKER_TABS
|
||||
const pickerTabs = isRemote && !remoteProjects ? REMOTE_SESSION_PICKER_TABS : SESSION_PICKER_TABS
|
||||
const [tab, setTab] = useState<SessionPickerTab>('sessions')
|
||||
const [prevOpen, setPrevOpen] = useState(open)
|
||||
|
||||
@@ -1184,7 +1270,10 @@ export function SessionPickerDialog({
|
||||
if (open) setTab('sessions')
|
||||
}
|
||||
|
||||
const activeTab: SessionPickerTab = isRemote && tab === 'projects' ? 'sessions' : tab
|
||||
const activeTab: SessionPickerTab = pickerTabs.includes(tab) ? tab : 'sessions'
|
||||
const scopeEnabled = !isRemote && Boolean(currentRepo)
|
||||
const allProjects = scopeEnabled ? allProjectsPreference : true
|
||||
const readyRepo = scopeEnabled && currentRepo && isRepoReady(currentRepo) ? currentRepo : undefined
|
||||
|
||||
const toggleTab = useCallback(() => {
|
||||
focusSearchAfterSwitchRef.current = true
|
||||
@@ -1208,6 +1297,187 @@ export function SessionPickerDialog({
|
||||
return () => cancelAnimationFrame(frame)
|
||||
}, [open, activeTab, hasFinePointer])
|
||||
|
||||
const addRepoButton = isRemote ? null : (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
aria-label="Add repository"
|
||||
onClick={() => {
|
||||
if (onAddRepo) onAddRepo()
|
||||
else setAddRepoOpen(true)
|
||||
}}
|
||||
className="h-9 w-9 shrink-0"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
</Button>
|
||||
)
|
||||
|
||||
const newSessionButton = readyRepo ? (
|
||||
<NewSessionButton
|
||||
directory={readyRepo.fullPath}
|
||||
label={getRepoDisplayName(readyRepo)}
|
||||
sessionPath={(sessionId) => getSessionPath(readyRepo.id, sessionId)}
|
||||
onOpenSession={onNavigate}
|
||||
/>
|
||||
) : (
|
||||
addRepoButton
|
||||
)
|
||||
|
||||
const withTrailing = (action: React.ReactNode): React.ReactNode => {
|
||||
if (!searchTrailing && !action) return undefined
|
||||
return (
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
{searchTrailing}
|
||||
{action}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const sessionsTrailing = withTrailing(newSessionButton)
|
||||
const projectsTrailing = withTrailing(addRepoButton)
|
||||
|
||||
const handleSessionsPointerDown = () => {
|
||||
scopePressRef.current = scopeEnabled && activeTab === 'sessions'
|
||||
}
|
||||
|
||||
const handleSessionsClick = () => {
|
||||
if (!scopePressRef.current) return
|
||||
scopePressRef.current = false
|
||||
toggleAllProjects()
|
||||
}
|
||||
|
||||
const handleSessionsKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
|
||||
if (!scopeEnabled || activeTab !== 'sessions') return
|
||||
if (event.key !== 'Enter' && event.key !== ' ') return
|
||||
event.preventDefault()
|
||||
toggleAllProjects()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Tabs
|
||||
value={activeTab}
|
||||
onValueChange={(value) => setTab(value as SessionPickerTab)}
|
||||
className="flex min-h-0 w-full min-w-0 flex-1 flex-col gap-0"
|
||||
>
|
||||
<div className="shrink-0 px-4 pt-4 sm:px-0 sm:pt-6">
|
||||
{renderTitle?.(SESSION_PICKER_TAB_LABELS[activeTab])}
|
||||
<TabsList>
|
||||
<TabsTrigger value="active">{SESSION_PICKER_TAB_LABELS.active}</TabsTrigger>
|
||||
<TabsTrigger
|
||||
value="sessions"
|
||||
onPointerDown={handleSessionsPointerDown}
|
||||
onClick={handleSessionsClick}
|
||||
onKeyDown={handleSessionsKeyDown}
|
||||
>
|
||||
{sessionsTabLabel(scopeEnabled, allProjects)}
|
||||
{scopeEnabled && (
|
||||
<ChevronsUpDown aria-hidden="true" className="ml-1 h-3 w-3 shrink-0 opacity-60" />
|
||||
)}
|
||||
</TabsTrigger>
|
||||
{pickerTabs.includes('projects') && (
|
||||
<TabsTrigger value="projects">{SESSION_PICKER_TAB_LABELS.projects}</TabsTrigger>
|
||||
)}
|
||||
</TabsList>
|
||||
</div>
|
||||
<TabsContent
|
||||
value="active"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
<OpenCodeServerProvider serverId={LOCAL_OPENCODE_SERVER_ID}>
|
||||
<ActivePickerContent
|
||||
open={open}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={onSelectSession}
|
||||
onSelectRemoteSession={onSelectRemoteSession}
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={activeSearchInputRef}
|
||||
searchTrailing={sessionsTrailing}
|
||||
/>
|
||||
</OpenCodeServerProvider>
|
||||
</TabsContent>
|
||||
<TabsContent
|
||||
value="sessions"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
{remote ? (
|
||||
<RemoteSessionPickerContent
|
||||
open={open}
|
||||
serverName={remote.serverName}
|
||||
projectDirectory={remote.projectDirectory}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={(session) => onSelectRemoteSession?.(session, remote.serverId)}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={searchInputRef}
|
||||
searchTrailing={sessionsTrailing}
|
||||
/>
|
||||
) : (
|
||||
<SessionPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={onSelectSession}
|
||||
onSelectRemoteSession={onSelectRemoteSession}
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
allProjects={allProjects}
|
||||
scopeEnabled={scopeEnabled}
|
||||
onToggleAllProjects={toggleAllProjects}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={searchInputRef}
|
||||
searchTrailing={sessionsTrailing}
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
{pickerTabs.includes('projects') && (
|
||||
<TabsContent
|
||||
value="projects"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
{remote ? (
|
||||
<RemoteProjectPickerContent
|
||||
serverId={remote.serverId}
|
||||
open={open}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
searchTrailing={projectsTrailing}
|
||||
onOpenProject={onNavigate}
|
||||
onSelectSession={onNavigate}
|
||||
/>
|
||||
) : (
|
||||
<ProjectPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
onSelectRepo={onSelectRepo}
|
||||
onNavigate={onNavigate}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
searchTrailing={projectsTrailing}
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
)}
|
||||
</Tabs>
|
||||
{addRepoOpen && !onAddRepo && <AddRepoDialog open onOpenChange={setAddRepoOpen} />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function SessionPickerDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
currentRepo,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
onSelectRepo,
|
||||
onNavigate,
|
||||
remote,
|
||||
}: SessionPickerDialogProps) {
|
||||
const searchInputRef = useRef<HTMLInputElement>(null)
|
||||
const hasFinePointer = useMediaQuery(FINE_POINTER_MEDIA_QUERY)
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent
|
||||
@@ -1223,78 +1493,18 @@ export function SessionPickerDialog({
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Tabs
|
||||
value={activeTab}
|
||||
onValueChange={(value) => setTab(value as SessionPickerTab)}
|
||||
className="flex min-h-0 w-full min-w-0 flex-1 flex-col gap-0"
|
||||
>
|
||||
<div className="shrink-0 px-4 pt-4 sm:px-0 sm:pt-6">
|
||||
<DialogTitle className="sr-only">{SESSION_PICKER_TAB_LABELS[activeTab]}</DialogTitle>
|
||||
<TabsList>
|
||||
<TabsTrigger value="active">Active</TabsTrigger>
|
||||
<TabsTrigger value="sessions">Sessions</TabsTrigger>
|
||||
{isRemote ? null : <TabsTrigger value="projects">Projects</TabsTrigger>}
|
||||
</TabsList>
|
||||
</div>
|
||||
<TabsContent
|
||||
value="active"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
<OpenCodeServerProvider serverId={LOCAL_OPENCODE_SERVER_ID}>
|
||||
<ActivePickerContent
|
||||
open={open}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={onSelectSession}
|
||||
onSelectRemoteSession={onSelectRemoteSession}
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={activeSearchInputRef}
|
||||
/>
|
||||
</OpenCodeServerProvider>
|
||||
</TabsContent>
|
||||
<TabsContent
|
||||
value="sessions"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
{remote ? (
|
||||
<RemoteSessionPickerContent
|
||||
open={open}
|
||||
serverName={remote.serverName}
|
||||
projectDirectory={remote.projectDirectory}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={(session) => onSelectRemoteSession?.(session, remote.serverId)}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={searchInputRef}
|
||||
/>
|
||||
) : (
|
||||
<SessionPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={onSelectSession}
|
||||
onSelectRemoteSession={onSelectRemoteSession}
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={searchInputRef}
|
||||
hasFinePointer={hasFinePointer}
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
{isRemote ? null : (
|
||||
<TabsContent
|
||||
value="projects"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
<ProjectPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
onSelectRepo={onSelectRepo}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
/>
|
||||
</TabsContent>
|
||||
)}
|
||||
</Tabs>
|
||||
<SessionPickerPanel
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={onSelectSession}
|
||||
onSelectRemoteSession={onSelectRemoteSession}
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
onSelectRepo={onSelectRepo}
|
||||
onNavigate={onNavigate}
|
||||
remote={remote}
|
||||
renderTitle={(label) => <DialogTitle className="sr-only">{label}</DialogTitle>}
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,332 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { render, screen, fireEvent, act } from '@testing-library/react'
|
||||
import { MemoryRouter, Route, Routes, useLocation, useNavigationType } from 'react-router-dom'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import type { ActiveWorkGroups, ActiveWorkItem } from '@/lib/activeWork'
|
||||
import { DEFAULT_ACTIVITY_WINDOW_MINUTES } from '@/api/types/settings'
|
||||
import { KeyboardShortcutsProvider } from '@/contexts/KeyboardShortcutsContext'
|
||||
import { useSidebarServerStore } from '@/stores/sidebarServerStore'
|
||||
import { stubMatchMedia } from '@/test/test-utils'
|
||||
import { SessionPickerSheet } from './SessionPickerSheet'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
sessionsData: [] as Session[],
|
||||
lastDirectories: [] as string[],
|
||||
lastAllDirectories: false,
|
||||
createSessionDirectories: [] as string[],
|
||||
deleteSessionMock: vi.fn(),
|
||||
locationData: undefined as
|
||||
| { directory: string; project: { id: string; directory: string; canonical: string } }
|
||||
| undefined,
|
||||
getOpenCodeLocation: vi.fn(),
|
||||
listProjects: vi.fn(),
|
||||
repos: [] as Repo[],
|
||||
activeWorkGroups: { needsInput: [], running: [], recent: [] } as ActiveWorkGroups,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSettings', () => ({
|
||||
useSettings: () => ({ preferences: undefined }),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/opencode', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/api/opencode')>()
|
||||
return { ...actual, getOpenCodeLocation: mocks.getOpenCodeLocation, listProjects: mocks.listProjects }
|
||||
})
|
||||
|
||||
vi.mock('@/api/repos', () => ({
|
||||
listRepos: vi.fn().mockResolvedValue([]),
|
||||
createRepo: vi.fn(),
|
||||
discoverRepos: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCode', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/hooks/useOpenCode')>()
|
||||
return {
|
||||
...actual,
|
||||
useSessionsAcrossDirectories: (
|
||||
directories: string[],
|
||||
options?: { search?: string; allDirectories?: boolean },
|
||||
) => {
|
||||
mocks.lastDirectories = directories
|
||||
mocks.lastAllDirectories = options?.allDirectories ?? false
|
||||
const search = options?.search?.toLowerCase() ?? ''
|
||||
const base = directories.length === 0 && !options?.allDirectories ? [] : mocks.sessionsData
|
||||
const data = search
|
||||
? base.filter((session) => (session.title ?? '').toLowerCase().includes(search))
|
||||
: base
|
||||
return {
|
||||
data,
|
||||
isLoading: false,
|
||||
isPlaceholderData: false,
|
||||
fetchNextPage: vi.fn(),
|
||||
hasNextPage: false,
|
||||
isFetchingNextPage: false,
|
||||
isFetchNextPageError: false,
|
||||
}
|
||||
},
|
||||
useDeleteSession: () => ({
|
||||
mutateAsync: mocks.deleteSessionMock,
|
||||
isPending: false,
|
||||
}),
|
||||
useCreateSession: (directory: string, onSuccess?: (session: { id: string }) => void) => ({
|
||||
mutate: () => {
|
||||
mocks.createSessionDirectories.push(directory)
|
||||
onSuccess?.({ id: 'ses_new' })
|
||||
},
|
||||
isPending: false,
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('@/hooks/useSessionPins', () => ({
|
||||
useSessionPins: () => ({ data: [] }),
|
||||
useToggleSessionPin: () => ({ mutate: vi.fn() }),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSidebarRepoGroups', () => ({
|
||||
useNavigableRepos: () => ({ repos: mocks.repos, isLoading: false, refetch: vi.fn() }),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useActiveWork: () => ({ groups: mocks.activeWorkGroups, isLoading: false, isError: false }),
|
||||
useActivityWindowMinutes: () => DEFAULT_ACTIVITY_WINDOW_MINUTES,
|
||||
useProjectActivityState: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCodeServers', () => ({
|
||||
useOpenCodeServers: () => ({
|
||||
servers: [{ id: 'srv_kitchen', name: 'Kitchen', enabled: true }],
|
||||
isLoading: false,
|
||||
}),
|
||||
useOpenCodeServerStatuses: () => ({ statuses: [], statusById: {}, isLoading: false }),
|
||||
}))
|
||||
|
||||
vi.mock('@/components/navigation/LinkedServersNav', () => ({
|
||||
LinkedServersNav: () => <div data-testid="linked-servers-nav" />,
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/sessionStatusStore', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/stores/sessionStatusStore')>()
|
||||
return { ...actual, useSessionStatusForSession: () => ({ type: 'idle' }) }
|
||||
})
|
||||
|
||||
function session(id: string, title: string, directory: string, updated = Date.now()): Session {
|
||||
return {
|
||||
id,
|
||||
projectID: 'proj',
|
||||
title,
|
||||
time: { created: updated, updated },
|
||||
location: { directory },
|
||||
cost: 0,
|
||||
tokens: {},
|
||||
} as unknown as Session
|
||||
}
|
||||
|
||||
function repo(id: number, name: string, fullPath: string): Repo {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
localPath: fullPath,
|
||||
fullPath,
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
}
|
||||
}
|
||||
|
||||
function activeWorkItem(id: string, directory: string): ActiveWorkItem {
|
||||
const now = Date.now()
|
||||
return {
|
||||
key: `1:${id}`,
|
||||
state: 'recent',
|
||||
session: session(id, `Active ${id}`, directory, now),
|
||||
repo: repo(1, 'alpha', directory),
|
||||
updatedAt: now,
|
||||
path: `/repos/1/sessions/${id}`,
|
||||
}
|
||||
}
|
||||
|
||||
function LocationProbe() {
|
||||
const location = useLocation()
|
||||
const navigationType = useNavigationType()
|
||||
return (
|
||||
<div data-testid="location">{`${location.pathname}${location.search} ${navigationType}`}</div>
|
||||
)
|
||||
}
|
||||
|
||||
function renderSheet(initialEntries: string[] = ['/repos/1?mobileTab=sessions']) {
|
||||
const onClose = vi.fn()
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<KeyboardShortcutsProvider>
|
||||
<MemoryRouter initialEntries={initialEntries}>
|
||||
<Routes>
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<>
|
||||
<SessionPickerSheet isOpen onClose={onClose} />
|
||||
<LocationProbe />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</KeyboardShortcutsProvider>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
return { onClose }
|
||||
}
|
||||
|
||||
describe('SessionPickerSheet', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
localStorage.clear()
|
||||
stubMatchMedia(true)
|
||||
useSidebarServerStore.setState({ serverId: LOCAL_OPENCODE_SERVER_ID })
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.sessionsData = []
|
||||
mocks.lastDirectories = []
|
||||
mocks.lastAllDirectories = false
|
||||
mocks.createSessionDirectories = []
|
||||
mocks.activeWorkGroups = { needsInput: [], running: [], recent: [] }
|
||||
mocks.listProjects.mockResolvedValue([])
|
||||
mocks.locationData = {
|
||||
directory: '/w/a',
|
||||
project: { id: 'global', directory: '/w/a', canonical: '/w/a' },
|
||||
}
|
||||
mocks.getOpenCodeLocation.mockResolvedValue(mocks.locationData)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Reflect.deleteProperty(window, 'matchMedia')
|
||||
})
|
||||
|
||||
it('renders the picker in a bottom sheet with Activity, Sessions and Projects tabs', () => {
|
||||
renderSheet(['/'])
|
||||
|
||||
expect(screen.getByRole('dialog', { name: 'Sessions' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Activity' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Sessions', selected: true })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Projects' })).toBeInTheDocument()
|
||||
expect(screen.getByTestId('linked-servers-nav')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('navigates to the chosen session, replacing the sheet history entry', async () => {
|
||||
mocks.sessionsData = [session('ses_one', 'Solo session', '/w/a')]
|
||||
|
||||
renderSheet()
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Solo session/ })
|
||||
fireEvent.click(row)
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/ses_one REPLACE')
|
||||
})
|
||||
|
||||
it('closes instead of navigating when the chosen session is already open', async () => {
|
||||
mocks.sessionsData = [session('ses_one', 'Solo session', '/w/a')]
|
||||
|
||||
const { onClose } = renderSheet(['/repos/1/sessions/ses_one?mobileTab=sessions'])
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Solo session/ })
|
||||
fireEvent.click(row)
|
||||
|
||||
expect(onClose).toHaveBeenCalled()
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/repos/1/sessions/ses_one?mobileTab=sessions POP',
|
||||
)
|
||||
})
|
||||
|
||||
it('creates a session in the current repo from the header action and opens it', async () => {
|
||||
renderSheet()
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'New session in alpha' }))
|
||||
|
||||
expect(mocks.createSessionDirectories).toEqual(['/w/a'])
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/ses_new REPLACE')
|
||||
})
|
||||
|
||||
it('opens the add repository dialog from the projects tab header action', async () => {
|
||||
const { onClose } = renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Projects' }))
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Add repository' }))
|
||||
|
||||
expect(await screen.findByRole('dialog', { name: 'Add Repository' })).toBeInTheDocument()
|
||||
expect(onClose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('lists and opens the linked server sessions when a linked server is selected', async () => {
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
mocks.sessionsData = [session('ses_remote', 'Remote session', '/home/me/app')]
|
||||
|
||||
renderSheet()
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Remote session/ })
|
||||
expect(row).toHaveTextContent('Kitchen')
|
||||
expect(mocks.lastDirectories).toEqual([])
|
||||
expect(mocks.lastAllDirectories).toBe(true)
|
||||
expect(screen.getByTestId('linked-servers-nav')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('tab', { name: 'This project' })).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(row)
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_kitchen/sessions/ses_remote REPLACE',
|
||||
)
|
||||
})
|
||||
|
||||
it('lists the linked server projects on the projects tab and opens one', async () => {
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
mocks.listProjects.mockResolvedValue([
|
||||
{
|
||||
id: 'p1',
|
||||
name: 'Alpha',
|
||||
canonical: '/projects/alpha',
|
||||
time: { created: 1, updated: 2 },
|
||||
sandboxes: [],
|
||||
},
|
||||
])
|
||||
|
||||
renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Projects' }))
|
||||
fireEvent.click(await screen.findByText('Alpha'))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_kitchen/projects?directory=%2Fprojects%2Falpha REPLACE',
|
||||
)
|
||||
})
|
||||
|
||||
it('follows the sidebar server selection to list that server', async () => {
|
||||
mocks.sessionsData = [session('ses_remote', 'Remote session', '/home/me/app')]
|
||||
|
||||
renderSheet()
|
||||
|
||||
act(() => {
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
})
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Remote session/ })
|
||||
expect(row).toHaveTextContent('Kitchen')
|
||||
expect(screen.queryByRole('tab', { name: 'This project' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('lists activity sessions and opens one', async () => {
|
||||
mocks.activeWorkGroups = {
|
||||
needsInput: [],
|
||||
running: [],
|
||||
recent: [activeWorkItem('ses_active', '/w/a')],
|
||||
}
|
||||
|
||||
renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Activity' }))
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Active ses_active/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/ses_active REPLACE')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,94 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import { BottomSheet } from '@/components/ui/bottom-sheet'
|
||||
import { LinkedServersNav } from '@/components/navigation/LinkedServersNav'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { SessionPickerPanel } from '@/components/session/SessionPickerDialog'
|
||||
import { OpenCodeServerProvider } from '@/contexts/OpenCodeServerContext'
|
||||
import { useSessionPickerRouteScope } from '@/hooks/useSessionPickerRouteScope'
|
||||
import { getRepoPath, getServerSessionPath, getSessionPath } from '@/lib/navigation'
|
||||
|
||||
interface SessionPickerSheetProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
}
|
||||
|
||||
/** The session picker in a bottom sheet; every navigation replaces the sheet's history entry. */
|
||||
export function SessionPickerSheet({ isOpen, onClose }: SessionPickerSheetProps) {
|
||||
const navigate = useNavigate()
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false)
|
||||
const { currentRepo, activeSessionID, remote } = useSessionPickerRouteScope(isOpen)
|
||||
const remoteServerId = remote?.serverId
|
||||
|
||||
const navigateReplacing = useCallback(
|
||||
(path: string) => {
|
||||
navigate(path, { replace: true })
|
||||
},
|
||||
[navigate],
|
||||
)
|
||||
|
||||
const handleSelectSession = useCallback(
|
||||
(session: Session, repo: Repo) => {
|
||||
if (session.id === activeSessionID) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
navigateReplacing(getSessionPath(repo.id, session.id))
|
||||
},
|
||||
[activeSessionID, navigateReplacing, onClose],
|
||||
)
|
||||
|
||||
const handleSelectRemoteSession = useCallback(
|
||||
(session: Session) => {
|
||||
if (!remoteServerId) return
|
||||
if (session.id === activeSessionID) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
navigateReplacing(getServerSessionPath(remoteServerId, session.id))
|
||||
},
|
||||
[activeSessionID, navigateReplacing, onClose, remoteServerId],
|
||||
)
|
||||
|
||||
const handleDeleteActiveSession = useCallback(() => {
|
||||
if (!currentRepo) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
navigateReplacing(getRepoPath(currentRepo.id))
|
||||
}, [currentRepo, navigateReplacing, onClose])
|
||||
|
||||
const panel = isOpen ? (
|
||||
<SessionPickerPanel
|
||||
open={isOpen}
|
||||
currentRepo={currentRepo}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={handleSelectSession}
|
||||
onSelectRemoteSession={handleSelectRemoteSession}
|
||||
onDeleteActiveSession={handleDeleteActiveSession}
|
||||
onSelectRepo={(repo) => navigateReplacing(getRepoPath(repo.id))}
|
||||
onNavigate={navigateReplacing}
|
||||
remote={remote}
|
||||
remoteProjects
|
||||
searchTrailing={<LinkedServersNav variant="header" />}
|
||||
onAddRepo={() => {
|
||||
onClose()
|
||||
setAddRepoOpen(true)
|
||||
}}
|
||||
/>
|
||||
) : null
|
||||
|
||||
return (
|
||||
<>
|
||||
<BottomSheet isOpen={isOpen} onClose={onClose} heightClass="h-[90dvh]" ariaLabel="Sessions">
|
||||
{remote ? (
|
||||
<OpenCodeServerProvider serverId={remote.serverId}>{panel}</OpenCodeServerProvider>
|
||||
) : (
|
||||
panel
|
||||
)}
|
||||
</BottomSheet>
|
||||
<AddRepoDialog open={addRepoOpen} onOpenChange={setAddRepoOpen} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -13,9 +13,9 @@ describe('useMobileTabBar', () => {
|
||||
|
||||
it('returns the correct openSheet when mobileTab param is set', () => {
|
||||
const { result } = renderHook(() => useMobileTabBar(), {
|
||||
wrapper: createRouterWrapper(['/?mobileTab=repos']),
|
||||
wrapper: createRouterWrapper(['/?mobileTab=sessions']),
|
||||
})
|
||||
expect(result.current.openSheet).toBe('repos')
|
||||
expect(result.current.openSheet).toBe('sessions')
|
||||
})
|
||||
|
||||
it('open sets the mobileTab param', () => {
|
||||
@@ -45,7 +45,7 @@ describe('useMobileTabBar', () => {
|
||||
})
|
||||
|
||||
it('handles all valid MobileSheetKey values', () => {
|
||||
const validKeys = ['repos', 'files', 'notifications', 'more'] as const
|
||||
const validKeys = ['sessions', 'files', 'notifications', 'more'] as const
|
||||
validKeys.forEach((key) => {
|
||||
const { result } = renderHook(() => useMobileTabBar(), {
|
||||
wrapper: createRouterWrapper([`/?mobileTab=${key}`]),
|
||||
@@ -56,7 +56,7 @@ describe('useMobileTabBar', () => {
|
||||
|
||||
it('returns stable openSheet identity across rerenders when search is unchanged', () => {
|
||||
const { result, rerender } = renderHook(() => useMobileTabBar(), {
|
||||
wrapper: createRouterWrapper(['/?mobileTab=repos']),
|
||||
wrapper: createRouterWrapper(['/?mobileTab=sessions']),
|
||||
})
|
||||
const firstOpenSheet = result.current.openSheet
|
||||
rerender()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useMemo } from 'react'
|
||||
import { useUrlParams } from './useUrlParams'
|
||||
|
||||
type MobileSheetKey = 'repos' | 'files' | 'notifications' | 'more'
|
||||
type MobileSheetKey = 'sessions' | 'files' | 'notifications' | 'more'
|
||||
|
||||
interface UseMobileTabBarReturn {
|
||||
openSheet: MobileSheetKey | null
|
||||
@@ -14,7 +14,7 @@ export function useMobileTabBar(): UseMobileTabBarReturn {
|
||||
|
||||
const openSheet = useMemo<MobileSheetKey | null>(() => {
|
||||
const v = searchParams.get('mobileTab')
|
||||
return (v === 'repos' || v === 'files' || v === 'notifications' || v === 'more') ? v : null
|
||||
return (v === 'sessions' || v === 'files' || v === 'notifications' || v === 'more') ? v : null
|
||||
}, [searchParams])
|
||||
|
||||
const open = useCallback((key: MobileSheetKey) => {
|
||||
|
||||
@@ -174,6 +174,27 @@ describe('useSessionsAcrossDirectories', () => {
|
||||
expect(result.current.data.map((session) => session.id)).toEqual(['ses_all1', 'ses_all2'])
|
||||
})
|
||||
|
||||
it('queries all directories when allDirectories is set without a directory scope', async () => {
|
||||
mocks.listSessionPage.mockResolvedValue({ items: [sessionInfo('ses_all', '/w/a')] })
|
||||
|
||||
const queryClient = createQueryClient()
|
||||
const { result } = renderHook(
|
||||
() => useSessionsAcrossDirectories([], { allDirectories: true }),
|
||||
{ wrapper: createWrapper(queryClient) },
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.isLoading).toBe(false)
|
||||
})
|
||||
|
||||
expect(mocks.listSessionPage).toHaveBeenCalledWith({
|
||||
limit: 25,
|
||||
order: 'desc',
|
||||
search: undefined,
|
||||
}, 'local')
|
||||
expect(result.current.data.map((session) => session.id)).toEqual(['ses_all'])
|
||||
})
|
||||
|
||||
it('requests child sessions and records includeChildren in the query key', async () => {
|
||||
mocks.listSessionPage.mockResolvedValue({ items: [sessionInfo('ses_child', '/w/a')] })
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ export const useSessionsAcrossDirectories = (
|
||||
}
|
||||
: undefined,
|
||||
getNextPageParam: (lastPage) => lastPage.nextParam,
|
||||
enabled: uniqueDirectories.length > 0,
|
||||
enabled: uniqueDirectories.length > 0 || allDirectories,
|
||||
staleTime: 10000,
|
||||
refetchOnWindowFocus: true,
|
||||
refetchOnReconnect: true,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import type { Repo } from '@/api/types'
|
||||
import { parseRepoRoute, parseServerProjectRoute, parseServerSessionRoute } from '@/lib/navigation'
|
||||
import { useNavigableRepos } from '@/hooks/useSidebarRepoGroups'
|
||||
import { useOpenCodeServers } from '@/hooks/useOpenCodeServers'
|
||||
import { useSidebarServerSelection } from '@/hooks/useSidebarServerSelection'
|
||||
|
||||
export interface SessionPickerRouteScope {
|
||||
currentRepo: Repo | undefined
|
||||
activeSessionID: string | undefined
|
||||
isRemote: boolean
|
||||
remote: { serverId: string; serverName?: string; projectDirectory?: string } | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves what a session picker opened on the current route should list: the Manager repo of a
|
||||
* repo route, or the selected linked server and its project directory.
|
||||
*/
|
||||
export function useSessionPickerRouteScope(enabled: boolean): SessionPickerRouteScope {
|
||||
const { pathname, search } = useLocation()
|
||||
const [selectedServerId] = useSidebarServerSelection()
|
||||
const { repos } = useNavigableRepos(enabled)
|
||||
const { servers } = useOpenCodeServers({ enabled })
|
||||
|
||||
const isRemote = selectedServerId !== LOCAL_OPENCODE_SERVER_ID
|
||||
const repoRoute = parseRepoRoute(pathname)
|
||||
const currentRepo = isRemote || repoRoute.repoId === null
|
||||
? undefined
|
||||
: repos.find((candidate) => candidate.id === repoRoute.repoId)
|
||||
const activeSessionID = repoRoute.sessionId
|
||||
?? parseServerSessionRoute(pathname)?.sessionId
|
||||
?? undefined
|
||||
const remoteProjectDirectory = isRemote
|
||||
? parseServerProjectRoute(pathname, search)?.directory
|
||||
: undefined
|
||||
|
||||
if (!isRemote) {
|
||||
return { currentRepo, activeSessionID, isRemote, remote: undefined }
|
||||
}
|
||||
|
||||
return {
|
||||
currentRepo,
|
||||
activeSessionID,
|
||||
isRemote,
|
||||
remote: {
|
||||
serverId: selectedServerId,
|
||||
serverName: servers.find((server) => server.id === selectedServerId)?.name,
|
||||
projectDirectory: remoteProjectDirectory,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ describe('useSettingsDialog', () => {
|
||||
}
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/?mobileTab=repos']}>
|
||||
<MemoryRouter initialEntries={['/?mobileTab=sessions']}>
|
||||
<Harness />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
@@ -285,7 +285,7 @@ describe('useSettingsDialog', () => {
|
||||
|
||||
act(() => { screen.getByText('back').click() })
|
||||
|
||||
expect(screen.getByTestId('search').textContent).toBe('?mobileTab=repos')
|
||||
expect(screen.getByTestId('search').textContent).toBe('?mobileTab=sessions')
|
||||
expect(screen.getByTestId('dialog-state').textContent).toBe('closed')
|
||||
})
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import { useShortcutActions } from "@/contexts/KeyboardShortcutsContext";
|
||||
import { useSettingsDialog } from "@/hooks/useSettingsDialog";
|
||||
import { useAutoScroll } from "@/hooks/useAutoScroll";
|
||||
import { useMobile } from "@/hooks/useMobile";
|
||||
import { useMobileTabBar } from "@/hooks/useMobileTabBar";
|
||||
import { useToolPanelLayout } from "@/hooks/useToolPanelLayout";
|
||||
import { useVisualViewport } from "@/hooks/useVisualViewport";
|
||||
import { useTTS } from "@/hooks/useTTS";
|
||||
@@ -156,6 +157,7 @@ export function SessionDetail() {
|
||||
const [forkPickerLoading, setForkPickerLoading] = useState(false);
|
||||
|
||||
const isMobile = useMobile();
|
||||
const { open: openMobileSheet } = useMobileTabBar();
|
||||
const { docked, showRail } = useToolPanelLayout();
|
||||
const sidePanel = useToolPanel(showRail);
|
||||
const { keyboardHeight } = useVisualViewport();
|
||||
@@ -368,7 +370,13 @@ export function SessionDetail() {
|
||||
enabled: !isVoiceConversationActive,
|
||||
});
|
||||
|
||||
const handleShowSessionsDialog = useCallback(() => setSessionsDialogOpen(true), []);
|
||||
const handleShowSessionsDialog = useCallback(() => {
|
||||
if (isMobile) {
|
||||
openMobileSheet('sessions');
|
||||
return;
|
||||
}
|
||||
setSessionsDialogOpen(true);
|
||||
}, [isMobile, openMobileSheet]);
|
||||
const handleShowMcpDialog = useCallback(() => setMcpDialogOpen(true), [setMcpDialogOpen]);
|
||||
const handleShowSkillsDialog = useCallback(() => setSkillsDialogOpen(true), [setSkillsDialogOpen]);
|
||||
const handleShowWalkthrough = useCallback((source?: WalkthroughSource) => {
|
||||
@@ -1057,6 +1065,10 @@ export function SessionDetail() {
|
||||
navigate(getRepoPath(selectedRepo.id))
|
||||
setSessionsDialogOpen(false)
|
||||
}}
|
||||
onNavigate={(path) => {
|
||||
navigate(path)
|
||||
setSessionsDialogOpen(false)
|
||||
}}
|
||||
/>
|
||||
|
||||
{sideQuestion && sessionId && (
|
||||
|
||||
@@ -476,6 +476,37 @@ describe('SessionDetail command actions', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('opens the sessions picker dialog from the sessions command on desktop', async () => {
|
||||
const { SessionPickerDialog } = await import('@/components/session/SessionPickerDialog')
|
||||
|
||||
renderSessionDetail()
|
||||
const showSessions = await commandHandler('showSessions')
|
||||
|
||||
act(() => {
|
||||
showSessions()
|
||||
})
|
||||
|
||||
const props = vi.mocked(SessionPickerDialog).mock.calls.at(-1)?.[0] as Record<string, unknown>
|
||||
expect(props).toMatchObject({ open: true })
|
||||
})
|
||||
|
||||
it('opens the mobile sessions sheet instead of the dialog from the sessions command', async () => {
|
||||
const { SessionPickerDialog } = await import('@/components/session/SessionPickerDialog')
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
const captured = { search: { current: '' }, pathname: { current: '' } }
|
||||
|
||||
renderSessionDetail(captured)
|
||||
const showSessions = await commandHandler('showSessions')
|
||||
|
||||
act(() => {
|
||||
showSessions()
|
||||
})
|
||||
|
||||
await waitFor(() => expect(captured.search.current).toBe('?mobileTab=sessions'))
|
||||
const props = vi.mocked(SessionPickerDialog).mock.calls.at(-1)?.[0] as Record<string, unknown>
|
||||
expect(props).toMatchObject({ open: false })
|
||||
})
|
||||
|
||||
it('shows the error toast when the transcript fetch fails', async () => {
|
||||
mocks.listSessionMessages.mockRejectedValueOnce(new Error('page fetch failed'))
|
||||
mocks.copyTextToClipboard.mockImplementation(async (content: string | Promise<string>) => {
|
||||
|
||||
Reference in new issue
Block a user