mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(frontend): compare the active session's server before closing the picker sheet
This commit is contained in:
1 parent
651b9b9995
commit
81fb2d4033
3 files changed
+43
-10
No files matched your search
@@ -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: [],
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user