mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Merge remote-tracking branch 'origin/feat/linked-opencode-servers' into feat/remote-server-automation
# Conflicts: # backend/src/services/remote-server-events.ts # frontend/src/components/navigation/MoreDrawer.test.tsx # frontend/src/components/navigation/moreDrawerItems.test.ts # frontend/src/lib/opencode-event-stream/openCodeEventStream.ts # frontend/src/pages/SessionDetail.tsx # frontend/src/pages/__tests__/SessionDetail.remote.test.tsx
This commit is contained in:
commit
780d31087b
92 files changed
+3828
-817
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { ContextUsageIndicator } from './ContextUsageIndicator'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useContextUsage: vi.fn(),
|
||||
useMobile: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useContextUsage', () => ({
|
||||
useContextUsage: mocks.useContextUsage,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useMobile', () => ({
|
||||
useMobile: mocks.useMobile,
|
||||
}))
|
||||
|
||||
function renderIndicator() {
|
||||
return render(<ContextUsageIndicator sessionID="ses_1" isConnected={true} />)
|
||||
}
|
||||
|
||||
describe('ContextUsageIndicator', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('renders tokens and percentage on desktop', () => {
|
||||
mocks.useMobile.mockReturnValue(false)
|
||||
mocks.useContextUsage.mockReturnValue({ usage: { totalTokens: 1234, usagePercentage: 42 }, isLoading: false })
|
||||
renderIndicator()
|
||||
|
||||
expect(screen.getByText('1,234 (42%)')).toBeInTheDocument()
|
||||
expect(screen.queryByText('42%')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders only the percentage on mobile', () => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
mocks.useContextUsage.mockReturnValue({ usage: { totalTokens: 1234, usagePercentage: 42 }, isLoading: false })
|
||||
renderIndicator()
|
||||
|
||||
expect(screen.getByText('42%')).toBeInTheDocument()
|
||||
expect(screen.queryByText('1,234 (42%)')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders only the token count on mobile without a percentage', () => {
|
||||
mocks.useMobile.mockReturnValue(true)
|
||||
mocks.useContextUsage.mockReturnValue({ usage: { totalTokens: 1234, usagePercentage: null }, isLoading: false })
|
||||
renderIndicator()
|
||||
|
||||
expect(screen.getByText('1,234')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useContextUsage } from '@/hooks/useContextUsage'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
|
||||
interface ContextUsageIndicatorProps {
|
||||
directory?: string
|
||||
@@ -22,6 +23,7 @@ export function ContextUsageIndicator({
|
||||
revertMessageID,
|
||||
}: ContextUsageIndicatorProps) {
|
||||
const { usage, isLoading } = useContextUsage(sessionID, directory, revertMessageID)
|
||||
const isMobile = useMobile()
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -43,14 +45,18 @@ export function ContextUsageIndicator({
|
||||
return null
|
||||
}
|
||||
|
||||
const tokenText = usage.usagePercentage === null
|
||||
const compactText = usage.usagePercentage === null
|
||||
? usage.totalTokens.toLocaleString()
|
||||
: `${usage.usagePercentage}%`
|
||||
|
||||
const fullText = usage.usagePercentage === null
|
||||
? usage.totalTokens.toLocaleString()
|
||||
: `${usage.totalTokens.toLocaleString()} (${usage.usagePercentage}%)`
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={`text-xs font-medium whitespace-nowrap ${getUsageTextColor(usage.usagePercentage ?? 0)}`}>
|
||||
{tokenText}
|
||||
{isMobile ? compactText : fullText}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -136,6 +136,8 @@ function activeWorkItem(
|
||||
key: `${directory}:${id}`,
|
||||
session: itemSession,
|
||||
repo: itemRepo,
|
||||
serverId: null,
|
||||
serverName: null,
|
||||
state,
|
||||
updatedAt: itemSession.time.updated,
|
||||
path: `/repos/${itemRepo.id}/sessions/${id}`,
|
||||
@@ -877,4 +879,76 @@ describe('SessionPickerDialog', () => {
|
||||
pinned: true,
|
||||
})
|
||||
})
|
||||
|
||||
describe('linked-server mode', () => {
|
||||
beforeEach(() => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a')]
|
||||
mocks.sessionsData = [session('ses_remote', 'Remote session', '/home/me/app')]
|
||||
})
|
||||
|
||||
it('lists the project sessions without Manager-only tabs and reports the chosen server session', async () => {
|
||||
const onSelectRemoteSession = vi.fn()
|
||||
renderPicker({
|
||||
remote: {
|
||||
serverId: 'srv_kitchen',
|
||||
serverName: 'Kitchen',
|
||||
projectDirectory: '/home/me/app',
|
||||
},
|
||||
onSelectRemoteSession,
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('tab', { name: 'Projects' })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Active' })).toBeInTheDocument()
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Remote session/ })
|
||||
expect(row).toHaveTextContent('Kitchen')
|
||||
|
||||
fireEvent.click(row)
|
||||
|
||||
expect(onSelectRemoteSession).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: 'ses_remote' }),
|
||||
'srv_kitchen',
|
||||
)
|
||||
})
|
||||
|
||||
it('navigates a remote active work row through the owning server', async () => {
|
||||
const onSelectRemoteSession = vi.fn()
|
||||
mocks.activeWorkGroups = {
|
||||
needsInput: [
|
||||
{
|
||||
key: '/home/me/app/ses_remote',
|
||||
session: session('ses_remote', 'Remote pending', '/home/me/app'),
|
||||
repo: null,
|
||||
serverId: 'srv_kitchen',
|
||||
serverName: 'Kitchen',
|
||||
state: 'needs-input',
|
||||
updatedAt: Date.now(),
|
||||
path: '/servers/srv_kitchen/sessions/ses_remote',
|
||||
},
|
||||
],
|
||||
running: [],
|
||||
recent: [],
|
||||
}
|
||||
renderPicker({
|
||||
remote: {
|
||||
serverId: 'srv_kitchen',
|
||||
serverName: 'Kitchen',
|
||||
projectDirectory: '/home/me/app',
|
||||
},
|
||||
onSelectRemoteSession,
|
||||
})
|
||||
openActiveTab()
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Remote pending/ })
|
||||
expect(row).toHaveTextContent('Kitchen')
|
||||
expect(screen.queryByRole('button', { name: 'Session actions' })).not.toBeInTheDocument()
|
||||
|
||||
fireEvent.click(row)
|
||||
|
||||
expect(onSelectRemoteSession).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ id: 'ses_remote' }),
|
||||
'srv_kitchen',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -48,6 +48,7 @@ const NEAR_BOTTOM_PX = 240
|
||||
type SessionPickerTab = 'active' | 'sessions' | 'projects'
|
||||
|
||||
const SESSION_PICKER_TABS: SessionPickerTab[] = ['active', 'sessions', 'projects']
|
||||
const REMOTE_SESSION_PICKER_TABS: SessionPickerTab[] = ['active', 'sessions']
|
||||
|
||||
const SESSION_PICKER_TAB_LABELS: Record<SessionPickerTab, string> = {
|
||||
active: 'Active',
|
||||
@@ -55,9 +56,15 @@ const SESSION_PICKER_TAB_LABELS: Record<SessionPickerTab, string> = {
|
||||
projects: 'Projects',
|
||||
}
|
||||
|
||||
function nextSessionPickerTab(tab: SessionPickerTab): SessionPickerTab {
|
||||
const index = SESSION_PICKER_TABS.indexOf(tab)
|
||||
return SESSION_PICKER_TABS[(index + 1) % SESSION_PICKER_TABS.length]
|
||||
function nextSessionPickerTab(tab: SessionPickerTab, tabs: SessionPickerTab[]): SessionPickerTab {
|
||||
const index = tabs.indexOf(tab)
|
||||
return tabs[(index + 1) % tabs.length]
|
||||
}
|
||||
|
||||
interface RemotePickerScope {
|
||||
serverId: string
|
||||
serverName?: string
|
||||
projectDirectory?: string
|
||||
}
|
||||
|
||||
interface SessionPickerDialogProps {
|
||||
@@ -66,14 +73,19 @@ interface SessionPickerDialogProps {
|
||||
currentRepo: Repo | undefined
|
||||
activeSessionID?: string
|
||||
onSelectSession: (session: Session, repo: Repo) => void
|
||||
onSelectRemoteSession?: (session: Session, serverId: string) => void
|
||||
onDeleteActiveSession: () => void
|
||||
onSelectRepo: (repo: Repo) => void
|
||||
/** Set on a linked-server route to list that server's sessions instead of Manager repos. */
|
||||
remote?: RemotePickerScope
|
||||
}
|
||||
|
||||
interface SessionPickerRow {
|
||||
key: string
|
||||
session: Session
|
||||
repo: Repo
|
||||
repo?: Repo
|
||||
serverId?: string
|
||||
serverName?: string
|
||||
updatedAt?: number
|
||||
}
|
||||
|
||||
@@ -87,14 +99,11 @@ function buildSections(
|
||||
sessions: Session[],
|
||||
pinnedKeys: ReadonlySet<string>,
|
||||
keyFn: (session: Session) => string,
|
||||
resolveRepo: (session: Session) => Repo | undefined,
|
||||
resolveRepo?: (session: Session) => Repo | undefined,
|
||||
): SessionPickerSection[] {
|
||||
const { pinned, today, older } = partitionSessions(sessions, pinnedKeys, keyFn)
|
||||
const toRows = (group: Session[]): SessionPickerRow[] =>
|
||||
group.flatMap((session) => {
|
||||
const repo = resolveRepo(session)
|
||||
return repo ? [{ key: keyFn(session), session, repo }] : []
|
||||
})
|
||||
group.map((session) => ({ key: keyFn(session), session, repo: resolveRepo?.(session) }))
|
||||
|
||||
const sections: SessionPickerSection[] = []
|
||||
const pinnedRows = toRows(pinned)
|
||||
@@ -189,6 +198,7 @@ interface SessionPickerRowItemProps {
|
||||
isPinned: boolean
|
||||
isPendingDelete: boolean
|
||||
showRepo: boolean
|
||||
showActions: boolean
|
||||
label?: string
|
||||
onOpen: (row: SessionPickerRow) => void
|
||||
onHover: (index: number) => void
|
||||
@@ -206,6 +216,7 @@ const SessionPickerRowItem = memo(function SessionPickerRowItem({
|
||||
isPinned,
|
||||
isPendingDelete,
|
||||
showRepo,
|
||||
showActions,
|
||||
label,
|
||||
onOpen,
|
||||
onHover,
|
||||
@@ -263,13 +274,18 @@ const SessionPickerRowItem = memo(function SessionPickerRowItem({
|
||||
: 'text-muted-foreground',
|
||||
)}
|
||||
>
|
||||
{showRepo && <span className="max-w-32 truncate">{getRepoDisplayName(row.repo)}</span>}
|
||||
{showRepo && row.repo ? (
|
||||
<span className="max-w-32 truncate">{getRepoDisplayName(row.repo)}</span>
|
||||
) : null}
|
||||
{showRepo && !row.repo && (row.serverName || row.serverId) ? (
|
||||
<span className="max-w-32 truncate">{row.serverName ?? row.serverId}</span>
|
||||
) : null}
|
||||
{!showRepo && label && <span className="max-w-32 truncate">{label}</span>}
|
||||
<span>{formatShortRelativeTime(new Date(row.updatedAt ?? row.session.time.updated))}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center pr-1">
|
||||
<DropdownMenu>
|
||||
{row.serverId || !showActions ? null : <DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
@@ -291,7 +307,7 @@ const SessionPickerRowItem = memo(function SessionPickerRowItem({
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => onRequestDelete(row.session)}>Delete</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</DropdownMenu>}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@@ -301,6 +317,7 @@ interface SessionPickerRowActionsOptions {
|
||||
directories: string[]
|
||||
activeSessionID?: string
|
||||
onSelectSession: (session: Session, repo: Repo) => void
|
||||
onSelectRemoteSession?: (session: Session, serverId: string) => void
|
||||
onDeleteActiveSession: () => void
|
||||
}
|
||||
|
||||
@@ -325,6 +342,7 @@ function useSessionPickerRowActions({
|
||||
directories,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
}: SessionPickerRowActionsOptions): SessionPickerRowActions {
|
||||
const { data: sessionPins } = useSessionPins()
|
||||
@@ -341,9 +359,13 @@ function useSessionPickerRowActions({
|
||||
const openRow = useCallback(
|
||||
(row: SessionPickerRow | undefined) => {
|
||||
if (!row) return
|
||||
onSelectSession(row.session, row.repo)
|
||||
if (row.serverId) {
|
||||
onSelectRemoteSession?.(row.session, row.serverId)
|
||||
return
|
||||
}
|
||||
if (row.repo) onSelectSession(row.session, row.repo)
|
||||
},
|
||||
[onSelectSession],
|
||||
[onSelectSession, onSelectRemoteSession],
|
||||
)
|
||||
|
||||
const performDelete = useCallback(
|
||||
@@ -358,7 +380,7 @@ function useSessionPickerRowActions({
|
||||
|
||||
const deleteRow = useCallback(
|
||||
(row: SessionPickerRow | undefined) => {
|
||||
if (!row) return
|
||||
if (!row || row.serverId) return
|
||||
if (pendingDeleteKey !== row.key) {
|
||||
setPendingDeleteKey(row.key)
|
||||
return
|
||||
@@ -372,6 +394,7 @@ function useSessionPickerRowActions({
|
||||
|
||||
const handleTogglePin = useCallback(
|
||||
(row: SessionPickerRow) => {
|
||||
if (row.serverId) return
|
||||
togglePin.mutate({
|
||||
sessionId: row.session.id,
|
||||
directory: row.session.location.directory,
|
||||
@@ -431,6 +454,7 @@ interface SessionPickerListProps {
|
||||
pinnedKeys: ReadonlySet<string>
|
||||
pendingDeleteKey: string | null
|
||||
showRepo: boolean
|
||||
showRowActions?: boolean
|
||||
labelFor?: (row: SessionPickerRow) => string | undefined
|
||||
emptyState: React.ReactNode
|
||||
onOpenRow: (row: SessionPickerRow) => void
|
||||
@@ -455,6 +479,7 @@ function SessionPickerList({
|
||||
pinnedKeys,
|
||||
pendingDeleteKey,
|
||||
showRepo,
|
||||
showRowActions = true,
|
||||
labelFor,
|
||||
emptyState,
|
||||
onOpenRow,
|
||||
@@ -504,6 +529,7 @@ function SessionPickerList({
|
||||
isPinned={pinnedKeys.has(row.key)}
|
||||
isPendingDelete={pendingDeleteKey === row.key}
|
||||
showRepo={showRepo}
|
||||
showActions={showRowActions}
|
||||
label={labelFor?.(row)}
|
||||
onOpen={onOpenRow}
|
||||
onHover={onHoverRow}
|
||||
@@ -527,6 +553,7 @@ interface SessionPickerContentProps {
|
||||
currentRepo: Repo | undefined
|
||||
activeSessionID?: string
|
||||
onSelectSession: (session: Session, repo: Repo) => void
|
||||
onSelectRemoteSession?: (session: Session, serverId: string) => void
|
||||
onDeleteActiveSession: () => void
|
||||
switchHint: string
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
@@ -538,6 +565,7 @@ function SessionPickerContent({
|
||||
currentRepo,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
switchHint,
|
||||
searchInputRef,
|
||||
@@ -616,11 +644,18 @@ function SessionPickerContent({
|
||||
directories,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
})
|
||||
|
||||
const sections = useMemo(
|
||||
() => buildSections(filteredSessions, pinnedKeys, getSessionKey, resolveRepo),
|
||||
() =>
|
||||
buildSections(
|
||||
filteredSessions.filter((session) => Boolean(resolveRepo(session))),
|
||||
pinnedKeys,
|
||||
getSessionKey,
|
||||
resolveRepo,
|
||||
),
|
||||
[filteredSessions, pinnedKeys, resolveRepo],
|
||||
)
|
||||
const rows = useMemo(() => sections.flatMap((section) => section.rows), [sections])
|
||||
@@ -787,6 +822,7 @@ interface ActivePickerContentProps {
|
||||
open: boolean
|
||||
activeSessionID?: string
|
||||
onSelectSession: (session: Session, repo: Repo) => void
|
||||
onSelectRemoteSession?: (session: Session, serverId: string) => void
|
||||
onDeleteActiveSession: () => void
|
||||
switchHint: string
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
@@ -796,6 +832,7 @@ function ActivePickerContent({
|
||||
open,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
switchHint,
|
||||
searchInputRef,
|
||||
@@ -815,7 +852,14 @@ function ActivePickerContent({
|
||||
const rows: SessionPickerRow[] = []
|
||||
for (const item of groups[definition.key]) {
|
||||
if (needle && !(item.session.title ?? '').toLowerCase().includes(needle)) continue
|
||||
rows.push({ key: item.key, session: item.session, repo: item.repo, updatedAt: item.updatedAt })
|
||||
rows.push({
|
||||
key: item.key,
|
||||
session: item.session,
|
||||
repo: item.repo ?? undefined,
|
||||
serverId: item.serverId ?? undefined,
|
||||
serverName: item.serverName ?? undefined,
|
||||
updatedAt: item.updatedAt,
|
||||
})
|
||||
}
|
||||
return rows.length > 0 ? [{ id: definition.key, heading: definition.heading, rows }] : []
|
||||
})
|
||||
@@ -838,7 +882,10 @@ function ActivePickerContent({
|
||||
} = usePickerCursor(rows, defaultCursorKey)
|
||||
|
||||
const directories = useMemo(
|
||||
() => Array.from(new Set(rows.map((row) => row.session.location.directory))),
|
||||
() =>
|
||||
Array.from(
|
||||
new Set(rows.filter((row) => !row.serverId).map((row) => row.session.location.directory)),
|
||||
),
|
||||
[rows],
|
||||
)
|
||||
|
||||
@@ -855,6 +902,7 @@ function ActivePickerContent({
|
||||
directories,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
})
|
||||
|
||||
@@ -934,14 +982,179 @@ function ActivePickerContent({
|
||||
)
|
||||
}
|
||||
|
||||
const EMPTY_PINNED_KEYS: ReadonlySet<string> = new Set()
|
||||
|
||||
interface RemoteSessionPickerContentProps {
|
||||
open: boolean
|
||||
serverName?: string
|
||||
projectDirectory?: string
|
||||
activeSessionID?: string
|
||||
onSelectSession: (session: Session) => void
|
||||
switchHint: string
|
||||
searchInputRef: React.RefObject<HTMLInputElement | null>
|
||||
}
|
||||
|
||||
function RemoteSessionPickerContent({
|
||||
open,
|
||||
serverName,
|
||||
projectDirectory,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
switchHint,
|
||||
searchInputRef,
|
||||
}: RemoteSessionPickerContentProps) {
|
||||
const listRef = useRef<HTMLDivElement>(null)
|
||||
const listId = useId()
|
||||
const optionBaseId = useId()
|
||||
|
||||
const {
|
||||
query,
|
||||
setQuery,
|
||||
trimmedQuery,
|
||||
filteredSessions,
|
||||
isSearchPending,
|
||||
isLoading,
|
||||
fetchNextPage,
|
||||
isFetchingNextPage,
|
||||
isFetchNextPageError,
|
||||
canFetchNextPage,
|
||||
} = useSessionSearch(projectDirectory ? [projectDirectory] : [])
|
||||
|
||||
const sections = useMemo(
|
||||
() => buildSections(filteredSessions, EMPTY_PINNED_KEYS, getSessionKey),
|
||||
[filteredSessions],
|
||||
)
|
||||
const rows = useMemo(() => sections.flatMap((section) => section.rows), [sections])
|
||||
|
||||
const activeRow = useMemo(
|
||||
() => rows.find((row) => row.session.id === activeSessionID),
|
||||
[rows, activeSessionID],
|
||||
)
|
||||
const defaultCursorKey = !trimmedQuery && activeRow ? activeRow.key : rows[0]?.key ?? null
|
||||
|
||||
const {
|
||||
rowIndexByKey,
|
||||
cursorIndex,
|
||||
cursorRow,
|
||||
registerRef,
|
||||
moveCursor,
|
||||
resetCursor,
|
||||
} = usePickerCursor(rows, defaultCursorKey)
|
||||
|
||||
const openRow = useCallback(
|
||||
(row: SessionPickerRow | undefined) => {
|
||||
if (row) onSelectSession(row.session)
|
||||
},
|
||||
[onSelectSession],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
resetCursor()
|
||||
}, [trimmedQuery, resetCursor])
|
||||
|
||||
const handleSearchKeyDown = usePickerKeyNav({
|
||||
rows,
|
||||
cursorIndex,
|
||||
cursorRow,
|
||||
moveCursor,
|
||||
onOpenRow: openRow,
|
||||
})
|
||||
|
||||
const handleListScroll = useCallback(
|
||||
(event: React.UIEvent<HTMLDivElement>) => {
|
||||
const { scrollTop, scrollHeight, clientHeight } = event.currentTarget
|
||||
if (scrollHeight - scrollTop - clientHeight <= NEAR_BOTTOM_PX && canFetchNextPage) {
|
||||
void fetchNextPage()
|
||||
}
|
||||
},
|
||||
[canFetchNextPage, fetchNextPage],
|
||||
)
|
||||
|
||||
const labelFor = useCallback(() => serverName, [serverName])
|
||||
|
||||
return (
|
||||
<div className="mt-4 flex min-h-0 flex-1 flex-col">
|
||||
<PickerSearchBar
|
||||
inputRef={searchInputRef}
|
||||
listId={listId}
|
||||
open={open}
|
||||
activeDescendantId={cursorIndex >= 0 ? optionId(optionBaseId, cursorIndex) : undefined}
|
||||
value={query}
|
||||
onChange={setQuery}
|
||||
onKeyDown={handleSearchKeyDown}
|
||||
placeholder="Search sessions..."
|
||||
name="remote-session-picker-search"
|
||||
/>
|
||||
|
||||
<SessionPickerList
|
||||
listRef={listRef}
|
||||
listId={listId}
|
||||
optionBaseId={optionBaseId}
|
||||
ariaLabel="Sessions"
|
||||
sections={sections}
|
||||
rows={rows}
|
||||
rowIndexByKey={rowIndexByKey}
|
||||
cursorIndex={cursorIndex}
|
||||
activeSessionID={activeSessionID}
|
||||
pinnedKeys={EMPTY_PINNED_KEYS}
|
||||
pendingDeleteKey={null}
|
||||
showRepo={false}
|
||||
showRowActions={false}
|
||||
labelFor={labelFor}
|
||||
emptyState={
|
||||
isLoading
|
||||
? 'Loading sessions...'
|
||||
: isSearchPending
|
||||
? 'Searching sessions...'
|
||||
: trimmedQuery
|
||||
? 'No sessions found'
|
||||
: 'No sessions yet'
|
||||
}
|
||||
onOpenRow={openRow}
|
||||
onHoverRow={moveCursor}
|
||||
onTogglePin={() => undefined}
|
||||
onRequestDelete={() => undefined}
|
||||
registerRef={registerRef}
|
||||
onScroll={handleListScroll}
|
||||
>
|
||||
{isFetchNextPageError && (
|
||||
<div className="flex flex-col items-center gap-2 py-4">
|
||||
<p className="text-sm text-muted-foreground">Failed to load more sessions</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
void fetchNextPage()
|
||||
}}
|
||||
disabled={isFetchingNextPage}
|
||||
>
|
||||
Retry
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
{isFetchingNextPage && rows.length > 0 && (
|
||||
<div className="py-4 text-center text-sm text-muted-foreground">Loading more sessions...</div>
|
||||
)}
|
||||
</SessionPickerList>
|
||||
|
||||
<div className="mt-2 shrink-0 px-4 text-xs text-muted-foreground pointer-coarse:hidden sm:px-0">
|
||||
↑↓ move · Enter open
|
||||
{switchHint ? ` · ${switchHint} sessions` : ''}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function SessionPickerDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
currentRepo,
|
||||
activeSessionID,
|
||||
onSelectSession,
|
||||
onSelectRemoteSession,
|
||||
onDeleteActiveSession,
|
||||
onSelectRepo,
|
||||
remote,
|
||||
}: SessionPickerDialogProps) {
|
||||
const searchInputRef = useRef<HTMLInputElement>(null)
|
||||
const activeSearchInputRef = useRef<HTMLInputElement>(null)
|
||||
@@ -960,6 +1173,8 @@ export function SessionPickerDialog({
|
||||
},
|
||||
[preferences],
|
||||
)
|
||||
const isRemote = remote !== undefined
|
||||
const pickerTabs = isRemote ? REMOTE_SESSION_PICKER_TABS : SESSION_PICKER_TABS
|
||||
const [tab, setTab] = useState<SessionPickerTab>('sessions')
|
||||
const [prevOpen, setPrevOpen] = useState(open)
|
||||
|
||||
@@ -968,10 +1183,12 @@ export function SessionPickerDialog({
|
||||
if (open) setTab('sessions')
|
||||
}
|
||||
|
||||
const activeTab: SessionPickerTab = isRemote && tab === 'projects' ? 'sessions' : tab
|
||||
|
||||
const toggleTab = useCallback(() => {
|
||||
focusSearchAfterSwitchRef.current = true
|
||||
setTab((current) => nextSessionPickerTab(current))
|
||||
}, [])
|
||||
setTab((current) => nextSessionPickerTab(current, pickerTabs))
|
||||
}, [pickerTabs])
|
||||
|
||||
useShortcutActions({ switchPickerTab: open ? toggleTab : undefined })
|
||||
|
||||
@@ -983,12 +1200,12 @@ export function SessionPickerDialog({
|
||||
if (!hasFinePointer && !focusSearchAfterSwitchRef.current) return
|
||||
const frame = requestAnimationFrame(() => {
|
||||
focusSearchAfterSwitchRef.current = false
|
||||
if (tab === 'projects') projectSearchInputRef.current?.focus()
|
||||
else if (tab === 'active') activeSearchInputRef.current?.focus()
|
||||
if (activeTab === 'projects') projectSearchInputRef.current?.focus()
|
||||
else if (activeTab === 'active') activeSearchInputRef.current?.focus()
|
||||
else searchInputRef.current?.focus()
|
||||
})
|
||||
return () => cancelAnimationFrame(frame)
|
||||
}, [open, tab, hasFinePointer])
|
||||
}, [open, activeTab, hasFinePointer])
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
@@ -1006,16 +1223,16 @@ export function SessionPickerDialog({
|
||||
}}
|
||||
>
|
||||
<Tabs
|
||||
value={tab}
|
||||
value={activeTab}
|
||||
onValueChange={(value) => setTab(value as SessionPickerTab)}
|
||||
className="flex min-h-0 w-full min-w-0 flex-1 flex-col gap-0"
|
||||
>
|
||||
<div className="shrink-0 px-4 pt-4 sm:px-0 sm:pt-6">
|
||||
<DialogTitle className="sr-only">{SESSION_PICKER_TAB_LABELS[tab]}</DialogTitle>
|
||||
<DialogTitle className="sr-only">{SESSION_PICKER_TAB_LABELS[activeTab]}</DialogTitle>
|
||||
<TabsList>
|
||||
<TabsTrigger value="active">Active</TabsTrigger>
|
||||
<TabsTrigger value="sessions">Sessions</TabsTrigger>
|
||||
<TabsTrigger value="projects">Projects</TabsTrigger>
|
||||
{isRemote ? null : <TabsTrigger value="projects">Projects</TabsTrigger>}
|
||||
</TabsList>
|
||||
</div>
|
||||
<TabsContent
|
||||
@@ -1026,6 +1243,7 @@ export function SessionPickerDialog({
|
||||
open={open}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={onSelectSession}
|
||||
onSelectRemoteSession={onSelectRemoteSession}
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={activeSearchInputRef}
|
||||
@@ -1035,29 +1253,44 @@ export function SessionPickerDialog({
|
||||
value="sessions"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
<SessionPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={onSelectSession}
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={searchInputRef}
|
||||
hasFinePointer={hasFinePointer}
|
||||
/>
|
||||
</TabsContent>
|
||||
<TabsContent
|
||||
value="projects"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
<ProjectPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
onSelectRepo={onSelectRepo}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
/>
|
||||
{remote ? (
|
||||
<RemoteSessionPickerContent
|
||||
open={open}
|
||||
serverName={remote.serverName}
|
||||
projectDirectory={remote.projectDirectory}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={(session) => onSelectRemoteSession?.(session, remote.serverId)}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={searchInputRef}
|
||||
/>
|
||||
) : (
|
||||
<SessionPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={onSelectSession}
|
||||
onSelectRemoteSession={onSelectRemoteSession}
|
||||
onDeleteActiveSession={onDeleteActiveSession}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={searchInputRef}
|
||||
hasFinePointer={hasFinePointer}
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
{isRemote ? null : (
|
||||
<TabsContent
|
||||
value="projects"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
<ProjectPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
onSelectRepo={onSelectRepo}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
/>
|
||||
</TabsContent>
|
||||
)}
|
||||
</Tabs>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
Reference in new issue
Block a user