mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +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} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user