mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
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:
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,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -3,12 +3,28 @@ import { Layers } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { MultiRunSheet } from '@/components/repo/MultiRunSheet'
|
||||
|
||||
interface RemoteMultiRunButtonProps {
|
||||
interface RemoteMultiRunProps {
|
||||
serverId: string
|
||||
directory: string
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
}
|
||||
|
||||
export function RemoteMultiRunButton({ serverId, directory }: RemoteMultiRunButtonProps) {
|
||||
/**
|
||||
* The multi-run sheet for one project on a linked OpenCode server, controlled by its caller.
|
||||
*/
|
||||
export function RemoteMultiRun({ serverId, directory, open, onOpenChange }: RemoteMultiRunProps) {
|
||||
return (
|
||||
<MultiRunSheet
|
||||
target={{ kind: 'server', serverId, directory }}
|
||||
directory={directory}
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function RemoteMultiRunButton({ serverId, directory }: { serverId: string; directory: string }) {
|
||||
const [mounted, setMounted] = useState(false)
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
@@ -24,8 +40,8 @@ export function RemoteMultiRunButton({ serverId, directory }: RemoteMultiRunButt
|
||||
Multi-run
|
||||
</Button>
|
||||
{mounted ? (
|
||||
<MultiRunSheet
|
||||
target={{ kind: 'server', serverId, directory }}
|
||||
<RemoteMultiRun
|
||||
serverId={serverId}
|
||||
directory={directory}
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getRepoDisplayName } from "@/lib/utils";
|
||||
import type { Repo } from "@/api/types";
|
||||
import type { GitStatusResponse } from "@/types/git"
|
||||
import { RepoActivityIndicator } from "@/components/activity/RepoActivityIndicator"
|
||||
import { RepoCardShell } from "./RepoCardShell"
|
||||
import { RepoRowActions } from "./RepoRowActions"
|
||||
|
||||
interface RepoCardProps {
|
||||
@@ -58,90 +59,65 @@ export function RepoCard({
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={handleCardClick}
|
||||
className={`relative border rounded-xl overflow-hidden transition-all duration-200 w-full ${
|
||||
isReady ? "cursor-pointer active:scale-[0.98] hover:border-primary/50 hover:bg-accent/50 hover:shadow-md" : "cursor-default"
|
||||
} ${
|
||||
isSelected
|
||||
? "border-primary bg-primary/5"
|
||||
: "border-border bg-card"
|
||||
}`}
|
||||
>
|
||||
<div className="p-1.5">
|
||||
<div>
|
||||
<div className="flex items-start gap-2 mb-1">
|
||||
<div className="flex items-center gap-2 min-w-0 flex-1">
|
||||
<h3 className="font-semibold text-base text-foreground truncate">
|
||||
{repoName}
|
||||
</h3>
|
||||
{isReady && (
|
||||
<div className={`w-2 h-2 rounded-full shrink-0 ${isDirty ? 'bg-highlight' : 'bg-success'}`} />
|
||||
)}
|
||||
<RepoActivityIndicator repo={repo} />
|
||||
</div>
|
||||
|
||||
{!manageMode && !isSelected && !hasSelectedRepos && (
|
||||
<RepoRowActions
|
||||
repo={repo}
|
||||
gitStatus={gitStatus}
|
||||
onDelete={onDelete}
|
||||
isDeleting={isDeleting}
|
||||
isMobile={isMobile}
|
||||
onActionsOpenChange={setActionsOpen}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<div className="flex flex-1 items-center gap-2 min-w-0 overflow-hidden">
|
||||
{isCloning ? (
|
||||
<span className="flex items-center gap-1.5">
|
||||
<Loader2 className="w-3.5 h-3.5 animate-spin text-primary" />
|
||||
Cloning...
|
||||
</span>
|
||||
) : (
|
||||
<>
|
||||
<span className={`flex items-center gap-1 shrink-0 ${repo.isWorktree ? 'text-primary' : ''}`}>
|
||||
<GitBranch className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate max-w-[80px]">{branchToDisplay || "main"}</span>
|
||||
</span>
|
||||
{isDirty && (
|
||||
<span className="flex items-center gap-1 text-highlight shrink-0">
|
||||
<AlertCircle className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="text-xs whitespace-nowrap">
|
||||
{unstagedCount > 0 && unstagedCount}
|
||||
{unstagedCount > 0 && stagedCount > 0 && "/"}
|
||||
{stagedCount > 0 && `${stagedCount}s`}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
{(ahead > 0 || behind > 0) && (
|
||||
<span className="flex items-center gap-1 text-info shrink-0">
|
||||
<span className="text-xs whitespace-nowrap">
|
||||
{ahead > 0 && `↑${ahead}`}
|
||||
{behind > 0 && `↓${behind}`}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
{repo.isLocal && (
|
||||
<span className="flex items-center gap-1 shrink-0">
|
||||
<FolderOpen className="w-3.5 h-3.5 shrink-0" />
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{activityLabel && (
|
||||
<span className="text-xs text-muted-foreground/70 shrink-0">
|
||||
{activityLabel}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
const meta = isCloning ? (
|
||||
<span className="flex items-center gap-1.5">
|
||||
<Loader2 className="w-3.5 h-3.5 animate-spin text-primary" />
|
||||
Cloning...
|
||||
</span>
|
||||
) : (
|
||||
<>
|
||||
<span className={`flex items-center gap-1 shrink-0 ${repo.isWorktree ? 'text-primary' : ''}`}>
|
||||
<GitBranch className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate max-w-[80px]">{branchToDisplay || "main"}</span>
|
||||
</span>
|
||||
{isDirty && (
|
||||
<span className="flex items-center gap-1 text-highlight shrink-0">
|
||||
<AlertCircle className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="text-xs whitespace-nowrap">
|
||||
{unstagedCount > 0 && unstagedCount}
|
||||
{unstagedCount > 0 && stagedCount > 0 && "/"}
|
||||
{stagedCount > 0 && `${stagedCount}s`}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
{(ahead > 0 || behind > 0) && (
|
||||
<span className="flex items-center gap-1 text-info shrink-0">
|
||||
<span className="text-xs whitespace-nowrap">
|
||||
{ahead > 0 && `↑${ahead}`}
|
||||
{behind > 0 && `↓${behind}`}
|
||||
</span>
|
||||
</span>
|
||||
)}
|
||||
{repo.isLocal && (
|
||||
<span className="flex items-center gap-1 shrink-0">
|
||||
<FolderOpen className="w-3.5 h-3.5 shrink-0" />
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<RepoCardShell
|
||||
title={repoName}
|
||||
statusDotClassName={isReady ? (isDirty ? 'bg-highlight' : 'bg-success') : undefined}
|
||||
activity={<RepoActivityIndicator repo={repo} />}
|
||||
actions={
|
||||
!manageMode && !isSelected && !hasSelectedRepos ? (
|
||||
<RepoRowActions
|
||||
repo={repo}
|
||||
gitStatus={gitStatus}
|
||||
onDelete={onDelete}
|
||||
isDeleting={isDeleting}
|
||||
isMobile={isMobile}
|
||||
onActionsOpenChange={setActionsOpen}
|
||||
/>
|
||||
) : undefined
|
||||
}
|
||||
meta={meta}
|
||||
activityLabel={activityLabel}
|
||||
isInteractive={isReady}
|
||||
isSelected={isSelected}
|
||||
onClick={handleCardClick}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
interface RepoCardShellProps {
|
||||
title: string;
|
||||
meta: ReactNode;
|
||||
statusDotClassName?: string;
|
||||
activity?: ReactNode;
|
||||
actions?: ReactNode;
|
||||
activityLabel?: string;
|
||||
isInteractive?: boolean;
|
||||
isSelected?: boolean;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
export function RepoCardShell({
|
||||
title,
|
||||
meta,
|
||||
statusDotClassName,
|
||||
activity,
|
||||
actions,
|
||||
activityLabel,
|
||||
isInteractive = false,
|
||||
isSelected = false,
|
||||
onClick,
|
||||
}: RepoCardShellProps) {
|
||||
return (
|
||||
<div
|
||||
onClick={onClick}
|
||||
className={`relative border rounded-xl overflow-hidden transition-all duration-200 w-full ${
|
||||
isInteractive ? "cursor-pointer active:scale-[0.98] hover:border-primary/50 hover:bg-accent/50 hover:shadow-md" : "cursor-default"
|
||||
} ${
|
||||
isSelected ? "border-primary bg-primary/5" : "border-border bg-card"
|
||||
}`}
|
||||
>
|
||||
<div className="p-1.5">
|
||||
<div>
|
||||
<div className="flex items-start gap-2 mb-1">
|
||||
<div className="flex items-center gap-2 min-w-0 flex-1">
|
||||
<h3 className="font-semibold text-base text-foreground truncate">
|
||||
{title}
|
||||
</h3>
|
||||
{statusDotClassName && (
|
||||
<div className={`w-2 h-2 rounded-full shrink-0 ${statusDotClassName}`} />
|
||||
)}
|
||||
{activity}
|
||||
</div>
|
||||
|
||||
{actions}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<div className="flex flex-1 items-center gap-2 min-w-0 overflow-hidden">
|
||||
{meta}
|
||||
</div>
|
||||
|
||||
{activityLabel && (
|
||||
<span className="text-xs text-muted-foreground/70 shrink-0">
|
||||
{activityLabel}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { Search, SlidersHorizontal, Trash2, X } from "lucide-react";
|
||||
import { SlidersHorizontal, Trash2, X } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { RepoSearchInput } from "./RepoSearchInput";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -120,17 +120,7 @@ export function RepoListControls({
|
||||
return (
|
||||
<div className="px-2 md:px-0 space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
||||
<Input
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
placeholder="Search repositories..."
|
||||
className="pl-9 h-9"
|
||||
autoComplete="off"
|
||||
name="repo-search"
|
||||
/>
|
||||
</div>
|
||||
<RepoSearchInput value={searchQuery} onValueChange={onSearchChange} />
|
||||
|
||||
{isMobile ? (
|
||||
<DropdownMenu open={showMenu} onOpenChange={setShowMenu}>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Search } from "lucide-react";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
interface RepoSearchInputProps {
|
||||
value: string;
|
||||
onValueChange: (query: string) => void;
|
||||
placeholder?: string;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export function RepoSearchInput({
|
||||
value,
|
||||
onValueChange,
|
||||
placeholder = "Search repositories...",
|
||||
name = "repo-search",
|
||||
}: RepoSearchInputProps) {
|
||||
return (
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
||||
<Input
|
||||
value={value}
|
||||
onChange={(event) => onValueChange(event.target.value)}
|
||||
placeholder={placeholder}
|
||||
className="pl-9 h-9"
|
||||
autoComplete="off"
|
||||
name={name}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,17 +4,27 @@ import { Button } from '@/components/ui/button'
|
||||
import type { ScheduleServerTarget } from '@/api/schedules'
|
||||
import { ServerSchedulesDialog } from './ServerSchedulesDialog'
|
||||
|
||||
interface RemoteSchedulesButtonProps {
|
||||
interface RemoteSchedulesDialogProps {
|
||||
serverId: string
|
||||
directory: string
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
}
|
||||
|
||||
/**
|
||||
* The schedule list for one project on a linked OpenCode server, controlled by its caller.
|
||||
*/
|
||||
export function RemoteSchedulesDialog({ serverId, directory, open, onOpenChange }: RemoteSchedulesDialogProps) {
|
||||
const target: ScheduleServerTarget = { serverId, directory }
|
||||
|
||||
return <ServerSchedulesDialog open={open} onOpenChange={onOpenChange} target={target} />
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the schedule list for one project on a linked OpenCode server.
|
||||
*/
|
||||
export function RemoteSchedulesButton({ serverId, directory }: RemoteSchedulesButtonProps) {
|
||||
export function RemoteSchedulesButton({ serverId, directory }: { serverId: string; directory: string }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const target: ScheduleServerTarget = { serverId, directory }
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -28,7 +38,12 @@ export function RemoteSchedulesButton({ serverId, directory }: RemoteSchedulesBu
|
||||
<CalendarClock className="mr-1 h-4 w-4" />
|
||||
<span className="hidden sm:inline">Schedules</span>
|
||||
</Button>
|
||||
<ServerSchedulesDialog open={open} onOpenChange={setOpen} target={target} />
|
||||
<RemoteSchedulesDialog
|
||||
serverId={serverId}
|
||||
directory={directory}
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { OpenCodeServerStatus } from '@opencode-manager/shared/schemas'
|
||||
|
||||
interface ConnectionStatusProps {
|
||||
status?: OpenCodeServerStatus
|
||||
isLoading: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Connection indicator for a linked server: checking, unknown, unreachable with its error, or
|
||||
* connected with the server version.
|
||||
*/
|
||||
export function ConnectionStatus({ status, isLoading }: ConnectionStatusProps) {
|
||||
if (isLoading) {
|
||||
return <span className="text-xs text-muted-foreground">Checking connection...</span>
|
||||
}
|
||||
|
||||
if (!status) {
|
||||
return (
|
||||
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||
<span className="h-2 w-2 rounded-full bg-muted-foreground/50" />
|
||||
Unknown
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
if (!status.connected) {
|
||||
return (
|
||||
<span className="flex items-center gap-1.5 text-xs text-destructive" title={status.error ?? undefined}>
|
||||
<span className="h-2 w-2 rounded-full bg-destructive" />
|
||||
Unreachable
|
||||
{status.error ? <span className="text-muted-foreground">· {status.error}</span> : null}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<span className="flex items-center gap-1.5 text-xs text-success">
|
||||
<span className="h-2 w-2 rounded-full bg-success" />
|
||||
Connected
|
||||
{status.version ? <span className="text-muted-foreground">· v{status.version}</span> : null}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
import { useMemo, useState, type FormEvent } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { Folder, FolderGit2, GitBranch, Loader2, Plus, Search, Server } from 'lucide-react'
|
||||
import { listProjects, type OpenCodeProject } from '@/api/opencode'
|
||||
import { useCreateSession } from '@/hooks/useOpenCode'
|
||||
import { useOpenCodeServers } from '@/hooks/useOpenCodeServers'
|
||||
import { useSettingsDialog } from '@/hooks/useSettingsDialog'
|
||||
import { useProjectActivityState } from '@/hooks/useActiveWork'
|
||||
import { serverScopedKey } from '@/lib/serverScope'
|
||||
import { getServerProjectPath, getServerSessionPath } from '@/lib/navigation'
|
||||
import { formatShortRelativeTime, getDirectoryName } from '@/lib/utils'
|
||||
import { OpenCodeServerProvider } from '@/contexts/OpenCodeServerContext'
|
||||
import { ActivityStateIndicator } from '@/components/activity/ActivityStateIndicator'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { LinkedServerStateCard } from '@/components/servers/LinkedServerStateCard'
|
||||
import { RemoteProjectRowActions } from '@/components/servers/RemoteProjectRowActions'
|
||||
import { RepoCardShell } from '@/components/repo/RepoCardShell'
|
||||
import { RepoCardSkeleton } from '@/components/repo/RepoCardSkeleton'
|
||||
import { RepoSearchInput } from '@/components/repo/RepoSearchInput'
|
||||
|
||||
function projectName(project: OpenCodeProject): string {
|
||||
return project.name?.trim() || getDirectoryName(project.canonical)
|
||||
}
|
||||
|
||||
function RemoteProjectCard({ project, serverId }: { project: OpenCodeProject; serverId: string }) {
|
||||
const navigate = useNavigate()
|
||||
const activityState = useProjectActivityState(serverId, project.canonical)
|
||||
const updatedAt = project.time.updated
|
||||
|
||||
return (
|
||||
<RepoCardShell
|
||||
title={projectName(project)}
|
||||
statusDotClassName="bg-success"
|
||||
activity={<ActivityStateIndicator state={activityState} />}
|
||||
actions={<RemoteProjectRowActions serverId={serverId} directory={project.canonical} />}
|
||||
meta={
|
||||
<span className="flex items-center gap-1 min-w-0">
|
||||
{project.vcs ? (
|
||||
<GitBranch className="w-3.5 h-3.5 shrink-0" aria-label={project.vcs} />
|
||||
) : (
|
||||
<Folder className="w-3.5 h-3.5 shrink-0" />
|
||||
)}
|
||||
<span className="truncate">{project.canonical}</span>
|
||||
</span>
|
||||
}
|
||||
activityLabel={updatedAt > 0 ? formatShortRelativeTime(new Date(updatedAt)) : undefined}
|
||||
isInteractive
|
||||
onClick={() => navigate(getServerProjectPath(serverId, project.canonical))}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function RemoteProjectListLoading() {
|
||||
return (
|
||||
<div className="flex flex-1 flex-col">
|
||||
<div className="px-2 md:px-0">
|
||||
<div className="h-10 bg-muted/50 animate-pulse rounded w-full" />
|
||||
</div>
|
||||
<div className="mx-2 md:mx-0 flex-1 min-h-0">
|
||||
<div className="h-full overflow-y-auto pt-4 pb-2 md:pb-0">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-2 gap-3 md:gap-4 w-full">
|
||||
{Array.from({ length: 6 }).map((_, index) => (
|
||||
<RepoCardSkeleton key={index} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function RemoteProjectListContent({ serverId }: { serverId: string }) {
|
||||
const navigate = useNavigate()
|
||||
const { servers, isLoading: serversLoading } = useOpenCodeServers()
|
||||
const { openTab } = useSettingsDialog()
|
||||
const createSession = useCreateSession()
|
||||
const [openDirectory, setOpenDirectory] = useState('')
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
|
||||
const server = servers.find((candidate) => candidate.id === serverId)
|
||||
const isDisabled = server !== undefined && !server.enabled
|
||||
|
||||
const projectsQuery = useQuery({
|
||||
queryKey: serverScopedKey(['opencode', 'projects'], serverId),
|
||||
queryFn: () => listProjects(serverId),
|
||||
enabled: server?.enabled === true,
|
||||
retry: false,
|
||||
})
|
||||
|
||||
const projects = useMemo(() => projectsQuery.data ?? [], [projectsQuery.data])
|
||||
|
||||
const filteredProjects = useMemo(() => {
|
||||
const query = searchQuery.trim().toLowerCase()
|
||||
if (!query) return projects
|
||||
|
||||
return projects.filter((project) =>
|
||||
projectName(project).toLowerCase().includes(query) ||
|
||||
project.canonical.toLowerCase().includes(query),
|
||||
)
|
||||
}, [projects, searchQuery])
|
||||
|
||||
const openSettings = () => openTab('servers')
|
||||
|
||||
const handleOpenDirectory = async (event: FormEvent) => {
|
||||
event.preventDefault()
|
||||
const directory = openDirectory.trim()
|
||||
if (!directory) return
|
||||
try {
|
||||
const session = await createSession.mutateAsync({ directory })
|
||||
navigate(getServerSessionPath(serverId, session.id))
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col px-0 md:p-4">
|
||||
{!serversLoading && !server ? (
|
||||
<LinkedServerStateCard
|
||||
icon={Server}
|
||||
title="Server not found"
|
||||
description="This linked server is no longer configured."
|
||||
actionLabel="Open server settings"
|
||||
onAction={openSettings}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{isDisabled ? (
|
||||
<LinkedServerStateCard
|
||||
icon={Server}
|
||||
title="This server is disabled"
|
||||
description="Enable it in Settings → Servers to browse its projects and sessions."
|
||||
actionLabel="Open server settings"
|
||||
onAction={openSettings}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{server && !isDisabled && projectsQuery.isError ? (
|
||||
<Card className="flex flex-col items-center gap-3 p-6 text-center">
|
||||
<Server className="h-8 w-8 text-muted-foreground" />
|
||||
<div>
|
||||
<p className="font-medium">Could not load projects</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{projectsQuery.error instanceof Error
|
||||
? projectsQuery.error.message
|
||||
: 'The server did not respond.'}
|
||||
</p>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" onClick={() => void projectsQuery.refetch()}>
|
||||
Retry
|
||||
</Button>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{server && !isDisabled && !projectsQuery.isError ? (
|
||||
projectsQuery.isLoading ? (
|
||||
<RemoteProjectListLoading />
|
||||
) : projects.length === 0 ? (
|
||||
<div className="flex flex-1 flex-col items-center justify-center p-12 text-center">
|
||||
<FolderGit2 className="w-12 h-12 mx-auto mb-4 text-muted-foreground" />
|
||||
<p className="font-medium">No projects on this server yet</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Start a session in a directory below to create one.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="px-2 md:px-0">
|
||||
<RepoSearchInput
|
||||
value={searchQuery}
|
||||
onValueChange={setSearchQuery}
|
||||
placeholder="Search projects..."
|
||||
name="remote-project-search"
|
||||
/>
|
||||
</div>
|
||||
<div className="mx-2 flex min-h-0 flex-1 md:mx-0">
|
||||
<div className="h-full w-full overflow-y-auto pt-4 md:pb-0 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
{filteredProjects.length === 0 ? (
|
||||
<div className="text-center p-12">
|
||||
<Search className="w-12 h-12 mx-auto mb-4 text-muted-foreground" />
|
||||
<p className="text-muted-foreground">
|
||||
No projects found matching "{searchQuery}"
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-2 gap-3 md:gap-4 w-full md:pb-0">
|
||||
{filteredProjects.map((project) => (
|
||||
<RemoteProjectCard
|
||||
key={project.id}
|
||||
project={project}
|
||||
serverId={serverId}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
) : null}
|
||||
|
||||
{server && !isDisabled ? (
|
||||
<section aria-label="Open directory" className="mt-4 flex shrink-0 flex-col gap-2 px-2 md:px-0">
|
||||
<h2 className="text-xs font-medium uppercase tracking-wider text-muted-foreground">Open directory</h2>
|
||||
<form onSubmit={handleOpenDirectory} className="flex items-center gap-2">
|
||||
<Input
|
||||
value={openDirectory}
|
||||
onChange={(event) => setOpenDirectory(event.target.value)}
|
||||
placeholder="/absolute/path/on/the/server"
|
||||
aria-label="Directory path"
|
||||
autoComplete="off"
|
||||
name="remote-directory"
|
||||
className="font-mono text-sm"
|
||||
/>
|
||||
<Button type="submit" disabled={!openDirectory.trim() || createSession.isPending} className="shrink-0">
|
||||
{createSession.isPending ? (
|
||||
<Loader2 className="mr-1 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Plus className="mr-1 h-4 w-4" />
|
||||
)}
|
||||
Start session
|
||||
</Button>
|
||||
</form>
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The projects of one linked server with their sessions and project actions, scoped to that server
|
||||
* so every hook inside it targets the linked server rather than the local one.
|
||||
*/
|
||||
export function RemoteProjectList({ serverId }: { serverId: string }) {
|
||||
return (
|
||||
<OpenCodeServerProvider serverId={serverId}>
|
||||
<RemoteProjectListContent serverId={serverId} />
|
||||
</OpenCodeServerProvider>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
import { useState, type ReactNode } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { CalendarClock, Layers, Loader2, MoreVertical, Plus } from 'lucide-react'
|
||||
import { useCreateSession } from '@/hooks/useOpenCode'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { getServerSessionPath } from '@/lib/navigation'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { RemoteSchedulesDialog } from '@/components/schedules/RemoteSchedulesButton'
|
||||
import { RemoteMultiRun } from '@/components/repo/RemoteMultiRunButton'
|
||||
|
||||
interface RemoteProjectRowActionsProps {
|
||||
serverId: string
|
||||
directory: string
|
||||
}
|
||||
|
||||
interface ProjectActionButtonProps {
|
||||
label: string
|
||||
onClick: () => void
|
||||
disabled?: boolean
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
function ProjectActionButton({ label, onClick, disabled, children }: ProjectActionButtonProps) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
aria-label={label}
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
className="h-8 w-8 p-0"
|
||||
title={label}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{label}</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The project actions for one remote project: new session, schedules, and multi-run. Desktop shows
|
||||
* inline icon buttons and mobile shows a menu, matching local repository rows.
|
||||
*/
|
||||
export function RemoteProjectRowActions({ serverId, directory }: RemoteProjectRowActionsProps) {
|
||||
const navigate = useNavigate()
|
||||
const isMobile = useMobile()
|
||||
const createSession = useCreateSession(directory)
|
||||
const [schedulesOpen, setSchedulesOpen] = useState(false)
|
||||
const [multiRunMounted, setMultiRunMounted] = useState(false)
|
||||
const [multiRunOpen, setMultiRunOpen] = useState(false)
|
||||
|
||||
const handleNewSession = async () => {
|
||||
try {
|
||||
const session = await createSession.mutateAsync({ agent: undefined })
|
||||
navigate(getServerSessionPath(serverId, session.id))
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const handleMultiRunOpen = () => {
|
||||
setMultiRunMounted(true)
|
||||
setMultiRunOpen(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="contents" onClick={(event) => event.stopPropagation()}>
|
||||
{isMobile ? (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
aria-label="Project actions"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 p-0"
|
||||
title="Project actions"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<MoreVertical className="w-4 h-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="end"
|
||||
className="z-[200]"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
onPointerDown={(event) => event.stopPropagation()}
|
||||
>
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
void handleNewSession()
|
||||
}}
|
||||
disabled={createSession.isPending}
|
||||
>
|
||||
{createSession.isPending ? (
|
||||
<Loader2 className="w-4 h-4 mr-2 animate-spin" />
|
||||
) : (
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
)}
|
||||
New session
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setSchedulesOpen(true)}>
|
||||
<CalendarClock className="w-4 h-4 mr-2" />
|
||||
Schedules
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={handleMultiRunOpen}>
|
||||
<Layers className="w-4 h-4 mr-2" />
|
||||
Multi-run
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
) : (
|
||||
<TooltipProvider delayDuration={200}>
|
||||
<div className="flex items-center gap-1">
|
||||
<ProjectActionButton
|
||||
label="New session"
|
||||
onClick={() => {
|
||||
void handleNewSession()
|
||||
}}
|
||||
disabled={createSession.isPending}
|
||||
>
|
||||
{createSession.isPending ? <Loader2 className="w-4 h-4 animate-spin" /> : <Plus className="w-4 h-4" />}
|
||||
</ProjectActionButton>
|
||||
<ProjectActionButton label="Schedules" onClick={() => setSchedulesOpen(true)}>
|
||||
<CalendarClock className="w-4 h-4" />
|
||||
</ProjectActionButton>
|
||||
<ProjectActionButton label="Multi-run" onClick={handleMultiRunOpen}>
|
||||
<Layers className="w-4 h-4" />
|
||||
</ProjectActionButton>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
)}
|
||||
|
||||
<RemoteSchedulesDialog
|
||||
serverId={serverId}
|
||||
directory={directory}
|
||||
open={schedulesOpen}
|
||||
onOpenChange={setSchedulesOpen}
|
||||
/>
|
||||
{multiRunMounted ? (
|
||||
<RemoteMultiRun
|
||||
serverId={serverId}
|
||||
directory={directory}
|
||||
open={multiRunOpen}
|
||||
onOpenChange={setMultiRunOpen}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom'
|
||||
import { RemoteProjectList } from '../RemoteProjectList'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
listProjects: vi.fn(),
|
||||
useCreateSession: vi.fn(),
|
||||
useOpenCodeServers: vi.fn(),
|
||||
useSettingsDialog: vi.fn(),
|
||||
openTab: vi.fn(),
|
||||
createSession: vi.fn(),
|
||||
isMobile: true,
|
||||
}))
|
||||
|
||||
vi.mock('@/api/opencode', () => ({
|
||||
listProjects: mocks.listProjects,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCode', () => ({
|
||||
useCreateSession: mocks.useCreateSession,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCodeServers', () => ({
|
||||
useOpenCodeServers: mocks.useOpenCodeServers,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSettingsDialog', () => ({
|
||||
useSettingsDialog: mocks.useSettingsDialog,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useMobile', () => ({
|
||||
useMobile: () => mocks.isMobile,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useProjectActivityState: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/schedules/ServerSchedulesDialog', () => ({
|
||||
ServerSchedulesDialog: ({
|
||||
open,
|
||||
target,
|
||||
}: {
|
||||
open: boolean
|
||||
target: { serverId: string; directory: string } | null
|
||||
}) =>
|
||||
open ? (
|
||||
<div
|
||||
data-testid="schedules-dialog"
|
||||
data-server={target?.serverId}
|
||||
data-directory={target?.directory}
|
||||
/>
|
||||
) : null,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/repo/MultiRunSheet', () => ({
|
||||
MultiRunSheet: ({
|
||||
open,
|
||||
target,
|
||||
directory,
|
||||
}: {
|
||||
open: boolean
|
||||
target: { kind: string; serverId?: string; directory?: string }
|
||||
directory?: string
|
||||
}) => (
|
||||
<div
|
||||
data-testid="multi-run-sheet"
|
||||
data-open={String(open)}
|
||||
data-kind={target.kind}
|
||||
data-server={target.serverId}
|
||||
data-directory={directory}
|
||||
/>
|
||||
),
|
||||
}))
|
||||
|
||||
const server = {
|
||||
id: 'srv_kitchen',
|
||||
name: 'Kitchen',
|
||||
baseUrl: 'https://kitchen.example.com',
|
||||
username: 'opencode',
|
||||
enabled: true,
|
||||
hasPassword: true,
|
||||
createdAt: 1,
|
||||
updatedAt: 2,
|
||||
}
|
||||
|
||||
const project = {
|
||||
id: 'prj_1',
|
||||
canonical: '/home/me/app',
|
||||
name: 'App',
|
||||
vcs: 'git',
|
||||
time: { created: Date.now() - 120_000, updated: Date.now() - 60_000, active: 2 },
|
||||
sandboxes: [],
|
||||
}
|
||||
|
||||
const otherProject = {
|
||||
id: 'prj_2',
|
||||
canonical: '/srv/other',
|
||||
name: 'Other',
|
||||
time: { created: Date.now() - 120_000, updated: Date.now() - 60_000, active: 2 },
|
||||
sandboxes: [],
|
||||
}
|
||||
|
||||
function createQueryClient() {
|
||||
return new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
||||
}
|
||||
|
||||
function renderProjectList(serverId = 'srv_kitchen') {
|
||||
return render(
|
||||
<QueryClientProvider client={createQueryClient()}>
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<Routes>
|
||||
<Route path="/" element={<RemoteProjectList serverId={serverId} />} />
|
||||
<Route path="/servers/:serverId/projects" element={<div data-testid="project-route" />} />
|
||||
<Route path="/servers/:serverId/sessions/:sessionId" element={<div data-testid="session-route" />} />
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
}
|
||||
|
||||
describe('RemoteProjectList', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.isMobile = true
|
||||
mocks.listProjects.mockResolvedValue([project])
|
||||
mocks.useCreateSession.mockReturnValue({ mutateAsync: mocks.createSession, isPending: false })
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [server], isLoading: false })
|
||||
mocks.useSettingsDialog.mockReturnValue({ openTab: mocks.openTab })
|
||||
})
|
||||
|
||||
it('lists projects from the remote server', async () => {
|
||||
renderProjectList()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('App')).toBeInTheDocument()
|
||||
})
|
||||
expect(screen.getByText('/home/me/app')).toBeInTheDocument()
|
||||
expect(mocks.listProjects).toHaveBeenCalledWith('srv_kitchen')
|
||||
})
|
||||
|
||||
it('opens the remote project page when a project card is clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProjectList()
|
||||
|
||||
await user.click(await screen.findByText('App'))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('project-route')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('creates a session in a project directory from the actions menu and navigates to it', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.createSession.mockResolvedValue({ id: 'ses_new' })
|
||||
renderProjectList()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Project actions' }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /New session/ }))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mocks.createSession).toHaveBeenCalledWith({ agent: undefined })
|
||||
})
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('session-route')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('opens the project schedules from the actions menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProjectList()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Project actions' }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Schedules/ }))
|
||||
|
||||
const dialog = await screen.findByTestId('schedules-dialog')
|
||||
expect(dialog).toHaveAttribute('data-server', 'srv_kitchen')
|
||||
expect(dialog).toHaveAttribute('data-directory', '/home/me/app')
|
||||
|
||||
await user.click(dialog)
|
||||
expect(screen.queryByTestId('project-route')).not.toBeInTheDocument()
|
||||
expect(screen.getByTestId('schedules-dialog')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens multi-run for the project from the actions menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProjectList()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Project actions' }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: /Multi-run/ }))
|
||||
|
||||
const sheet = await screen.findByTestId('multi-run-sheet')
|
||||
expect(sheet).toHaveAttribute('data-open', 'true')
|
||||
expect(sheet).toHaveAttribute('data-kind', 'server')
|
||||
expect(sheet).toHaveAttribute('data-server', 'srv_kitchen')
|
||||
expect(sheet).toHaveAttribute('data-directory', '/home/me/app')
|
||||
})
|
||||
|
||||
it('shows inline project actions on desktop without opening the project', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.isMobile = false
|
||||
renderProjectList()
|
||||
|
||||
await screen.findByText('App')
|
||||
expect(screen.queryByRole('button', { name: 'Project actions' })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'New session' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Multi-run' })).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Schedules' }))
|
||||
|
||||
expect(await screen.findByTestId('schedules-dialog')).toHaveAttribute('data-directory', '/home/me/app')
|
||||
expect(screen.queryByTestId('project-route')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens a session in an arbitrary directory', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.createSession.mockResolvedValue({ id: 'ses_other' })
|
||||
renderProjectList()
|
||||
|
||||
await user.type(screen.getByLabelText('Directory path'), '/srv/other')
|
||||
await user.click(screen.getByRole('button', { name: /Start session/ }))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mocks.createSession).toHaveBeenCalledWith({ directory: '/srv/other' })
|
||||
})
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('session-route')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('filters projects by name and path', async () => {
|
||||
const user = userEvent.setup()
|
||||
mocks.listProjects.mockResolvedValue([project, otherProject])
|
||||
renderProjectList()
|
||||
|
||||
await screen.findByText('App')
|
||||
const search = screen.getByPlaceholderText('Search projects...')
|
||||
|
||||
await user.type(search, '/srv/other')
|
||||
expect(screen.queryByText('App')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Other')).toBeInTheDocument()
|
||||
|
||||
await user.clear(search)
|
||||
await user.type(search, 'app')
|
||||
expect(screen.getByText('App')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Other')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows an empty search result state', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProjectList()
|
||||
|
||||
await screen.findByText('App')
|
||||
await user.type(screen.getByPlaceholderText('Search projects...'), 'missing')
|
||||
|
||||
expect(screen.getByText('No projects found matching "missing"')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the disabled state without loading projects', async () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({
|
||||
servers: [{ ...server, enabled: false }],
|
||||
isLoading: false,
|
||||
})
|
||||
|
||||
renderProjectList()
|
||||
|
||||
expect(screen.getByText('This server is disabled')).toBeInTheDocument()
|
||||
expect(mocks.listProjects).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows a missing server state when the server is no longer configured', async () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [], isLoading: false })
|
||||
|
||||
renderProjectList('srv_gone')
|
||||
|
||||
expect(screen.getByText('Server not found')).toBeInTheDocument()
|
||||
expect(mocks.listProjects).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows an empty state when the server has no projects', async () => {
|
||||
mocks.listProjects.mockResolvedValue([])
|
||||
|
||||
renderProjectList()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('No projects on this server yet')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('scopes the list to the given server rather than the route', async () => {
|
||||
renderProjectList('srv_kitchen')
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mocks.listProjects).toHaveBeenCalledWith('srv_kitchen')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user