mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(servers): compact server switcher and mobile navigation for linked servers
Replace the Servers list with a single dropdown switcher in the sidebar, collapsed rail and mobile repo sheet, flagging activity on other servers. Show the More button on remote sessions, the tab bar on server and project pages, and the server name in a distinct color in the session header.
This commit is contained in:
1 parent
8277ec253e
commit
96e22dfa66
10 files changed
+510
-271
No files matched your search
@@ -250,7 +250,7 @@ describe('DesktopSidebar', () => {
|
||||
expect(screen.getByText('Logout')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides the Servers group when no linked servers exist', () => {
|
||||
it('hides the server switcher when no linked servers exist', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
@@ -261,7 +261,7 @@ describe('DesktopSidebar', () => {
|
||||
|
||||
render(<DesktopSidebar />, { wrapper: createWrapper(['/']) })
|
||||
|
||||
expect(screen.queryByText('Servers')).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: /Switch server/ })).toBeNull()
|
||||
})
|
||||
it('renders home, repos and account items and no session tree when collapsed', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
|
||||
@@ -6,9 +6,6 @@ import { useSidebarWidth } from '@/hooks/useSidebarWidth'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { useOpenNavItem } from '@/hooks/useOpenNavItem'
|
||||
import { useOpenCodeServers } from '@/hooks/useOpenCodeServers'
|
||||
import { useSidebarServerSelection } from '@/hooks/useSidebarServerSelection'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import { buildNavModel, type MoreDrawerItem, type NavPrimaryCta } from '@/components/navigation/moreDrawerItems'
|
||||
import { RepoQuickSwitchSheet } from '@/components/navigation/RepoQuickSwitchSheet'
|
||||
import { DesktopSessionTree } from '@/components/navigation/DesktopSessionTree'
|
||||
@@ -31,12 +28,6 @@ export function DesktopSidebar() {
|
||||
const [sidebarWidth, setSidebarWidth] = useSidebarWidth()
|
||||
const [repoSwitcherOpen, setRepoSwitcherOpen] = useState(false)
|
||||
const { isAuthenticated, isLoading, logout } = useAuth()
|
||||
const [selectedServerId] = useSidebarServerSelection()
|
||||
const { servers } = useOpenCodeServers()
|
||||
const selectedServerName =
|
||||
selectedServerId === LOCAL_OPENCODE_SERVER_ID
|
||||
? null
|
||||
: servers.find((server) => server.id === selectedServerId)?.name ?? null
|
||||
|
||||
const isDesktop = useDesktop()
|
||||
|
||||
@@ -115,11 +106,13 @@ export function DesktopSidebar() {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<LinkedServersNav />
|
||||
<div className="px-2 py-1">
|
||||
<LinkedServersNav />
|
||||
</div>
|
||||
|
||||
<section aria-label="Sessions" className="flex min-h-0 flex-1 flex-col border-t border-border">
|
||||
<h2 className="px-3 py-1.5 text-xs font-medium uppercase tracking-wider text-muted-foreground">
|
||||
Sessions{selectedServerName ? ` · ${selectedServerName}` : ''}
|
||||
Sessions
|
||||
</h2>
|
||||
<DesktopSessionTree />
|
||||
</section>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { MemoryRouter, useLocation } from 'react-router-dom'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import { LinkedServersNav } from './LinkedServersNav'
|
||||
@@ -37,25 +38,24 @@ const office = { ...kitchen, id: 'srv_office', name: 'Office' }
|
||||
|
||||
function LocationDisplay() {
|
||||
const location = useLocation()
|
||||
return <div data-testid="location">{location.pathname}</div>
|
||||
return <div data-testid="location">{`${location.pathname}${location.search}`}</div>
|
||||
}
|
||||
|
||||
function renderNav(pathname = '/') {
|
||||
function renderNav(pathname = '/', variant?: 'sidebar' | 'rail' | 'sheet') {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[pathname]}>
|
||||
<LinkedServersNav />
|
||||
<LinkedServersNav variant={variant} />
|
||||
<LocationDisplay />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
}
|
||||
|
||||
function renderRail(pathname = '/') {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[pathname]}>
|
||||
<LinkedServersNav variant="rail" />
|
||||
<LocationDisplay />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
function setServers(servers: Array<typeof kitchen>) {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers, isLoading: false })
|
||||
}
|
||||
|
||||
function triggerName(name: string) {
|
||||
return `Switch server, current: ${name}`
|
||||
}
|
||||
|
||||
describe('LinkedServersNav', () => {
|
||||
@@ -63,12 +63,15 @@ describe('LinkedServersNav', () => {
|
||||
vi.clearAllMocks()
|
||||
localStorage.clear()
|
||||
useSidebarServerStore.setState({ serverId: LOCAL_OPENCODE_SERVER_ID })
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [], isLoading: false })
|
||||
setServers([])
|
||||
mocks.useServerActivityState.mockReturnValue(null)
|
||||
mocks.useLocalActivityState.mockReturnValue(null)
|
||||
mocks.useOpenCodeServerStatuses.mockReturnValue({
|
||||
statuses: [],
|
||||
statusById: { srv_kitchen: { serverId: 'srv_kitchen', connected: true, version: null, error: null } },
|
||||
statusById: {
|
||||
srv_kitchen: { serverId: 'srv_kitchen', connected: true, version: null, error: null },
|
||||
srv_office: { serverId: 'srv_office', connected: false, version: null, error: null },
|
||||
},
|
||||
isLoading: false,
|
||||
})
|
||||
})
|
||||
@@ -76,154 +79,179 @@ describe('LinkedServersNav', () => {
|
||||
it('renders nothing when no linked servers exist', () => {
|
||||
renderNav()
|
||||
|
||||
expect(screen.queryByText('Servers')).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /Local/ })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /Switch server/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('lists the local machine and enabled servers as toggle buttons with connection dots', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen, office], isLoading: false })
|
||||
it('renders nothing for disabled linked servers', () => {
|
||||
setServers([{ ...kitchen, enabled: false }])
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(screen.getByText('Servers')).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: /Local/ })).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(screen.getByRole('button', { name: /Kitchen/ })).toHaveAttribute('aria-pressed', 'false')
|
||||
expect(screen.getByRole('button', { name: /Office/ })).toHaveAttribute('aria-pressed', 'false')
|
||||
expect(screen.queryByRole('button', { name: /Switch server/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the local machine on the trigger by default', () => {
|
||||
setServers([kitchen])
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(screen.getByRole('button', { name: triggerName('Local') })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('heading', { name: 'Servers' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the selected server name and connection dot on the trigger', async () => {
|
||||
setServers([kitchen])
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(await screen.findByRole('button', { name: triggerName('Kitchen') })).toBeInTheDocument()
|
||||
expect(screen.getByRole('img', { name: 'Connected' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('img', { name: 'Disconnected' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides disabled servers', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({
|
||||
servers: [kitchen, { ...office, enabled: false }],
|
||||
isLoading: false,
|
||||
})
|
||||
it('lists the local machine and enabled servers in the menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
setServers([kitchen, { ...office, enabled: false }])
|
||||
|
||||
renderNav()
|
||||
await user.click(screen.getByRole('button', { name: triggerName('Local') }))
|
||||
|
||||
expect(screen.getByRole('button', { name: /Kitchen/ })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /Office/ })).not.toBeInTheDocument()
|
||||
expect(await screen.findByRole('menuitem', { name: /Local/ })).toHaveAttribute('aria-current', 'true')
|
||||
expect(screen.getByRole('menuitem', { name: /Kitchen/ })).toBeInTheDocument()
|
||||
expect(screen.getByRole('img', { name: 'Connected' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('menuitem', { name: /Office/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('selects a server without navigating', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen, office], isLoading: false })
|
||||
it('selects a server without navigating', async () => {
|
||||
const user = userEvent.setup()
|
||||
setServers([kitchen, office])
|
||||
|
||||
renderNav()
|
||||
await user.click(screen.getByRole('button', { name: triggerName('Local') }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Office/ }))
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /Office/ }))
|
||||
|
||||
expect(screen.getByRole('button', { name: /Office/ })).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(screen.getByRole('button', { name: /Office/ })).toHaveAttribute('aria-current', 'true')
|
||||
expect(screen.getByRole('button', { name: /Kitchen/ })).toHaveAttribute('aria-pressed', 'false')
|
||||
expect(screen.getByRole('button', { name: /Local/ })).toHaveAttribute('aria-pressed', 'false')
|
||||
expect(await screen.findByRole('button', { name: triggerName('Office') })).toBeInTheDocument()
|
||||
expect(useSidebarServerStore.getState().serverId).toBe('srv_office')
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/')
|
||||
})
|
||||
|
||||
it('selects the local machine without navigating', () => {
|
||||
it('selects the local machine without navigating', async () => {
|
||||
const user = userEvent.setup()
|
||||
setServers([kitchen])
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
|
||||
|
||||
renderNav()
|
||||
await user.click(screen.getByRole('button', { name: triggerName('Kitchen') }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Local/ }))
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /Local/ }))
|
||||
|
||||
expect(screen.getByRole('button', { name: /Local/ })).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(await screen.findByRole('button', { name: triggerName('Local') })).toBeInTheDocument()
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/')
|
||||
})
|
||||
|
||||
it('follows a linked server route', async () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
|
||||
setServers([kitchen])
|
||||
|
||||
renderNav('/servers/srv_kitchen/sessions/abc')
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: /Kitchen/ })).toHaveAttribute('aria-pressed', 'true'),
|
||||
)
|
||||
expect(screen.getByRole('button', { name: /Local/ })).toHaveAttribute('aria-pressed', 'false')
|
||||
expect(await screen.findByRole('button', { name: triggerName('Kitchen') })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('falls back to local when the persisted server is disabled', async () => {
|
||||
useSidebarServerStore.setState({ serverId: 'srv_office' })
|
||||
mocks.useOpenCodeServers.mockReturnValue({
|
||||
servers: [kitchen, { ...office, enabled: false }],
|
||||
isLoading: false,
|
||||
})
|
||||
setServers([kitchen, { ...office, enabled: false }])
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(await screen.findByRole('button', { name: triggerName('Local') })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows an attention dot for another server that needs input', async () => {
|
||||
setServers([kitchen, office])
|
||||
mocks.useServerActivityState.mockImplementation((serverId: string) =>
|
||||
serverId === 'srv_office' ? 'needs-input' : null,
|
||||
)
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(screen.getByRole('img', { name: 'Office needs input' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('img', { name: 'Office is running' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows a running attention dot for another running server', () => {
|
||||
setServers([kitchen])
|
||||
mocks.useServerActivityState.mockReturnValue('running')
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(screen.getByRole('img', { name: 'Kitchen is running' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows local attention while a remote server is selected', () => {
|
||||
setServers([kitchen])
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
mocks.useLocalActivityState.mockReturnValue('needs-input')
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(screen.getByRole('img', { name: 'Local needs input' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not show an attention dot for the selected server', async () => {
|
||||
setServers([kitchen])
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
mocks.useServerActivityState.mockReturnValue('needs-input')
|
||||
|
||||
renderNav()
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: /Local/ })).toHaveAttribute('aria-pressed', 'true'),
|
||||
expect(screen.getByRole('button', { name: triggerName('Kitchen') })).toBeInTheDocument(),
|
||||
)
|
||||
expect(screen.queryByRole('img', { name: 'Kitchen needs input' })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('img', { name: 'Session needs input' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders the local machine and enabled servers as icon toggles in the collapsed rail', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
|
||||
it('opens settings on the servers tab from the menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
setServers([kitchen])
|
||||
|
||||
renderRail('/servers/srv_kitchen/sessions/abc')
|
||||
renderNav()
|
||||
await user.click(screen.getByRole('button', { name: triggerName('Local') }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Manage servers/ }))
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Local' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Kitchen' })).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(screen.queryByText('Servers')).not.toBeInTheDocument()
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/?settings=open&settingsTab=servers')
|
||||
})
|
||||
|
||||
it('renders a single icon trigger in the collapsed rail', async () => {
|
||||
const user = userEvent.setup()
|
||||
setServers([kitchen])
|
||||
|
||||
renderNav('/', 'rail')
|
||||
|
||||
const trigger = screen.getByRole('button', { name: triggerName('Local') })
|
||||
expect(trigger).toBeInTheDocument()
|
||||
expect(screen.queryByText('Local')).not.toBeInTheDocument()
|
||||
|
||||
await user.click(trigger)
|
||||
expect(await screen.findByRole('menuitem', { name: /Kitchen/ })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders nothing in the collapsed rail when no linked servers exist', () => {
|
||||
renderRail()
|
||||
renderNav('/', 'rail')
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Local' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Kitchen' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /Switch server/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('switches the selected server in the sheet variant without navigating', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
|
||||
it('renders a thin trigger row in the sheet variant', async () => {
|
||||
const user = userEvent.setup()
|
||||
setServers([kitchen])
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<LinkedServersNav variant="sheet" />
|
||||
<LocationDisplay />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
renderNav('/', 'sheet')
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Servers' })).toBeInTheDocument()
|
||||
fireEvent.click(screen.getByRole('button', { name: /Kitchen/ }))
|
||||
expect(screen.queryByRole('heading', { name: 'Servers' })).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: triggerName('Local') }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Kitchen/ }))
|
||||
|
||||
expect(screen.getByRole('button', { name: /Kitchen/ })).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(await screen.findByRole('button', { name: triggerName('Kitchen') })).toBeInTheDocument()
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/')
|
||||
})
|
||||
|
||||
it('shows the activity indicator only for the server with an active session', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen, office], isLoading: false })
|
||||
mocks.useServerActivityState.mockImplementation((serverId: string) =>
|
||||
serverId === 'srv_kitchen' ? 'needs-input' : null,
|
||||
)
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(mocks.useServerActivityState).toHaveBeenCalledWith('srv_kitchen')
|
||||
expect(mocks.useServerActivityState).toHaveBeenCalledWith('srv_office')
|
||||
expect(screen.getByRole('img', { name: 'Session needs input' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('img', { name: 'Sessions running' })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('img', { name: 'Connected' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows local activity on the local row', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
|
||||
mocks.useLocalActivityState.mockReturnValue('running')
|
||||
|
||||
renderNav()
|
||||
|
||||
expect(screen.getByRole('img', { name: 'Sessions running' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the running indicator in the sheet variant', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
|
||||
mocks.useServerActivityState.mockReturnValue('running')
|
||||
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<LinkedServersNav variant="sheet" />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
expect(screen.getByRole('img', { name: 'Sessions running' })).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,19 +1,32 @@
|
||||
import { Laptop, Server } from 'lucide-react'
|
||||
import { LOCAL_OPENCODE_SERVER_ID, type OpenCodeServer } from '@opencode-manager/shared/schemas'
|
||||
import { Check, ChevronDown, Laptop, Server, Settings2 } from 'lucide-react'
|
||||
import {
|
||||
LOCAL_OPENCODE_SERVER_ID,
|
||||
type OpenCodeServer,
|
||||
type OpenCodeServerStatus,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import { useOpenCodeServers, useOpenCodeServerStatuses } from '@/hooks/useOpenCodeServers'
|
||||
import { useLocalActivityState, useServerActivityState } from '@/hooks/useActiveWork'
|
||||
import { useSettingsDialog } from '@/hooks/useSettingsDialog'
|
||||
import { useSidebarServerSelection } from '@/hooks/useSidebarServerSelection'
|
||||
import { ActivityStateIndicator } from '@/components/activity/ActivityStateIndicator'
|
||||
import { SidebarSection } from '@/components/ui/sidebar'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export type LinkedServersVariant = 'sidebar' | 'rail' | 'sheet'
|
||||
|
||||
interface LinkedServersNavProps {
|
||||
/** `sidebar` renders the labelled section, `rail` the collapsed icon column, `sheet` the mobile sheet group. */
|
||||
/** `sidebar` renders the full-width trigger row, `rail` the collapsed icon button, `sheet` the mobile sheet row. */
|
||||
variant?: LinkedServersVariant
|
||||
}
|
||||
|
||||
type ActivityState = 'needs-input' | 'running' | null
|
||||
|
||||
function ServerConnectionDot({ connected }: { connected: boolean }) {
|
||||
const label = connected ? 'Connected' : 'Disconnected'
|
||||
|
||||
@@ -27,158 +40,206 @@ function ServerConnectionDot({ connected }: { connected: boolean }) {
|
||||
)
|
||||
}
|
||||
|
||||
function rowClassName(active: boolean, variant: 'sidebar' | 'sheet') {
|
||||
return cn(
|
||||
'flex items-center gap-3 rounded-md p-2.5 text-sm transition-colors duration-150',
|
||||
'focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
||||
active ? 'bg-accent text-accent-foreground' : 'text-foreground hover:bg-accent/50',
|
||||
variant === 'sheet' && 'mx-2 p-2 text-left',
|
||||
function LocalActivityIndicator() {
|
||||
const activity = useLocalActivityState()
|
||||
|
||||
return <ActivityStateIndicator state={activity} />
|
||||
}
|
||||
|
||||
function ServerActivityIndicator({ serverId }: { serverId: string }) {
|
||||
const activity = useServerActivityState(serverId)
|
||||
|
||||
return <ActivityStateIndicator state={activity} />
|
||||
}
|
||||
|
||||
function AttentionDot({ activity, label }: { activity: ActivityState; label: string }) {
|
||||
if (activity === null) return null
|
||||
|
||||
const needsInput = activity === 'needs-input'
|
||||
|
||||
return (
|
||||
<span
|
||||
role="img"
|
||||
aria-label={needsInput ? `${label} needs input` : `${label} is running`}
|
||||
className={cn(
|
||||
'absolute inset-0 rounded-full',
|
||||
needsInput ? 'z-[2] bg-warning' : 'z-[1] bg-info',
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function railClassName(active: boolean) {
|
||||
return cn(
|
||||
'flex items-center justify-center rounded-md p-2.5 transition-colors duration-150',
|
||||
'focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
||||
active ? 'bg-accent text-accent-foreground' : 'text-foreground hover:bg-accent/50',
|
||||
function LocalAttentionDot() {
|
||||
const activity = useLocalActivityState()
|
||||
|
||||
return <AttentionDot activity={activity} label="Local" />
|
||||
}
|
||||
|
||||
function ServerAttentionDot({ server }: { server: OpenCodeServer }) {
|
||||
const activity = useServerActivityState(server.id)
|
||||
|
||||
return <AttentionDot activity={activity} label={server.name} />
|
||||
}
|
||||
|
||||
function OtherServersAttention({
|
||||
servers,
|
||||
selectedServerId,
|
||||
}: {
|
||||
servers: OpenCodeServer[]
|
||||
selectedServerId: string
|
||||
}) {
|
||||
const otherServers = servers.filter((server) => server.id !== selectedServerId)
|
||||
const showLocal = selectedServerId !== LOCAL_OPENCODE_SERVER_ID
|
||||
|
||||
if (!showLocal && otherServers.length === 0) return null
|
||||
|
||||
return (
|
||||
<span className="pointer-events-none absolute -right-0.5 -top-0.5 h-2 w-2">
|
||||
{showLocal && <LocalAttentionDot />}
|
||||
{otherServers.map((server) => (
|
||||
<ServerAttentionDot key={server.id} server={server} />
|
||||
))}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
interface LocalServerRowProps {
|
||||
variant: 'sidebar' | 'sheet'
|
||||
active: boolean
|
||||
onSelect: () => void
|
||||
}
|
||||
|
||||
function LocalServerRow({ variant, active, onSelect }: LocalServerRowProps) {
|
||||
function LocalServerMenuItem({ active, onSelect }: { active: boolean; onSelect: () => void }) {
|
||||
const activity = useLocalActivityState()
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSelect}
|
||||
aria-pressed={active}
|
||||
<DropdownMenuItem
|
||||
onSelect={onSelect}
|
||||
aria-current={active ? 'true' : undefined}
|
||||
className={rowClassName(active, variant)}
|
||||
className="gap-2"
|
||||
>
|
||||
<Laptop className="h-5 w-5 shrink-0" />
|
||||
<Laptop className="h-4 w-4 shrink-0" />
|
||||
<span className="min-w-0 flex-1 truncate">Local</span>
|
||||
<ActivityStateIndicator state={activity} />
|
||||
</button>
|
||||
{active && <Check className="h-4 w-4 shrink-0" />}
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
}
|
||||
|
||||
interface LinkedServerRowProps {
|
||||
function LinkedServerMenuItem({
|
||||
server,
|
||||
active,
|
||||
connected,
|
||||
onSelect,
|
||||
}: {
|
||||
server: OpenCodeServer
|
||||
variant: 'sidebar' | 'sheet'
|
||||
active: boolean
|
||||
connected: boolean
|
||||
onSelect: () => void
|
||||
}
|
||||
|
||||
function LinkedServerRow({ server, variant, active, connected, onSelect }: LinkedServerRowProps) {
|
||||
}) {
|
||||
const activity = useServerActivityState(server.id)
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSelect}
|
||||
aria-pressed={active}
|
||||
<DropdownMenuItem
|
||||
onSelect={onSelect}
|
||||
aria-current={active ? 'true' : undefined}
|
||||
className={rowClassName(active, variant)}
|
||||
className="gap-2"
|
||||
>
|
||||
<Server className="h-5 w-5 shrink-0" />
|
||||
<Server className="h-4 w-4 shrink-0" />
|
||||
<span className="min-w-0 flex-1 truncate">{server.name}</span>
|
||||
<ActivityStateIndicator state={activity} />
|
||||
<ServerConnectionDot connected={connected} />
|
||||
</button>
|
||||
{active && <Check className="h-4 w-4 shrink-0" />}
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
}
|
||||
|
||||
function LinkedServersMenuContent({
|
||||
servers,
|
||||
selectedServerId,
|
||||
statusById,
|
||||
onSelect,
|
||||
}: {
|
||||
servers: OpenCodeServer[]
|
||||
selectedServerId: string
|
||||
statusById: Record<string, OpenCodeServerStatus>
|
||||
onSelect: (serverId: string) => void
|
||||
}) {
|
||||
const { setActiveTab } = useSettingsDialog()
|
||||
|
||||
return (
|
||||
<DropdownMenuContent align="start" className="z-[300] w-56">
|
||||
<LocalServerMenuItem
|
||||
active={selectedServerId === LOCAL_OPENCODE_SERVER_ID}
|
||||
onSelect={() => onSelect(LOCAL_OPENCODE_SERVER_ID)}
|
||||
/>
|
||||
{servers.map((server) => (
|
||||
<LinkedServerMenuItem
|
||||
key={server.id}
|
||||
server={server}
|
||||
active={selectedServerId === server.id}
|
||||
connected={statusById[server.id]?.connected ?? false}
|
||||
onSelect={() => onSelect(server.id)}
|
||||
/>
|
||||
))}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onSelect={() => setActiveTab('servers')} className="gap-2">
|
||||
<Settings2 className="h-4 w-4 shrink-0" />
|
||||
<span>Manage servers…</span>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The server switcher. Selecting a row changes which server's projects and sessions the sidebar
|
||||
* lists; it never navigates. Hidden when no linked server is enabled.
|
||||
* The server switcher. The trigger names the selected server and opens a menu that changes which
|
||||
* server's projects and sessions the sidebar lists; selecting never navigates. Hidden when no
|
||||
* linked server is enabled.
|
||||
*/
|
||||
export function LinkedServersNav({ variant = 'sidebar' }: LinkedServersNavProps) {
|
||||
const { servers, isLoading } = useOpenCodeServers()
|
||||
const { statusById } = useOpenCodeServerStatuses()
|
||||
const [selectedServerId, selectServer] = useSidebarServerSelection()
|
||||
const enabledServers = servers.filter((server) => server.enabled)
|
||||
const localActive = selectedServerId === LOCAL_OPENCODE_SERVER_ID
|
||||
|
||||
if (isLoading || enabledServers.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (variant === 'rail') {
|
||||
return (
|
||||
<div className="flex flex-col gap-1 px-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => selectServer(LOCAL_OPENCODE_SERVER_ID)}
|
||||
title="Local"
|
||||
aria-pressed={localActive}
|
||||
aria-current={localActive ? 'true' : undefined}
|
||||
className={railClassName(localActive)}
|
||||
>
|
||||
<Laptop className="h-5 w-5 shrink-0" />
|
||||
<span className="sr-only">Local</span>
|
||||
</button>
|
||||
{enabledServers.map((server) => {
|
||||
const active = selectedServerId === server.id
|
||||
|
||||
return (
|
||||
<button
|
||||
key={server.id}
|
||||
type="button"
|
||||
onClick={() => selectServer(server.id)}
|
||||
title={server.name}
|
||||
aria-pressed={active}
|
||||
aria-current={active ? 'true' : undefined}
|
||||
className={railClassName(active)}
|
||||
>
|
||||
<Server className="h-5 w-5 shrink-0" />
|
||||
<span className="sr-only">{server.name}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rows = [
|
||||
<LocalServerRow
|
||||
key={LOCAL_OPENCODE_SERVER_ID}
|
||||
variant={variant}
|
||||
active={localActive}
|
||||
onSelect={() => selectServer(LOCAL_OPENCODE_SERVER_ID)}
|
||||
/>,
|
||||
...enabledServers.map((server) => (
|
||||
<LinkedServerRow
|
||||
key={server.id}
|
||||
server={server}
|
||||
variant={variant}
|
||||
active={selectedServerId === server.id}
|
||||
connected={statusById[server.id]?.connected ?? false}
|
||||
onSelect={() => selectServer(server.id)}
|
||||
/>
|
||||
)),
|
||||
]
|
||||
|
||||
if (variant === 'sheet') {
|
||||
return (
|
||||
<section aria-label="Servers" className="flex flex-col border-b border-border pb-1">
|
||||
<h2 className="px-4 pt-2 pb-0.5 text-xs font-medium uppercase tracking-wider text-muted-foreground">
|
||||
Servers
|
||||
</h2>
|
||||
{rows}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
const selectedServer = enabledServers.find((server) => server.id === selectedServerId)
|
||||
const localActive = selectedServerId === LOCAL_OPENCODE_SERVER_ID
|
||||
const selectedName = localActive ? 'Local' : selectedServer?.name ?? 'Local'
|
||||
const isRail = variant === 'rail'
|
||||
const connectionConnected = statusById[selectedServerId]?.connected ?? false
|
||||
|
||||
return (
|
||||
<SidebarSection label="Servers" collapsed={false}>
|
||||
{rows}
|
||||
</SidebarSection>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Switch server, current: ${selectedName}`}
|
||||
className={cn(
|
||||
'flex items-center rounded-md text-sm text-foreground transition-colors duration-150',
|
||||
'hover:bg-accent/50',
|
||||
'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' : 'h-9 w-full gap-2 px-2',
|
||||
)}
|
||||
>
|
||||
<span className="relative flex shrink-0">
|
||||
{localActive ? <Laptop className="h-4 w-4" /> : <Server className="h-4 w-4" />}
|
||||
<OtherServersAttention servers={enabledServers} selectedServerId={selectedServerId} />
|
||||
</span>
|
||||
{!isRail && <span className="min-w-0 flex-1 truncate text-left">{selectedName}</span>}
|
||||
{!isRail &&
|
||||
(localActive ? (
|
||||
<LocalActivityIndicator />
|
||||
) : (
|
||||
<ServerActivityIndicator serverId={selectedServerId} />
|
||||
))}
|
||||
{!isRail && !localActive && <ServerConnectionDot connected={connectionConnected} />}
|
||||
{!isRail && <ChevronDown className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />}
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<LinkedServersMenuContent
|
||||
servers={enabledServers}
|
||||
selectedServerId={selectedServerId}
|
||||
statusById={statusById}
|
||||
onSelect={selectServer}
|
||||
/>
|
||||
</DropdownMenu>
|
||||
)
|
||||
}
|
||||
@@ -194,6 +194,97 @@ describe('MobileTabBar', () => {
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/assistant')
|
||||
})
|
||||
|
||||
it('renders global tabs on a linked server page without the local Files tab', () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={['/servers/srv_kitchen']}>
|
||||
<MobileTabBar />
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
const labels = screen.getAllByRole('button').map((button) => button.textContent)
|
||||
expect(labels).toEqual(['Repos', 'Assistant', 'Schedules', 'More'])
|
||||
expect(screen.queryByText('Files')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Git')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders global tabs with Git on a linked server project page', () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={['/servers/srv_kitchen/projects?directory=%2Fhome%2Fme%2Fapp']}>
|
||||
<MobileTabBar />
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
const labels = screen.getAllByRole('button').map((button) => button.textContent)
|
||||
expect(labels).toEqual(['Repos', 'Git', 'Assistant', 'More'])
|
||||
expect(screen.queryByText('Files')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Schedules')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens the remote source control dialog from the Git tab on a linked server project page', async () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={['/servers/srv_kitchen/projects?directory=%2Fhome%2Fme%2Fapp']}>
|
||||
<Routes>
|
||||
<Route path="*" element={<>
|
||||
<MobileTabBar />
|
||||
<LocationSpy />
|
||||
</>} />
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Git' }))
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/servers/srv_kitchen/projects')
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('directory=%2Fhome%2Fme%2Fapp')
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('dialog=sourceControl')
|
||||
})
|
||||
|
||||
it('opens the repos sheet from the Repos tab on a linked server page', async () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
const user = userEvent.setup()
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={['/servers/srv_kitchen']}>
|
||||
<Routes>
|
||||
<Route path="*" element={<>
|
||||
<MobileTabBar />
|
||||
<LocationSpy />
|
||||
</>} />
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Repos' }))
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('mobileTab=repos')
|
||||
})
|
||||
|
||||
it('does not render tab bar on a linked server session path', () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
const { container } = render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={['/servers/srv_kitchen/sessions/ses_remote']}>
|
||||
<MobileTabBar />
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders schedule tabs on /repos/:id/schedules path', () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
|
||||
@@ -7,7 +7,12 @@ import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { useScheduleUrlState, type ScheduleTab } from '@/hooks/useScheduleUrlState'
|
||||
import { useUnreadScheduleRuns } from '@/hooks/useSchedules'
|
||||
import { getAssistantPath, isAssistantPath, parseRepoRoute } from '@/lib/navigation'
|
||||
import {
|
||||
getAssistantPath,
|
||||
isAssistantPath,
|
||||
parseRepoRoute,
|
||||
parseServerProjectRoute,
|
||||
} from '@/lib/navigation'
|
||||
import { openDialogParam } from '@/hooks/useDialogParam'
|
||||
|
||||
interface TabDef {
|
||||
@@ -27,50 +32,75 @@ interface GlobalTabsArgs {
|
||||
navigate: ReturnType<typeof useNavigate>
|
||||
isInsideRepo: boolean
|
||||
repoId: number | null
|
||||
serverScope: ServerRouteScope
|
||||
updateParams: ReturnType<typeof useUrlParams>['updateParams']
|
||||
unreadScheduleCount: number
|
||||
}
|
||||
|
||||
type TabBarMode = 'hidden' | 'global' | 'schedule'
|
||||
|
||||
type ServerRouteScope = 'server' | 'project' | null
|
||||
|
||||
interface MobileTabRouteState {
|
||||
mode: TabBarMode
|
||||
isInsideRepo: boolean
|
||||
repoId: number | null
|
||||
serverScope: ServerRouteScope
|
||||
}
|
||||
|
||||
function getMobileTabRouteState(pathname: string): MobileTabRouteState {
|
||||
const SERVER_PAGE_PATH = /^\/servers\/[^/]+$/
|
||||
const SERVER_PROJECT_PAGE_PATH = /^\/servers\/[^/]+\/projects$/
|
||||
|
||||
function getServerRouteScope(pathname: string, search: string): ServerRouteScope {
|
||||
if (SERVER_PROJECT_PAGE_PATH.test(pathname)) {
|
||||
return parseServerProjectRoute(pathname, search) ? 'project' : 'server'
|
||||
}
|
||||
if (SERVER_PAGE_PATH.test(pathname)) {
|
||||
return 'server'
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function getMobileTabRouteState(pathname: string, search: string): MobileTabRouteState {
|
||||
if (isAssistantPath(pathname)) {
|
||||
return { mode: 'global', isInsideRepo: false, repoId: null }
|
||||
return { mode: 'global', isInsideRepo: false, repoId: null, serverScope: null }
|
||||
}
|
||||
|
||||
if (pathname === '/' || pathname === '/schedules') {
|
||||
return { mode: 'global', isInsideRepo: false, repoId: null, serverScope: null }
|
||||
}
|
||||
|
||||
const serverScope = getServerRouteScope(pathname, search)
|
||||
if (serverScope === 'server' || serverScope === 'project') {
|
||||
return { mode: 'global', isInsideRepo: false, repoId: null, serverScope }
|
||||
}
|
||||
|
||||
const { repoId, section: repoSection } = parseRepoRoute(pathname)
|
||||
|
||||
if (pathname === '/' || pathname === '/schedules') {
|
||||
return { mode: 'global', isInsideRepo: false, repoId: null }
|
||||
}
|
||||
|
||||
if (repoId === null) {
|
||||
return { mode: 'hidden', isInsideRepo: false, repoId: null }
|
||||
return { mode: 'hidden', isInsideRepo: false, repoId: null, serverScope: null }
|
||||
}
|
||||
|
||||
switch (repoSection) {
|
||||
case null:
|
||||
return { mode: 'global', isInsideRepo: true, repoId }
|
||||
return { mode: 'global', isInsideRepo: true, repoId, serverScope: null }
|
||||
case 'schedules':
|
||||
return { mode: 'schedule', isInsideRepo: true, repoId }
|
||||
return { mode: 'schedule', isInsideRepo: true, repoId, serverScope: null }
|
||||
default:
|
||||
return { mode: 'hidden', isInsideRepo: false, repoId }
|
||||
return { mode: 'hidden', isInsideRepo: false, repoId, serverScope: null }
|
||||
}
|
||||
}
|
||||
|
||||
function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideRepo, repoId, updateParams, unreadScheduleCount }: GlobalTabsArgs): TabDef[] {
|
||||
function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideRepo, repoId, serverScope, updateParams, unreadScheduleCount }: GlobalTabsArgs): TabDef[] {
|
||||
const openRepoDialog = (dialog: string) => {
|
||||
openDialogParam(updateParams, dialog)
|
||||
}
|
||||
|
||||
const inRepo = isInsideRepo && repoId !== null
|
||||
const inServerRoute = serverScope !== null
|
||||
const filesAreScoped = inRepo || isAssistantPath(pathname)
|
||||
const showsGit = inRepo || serverScope === 'project'
|
||||
const showsSchedules = !inRepo && serverScope !== 'project'
|
||||
|
||||
const handleFilesClick = () => {
|
||||
if (filesAreScoped) {
|
||||
@@ -93,14 +123,16 @@ function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideR
|
||||
onClick: () => open('repos'),
|
||||
active: openSheet === 'repos' || (pathname === '/' && !openSheet),
|
||||
},
|
||||
{
|
||||
key: 'files',
|
||||
label: 'Files',
|
||||
icon: FolderOpen,
|
||||
onClick: handleFilesClick,
|
||||
active: openSheet === 'files',
|
||||
},
|
||||
...(inRepo
|
||||
...(!inServerRoute
|
||||
? [{
|
||||
key: 'files',
|
||||
label: 'Files',
|
||||
icon: FolderOpen,
|
||||
onClick: handleFilesClick,
|
||||
active: openSheet === 'files',
|
||||
}]
|
||||
: []),
|
||||
...(showsGit
|
||||
? [{
|
||||
key: 'source-control',
|
||||
label: 'Git',
|
||||
@@ -116,7 +148,7 @@ function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideR
|
||||
onClick: handleAssistantClick,
|
||||
active: isAssistantPath(pathname) && !openSheet,
|
||||
},
|
||||
...(!inRepo
|
||||
...(showsSchedules
|
||||
? [{
|
||||
key: 'schedules',
|
||||
label: 'Schedules',
|
||||
@@ -198,14 +230,14 @@ const TabBarRow = memo(function TabBarRow({ tabs }: TabBarRowProps) {
|
||||
})
|
||||
|
||||
export const MobileTabBar = memo(function MobileTabBar() {
|
||||
const { pathname } = useLocation()
|
||||
const { pathname, search } = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const { openSheet, open, close } = useMobileTabBar()
|
||||
const { updateParams } = useUrlParams()
|
||||
const { scheduleTab, setScheduleTab } = useScheduleUrlState()
|
||||
const { data: unreadRuns } = useUnreadScheduleRuns()
|
||||
const isMobile = useMobile()
|
||||
const routeState = useMemo(() => getMobileTabRouteState(pathname), [pathname])
|
||||
const routeState = useMemo(() => getMobileTabRouteState(pathname, search), [pathname, search])
|
||||
const unreadScheduleCount = unreadRuns?.total ?? 0
|
||||
|
||||
const tabs = useMemo<TabDef[]>(
|
||||
@@ -219,6 +251,7 @@ export const MobileTabBar = memo(function MobileTabBar() {
|
||||
navigate,
|
||||
isInsideRepo: routeState.isInsideRepo,
|
||||
repoId: routeState.repoId,
|
||||
serverScope: routeState.serverScope,
|
||||
updateParams,
|
||||
unreadScheduleCount,
|
||||
})),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, it, expect, vi } from 'vitest'
|
||||
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
@@ -990,7 +991,8 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
expect(handleClose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders the Servers group with enabled linked servers', async () => {
|
||||
it('renders the server switcher when enabled linked servers exist', async () => {
|
||||
const user = userEvent.setup()
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
setLinkedServers([
|
||||
createLinkedServer('srv_kitchen', 'Kitchen'),
|
||||
@@ -999,13 +1001,18 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
|
||||
render(<RepoQuickSwitchSheet isOpen onClose={vi.fn()} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Servers' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: /Kitchen/ })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /Office/ })).not.toBeInTheDocument()
|
||||
const trigger = await screen.findByRole('button', { name: 'Switch server, current: Local' })
|
||||
expect(trigger).toBeInTheDocument()
|
||||
expect(screen.queryByRole('heading', { name: 'Servers' })).not.toBeInTheDocument()
|
||||
|
||||
await user.click(trigger)
|
||||
|
||||
expect(await screen.findByRole('menuitem', { name: /Kitchen/ })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('menuitem', { name: /Office/ })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('img', { name: 'Connected' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides the Servers group when no linked servers exist', async () => {
|
||||
it('hides the server switcher when no linked servers exist', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
|
||||
render(<RepoQuickSwitchSheet isOpen onClose={vi.fn()} />, { wrapper: createWrapper() })
|
||||
@@ -1014,10 +1021,11 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('heading', { name: 'Servers' })).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: /Switch server/ })).toBeNull()
|
||||
})
|
||||
|
||||
it('switches to a linked server without navigating or closing the sheet', async () => {
|
||||
const user = userEvent.setup()
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
vi.mocked(listProjects).mockResolvedValue([createProject('p1', 'Alpha', '/projects/alpha')])
|
||||
setLinkedServers([createLinkedServer('srv_kitchen', 'Kitchen')])
|
||||
@@ -1041,7 +1049,8 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: /Kitchen/ }))
|
||||
await user.click(await screen.findByRole('button', { name: 'Switch server, current: Local' }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Kitchen/ }))
|
||||
|
||||
expect(await screen.findByText('Alpha')).toBeInTheDocument()
|
||||
expect(screen.queryByText('repo1')).not.toBeInTheDocument()
|
||||
@@ -1051,6 +1060,7 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
})
|
||||
|
||||
it('opens a remote project from the sheet and closes it', async () => {
|
||||
const user = userEvent.setup()
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
vi.mocked(listProjects).mockResolvedValue([createProject('p1', 'Alpha', '/projects/alpha')])
|
||||
setLinkedServers([createLinkedServer('srv_kitchen', 'Kitchen')])
|
||||
@@ -1074,8 +1084,9 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: /Kitchen/ }))
|
||||
fireEvent.click(await screen.findByRole('button', { name: /^Alpha/ }))
|
||||
await user.click(await screen.findByRole('button', { name: 'Switch server, current: Local' }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Kitchen/ }))
|
||||
await user.click(await screen.findByRole('button', { name: /^Alpha/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_kitchen/projects?directory=%2Fprojects%2Falpha',
|
||||
|
||||
@@ -104,7 +104,11 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
</div>
|
||||
</BottomSheetHeader>
|
||||
<BottomSheetContent className="flex flex-col px-0 pt-0 gap-0">
|
||||
{isOpen && <LinkedServersNav variant="sheet" />}
|
||||
{isOpen && (
|
||||
<div className="px-2 pt-1">
|
||||
<LinkedServersNav variant="sheet" />
|
||||
</div>
|
||||
)}
|
||||
{isOpen && !searchQuery.trim() && (
|
||||
<CompactActivityList onNavigate={(path) => navigateAndClose(path)} />
|
||||
)}
|
||||
|
||||
@@ -792,7 +792,14 @@ export function SessionDetail() {
|
||||
onChange={handleRenameSession}
|
||||
subtitle={
|
||||
<span className="text-highlight">
|
||||
{workspaceDisplayName}
|
||||
{isRemoteServer ? (
|
||||
<>
|
||||
<span className="text-info">{linkedServer?.name ?? 'Linked server'}</span>
|
||||
{sessionDirectory && ` · ${getDirectoryName(sessionDirectory)}`}
|
||||
</>
|
||||
) : (
|
||||
workspaceDisplayName
|
||||
)}
|
||||
{sessionBranch && <span className="font-mono sm:hidden"> · {sessionBranch}</span>}
|
||||
</span>
|
||||
}
|
||||
@@ -823,7 +830,7 @@ export function SessionDetail() {
|
||||
isReconnecting={streamReconnecting}
|
||||
revertMessageID={revertMessageID}
|
||||
/>
|
||||
{!isRemoteServer && <SessionMoreButton />}
|
||||
<SessionMoreButton />
|
||||
</Header.Actions>
|
||||
</Header>
|
||||
|
||||
|
||||
@@ -266,8 +266,9 @@ describe('SessionDetail remote server mode', () => {
|
||||
renderRemoteSession()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Kitchen · app')).toBeInTheDocument()
|
||||
expect(screen.getByText('Kitchen')).toHaveClass('text-info')
|
||||
})
|
||||
expect(screen.getByText('Kitchen').parentElement).toHaveTextContent('Kitchen · app')
|
||||
})
|
||||
|
||||
it('uses the session directory as the only directory source', async () => {
|
||||
@@ -293,12 +294,22 @@ describe('SessionDetail remote server mode', () => {
|
||||
expect(mocks.RepoActionsDialog).not.toHaveBeenCalled()
|
||||
expect(mocks.ResetPermissionsDialog).not.toHaveBeenCalled()
|
||||
expect(mocks.ChangesWalkthroughSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.SessionMoreButton).not.toHaveBeenCalled()
|
||||
expect(mocks.SessionMoreButton).toHaveBeenCalled()
|
||||
expect(vi.mocked(PendingActionsGroup).mock.calls.at(-1)?.[0]).toEqual(
|
||||
expect.objectContaining({ showScheduleReports: false }),
|
||||
)
|
||||
})
|
||||
|
||||
it('renders the More button so the drawer stays reachable on a remote session', async () => {
|
||||
renderRemoteSession()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('message-thread')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(mocks.SessionMoreButton).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows the session goal bar for a remote session', async () => {
|
||||
renderRemoteSession()
|
||||
|
||||
|
||||
Reference in new issue
Block a user