mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(frontend): consolidate session picker navigation and remote project loading
This commit is contained in:
1 parent
81fb2d4033
commit
52aeb7780f
42 files changed
+1486
-769
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { Progress } from '@/components/ui/progress'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { CONTEXT_USAGE_BG_CLASS, contextUsageTone } from '@/lib/contextUsage'
|
||||
|
||||
@@ -6,20 +7,19 @@ interface ContextUsageMeterProps {
|
||||
className?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Thin context-window fill bar. Its accessible label lives on the model pill, so the bar itself is hidden
|
||||
* from assistive technology.
|
||||
*/
|
||||
export function ContextUsageMeter({ percentage, className }: ContextUsageMeterProps) {
|
||||
const width = percentage === null ? 0 : Math.min(percentage, 100)
|
||||
|
||||
return (
|
||||
<div
|
||||
<Progress
|
||||
data-testid="context-usage-meter"
|
||||
aria-hidden="true"
|
||||
className={cn('h-0.5 w-full overflow-hidden bg-border/50', className)}
|
||||
>
|
||||
<div
|
||||
data-testid="context-usage-meter-fill"
|
||||
className={cn('h-full', CONTEXT_USAGE_BG_CLASS[contextUsageTone(percentage)])}
|
||||
style={{ width: `${width}%` }}
|
||||
/>
|
||||
</div>
|
||||
value={percentage ?? 0}
|
||||
className={cn('h-0.5 rounded-none bg-border/50', className)}
|
||||
indicatorClassName={cn('transition-none', CONTEXT_USAGE_BG_CLASS[contextUsageTone(percentage)])}
|
||||
indicatorTestId="context-usage-meter-fill"
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,21 +1,65 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { render, screen, act } from '@testing-library/react'
|
||||
import { afterEach, describe, it, expect, vi } from 'vitest'
|
||||
import { ReconnectingBanner } from './ReconnectingBanner'
|
||||
|
||||
const GRACE_PERIOD_MS = 5000
|
||||
|
||||
describe('ReconnectingBanner', () => {
|
||||
it('stays hidden before the stream has connected', () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('stays hidden during the initial grace period', () => {
|
||||
vi.useFakeTimers()
|
||||
render(<ReconnectingBanner connected={false} />)
|
||||
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(GRACE_PERIOD_MS - 1)
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('status')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('reports a stream that never connects once the grace period elapses', () => {
|
||||
vi.useFakeTimers()
|
||||
render(<ReconnectingBanner connected={false} />)
|
||||
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(GRACE_PERIOD_MS)
|
||||
})
|
||||
|
||||
const banner = screen.getByRole('status')
|
||||
expect(banner).toHaveTextContent('Not connected — live updates unavailable')
|
||||
expect(banner).toHaveAttribute('aria-live', 'polite')
|
||||
})
|
||||
|
||||
it('hides the not-connected banner as soon as the stream connects', () => {
|
||||
vi.useFakeTimers()
|
||||
const { rerender } = render(<ReconnectingBanner connected={false} />)
|
||||
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(GRACE_PERIOD_MS)
|
||||
})
|
||||
expect(screen.getByRole('status')).toBeInTheDocument()
|
||||
|
||||
rerender(<ReconnectingBanner connected />)
|
||||
|
||||
expect(screen.queryByRole('status')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('stays hidden while the stream is connected', () => {
|
||||
vi.useFakeTimers()
|
||||
render(<ReconnectingBanner connected />)
|
||||
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(GRACE_PERIOD_MS * 2)
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('status')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('reports a dropped stream once it connected', () => {
|
||||
vi.useFakeTimers()
|
||||
const { rerender } = render(<ReconnectingBanner connected />)
|
||||
|
||||
rerender(<ReconnectingBanner connected={false} />)
|
||||
@@ -25,7 +69,20 @@ describe('ReconnectingBanner', () => {
|
||||
expect(banner).toHaveAttribute('aria-live', 'polite')
|
||||
})
|
||||
|
||||
it('keeps the reconnect message when the drop outlasts the grace period', () => {
|
||||
vi.useFakeTimers()
|
||||
const { rerender } = render(<ReconnectingBanner connected />)
|
||||
|
||||
rerender(<ReconnectingBanner connected={false} />)
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(GRACE_PERIOD_MS * 2)
|
||||
})
|
||||
|
||||
expect(screen.getByRole('status')).toHaveTextContent('Reconnecting… live updates paused')
|
||||
})
|
||||
|
||||
it('hides again when the stream reconnects', () => {
|
||||
vi.useFakeTimers()
|
||||
const { rerender } = render(<ReconnectingBanner connected />)
|
||||
|
||||
rerender(<ReconnectingBanner connected={false} />)
|
||||
@@ -33,4 +90,13 @@ describe('ReconnectingBanner', () => {
|
||||
|
||||
expect(screen.queryByRole('status')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('clears the grace timer on unmount', () => {
|
||||
vi.useFakeTimers()
|
||||
const { unmount } = render(<ReconnectingBanner connected={false} />)
|
||||
|
||||
unmount()
|
||||
|
||||
expect(vi.getTimerCount()).toBe(0)
|
||||
})
|
||||
})
|
||||
@@ -1,25 +1,42 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
const NOT_CONNECTED_GRACE_PERIOD_MS = 5000
|
||||
|
||||
export interface ReconnectingBannerProps {
|
||||
connected: boolean
|
||||
}
|
||||
|
||||
export function ReconnectingBanner({ connected }: ReconnectingBannerProps) {
|
||||
const [hasConnected, setHasConnected] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (connected) setHasConnected(true)
|
||||
}, [connected])
|
||||
|
||||
if (connected || !hasConnected) return null
|
||||
|
||||
function StatusBanner({ message }: { message: string }) {
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
className="w-full border-b border-warning/40 bg-warning/10 px-3 py-1 text-xs text-warning"
|
||||
>
|
||||
Reconnecting… live updates paused
|
||||
{message}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function ReconnectingBanner({ connected }: ReconnectingBannerProps) {
|
||||
const [hasConnected, setHasConnected] = useState(false)
|
||||
const [graceElapsed, setGraceElapsed] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (connected) setHasConnected(true)
|
||||
}, [connected])
|
||||
|
||||
useEffect(() => {
|
||||
if (connected) {
|
||||
setGraceElapsed(false)
|
||||
return
|
||||
}
|
||||
const timer = setTimeout(() => setGraceElapsed(true), NOT_CONNECTED_GRACE_PERIOD_MS)
|
||||
return () => clearTimeout(timer)
|
||||
}, [connected])
|
||||
|
||||
if (connected) return null
|
||||
if (hasConnected) return <StatusBanner message="Reconnecting… live updates paused" />
|
||||
if (graceElapsed) return <StatusBanner message="Not connected — live updates unavailable" />
|
||||
return null
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import { SessionDetailsSheet, type SessionDetailsSheetProps } from './SessionDet
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useMobile: vi.fn(),
|
||||
useUpdateSession: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useMobile', () => ({
|
||||
@@ -15,34 +14,27 @@ vi.mock('@/hooks/useMobile', () => ({
|
||||
useSwipeDismiss: vi.fn(() => ({ bind: vi.fn(), swipeProgress: 0, swipeStyles: {} })),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCode', () => ({ useUpdateSession: mocks.useUpdateSession }))
|
||||
|
||||
type RenameMutation = {
|
||||
mutate: ReturnType<typeof vi.fn>
|
||||
reset: ReturnType<typeof vi.fn>
|
||||
error: Error | null
|
||||
isPending: boolean
|
||||
}
|
||||
|
||||
const baseProps: SessionDetailsSheetProps = {
|
||||
open: true,
|
||||
onOpenChange: vi.fn(),
|
||||
sessionId: 'ses_1',
|
||||
title: 'Fix the header',
|
||||
remote: false,
|
||||
project: 'oc-manager',
|
||||
onRename: vi.fn(() => Promise.resolve()),
|
||||
}
|
||||
|
||||
function mockRename(overrides: Partial<RenameMutation> = {}): RenameMutation {
|
||||
const mutation: RenameMutation = {
|
||||
mutate: vi.fn(),
|
||||
reset: vi.fn(),
|
||||
error: null,
|
||||
isPending: false,
|
||||
...overrides,
|
||||
}
|
||||
mocks.useUpdateSession.mockReturnValue(mutation)
|
||||
return mutation
|
||||
function createDeferred() {
|
||||
let resolve!: () => void
|
||||
let reject!: (error: Error) => void
|
||||
const promise = new Promise<void>((res, rej) => {
|
||||
resolve = res
|
||||
reject = rej
|
||||
})
|
||||
return { promise, resolve, reject }
|
||||
}
|
||||
|
||||
function failingRename(error = new Error('nope')) {
|
||||
return vi.fn(() => Promise.reject(error))
|
||||
}
|
||||
|
||||
function renderSheet(overrides: Partial<SessionDetailsSheetProps> = {}) {
|
||||
@@ -53,7 +45,6 @@ describe('SessionDetailsSheet', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.useMobile.mockReturnValue(false)
|
||||
mockRename()
|
||||
})
|
||||
|
||||
it('lists the local session details', () => {
|
||||
@@ -118,101 +109,108 @@ describe('SessionDetailsSheet', () => {
|
||||
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled()
|
||||
})
|
||||
|
||||
it('saves the trimmed title and leaves edit mode on success', () => {
|
||||
const mutation = mockRename()
|
||||
renderSheet()
|
||||
it('saves the trimmed title and leaves edit mode on success', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onRename = vi.fn(() => Promise.resolve())
|
||||
renderSheet({ onRename })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
fireEvent.change(screen.getByLabelText('Session title'), {
|
||||
target: { value: ' New name ' },
|
||||
})
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }))
|
||||
|
||||
expect(mutation.mutate).toHaveBeenCalledWith(
|
||||
{ sessionID: 'ses_1', title: 'New name' },
|
||||
expect.objectContaining({ onSuccess: expect.any(Function) }),
|
||||
)
|
||||
|
||||
const options = mutation.mutate.mock.calls[0]![1] as { onSuccess: () => void }
|
||||
act(() => options.onSuccess())
|
||||
await user.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
await user.clear(screen.getByLabelText('Session title'))
|
||||
await user.type(screen.getByLabelText('Session title'), ' New name ')
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
|
||||
expect(onRename).toHaveBeenCalledWith('New name')
|
||||
expect(screen.queryByLabelText('Session title')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Fix the header')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('saves on Enter', () => {
|
||||
const mutation = mockRename()
|
||||
renderSheet()
|
||||
it('saves on Enter', async () => {
|
||||
const onRename = vi.fn(() => Promise.resolve())
|
||||
renderSheet({ onRename })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
fireEvent.change(screen.getByLabelText('Session title'), { target: { value: 'Entered' } })
|
||||
fireEvent.keyDown(screen.getByLabelText('Session title'), { key: 'Enter' })
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(screen.getByLabelText('Session title'), { key: 'Enter' })
|
||||
})
|
||||
|
||||
expect(mutation.mutate).toHaveBeenCalledWith(
|
||||
{ sessionID: 'ses_1', title: 'Entered' },
|
||||
expect.objectContaining({ onSuccess: expect.any(Function) }),
|
||||
)
|
||||
expect(onRename).toHaveBeenCalledWith('Entered')
|
||||
})
|
||||
|
||||
it('ignores Enter while an IME composition is active', () => {
|
||||
const mutation = mockRename()
|
||||
renderSheet()
|
||||
const onRename = vi.fn(() => Promise.resolve())
|
||||
renderSheet({ onRename })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
const input = screen.getByLabelText('Session title')
|
||||
fireEvent.change(input, { target: { value: 'にほんご' } })
|
||||
fireEvent.keyDown(input, { key: 'Enter', isComposing: true })
|
||||
|
||||
expect(mutation.mutate).not.toHaveBeenCalled()
|
||||
expect(onRename).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('cancels editing and resets the rename error', () => {
|
||||
const mutation = mockRename({ error: new Error('nope') })
|
||||
renderSheet()
|
||||
it('shows the rename failure inline', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderSheet({ onRename: failingRename() })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
expect(screen.getByText('Rename failed')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
|
||||
expect(await screen.findByText('Rename failed')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Session title')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('cancels editing and clears the rename error', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderSheet({ onRename: failingRename() })
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
expect(await screen.findByText('Rename failed')).toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Cancel' }))
|
||||
|
||||
expect(screen.queryByText('Rename failed')).not.toBeInTheDocument()
|
||||
expect(screen.queryByLabelText('Session title')).not.toBeInTheDocument()
|
||||
expect(mutation.reset).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows the rename failure inline', () => {
|
||||
mockRename({ error: new Error('nope') })
|
||||
renderSheet()
|
||||
it('disables the title field while a rename is pending', async () => {
|
||||
const user = userEvent.setup()
|
||||
const deferred = createDeferred()
|
||||
renderSheet({ onRename: () => deferred.promise })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
|
||||
expect(screen.getByText('Rename failed')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('disables the title field while a rename is pending', () => {
|
||||
mockRename({ isPending: true })
|
||||
renderSheet()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
|
||||
expect(screen.getByLabelText('Session title')).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled()
|
||||
|
||||
await act(async () => {
|
||||
deferred.resolve()
|
||||
})
|
||||
})
|
||||
|
||||
it('does not dismiss while a rename is pending', async () => {
|
||||
const user = userEvent.setup()
|
||||
const deferred = createDeferred()
|
||||
const onOpenChange = vi.fn()
|
||||
mockRename({ isPending: true })
|
||||
renderSheet({ onOpenChange })
|
||||
renderSheet({ onOpenChange, onRename: () => deferred.promise })
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
await user.keyboard('{Escape}')
|
||||
await user.click(screen.getByRole('button', { name: 'Close' }))
|
||||
|
||||
expect(onOpenChange).not.toHaveBeenCalled()
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument()
|
||||
|
||||
await act(async () => {
|
||||
deferred.resolve()
|
||||
})
|
||||
})
|
||||
|
||||
it('resets to view mode and clears the error when reopened', () => {
|
||||
const mutation = mockRename({ error: new Error('nope') })
|
||||
it('resets to view mode and clears the error when reopened', async () => {
|
||||
const user = userEvent.setup()
|
||||
|
||||
function Host() {
|
||||
const [open, setOpen] = useState(true)
|
||||
@@ -221,22 +219,28 @@ describe('SessionDetailsSheet', () => {
|
||||
<button type="button" onClick={() => setOpen((current) => !current)}>
|
||||
toggle
|
||||
</button>
|
||||
<SessionDetailsSheet {...baseProps} open={open} onOpenChange={setOpen} />
|
||||
<SessionDetailsSheet
|
||||
{...baseProps}
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
onRename={failingRename()}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
render(<Host />)
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
expect(screen.getByLabelText('Session title')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Rename' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Save' }))
|
||||
expect(await screen.findByText('Rename failed')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByText('toggle'))
|
||||
fireEvent.click(screen.getByText('toggle'))
|
||||
|
||||
expect(screen.queryByLabelText('Session title')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Rename failed')).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'Rename' })).toBeInTheDocument()
|
||||
expect(mutation.reset).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders as a bottom sheet on mobile', () => {
|
||||
|
||||
@@ -4,19 +4,18 @@ import { BottomSheet, BottomSheetContent, BottomSheetHeader } from '@/components
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { useUpdateSession } from '@/hooks/useOpenCode'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export interface SessionDetailsSheetProps {
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
sessionId: string
|
||||
title?: string
|
||||
serverName?: string
|
||||
remote: boolean
|
||||
project: string
|
||||
branch?: string | null
|
||||
directory?: string
|
||||
onRename: (title: string) => Promise<void>
|
||||
}
|
||||
|
||||
interface InfoRowProps {
|
||||
@@ -43,31 +42,32 @@ function InfoRow({ label, value, mono, leading }: InfoRowProps) {
|
||||
export function SessionDetailsSheet({
|
||||
open,
|
||||
onOpenChange,
|
||||
sessionId,
|
||||
title,
|
||||
serverName,
|
||||
remote,
|
||||
project,
|
||||
branch,
|
||||
directory,
|
||||
onRename,
|
||||
}: SessionDetailsSheetProps) {
|
||||
const isMobile = useMobile()
|
||||
const renameSession = useUpdateSession(directory)
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [draft, setDraft] = useState('')
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [renameFailed, setRenameFailed] = useState(false)
|
||||
const [lastOpen, setLastOpen] = useState(open)
|
||||
|
||||
if (open !== lastOpen) {
|
||||
setLastOpen(open)
|
||||
if (open) {
|
||||
setEditing(false)
|
||||
if (renameSession.error) renameSession.reset()
|
||||
setRenameFailed(false)
|
||||
}
|
||||
}
|
||||
|
||||
const displayTitle = title?.trim() ? title : 'Untitled Session'
|
||||
const trimmedDraft = draft.trim()
|
||||
const canSave = trimmedDraft.length > 0 && !renameSession.isPending
|
||||
const canSave = trimmedDraft.length > 0 && !saving
|
||||
|
||||
const startEditing = () => {
|
||||
setDraft(title ?? '')
|
||||
@@ -76,19 +76,25 @@ export function SessionDetailsSheet({
|
||||
|
||||
const cancelEditing = () => {
|
||||
setEditing(false)
|
||||
if (renameSession.error) renameSession.reset()
|
||||
setRenameFailed(false)
|
||||
}
|
||||
|
||||
const save = () => {
|
||||
const save = async () => {
|
||||
if (!canSave) return
|
||||
renameSession.mutate(
|
||||
{ sessionID: sessionId, title: trimmedDraft },
|
||||
{ onSuccess: () => setEditing(false) },
|
||||
)
|
||||
setSaving(true)
|
||||
setRenameFailed(false)
|
||||
try {
|
||||
await onRename(trimmedDraft)
|
||||
setEditing(false)
|
||||
} catch {
|
||||
setRenameFailed(true)
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
if (renameSession.isPending) return
|
||||
if (saving) return
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
@@ -116,13 +122,13 @@ export function SessionDetailsSheet({
|
||||
event.preventDefault()
|
||||
save()
|
||||
}}
|
||||
disabled={renameSession.isPending}
|
||||
disabled={saving}
|
||||
aria-label="Session title"
|
||||
placeholder="Session title"
|
||||
autoFocus
|
||||
className="w-full min-w-0 rounded border border-border bg-background px-3 py-2 text-sm font-semibold outline-none focus:border-primary focus:ring-2 focus:ring-primary/20 disabled:opacity-60"
|
||||
/>
|
||||
{renameSession.error && (
|
||||
{renameFailed && (
|
||||
<span className="text-xs text-destructive">Rename failed</span>
|
||||
)}
|
||||
<div className="flex items-center gap-2 pt-1">
|
||||
@@ -178,7 +184,7 @@ export function SessionDetailsSheet({
|
||||
isOpen={open}
|
||||
onClose={handleClose}
|
||||
ariaLabel="Session details"
|
||||
dismissible={!renameSession.isPending}
|
||||
dismissible={!saving}
|
||||
>
|
||||
<BottomSheetHeader title="Session details" />
|
||||
<BottomSheetContent>{body}</BottomSheetContent>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import type { ActiveWorkGroups, ActiveWorkItem, ActiveWorkState } from '@/lib/activeWork'
|
||||
import { stubMatchMedia } from '@/test/test-utils'
|
||||
import { makeRepo, makeSession } from '@/test/fixtures/session-picker'
|
||||
import { DEFAULT_ACTIVITY_WINDOW_MINUTES } from '@/api/types/settings'
|
||||
import { KeyboardShortcutsProvider } from '@/contexts/KeyboardShortcutsContext'
|
||||
import { OpenCodeServerProvider } from '@/contexts/OpenCodeServerContext'
|
||||
@@ -21,6 +22,7 @@ const mocks = vi.hoisted(() => ({
|
||||
| { directory: string; project: { id: string; directory: string; canonical: string } }
|
||||
| undefined,
|
||||
sessionsHook: vi.fn(),
|
||||
lastSessionServerId: null as string | null,
|
||||
fetchNextPage: vi.fn(),
|
||||
deleteSessionMock: vi.fn(),
|
||||
deletedSessionServerId: null as string | null,
|
||||
@@ -66,6 +68,7 @@ vi.mock('@/hooks/useOpenCode', async (importOriginal) => {
|
||||
options?: { search?: string; allDirectories?: boolean; project?: { id: string; subpath: string } },
|
||||
) => {
|
||||
mocks.sessionsHook()
|
||||
mocks.lastSessionServerId = useOpenCodeServerId()
|
||||
mocks.lastDirectories = directories
|
||||
mocks.lastAllDirectories = options?.allDirectories ?? false
|
||||
mocks.lastProject = options?.project
|
||||
@@ -127,30 +130,6 @@ vi.mock('@/stores/sessionStatusStore', async (importOriginal) => {
|
||||
return { ...actual, useSessionStatusForSession: () => ({ type: 'idle' }) }
|
||||
})
|
||||
|
||||
function session(id: string, title: string, directory: string, updated = Date.now()): Session {
|
||||
return {
|
||||
id,
|
||||
projectID: 'proj',
|
||||
title,
|
||||
time: { created: updated, updated },
|
||||
location: { directory },
|
||||
cost: 0,
|
||||
tokens: {},
|
||||
} as unknown as Session
|
||||
}
|
||||
|
||||
function repo(id: number, name: string, fullPath: string): Repo {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
localPath: fullPath,
|
||||
fullPath,
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
}
|
||||
}
|
||||
|
||||
function activeWorkItem(
|
||||
id: string,
|
||||
title: string,
|
||||
@@ -158,7 +137,7 @@ function activeWorkItem(
|
||||
state: ActiveWorkState = 'recent',
|
||||
): ActiveWorkItem {
|
||||
const itemRepo = mocks.repos.find((candidate) => candidate.fullPath === directory) ?? mocks.repos[0]
|
||||
const itemSession = session(id, title, directory)
|
||||
const itemSession = makeSession(id, title, directory)
|
||||
return {
|
||||
key: `${directory}:${id}`,
|
||||
session: itemSession,
|
||||
@@ -233,8 +212,9 @@ describe('SessionPickerDialog', () => {
|
||||
}
|
||||
mocks.getOpenCodeLocation.mockResolvedValue(mocks.locationData)
|
||||
mocks.lastProject = undefined
|
||||
mocks.lastSessionServerId = null
|
||||
mocks.sessionPins = []
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
mocks.sessionsData = []
|
||||
mocks.activeWorkGroups = { needsInput: [], running: [], recent: [] }
|
||||
mocks.activeWorkWindowMs = 0
|
||||
@@ -247,8 +227,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('opens with the active session as the cursor and marks it with a dot', () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_active', 'Active session', '/w/a', 3000),
|
||||
session('ses_other', 'Other session', '/w/a', 2000),
|
||||
makeSession('ses_active', 'Active session', '/w/a', 3000),
|
||||
makeSession('ses_other', 'Other session', '/w/a', 2000),
|
||||
]
|
||||
|
||||
renderPicker({ activeSessionID: 'ses_active' })
|
||||
@@ -262,8 +242,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('filters rows immediately as the query is typed', () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_alpha', 'alpha task', '/w/a', 2000),
|
||||
session('ses_beta', 'beta task', '/w/a', 1000),
|
||||
makeSession('ses_alpha', 'alpha task', '/w/a', 2000),
|
||||
makeSession('ses_beta', 'beta task', '/w/a', 1000),
|
||||
]
|
||||
|
||||
renderPicker()
|
||||
@@ -276,9 +256,9 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('moves the cursor with arrow keys and Ctrl+N/Ctrl+P, wrapping, and opens the row on Enter', () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_1', 'First', '/w/a', 3000),
|
||||
session('ses_2', 'Second', '/w/a', 2000),
|
||||
session('ses_3', 'Third', '/w/a', 1000),
|
||||
makeSession('ses_1', 'First', '/w/a', 3000),
|
||||
makeSession('ses_2', 'Second', '/w/a', 2000),
|
||||
makeSession('ses_3', 'Third', '/w/a', 1000),
|
||||
]
|
||||
const { onSelectSession } = renderPicker()
|
||||
|
||||
@@ -312,8 +292,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('toggles scope with Ctrl+A, persists it, queries every repo directory and shows repo labels', () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
session('ses_b', 'Beta session', '/w/b', 1000),
|
||||
makeSession('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
makeSession('ses_b', 'Beta session', '/w/b', 1000),
|
||||
]
|
||||
|
||||
renderPicker()
|
||||
@@ -381,8 +361,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('labels the sessions tab Sessions and lists every project without a current repo', () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
session('ses_b', 'Beta session', '/w/b', 1000),
|
||||
makeSession('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
makeSession('ses_b', 'Beta session', '/w/b', 1000),
|
||||
]
|
||||
|
||||
renderPicker({ currentRepo: undefined })
|
||||
@@ -428,8 +408,8 @@ describe('SessionPickerDialog', () => {
|
||||
it('starts a new session in a project row and marks a repo that is not ready', async () => {
|
||||
const onNavigate = vi.fn()
|
||||
mocks.repos = [
|
||||
repo(1, 'alpha', '/w/a'),
|
||||
{ ...repo(2, 'beta', '/w/b'), cloneStatus: 'cloning' },
|
||||
makeRepo(1, 'alpha', '/w/a'),
|
||||
{ ...makeRepo(2, 'beta', '/w/b'), cloneStatus: 'cloning' },
|
||||
]
|
||||
renderPicker({ onNavigate })
|
||||
|
||||
@@ -444,15 +424,15 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('lists project sessions across worktrees and labels them with the folder name', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a')]
|
||||
mocks.locationData = {
|
||||
directory: '/w/a',
|
||||
project: { id: 'proj_x', directory: '/w/a', canonical: '/w/a' },
|
||||
}
|
||||
mocks.sessionsData = [
|
||||
session('ses_root', 'Root session', '/w/a', 3000),
|
||||
session('ses_wt', 'Worktree session', '/w/.opencode/state/opencode/worktree/proj_x/test', 2000),
|
||||
session('ses_schedule', 'Schedule session', '/w/schedule-worktrees/job-11-run-361', 1000),
|
||||
makeSession('ses_root', 'Root session', '/w/a', 3000),
|
||||
makeSession('ses_wt', 'Worktree session', '/w/.opencode/state/opencode/worktree/proj_x/test', 2000),
|
||||
makeSession('ses_schedule', 'Schedule session', '/w/schedule-worktrees/job-11-run-361', 1000),
|
||||
]
|
||||
|
||||
renderPicker()
|
||||
@@ -471,10 +451,10 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('falls back to the repo directory listing when the location project is global', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
mocks.sessionsData = [
|
||||
session('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
session('ses_b', 'Beta session', '/w/b', 1000),
|
||||
makeSession('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
makeSession('ses_b', 'Beta session', '/w/b', 1000),
|
||||
]
|
||||
|
||||
renderPicker()
|
||||
@@ -486,12 +466,12 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('falls back to the repo directory listing when the location lookup fails', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
mocks.locationData = undefined
|
||||
mocks.getOpenCodeLocation.mockRejectedValue(new Error('location unavailable'))
|
||||
mocks.sessionsData = [
|
||||
session('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
session('ses_b', 'Beta session', '/w/b', 1000),
|
||||
makeSession('ses_a', 'Alpha session', '/w/a', 2000),
|
||||
makeSession('ses_b', 'Beta session', '/w/b', 1000),
|
||||
]
|
||||
|
||||
renderPicker()
|
||||
@@ -507,7 +487,7 @@ describe('SessionPickerDialog', () => {
|
||||
| undefined
|
||||
mocks.locationData = undefined
|
||||
mocks.getOpenCodeLocation.mockReturnValue(new Promise((resolve) => { resolveLocation = resolve }))
|
||||
mocks.sessionsData = [session('ses_a', 'Alpha session', '/w/a', 2000)]
|
||||
mocks.sessionsData = [makeSession('ses_a', 'Alpha session', '/w/a', 2000)]
|
||||
|
||||
renderPicker()
|
||||
|
||||
@@ -526,7 +506,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('does not query sessions while closed and queries after opening', async () => {
|
||||
mocks.sessionsData = [session('ses_1', 'First', '/w/a', 3000)]
|
||||
mocks.sessionsData = [makeSession('ses_1', 'First', '/w/a', 3000)]
|
||||
|
||||
function Host() {
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -556,8 +536,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('deletes on a second Ctrl+D and clears the pending state on a move', async () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_1', 'First', '/w/a', 3000),
|
||||
session('ses_2', 'Second', '/w/a', 2000),
|
||||
makeSession('ses_1', 'First', '/w/a', 3000),
|
||||
makeSession('ses_2', 'Second', '/w/a', 2000),
|
||||
]
|
||||
const { onDeleteActiveSession } = renderPicker()
|
||||
|
||||
@@ -581,7 +561,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('notifies when the active session is deleted before the delete completes', async () => {
|
||||
mocks.sessionsData = [session('ses_active', 'Active', '/w/a', 3000)]
|
||||
mocks.sessionsData = [makeSession('ses_active', 'Active', '/w/a', 3000)]
|
||||
let resolveDelete: () => void = () => undefined
|
||||
mocks.deleteSessionMock.mockReturnValue(
|
||||
new Promise<void>((resolve) => {
|
||||
@@ -603,8 +583,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('moves the cursor when a mouse pointer moves over a row', () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_1', 'First', '/w/a', 3000),
|
||||
session('ses_2', 'Second', '/w/a', 2000),
|
||||
makeSession('ses_1', 'First', '/w/a', 3000),
|
||||
makeSession('ses_2', 'Second', '/w/a', 2000),
|
||||
]
|
||||
renderPicker()
|
||||
|
||||
@@ -617,7 +597,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('opens the delete confirmation from the row menu', async () => {
|
||||
mocks.sessionsData = [session('ses_1', 'First', '/w/a', 3000)]
|
||||
mocks.sessionsData = [makeSession('ses_1', 'First', '/w/a', 3000)]
|
||||
renderPicker()
|
||||
const user = userEvent.setup()
|
||||
|
||||
@@ -629,8 +609,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('groups older sessions under per-day headings', () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_jan2', 'Jan two', '/w/a', new Date(2020, 0, 2, 12).getTime()),
|
||||
session('ses_jan1', 'Jan one', '/w/a', new Date(2020, 0, 1, 12).getTime()),
|
||||
makeSession('ses_jan2', 'Jan two', '/w/a', new Date(2020, 0, 2, 12).getTime()),
|
||||
makeSession('ses_jan1', 'Jan one', '/w/a', new Date(2020, 0, 1, 12).getTime()),
|
||||
]
|
||||
|
||||
renderPicker()
|
||||
@@ -641,8 +621,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('resets the query and cursor on reopen', async () => {
|
||||
mocks.sessionsData = [
|
||||
session('ses_active', 'Active session', '/w/a', 3000),
|
||||
session('ses_other', 'Other session', '/w/a', 2000),
|
||||
makeSession('ses_active', 'Active session', '/w/a', 3000),
|
||||
makeSession('ses_other', 'Other session', '/w/a', 2000),
|
||||
]
|
||||
|
||||
function Host() {
|
||||
@@ -700,7 +680,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('focuses the projects search input after clicking the Projects tab and filters on typing', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
@@ -715,7 +695,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('focuses the projects search input after switching tabs with the shortcut', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
@@ -727,7 +707,7 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('focuses the projects search input after the switch shortcut on a coarse pointer device', async () => {
|
||||
stubMatchMedia(false)
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
@@ -739,7 +719,7 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('does not focus the projects search input when switching tabs by pointer on a coarse pointer device', async () => {
|
||||
stubMatchMedia(false)
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
const user = userEvent.setup()
|
||||
renderPicker()
|
||||
|
||||
@@ -749,7 +729,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('lists repos in the projects tab and opens the cursor repo on Enter', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
const { onSelectRepo } = renderPicker()
|
||||
|
||||
openProjectsTab()
|
||||
@@ -765,7 +745,7 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('navigates the projects tab with wrapping arrows, PageUp/PageDown and Enter', async () => {
|
||||
mocks.repos = Array.from({ length: 12 }, (_, index) =>
|
||||
repo(index + 1, `repo-${index + 1}`, `/w/r${index + 1}`),
|
||||
makeRepo(index + 1, `repo-${index + 1}`, `/w/r${index + 1}`),
|
||||
)
|
||||
const { onSelectRepo } = renderPicker()
|
||||
|
||||
@@ -793,7 +773,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('opens a repo on click in the projects tab', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
const { onSelectRepo } = renderPicker()
|
||||
|
||||
openProjectsTab()
|
||||
@@ -805,8 +785,8 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
it('filters projects by name and branch', async () => {
|
||||
mocks.repos = [
|
||||
{ ...repo(1, 'alpha', '/w/a'), currentBranch: 'feature/x' },
|
||||
repo(2, 'beta', '/w/b'),
|
||||
{ ...makeRepo(1, 'alpha', '/w/a'), currentBranch: 'feature/x' },
|
||||
makeRepo(2, 'beta', '/w/b'),
|
||||
]
|
||||
renderPicker()
|
||||
|
||||
@@ -912,7 +892,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('groups active work into needs input, running and recent sections with repo labels', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
mocks.activeWorkGroups = {
|
||||
needsInput: [activeWorkItem('ses_ni', 'Needs input task', '/w/a', 'needs-input')],
|
||||
running: [activeWorkItem('ses_run', 'Running task', '/w/b', 'running')],
|
||||
@@ -958,7 +938,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('opens the cursor active row with Enter and selects its session and repo', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
mocks.activeWorkGroups = {
|
||||
needsInput: [],
|
||||
running: [activeWorkItem('ses_run', 'Running task', '/w/b', 'running')],
|
||||
@@ -979,7 +959,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('filters active work rows by title and drops sections left empty', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
mocks.activeWorkGroups = {
|
||||
needsInput: [activeWorkItem('ses_ni', 'Needs input task', '/w/a', 'needs-input')],
|
||||
running: [],
|
||||
@@ -999,7 +979,7 @@ describe('SessionPickerDialog', () => {
|
||||
})
|
||||
|
||||
it('pins an active work row from the shared row menu', async () => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
mocks.activeWorkGroups = {
|
||||
needsInput: [],
|
||||
running: [activeWorkItem('ses_run', 'Running task', '/w/b', 'running')],
|
||||
@@ -1022,11 +1002,11 @@ describe('SessionPickerDialog', () => {
|
||||
|
||||
describe('linked-server mode', () => {
|
||||
beforeEach(() => {
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a')]
|
||||
mocks.sessionsData = [session('ses_remote', 'Remote session', '/home/me/app')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a')]
|
||||
mocks.sessionsData = [makeSession('ses_remote', 'Remote session', '/home/me/app')]
|
||||
})
|
||||
|
||||
it('lists the project sessions without Manager-only tabs and reports the chosen server session', async () => {
|
||||
it('lists the project sessions with the linked server projects tab and reports the chosen server session', async () => {
|
||||
const onSelectRemoteSession = vi.fn()
|
||||
renderPicker({
|
||||
remote: {
|
||||
@@ -1037,7 +1017,7 @@ describe('SessionPickerDialog', () => {
|
||||
onSelectRemoteSession,
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('tab', { name: 'Projects' })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Projects' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: 'Activity' })).toBeInTheDocument()
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Remote session/ })
|
||||
@@ -1051,13 +1031,22 @@ describe('SessionPickerDialog', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('queries the linked server sessions without a host-supplied server provider', async () => {
|
||||
renderPicker({
|
||||
remote: { serverId: 'srv-1', serverName: 'Kitchen', projectDirectory: '/home/me/app' },
|
||||
})
|
||||
|
||||
expect(await screen.findByRole('option', { name: /Remote session/ })).toBeInTheDocument()
|
||||
expect(mocks.lastSessionServerId).toBe('srv-1')
|
||||
})
|
||||
|
||||
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'),
|
||||
session: makeSession('ses_remote', 'Remote pending', '/home/me/app'),
|
||||
repo: null,
|
||||
serverId: 'srv_kitchen',
|
||||
serverName: 'Kitchen',
|
||||
|
||||
@@ -3,9 +3,8 @@ import { useQuery } from '@tanstack/react-query'
|
||||
import { format, startOfDay } from 'date-fns'
|
||||
import { ChevronsUpDown, MoreHorizontal, Pin, PinOff, Plus } from 'lucide-react'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import { getOpenCodeLocation } from '@/api/opencode'
|
||||
import { OpenCodeServerProvider, useOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
||||
import { serverScopedKey } from '@/lib/serverScope'
|
||||
import { openCodeLocationQueryOptions } from '@/lib/openCodeLocation'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import { ACTIVE_WORK_GROUPS, MS_PER_MINUTE, formatActivityEmptyMessage } from '@/lib/activeWork'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -53,7 +52,6 @@ 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: 'Activity',
|
||||
@@ -71,7 +69,7 @@ function sessionsTabLabel(scopeEnabled: boolean, allProjects: boolean): string {
|
||||
return allProjects ? 'All sessions' : 'This project'
|
||||
}
|
||||
|
||||
interface RemotePickerScope {
|
||||
export interface RemotePickerScope {
|
||||
serverId: string
|
||||
serverName?: string
|
||||
projectDirectory?: string
|
||||
@@ -601,10 +599,8 @@ function SessionPickerContent({
|
||||
|
||||
const serverId = useOpenCodeServerId()
|
||||
const locationQuery = useQuery({
|
||||
queryKey: serverScopedKey(['opencode', 'location', currentRepo?.fullPath], serverId),
|
||||
queryFn: () => getOpenCodeLocation(currentRepo!.fullPath, serverId),
|
||||
...openCodeLocationQueryOptions(currentRepo?.fullPath ?? '', serverId),
|
||||
enabled: !allProjects && Boolean(currentRepo?.fullPath),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
})
|
||||
|
||||
const location = locationQuery.data
|
||||
@@ -1212,13 +1208,25 @@ export interface SessionPickerPanelProps {
|
||||
onSelectRepo: (repo: Repo) => void
|
||||
onNavigate: (path: string) => void
|
||||
remote?: RemotePickerScope
|
||||
remoteProjects?: boolean
|
||||
searchTrailing?: React.ReactNode
|
||||
onAddRepo?: () => void
|
||||
renderTitle?: (label: string) => React.ReactNode
|
||||
}
|
||||
|
||||
export function SessionPickerPanel({
|
||||
/**
|
||||
* Picker content shared by the desktop dialog and the mobile sheet. A remote scope supplies its own
|
||||
* server, so every host reads the linked server's sessions without wrapping the panel itself.
|
||||
*/
|
||||
export function SessionPickerPanel(props: SessionPickerPanelProps) {
|
||||
if (!props.remote) return <SessionPickerPanelBody {...props} />
|
||||
return (
|
||||
<OpenCodeServerProvider serverId={props.remote.serverId}>
|
||||
<SessionPickerPanelBody {...props} />
|
||||
</OpenCodeServerProvider>
|
||||
)
|
||||
}
|
||||
|
||||
function SessionPickerPanelBody({
|
||||
open,
|
||||
currentRepo,
|
||||
activeSessionID,
|
||||
@@ -1228,7 +1236,6 @@ export function SessionPickerPanel({
|
||||
onSelectRepo,
|
||||
onNavigate,
|
||||
remote,
|
||||
remoteProjects = false,
|
||||
searchTrailing,
|
||||
onAddRepo,
|
||||
renderTitle,
|
||||
@@ -1254,24 +1261,22 @@ export function SessionPickerPanel({
|
||||
[preferences],
|
||||
)
|
||||
const isRemote = remote !== undefined
|
||||
const pickerTabs = isRemote && !remoteProjects ? REMOTE_SESSION_PICKER_TABS : SESSION_PICKER_TABS
|
||||
const [tab, setTab] = useState<SessionPickerTab>('sessions')
|
||||
const [activeTab, setActiveTab] = useState<SessionPickerTab>('sessions')
|
||||
const [prevOpen, setPrevOpen] = useState(open)
|
||||
|
||||
if (prevOpen !== open) {
|
||||
setPrevOpen(open)
|
||||
if (open) setTab('sessions')
|
||||
if (open) setActiveTab('sessions')
|
||||
}
|
||||
|
||||
const activeTab: SessionPickerTab = pickerTabs.includes(tab) ? tab : 'sessions'
|
||||
const scopeEnabled = !isRemote && Boolean(currentRepo)
|
||||
const allProjects = scopeEnabled ? allProjectsPreference : true
|
||||
const readyRepo = scopeEnabled && currentRepo && isRepoReady(currentRepo) ? currentRepo : undefined
|
||||
|
||||
const toggleTab = useCallback(() => {
|
||||
focusSearchAfterSwitchRef.current = true
|
||||
setTab((current) => nextSessionPickerTab(current, pickerTabs))
|
||||
}, [pickerTabs])
|
||||
setActiveTab((current) => nextSessionPickerTab(current, SESSION_PICKER_TABS))
|
||||
}, [])
|
||||
|
||||
useShortcutActions({ switchPickerTab: open ? toggleTab : undefined })
|
||||
|
||||
@@ -1330,18 +1335,26 @@ export function SessionPickerPanel({
|
||||
const sessionsTrailing = withTrailing(newSessionButton)
|
||||
const projectsTrailing = withTrailing(addRepoButton)
|
||||
|
||||
const canToggleScope = scopeEnabled && activeTab === 'sessions'
|
||||
|
||||
/**
|
||||
* The sessions tab re-activates itself to toggle the scope. Pointer activation records whether the
|
||||
* tab was already selected before Radix activates it, so the click that follows only toggles a
|
||||
* tab that was already current. Keyboard activation toggles on Enter/Space directly and suppresses
|
||||
* the click Radix would otherwise synthesize for the same key press.
|
||||
*/
|
||||
const handleSessionsPointerDown = () => {
|
||||
scopePressRef.current = scopeEnabled && activeTab === 'sessions'
|
||||
scopePressRef.current = canToggleScope
|
||||
}
|
||||
|
||||
const handleSessionsClick = () => {
|
||||
if (!scopePressRef.current) return
|
||||
if (!canToggleScope || !scopePressRef.current) return
|
||||
scopePressRef.current = false
|
||||
toggleAllProjects()
|
||||
}
|
||||
|
||||
const handleSessionsKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
|
||||
if (!scopeEnabled || activeTab !== 'sessions') return
|
||||
if (!canToggleScope) return
|
||||
if (event.key !== 'Enter' && event.key !== ' ') return
|
||||
event.preventDefault()
|
||||
toggleAllProjects()
|
||||
@@ -1351,7 +1364,7 @@ export function SessionPickerPanel({
|
||||
<>
|
||||
<Tabs
|
||||
value={activeTab}
|
||||
onValueChange={(value) => setTab(value as SessionPickerTab)}
|
||||
onValueChange={(value) => setActiveTab(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">
|
||||
@@ -1369,9 +1382,7 @@ export function SessionPickerPanel({
|
||||
<ChevronsUpDown aria-hidden="true" className="ml-1 h-3 w-3 shrink-0 opacity-60" />
|
||||
)}
|
||||
</TabsTrigger>
|
||||
{pickerTabs.includes('projects') && (
|
||||
<TabsTrigger value="projects">{SESSION_PICKER_TAB_LABELS.projects}</TabsTrigger>
|
||||
)}
|
||||
<TabsTrigger value="projects">{SESSION_PICKER_TAB_LABELS.projects}</TabsTrigger>
|
||||
</TabsList>
|
||||
</div>
|
||||
<TabsContent
|
||||
@@ -1423,33 +1434,31 @@ export function SessionPickerPanel({
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
{pickerTabs.includes('projects') && (
|
||||
<TabsContent
|
||||
value="projects"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
{remote ? (
|
||||
<RemoteProjectPickerContent
|
||||
serverId={remote.serverId}
|
||||
open={open}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
searchTrailing={projectsTrailing}
|
||||
onOpenProject={onNavigate}
|
||||
onSelectSession={onNavigate}
|
||||
/>
|
||||
) : (
|
||||
<ProjectPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
onSelectRepo={onSelectRepo}
|
||||
onNavigate={onNavigate}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
searchTrailing={projectsTrailing}
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
)}
|
||||
<TabsContent
|
||||
value="projects"
|
||||
className="mt-0 flex min-h-0 w-full min-w-0 flex-1 flex-col px-0"
|
||||
>
|
||||
{remote ? (
|
||||
<RemoteProjectPickerContent
|
||||
serverId={remote.serverId}
|
||||
open={open}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
searchTrailing={projectsTrailing}
|
||||
onOpenProject={onNavigate}
|
||||
onSelectSession={onNavigate}
|
||||
/>
|
||||
) : (
|
||||
<ProjectPickerContent
|
||||
open={open}
|
||||
currentRepo={currentRepo}
|
||||
onSelectRepo={onSelectRepo}
|
||||
onNavigate={onNavigate}
|
||||
switchHint={switchHint}
|
||||
searchInputRef={projectSearchInputRef}
|
||||
searchTrailing={projectsTrailing}
|
||||
/>
|
||||
)}
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
{addRepoOpen && !onAddRepo && <AddRepoDialog open onOpenChange={setAddRepoOpen} />}
|
||||
</>
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { render, screen, fireEvent, act } from '@testing-library/react'
|
||||
import { MemoryRouter, Route, Routes, useLocation, useNavigationType } from 'react-router-dom'
|
||||
import { render, screen, fireEvent, act, waitFor } from '@testing-library/react'
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import type { ActiveWorkGroups, ActiveWorkItem } from '@/lib/activeWork'
|
||||
import { DEFAULT_ACTIVITY_WINDOW_MINUTES } from '@/api/types/settings'
|
||||
import { KeyboardShortcutsProvider } from '@/contexts/KeyboardShortcutsContext'
|
||||
import { useSidebarServerStore } from '@/stores/sidebarServerStore'
|
||||
import { stubMatchMedia } from '@/test/test-utils'
|
||||
import { LocationCatcher, stubMatchMedia } from '@/test/test-utils'
|
||||
import { makeRepo, makeSession } from '@/test/fixtures/session-picker'
|
||||
import { SessionPickerSheet } from './SessionPickerSheet'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
@@ -22,6 +23,7 @@ const mocks = vi.hoisted(() => ({
|
||||
| undefined,
|
||||
getOpenCodeLocation: vi.fn(),
|
||||
listProjects: vi.fn(),
|
||||
getSession: vi.fn(),
|
||||
repos: [] as Repo[],
|
||||
activeWorkGroups: { needsInput: [], running: [], recent: [] } as ActiveWorkGroups,
|
||||
}))
|
||||
@@ -32,7 +34,12 @@ vi.mock('@/hooks/useSettings', () => ({
|
||||
|
||||
vi.mock('@/api/opencode', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/api/opencode')>()
|
||||
return { ...actual, getOpenCodeLocation: mocks.getOpenCodeLocation, listProjects: mocks.listProjects }
|
||||
return {
|
||||
...actual,
|
||||
getOpenCodeLocation: mocks.getOpenCodeLocation,
|
||||
listProjects: mocks.listProjects,
|
||||
getSession: mocks.getSession,
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('@/api/repos', () => ({
|
||||
@@ -112,30 +119,6 @@ vi.mock('@/stores/sessionStatusStore', async (importOriginal) => {
|
||||
return { ...actual, useSessionStatusForSession: () => ({ type: 'idle' }) }
|
||||
})
|
||||
|
||||
function session(id: string, title: string, directory: string, updated = Date.now()): Session {
|
||||
return {
|
||||
id,
|
||||
projectID: 'proj',
|
||||
title,
|
||||
time: { created: updated, updated },
|
||||
location: { directory },
|
||||
cost: 0,
|
||||
tokens: {},
|
||||
} as unknown as Session
|
||||
}
|
||||
|
||||
function repo(id: number, name: string, fullPath: string): Repo {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
localPath: fullPath,
|
||||
fullPath,
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
}
|
||||
}
|
||||
|
||||
function activeWorkItem(
|
||||
id: string,
|
||||
directory: string,
|
||||
@@ -145,8 +128,8 @@ function activeWorkItem(
|
||||
return {
|
||||
key: `${server?.id ?? LOCAL_OPENCODE_SERVER_ID}:${id}`,
|
||||
state: 'recent',
|
||||
session: session(id, `Active ${id}`, directory, now),
|
||||
repo: server ? null : repo(1, 'alpha', directory),
|
||||
session: makeSession(id, `Active ${id}`, directory, now),
|
||||
repo: server ? null : makeRepo(1, 'alpha', directory),
|
||||
serverId: server?.id ?? null,
|
||||
serverName: server?.name ?? null,
|
||||
updatedAt: now,
|
||||
@@ -154,17 +137,16 @@ function activeWorkItem(
|
||||
}
|
||||
}
|
||||
|
||||
function LocationProbe() {
|
||||
const location = useLocation()
|
||||
const navigationType = useNavigationType()
|
||||
return (
|
||||
<div data-testid="location">{`${location.pathname}${location.search} ${navigationType}`}</div>
|
||||
)
|
||||
}
|
||||
|
||||
function renderSheet(initialEntries: string[] = ['/repos/1?mobileTab=sessions']) {
|
||||
function renderSheet(
|
||||
initialEntries: string[] = ['/repos/1?mobileTab=sessions'],
|
||||
options: { isOpen?: boolean; cachedRepos?: Repo[] } = {},
|
||||
) {
|
||||
const onClose = vi.fn()
|
||||
const capturedPathname: { current: string } = { current: '' }
|
||||
const capturedSearch: { current: string } = { current: '' }
|
||||
const capturedNavigationType: { current: string } = { current: '' }
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
||||
if (options.cachedRepos) queryClient.setQueryData(['repos'], options.cachedRepos)
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<KeyboardShortcutsProvider>
|
||||
@@ -174,8 +156,12 @@ function renderSheet(initialEntries: string[] = ['/repos/1?mobileTab=sessions'])
|
||||
path="*"
|
||||
element={
|
||||
<>
|
||||
<SessionPickerSheet isOpen onClose={onClose} />
|
||||
<LocationProbe />
|
||||
<SessionPickerSheet isOpen={options.isOpen ?? true} onClose={onClose} />
|
||||
<LocationCatcher
|
||||
capturedPathname={capturedPathname}
|
||||
capturedSearch={capturedSearch}
|
||||
capturedNavigationType={capturedNavigationType}
|
||||
/>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
@@ -184,7 +170,11 @@ function renderSheet(initialEntries: string[] = ['/repos/1?mobileTab=sessions'])
|
||||
</KeyboardShortcutsProvider>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
return { onClose }
|
||||
return {
|
||||
onClose,
|
||||
location: () =>
|
||||
`${capturedPathname.current}${capturedSearch.current} ${capturedNavigationType.current}`,
|
||||
}
|
||||
}
|
||||
|
||||
describe('SessionPickerSheet', () => {
|
||||
@@ -193,7 +183,7 @@ describe('SessionPickerSheet', () => {
|
||||
localStorage.clear()
|
||||
stubMatchMedia(true)
|
||||
useSidebarServerStore.setState({ serverId: LOCAL_OPENCODE_SERVER_ID })
|
||||
mocks.repos = [repo(1, 'alpha', '/w/a'), repo(2, 'beta', '/w/b')]
|
||||
mocks.repos = [makeRepo(1, 'alpha', '/w/a'), makeRepo(2, 'beta', '/w/b')]
|
||||
mocks.sessionsData = []
|
||||
mocks.lastDirectories = []
|
||||
mocks.lastAllDirectories = false
|
||||
@@ -205,6 +195,7 @@ describe('SessionPickerSheet', () => {
|
||||
project: { id: 'global', directory: '/w/a', canonical: '/w/a' },
|
||||
}
|
||||
mocks.getOpenCodeLocation.mockResolvedValue(mocks.locationData)
|
||||
mocks.getSession.mockResolvedValue(null)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
@@ -222,37 +213,35 @@ describe('SessionPickerSheet', () => {
|
||||
})
|
||||
|
||||
it('navigates to the chosen session, replacing the sheet history entry', async () => {
|
||||
mocks.sessionsData = [session('ses_one', 'Solo session', '/w/a')]
|
||||
mocks.sessionsData = [makeSession('ses_one', 'Solo session', '/w/a')]
|
||||
|
||||
renderSheet()
|
||||
const { location } = renderSheet()
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Solo session/ })
|
||||
fireEvent.click(row)
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/ses_one REPLACE')
|
||||
expect(location()).toBe('/repos/1/sessions/ses_one REPLACE')
|
||||
})
|
||||
|
||||
it('closes instead of navigating when the chosen session is already open', async () => {
|
||||
mocks.sessionsData = [session('ses_one', 'Solo session', '/w/a')]
|
||||
mocks.sessionsData = [makeSession('ses_one', 'Solo session', '/w/a')]
|
||||
|
||||
const { onClose } = renderSheet(['/repos/1/sessions/ses_one?mobileTab=sessions'])
|
||||
const { onClose, location } = renderSheet(['/repos/1/sessions/ses_one?mobileTab=sessions'])
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Solo session/ })
|
||||
fireEvent.click(row)
|
||||
|
||||
expect(onClose).toHaveBeenCalled()
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/repos/1/sessions/ses_one?mobileTab=sessions POP',
|
||||
)
|
||||
expect(location()).toBe('/repos/1/sessions/ses_one?mobileTab=sessions POP')
|
||||
})
|
||||
|
||||
it('creates a session in the current repo from the header action and opens it', async () => {
|
||||
renderSheet()
|
||||
const { location } = renderSheet()
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'New session in alpha' }))
|
||||
|
||||
expect(mocks.createSessionDirectories).toEqual(['/w/a'])
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/ses_new REPLACE')
|
||||
expect(location()).toBe('/repos/1/sessions/ses_new REPLACE')
|
||||
})
|
||||
|
||||
it('opens the add repository dialog from the projects tab header action', async () => {
|
||||
@@ -267,9 +256,9 @@ describe('SessionPickerSheet', () => {
|
||||
|
||||
it('lists and opens the linked server sessions when a linked server is selected', async () => {
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
mocks.sessionsData = [session('ses_remote', 'Remote session', '/home/me/app')]
|
||||
mocks.sessionsData = [makeSession('ses_remote', 'Remote session', '/home/me/app')]
|
||||
|
||||
renderSheet()
|
||||
const { location } = renderSheet()
|
||||
|
||||
const row = await screen.findByRole('option', { name: /Remote session/ })
|
||||
expect(row).toHaveTextContent('Kitchen')
|
||||
@@ -280,9 +269,7 @@ describe('SessionPickerSheet', () => {
|
||||
|
||||
fireEvent.click(row)
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_kitchen/sessions/ses_remote REPLACE',
|
||||
)
|
||||
expect(location()).toBe('/servers/srv_kitchen/sessions/ses_remote REPLACE')
|
||||
})
|
||||
|
||||
it('lists the linked server projects on the projects tab and opens one', async () => {
|
||||
@@ -297,18 +284,16 @@ describe('SessionPickerSheet', () => {
|
||||
},
|
||||
])
|
||||
|
||||
renderSheet()
|
||||
const { location } = renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Projects' }))
|
||||
fireEvent.click(await screen.findByText('Alpha'))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_kitchen/projects?directory=%2Fprojects%2Falpha REPLACE',
|
||||
)
|
||||
expect(location()).toBe('/servers/srv_kitchen/projects?directory=%2Fprojects%2Falpha REPLACE')
|
||||
})
|
||||
|
||||
it('follows the sidebar server selection to list that server', async () => {
|
||||
mocks.sessionsData = [session('ses_remote', 'Remote session', '/home/me/app')]
|
||||
mocks.sessionsData = [makeSession('ses_remote', 'Remote session', '/home/me/app')]
|
||||
|
||||
renderSheet()
|
||||
|
||||
@@ -328,12 +313,12 @@ describe('SessionPickerSheet', () => {
|
||||
recent: [activeWorkItem('ses_active', '/w/a')],
|
||||
}
|
||||
|
||||
renderSheet()
|
||||
const { location } = renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Activity' }))
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Active ses_active/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/ses_active REPLACE')
|
||||
expect(location()).toBe('/repos/1/sessions/ses_active REPLACE')
|
||||
})
|
||||
|
||||
it('opens a remote activity row on its own server while the local server is selected', async () => {
|
||||
@@ -343,14 +328,12 @@ describe('SessionPickerSheet', () => {
|
||||
recent: [activeWorkItem('ses_kitchen', '/home/me/app', { id: 'srv_kitchen', name: 'Kitchen' })],
|
||||
}
|
||||
|
||||
renderSheet()
|
||||
const { location } = renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Activity' }))
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Active ses_kitchen/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_kitchen/sessions/ses_kitchen REPLACE',
|
||||
)
|
||||
expect(location()).toBe('/servers/srv_kitchen/sessions/ses_kitchen REPLACE')
|
||||
})
|
||||
|
||||
it('opens a remote activity row of the same session id that is open on another server', async () => {
|
||||
@@ -361,26 +344,28 @@ describe('SessionPickerSheet', () => {
|
||||
recent: [activeWorkItem('ses_shared', '/home/me/hall', { id: 'srv_hall', name: 'Hall' })],
|
||||
}
|
||||
|
||||
const { onClose } = renderSheet(['/servers/srv_kitchen/sessions/ses_shared?mobileTab=sessions'])
|
||||
const { onClose, location } = renderSheet([
|
||||
'/servers/srv_kitchen/sessions/ses_shared?mobileTab=sessions',
|
||||
])
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Activity' }))
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Active ses_shared/ }))
|
||||
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_hall/sessions/ses_shared REPLACE',
|
||||
)
|
||||
expect(location()).toBe('/servers/srv_hall/sessions/ses_shared REPLACE')
|
||||
})
|
||||
|
||||
it('opens a local session row that shares the id of the open remote session', async () => {
|
||||
mocks.sessionsData = [session('ses_shared', 'Shared session', '/w/a')]
|
||||
mocks.sessionsData = [makeSession('ses_shared', 'Shared session', '/w/a')]
|
||||
|
||||
const { onClose } = renderSheet(['/servers/srv_kitchen/sessions/ses_shared?mobileTab=sessions'])
|
||||
const { onClose, location } = renderSheet([
|
||||
'/servers/srv_kitchen/sessions/ses_shared?mobileTab=sessions',
|
||||
])
|
||||
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Shared session/ }))
|
||||
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/ses_shared REPLACE')
|
||||
expect(location()).toBe('/repos/1/sessions/ses_shared REPLACE')
|
||||
})
|
||||
|
||||
it('opens a session row of another linked server than the selected one', async () => {
|
||||
@@ -391,13 +376,67 @@ describe('SessionPickerSheet', () => {
|
||||
recent: [activeWorkItem('ses_hall', '/home/me/hall', { id: 'srv_hall', name: 'Hall' })],
|
||||
}
|
||||
|
||||
renderSheet()
|
||||
const { location } = renderSheet()
|
||||
|
||||
fireEvent.mouseDown(screen.getByRole('tab', { name: 'Activity' }))
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Active ses_hall/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent(
|
||||
'/servers/srv_hall/sessions/ses_hall REPLACE',
|
||||
expect(location()).toBe('/servers/srv_hall/sessions/ses_hall REPLACE')
|
||||
})
|
||||
|
||||
it('keeps the assistant session flag when choosing another session of the same repo', async () => {
|
||||
mocks.sessionsData = [makeSession('ses_b', 'Second assistant session', '/w/a')]
|
||||
|
||||
const { location } = renderSheet(['/repos/1/sessions/ses_a?assistant=1&mobileTab=sessions'])
|
||||
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Second assistant session/ }))
|
||||
|
||||
expect(location()).toBe('/repos/1/sessions/ses_b?assistant=1 REPLACE')
|
||||
})
|
||||
|
||||
it('drops the assistant session flag when choosing a session of another repo', async () => {
|
||||
localStorage.setItem('oc:session-picker:all-projects', 'true')
|
||||
mocks.sessionsData = [
|
||||
makeSession('ses_a', 'Assistant session', '/w/a'),
|
||||
makeSession('ses_b', 'Beta session', '/w/b'),
|
||||
]
|
||||
|
||||
const { location } = renderSheet(['/repos/1/sessions/ses_a?assistant=1&mobileTab=sessions'])
|
||||
|
||||
fireEvent.click(await screen.findByRole('option', { name: /Beta session/ }))
|
||||
|
||||
expect(location()).toBe('/repos/2/sessions/ses_b REPLACE')
|
||||
})
|
||||
|
||||
it('scopes the sheet to the open remote session directory on a linked server session route', async () => {
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
mocks.getSession.mockResolvedValue(makeSession('ses_remote', 'Remote session', '/home/me/app'))
|
||||
|
||||
renderSheet(['/servers/srv_kitchen/sessions/ses_remote?mobileTab=sessions'])
|
||||
|
||||
await waitFor(() => expect(mocks.lastDirectories).toEqual(['/home/me/app']))
|
||||
expect(mocks.lastAllDirectories).toBe(false)
|
||||
})
|
||||
|
||||
it('does not resolve the remote session directory while the sheet is closed', async () => {
|
||||
useSidebarServerStore.setState({ serverId: 'srv_kitchen' })
|
||||
|
||||
renderSheet(['/servers/srv_kitchen/sessions/ses_remote'], { isOpen: false })
|
||||
|
||||
await waitFor(() => expect(mocks.getSession).not.toHaveBeenCalled())
|
||||
})
|
||||
|
||||
it('prefetches the project location on a repo route while the sheet is closed', async () => {
|
||||
renderSheet(['/repos/1'], { isOpen: false, cachedRepos: mocks.repos })
|
||||
|
||||
await waitFor(() =>
|
||||
expect(mocks.getOpenCodeLocation).toHaveBeenCalledWith('/w/a', LOCAL_OPENCODE_SERVER_ID),
|
||||
)
|
||||
})
|
||||
|
||||
it('does not prefetch the project location outside a repo route', async () => {
|
||||
renderSheet(['/'], { isOpen: false, cachedRepos: mocks.repos })
|
||||
|
||||
await waitFor(() => expect(mocks.getOpenCodeLocation).not.toHaveBeenCalled())
|
||||
})
|
||||
})
|
||||
@@ -1,14 +1,11 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import { useState } from 'react'
|
||||
import { BottomSheet } from '@/components/ui/bottom-sheet'
|
||||
import { LinkedServersNav } from '@/components/navigation/LinkedServersNav'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { SessionPickerPanel } from '@/components/session/SessionPickerDialog'
|
||||
import { OpenCodeServerProvider } from '@/contexts/OpenCodeServerContext'
|
||||
import { useSessionPickerRouteScope } from '@/hooks/useSessionPickerRouteScope'
|
||||
import { getRepoPath, getServerSessionPath, getSessionPath } from '@/lib/navigation'
|
||||
import { useSessionPickerLocationPrefetch } from '@/hooks/useSessionPickerLocationPrefetch'
|
||||
import { useSessionPickerNavigation } from '@/hooks/useSessionPickerNavigation'
|
||||
|
||||
interface SessionPickerSheetProps {
|
||||
isOpen: boolean
|
||||
@@ -16,59 +13,18 @@ interface SessionPickerSheetProps {
|
||||
}
|
||||
|
||||
export function SessionPickerSheet({ isOpen, onClose }: SessionPickerSheetProps) {
|
||||
const navigate = useNavigate()
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false)
|
||||
const { currentRepo, activeSessionID, activeServerId, remote } = useSessionPickerRouteScope(isOpen)
|
||||
|
||||
const navigateReplacing = useCallback(
|
||||
(path: string) => {
|
||||
navigate(path, { replace: true })
|
||||
},
|
||||
[navigate],
|
||||
)
|
||||
|
||||
const handleSelectSession = useCallback(
|
||||
(session: Session, repo: Repo) => {
|
||||
if (session.id === activeSessionID && activeServerId === LOCAL_OPENCODE_SERVER_ID) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
navigateReplacing(getSessionPath(repo.id, session.id))
|
||||
},
|
||||
[activeServerId, activeSessionID, navigateReplacing, onClose],
|
||||
)
|
||||
|
||||
const handleSelectRemoteSession = useCallback(
|
||||
(session: Session, serverId: string) => {
|
||||
if (session.id === activeSessionID && serverId === activeServerId) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
navigateReplacing(getServerSessionPath(serverId, session.id))
|
||||
},
|
||||
[activeServerId, activeSessionID, navigateReplacing, onClose],
|
||||
)
|
||||
|
||||
const handleDeleteActiveSession = useCallback(() => {
|
||||
if (!currentRepo) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
navigateReplacing(getRepoPath(currentRepo.id))
|
||||
}, [currentRepo, navigateReplacing, onClose])
|
||||
const { currentRepo, activeSessionID, remote } = useSessionPickerRouteScope(isOpen)
|
||||
const pickerNavigation = useSessionPickerNavigation({ mode: 'replace', onClose })
|
||||
useSessionPickerLocationPrefetch()
|
||||
|
||||
const panel = isOpen ? (
|
||||
<SessionPickerPanel
|
||||
open={isOpen}
|
||||
currentRepo={currentRepo}
|
||||
activeSessionID={activeSessionID}
|
||||
onSelectSession={handleSelectSession}
|
||||
onSelectRemoteSession={handleSelectRemoteSession}
|
||||
onDeleteActiveSession={handleDeleteActiveSession}
|
||||
onSelectRepo={(repo) => navigateReplacing(getRepoPath(repo.id))}
|
||||
onNavigate={navigateReplacing}
|
||||
{...pickerNavigation}
|
||||
remote={remote}
|
||||
remoteProjects
|
||||
searchTrailing={<LinkedServersNav variant="header" />}
|
||||
onAddRepo={() => {
|
||||
onClose()
|
||||
@@ -80,11 +36,7 @@ export function SessionPickerSheet({ isOpen, onClose }: SessionPickerSheetProps)
|
||||
return (
|
||||
<>
|
||||
<BottomSheet isOpen={isOpen} onClose={onClose} heightClass="h-[90dvh]" ariaLabel="Sessions">
|
||||
{remote ? (
|
||||
<OpenCodeServerProvider serverId={remote.serverId}>{panel}</OpenCodeServerProvider>
|
||||
) : (
|
||||
panel
|
||||
)}
|
||||
{panel}
|
||||
</BottomSheet>
|
||||
<AddRepoDialog open={addRepoOpen} onOpenChange={setAddRepoOpen} />
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user