From 81fb2d40339ecfa4992b1316904528ae71523ef0 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Fri, 23 Oct 2026 21:25:22 -0400 Subject: [PATCH] fix(frontend): compare the active session's server before closing the picker sheet --- .../session/SessionPickerSheet.test.tsx | 32 ++++++++++++++++++- .../components/session/SessionPickerSheet.tsx | 11 ++++--- .../src/hooks/useSessionPickerRouteScope.ts | 10 +++--- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/session/SessionPickerSheet.test.tsx b/frontend/src/components/session/SessionPickerSheet.test.tsx index 2181373c..7440cd75 100644 --- a/frontend/src/components/session/SessionPickerSheet.test.tsx +++ b/frontend/src/components/session/SessionPickerSheet.test.tsx @@ -353,7 +353,37 @@ describe('SessionPickerSheet', () => { ) }) - it('opens an activity row of another linked server than the selected one', async () => { + it('opens a remote activity row of the same session id that is open on another server', async () => { + useSidebarServerStore.setState({ serverId: 'srv_kitchen' }) + mocks.activeWorkGroups = { + needsInput: [], + running: [], + recent: [activeWorkItem('ses_shared', '/home/me/hall', { id: 'srv_hall', name: 'Hall' })], + } + + const { onClose } = 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', + ) + }) + + 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')] + + const { onClose } = 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') + }) + + it('opens a session row of another linked server than the selected one', async () => { useSidebarServerStore.setState({ serverId: 'srv_kitchen' }) mocks.activeWorkGroups = { needsInput: [], diff --git a/frontend/src/components/session/SessionPickerSheet.tsx b/frontend/src/components/session/SessionPickerSheet.tsx index 2934046a..19422d3d 100644 --- a/frontend/src/components/session/SessionPickerSheet.tsx +++ b/frontend/src/components/session/SessionPickerSheet.tsx @@ -1,5 +1,6 @@ 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 { BottomSheet } from '@/components/ui/bottom-sheet' import { LinkedServersNav } from '@/components/navigation/LinkedServersNav' @@ -17,7 +18,7 @@ interface SessionPickerSheetProps { export function SessionPickerSheet({ isOpen, onClose }: SessionPickerSheetProps) { const navigate = useNavigate() const [addRepoOpen, setAddRepoOpen] = useState(false) - const { currentRepo, activeSessionID, remote } = useSessionPickerRouteScope(isOpen) + const { currentRepo, activeSessionID, activeServerId, remote } = useSessionPickerRouteScope(isOpen) const navigateReplacing = useCallback( (path: string) => { @@ -28,24 +29,24 @@ export function SessionPickerSheet({ isOpen, onClose }: SessionPickerSheetProps) const handleSelectSession = useCallback( (session: Session, repo: Repo) => { - if (session.id === activeSessionID) { + if (session.id === activeSessionID && activeServerId === LOCAL_OPENCODE_SERVER_ID) { onClose() return } navigateReplacing(getSessionPath(repo.id, session.id)) }, - [activeSessionID, navigateReplacing, onClose], + [activeServerId, activeSessionID, navigateReplacing, onClose], ) const handleSelectRemoteSession = useCallback( (session: Session, serverId: string) => { - if (session.id === activeSessionID) { + if (session.id === activeSessionID && serverId === activeServerId) { onClose() return } navigateReplacing(getServerSessionPath(serverId, session.id)) }, - [activeSessionID, navigateReplacing, onClose], + [activeServerId, activeSessionID, navigateReplacing, onClose], ) const handleDeleteActiveSession = useCallback(() => { diff --git a/frontend/src/hooks/useSessionPickerRouteScope.ts b/frontend/src/hooks/useSessionPickerRouteScope.ts index f9625292..7b13797f 100644 --- a/frontend/src/hooks/useSessionPickerRouteScope.ts +++ b/frontend/src/hooks/useSessionPickerRouteScope.ts @@ -9,6 +9,7 @@ import { useSidebarServerSelection } from '@/hooks/useSidebarServerSelection' export interface SessionPickerRouteScope { currentRepo: Repo | undefined activeSessionID: string | undefined + activeServerId: string | undefined isRemote: boolean remote: { serverId: string; serverName?: string; projectDirectory?: string } | undefined } @@ -21,23 +22,24 @@ export function useSessionPickerRouteScope(enabled: boolean): SessionPickerRoute const isRemote = selectedServerId !== LOCAL_OPENCODE_SERVER_ID const repoRoute = parseRepoRoute(pathname) + const serverSessionRoute = parseServerSessionRoute(pathname) const currentRepo = isRemote || repoRoute.repoId === null ? undefined : repos.find((candidate) => candidate.id === repoRoute.repoId) - const activeSessionID = repoRoute.sessionId - ?? parseServerSessionRoute(pathname)?.sessionId - ?? undefined + const activeSessionID = repoRoute.sessionId ?? serverSessionRoute?.sessionId ?? undefined + const activeServerId = repoRoute.sessionId ? LOCAL_OPENCODE_SERVER_ID : serverSessionRoute?.serverId const remoteProjectDirectory = isRemote ? parseServerProjectRoute(pathname, search)?.directory : undefined if (!isRemote) { - return { currentRepo, activeSessionID, isRemote, remote: undefined } + return { currentRepo, activeSessionID, activeServerId, isRemote, remote: undefined } } return { currentRepo, activeSessionID, + activeServerId, isRemote, remote: { serverId: selectedServerId,