feat(servers): show linked server projects on the home page and remove the server page

The home page follows the sidebar server selection and lists a linked server's projects with the same cards, search and row actions as local repositories. /servers/:id now selects that server and redirects home. Back from a remote session goes to its project page and back from a project goes home, and the selection follows the route app-wide so mobile keeps the linked server.
This commit is contained in:
Chris Scott committed 2026-10-19 15:01:48 -04:00
1 parent c1e09f34a5
commit c18c3584ef
32 files changed
+1576 -789

No files matched your search

@@ -4,6 +4,7 @@ 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'
import { useSidebarServerRouteSync } from '@/hooks/useSidebarServerSelection'
import { useSidebarServerStore } from '@/stores/sidebarServerStore'
const mocks = vi.hoisted(() => ({
@@ -41,9 +42,15 @@ function LocationDisplay() {
return <div data-testid="location">{`${location.pathname}${location.search}`}</div>
}
function SidebarServerRouteSync() {
useSidebarServerRouteSync()
return null
}
function renderNav(pathname = '/', variant?: 'sidebar' | 'rail' | 'sheet') {
return render(
<MemoryRouter initialEntries={[pathname]}>
<SidebarServerRouteSync />
<LinkedServersNav variant={variant} />
<LocationDisplay />
</MemoryRouter>,
@@ -13,8 +13,10 @@ import userEvent from '@testing-library/user-event'
import { describe, it, expect, beforeEach } from 'vitest'
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
import { MobileTabBar } from './MobileTabBar'
import { useMobile } from '@/hooks/useMobile'
import { useSidebarServerStore } from '@/stores/sidebarServerStore'
function LocationSpy() {
const { pathname, search } = useLocation()
@@ -24,6 +26,8 @@ function LocationSpy() {
describe('MobileTabBar', () => {
beforeEach(() => {
vi.clearAllMocks()
localStorage.clear()
useSidebarServerStore.setState({ serverId: LOCAL_OPENCODE_SERVER_ID })
})
it('renders nothing when useMobile returns false', () => {
@@ -194,20 +198,17 @@ describe('MobileTabBar', () => {
expect(screen.getByTestId('location')).toHaveTextContent('/assistant')
})
it('renders global tabs on a linked server page without the local Files tab', () => {
it('hides the tab bar on a linked server page path', () => {
vi.mocked(useMobile).mockReturnValue(true)
const queryClient = new QueryClient()
render(
const { container } = 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()
expect(container.firstChild).toBeNull()
})
it('renders global tabs with Git on a linked server project page', () => {
@@ -250,14 +251,14 @@ describe('MobileTabBar', () => {
expect(screen.getByTestId('location')).toHaveTextContent('dialog=sourceControl')
})
it('opens the repos sheet from the Repos tab on a linked server page', async () => {
it('opens the repos sheet from the Repos 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']}>
<MemoryRouter initialEntries={['/servers/srv_kitchen/projects?directory=%2Fhome%2Fme%2Fapp']}>
<Routes>
<Route path="*" element={<>
<MobileTabBar />
@@ -319,6 +320,22 @@ describe('MobileTabBar', () => {
expect(screen.queryByText('Git')).not.toBeInTheDocument()
})
it('hides the Files tab on the home page when a linked server is selected', () => {
vi.mocked(useMobile).mockReturnValue(true)
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
const queryClient = new QueryClient()
render(
<QueryClientProvider client={queryClient}>
<MemoryRouter initialEntries={['/']}>
<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()
})
it('renders tab bar on /schedules path', () => {
vi.mocked(useMobile).mockReturnValue(true)
const queryClient = new QueryClient()
@@ -7,6 +7,8 @@ import { useMobileTabBar } from '@/hooks/useMobileTabBar'
import { useUrlParams } from '@/hooks/useUrlParams'
import { useScheduleUrlState, type ScheduleTab } from '@/hooks/useScheduleUrlState'
import { useUnreadScheduleRuns } from '@/hooks/useSchedules'
import { useSidebarServerSelection } from '@/hooks/useSidebarServerSelection'
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
import {
getAssistantPath,
isAssistantPath,
@@ -35,11 +37,12 @@ interface GlobalTabsArgs {
serverScope: ServerRouteScope
updateParams: ReturnType<typeof useUrlParams>['updateParams']
unreadScheduleCount: number
localServerSelected: boolean
}
type TabBarMode = 'hidden' | 'global' | 'schedule'
type ServerRouteScope = 'server' | 'project' | null
type ServerRouteScope = 'project' | null
interface MobileTabRouteState {
mode: TabBarMode
@@ -48,17 +51,8 @@ interface MobileTabRouteState {
serverScope: ServerRouteScope
}
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
return parseServerProjectRoute(pathname, search) ? 'project' : null
}
function getMobileTabRouteState(pathname: string, search: string): MobileTabRouteState {
@@ -71,7 +65,7 @@ function getMobileTabRouteState(pathname: string, search: string): MobileTabRout
}
const serverScope = getServerRouteScope(pathname, search)
if (serverScope === 'server' || serverScope === 'project') {
if (serverScope !== null) {
return { mode: 'global', isInsideRepo: false, repoId: null, serverScope }
}
@@ -91,7 +85,7 @@ function getMobileTabRouteState(pathname: string, search: string): MobileTabRout
}
}
function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideRepo, repoId, serverScope, updateParams, unreadScheduleCount }: GlobalTabsArgs): TabDef[] {
function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideRepo, repoId, serverScope, updateParams, unreadScheduleCount, localServerSelected }: GlobalTabsArgs): TabDef[] {
const openRepoDialog = (dialog: string) => {
openDialogParam(updateParams, dialog)
}
@@ -99,6 +93,7 @@ function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideR
const inRepo = isInsideRepo && repoId !== null
const inServerRoute = serverScope !== null
const filesAreScoped = inRepo || isAssistantPath(pathname)
const showsFiles = !inServerRoute && (filesAreScoped || localServerSelected)
const showsGit = inRepo || serverScope === 'project'
const showsSchedules = !inRepo && serverScope !== 'project'
@@ -123,7 +118,7 @@ function buildGlobalTabs({ pathname, openSheet, open, close, navigate, isInsideR
onClick: () => open('repos'),
active: openSheet === 'repos' || (pathname === '/' && !openSheet),
},
...(!inServerRoute
...(showsFiles
? [{
key: 'files',
label: 'Files',
@@ -237,6 +232,8 @@ export const MobileTabBar = memo(function MobileTabBar() {
const { scheduleTab, setScheduleTab } = useScheduleUrlState()
const { data: unreadRuns } = useUnreadScheduleRuns()
const isMobile = useMobile()
const [selectedServerId] = useSidebarServerSelection()
const localServerSelected = selectedServerId === LOCAL_OPENCODE_SERVER_ID
const routeState = useMemo(() => getMobileTabRouteState(pathname, search), [pathname, search])
const unreadScheduleCount = unreadRuns?.total ?? 0
@@ -254,6 +251,7 @@ export const MobileTabBar = memo(function MobileTabBar() {
serverScope: routeState.serverScope,
updateParams,
unreadScheduleCount,
localServerSelected,
})),
[
routeState,
@@ -266,6 +264,7 @@ export const MobileTabBar = memo(function MobileTabBar() {
navigate,
updateParams,
unreadScheduleCount,
localServerSelected,
],
)