mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(frontend): open session details from the header
Pressing the session title opens a details sheet with server, project, branch and directory and inline rename. Linked-server sessions show a server icon and their branch, child sessions show a parent session pill, a banner marks paused live updates while the stream reconnects, and the header context indicator is removed now that usage lives on the model pill.
This commit is contained in:
1 parent
52162d5c4a
commit
d99fcc268e
20 files changed
+732
-418
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { FolderGit2, GitBranch, Loader2, Plus, Server } from 'lucide-react'
|
||||
import { getVcsInfo, listProjects } from '@/api/opencode'
|
||||
import { listProjects } from '@/api/opencode'
|
||||
import { useCreateSession } from '@/hooks/useOpenCode'
|
||||
import { useVcsInfo } from '@/hooks/useVcsInfo'
|
||||
import { useOpenCodeServers } from '@/hooks/useOpenCodeServers'
|
||||
import { useSettingsDialog } from '@/hooks/useSettingsDialog'
|
||||
import { useSSE } from '@/hooks/useSSE'
|
||||
@@ -50,12 +51,7 @@ function RemoteProjectContent({ serverId, directory }: { serverId: string; direc
|
||||
retry: false,
|
||||
})
|
||||
|
||||
const vcsQuery = useQuery({
|
||||
queryKey: [...serverScopedKey(['opencode', 'vcs', directory ?? ''], serverId), 'info'],
|
||||
queryFn: () => getVcsInfo(directory ?? '', serverId),
|
||||
enabled: isReady,
|
||||
retry: false,
|
||||
})
|
||||
const vcsQuery = useVcsInfo(directory, serverId, { enabled: isReady })
|
||||
|
||||
useSSE(directory)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { repoQueryOptions } from "@/lib/repoQuery";
|
||||
import { MessageThread } from "@/components/message/MessageThread";
|
||||
import { PromptInput, type PromptInputHandle } from "@/components/message/PromptInput";
|
||||
import { FloatingTTSButton } from '@/components/message/FloatingTTSButton'
|
||||
import { X, CornerUpLeft, GitBranch, ArrowDown } from "lucide-react";
|
||||
import { X, CornerUpLeft, GitBranch, ArrowDown, Server } from "lucide-react";
|
||||
import { SquareFill } from "@/components/ui/square-fill";
|
||||
import { Header } from "@/components/ui/header";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -14,15 +14,14 @@ import { getRepoPath, getServerProjectPath, getServerSessionPath, getSessionList
|
||||
import { FetchError } from '@/api/fetchWrapper'
|
||||
|
||||
import { FileBrowserSheet } from "@/components/file-browser/FileBrowserSheet";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { NotFoundState } from "@/components/ui/not-found-state";
|
||||
import { ContextUsageIndicator } from "@/components/session/ContextUsageIndicator";
|
||||
import { useSession, useInterruptSession, useUpdateSession, useCreateSession } from "@/hooks/useOpenCode";
|
||||
import { useSessionTranscript } from "@/hooks/useSessionTranscript";
|
||||
import { useAutoOpenWalkthrough } from "@/hooks/useAutoOpenWalkthrough";
|
||||
import { useRepoActivity } from "@/hooks/useRepoActivity";
|
||||
import { useRepoSiblings } from "@/hooks/useRepoSiblings";
|
||||
import { useSSE } from "@/hooks/useSSE";
|
||||
import { useVcsInfo } from "@/hooks/useVcsInfo";
|
||||
import { useUIState } from "@/stores/uiStateStore";
|
||||
import { useSettings } from "@/hooks/useSettings";
|
||||
import { useModelSelection } from "@/hooks/useModelSelection";
|
||||
@@ -71,6 +70,8 @@ import { SourceControlPanel, RemoteSourceControlPanel } from "@/components/sourc
|
||||
import { TerminalPanel } from "@/components/terminal/TerminalPanel";
|
||||
import { PreviewPanel } from "@/components/preview/PreviewPanel";
|
||||
import { SessionSendErrorBanner } from "@/components/session/SessionSendErrorBanner";
|
||||
import { ReconnectingBanner } from "@/components/session/ReconnectingBanner";
|
||||
import { SessionDetailsSheet } from "@/components/session/SessionDetailsSheet";
|
||||
import { BackgroundWorkBar } from "@/components/session/BackgroundWorkBar";
|
||||
import { SessionGoalBar } from "@/components/session/SessionGoalBar";
|
||||
import { useDialogParam } from "@/hooks/useDialogParam";
|
||||
@@ -135,6 +136,7 @@ export function SessionDetail() {
|
||||
const [messageContainer, setMessageContainer] = useState<HTMLDivElement | null>(null);
|
||||
const promptInputRef = useRef<PromptInputHandle>(null);
|
||||
const [sessionsDialogOpen, setSessionsDialogOpen] = useState(false);
|
||||
const [sessionDetailsOpen, setSessionDetailsOpen] = useState(false);
|
||||
const [fileBrowserOpen, setFileBrowserOpen] = useDialogParam('files');
|
||||
const [mcpDialogOpen, setMcpDialogOpen] = useDialogParam('mcp');
|
||||
const [skillsDialogOpen, setSkillsDialogOpen] = useDialogParam('skills');
|
||||
@@ -230,11 +232,19 @@ export function SessionDetail() {
|
||||
return project?.canonical ?? sessionDirectory;
|
||||
}, [isRemoteServer, remoteProjects, sessionDirectory]);
|
||||
|
||||
const remoteProjectName = useMemo(() => {
|
||||
if (!isRemoteServer) return undefined;
|
||||
return remoteProjects?.find((entry) => entry.canonical === remoteProjectDirectory)?.name?.trim() || undefined;
|
||||
}, [isRemoteServer, remoteProjects, remoteProjectDirectory]);
|
||||
|
||||
const sessionBranch = useMemo(
|
||||
() => (repo && !isAssistantSession ? resolveSessionBranch(repo, sessionDirectory, repoSiblings) : null),
|
||||
[repo, isAssistantSession, sessionDirectory, repoSiblings],
|
||||
);
|
||||
|
||||
const { data: remoteVcsInfo } = useVcsInfo(sessionDirectory, serverId, { enabled: isRemoteServer });
|
||||
const headerBranch = isRemoteServer ? remoteVcsInfo?.branch.current ?? null : sessionBranch;
|
||||
|
||||
const { data: session, isLoading: sessionLoading, error: sessionQueryError } = useSession(
|
||||
sessionId,
|
||||
sessionDirectory,
|
||||
@@ -785,10 +795,8 @@ export function SessionDetail() {
|
||||
}
|
||||
|
||||
const linkedServer = linkedServers.find((candidate) => candidate.id === serverId);
|
||||
const workspaceDisplayName = isRemoteServer
|
||||
? [linkedServer?.name ?? 'Linked server', sessionDirectory ? getDirectoryName(sessionDirectory) : undefined]
|
||||
.filter(Boolean)
|
||||
.join(' · ')
|
||||
const projectDisplayName = isRemoteServer
|
||||
? remoteProjectName ?? (sessionDirectory ? getDirectoryName(sessionDirectory) : 'Project')
|
||||
: isAssistantSession || !repo
|
||||
? 'Assistant'
|
||||
: getRepoDisplayName(repo);
|
||||
@@ -807,51 +815,52 @@ export function SessionDetail() {
|
||||
>
|
||||
<Header className="bg-background [&_button]:bg-background [&_button]:text-foreground [&_button]:border-border [&_button:hover]:bg-accent">
|
||||
<div className="flex items-center gap-1.5 sm:gap-3 min-w-0 flex-1">
|
||||
{session?.parentID ? (
|
||||
<>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleParentSessionClick}
|
||||
className="text-primary hover:text-primary-hover hover:bg-primary/10 h-7 px-2 gap-1"
|
||||
title="Back to parent session"
|
||||
<Header.BackButton to={sessionBackPath} className="text-xs sm:text-sm" />
|
||||
<div className="min-w-0 flex-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSessionDetailsOpen(true)}
|
||||
aria-label="Session details"
|
||||
className="block min-w-0 max-w-full cursor-pointer text-left"
|
||||
>
|
||||
<h1 className="text-xs sm:text-base font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate hover:opacity-80 transition-opacity">
|
||||
{session?.title || "Untitled Session"}
|
||||
</h1>
|
||||
</button>
|
||||
{session?.parentID ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
handleParentSessionClick();
|
||||
}}
|
||||
aria-label="Parent session"
|
||||
className="mt-0.5 inline-flex max-w-full items-center gap-1 rounded-full border border-info/40 px-2 py-0.5 text-[10px] sm:text-xs text-info transition-colors hover:bg-info/10"
|
||||
>
|
||||
<CornerUpLeft className="w-3.5 h-3.5" />
|
||||
<span className="hidden sm:inline text-xs">Parent</span>
|
||||
</Button>
|
||||
<div className="hidden sm:block">
|
||||
<Header.BackButton to={sessionBackPath} className="text-xs sm:text-sm" />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<Header.BackButton to={sessionBackPath} className="text-xs sm:text-sm" />
|
||||
)}
|
||||
<Header.EditableTitle
|
||||
value={session?.title || "Untitled Session"}
|
||||
onChange={handleRenameSession}
|
||||
subtitle={
|
||||
<span className="text-highlight">
|
||||
{isRemoteServer ? (
|
||||
<>
|
||||
<span className="text-info">{linkedServer?.name ?? 'Linked server'}</span>
|
||||
{sessionDirectory && ` · ${getDirectoryName(sessionDirectory)}`}
|
||||
</>
|
||||
) : (
|
||||
workspaceDisplayName
|
||||
<CornerUpLeft className="h-3 w-3 shrink-0" />
|
||||
<span className="truncate">Parent session</span>
|
||||
</button>
|
||||
) : (
|
||||
<p className="flex min-w-0 items-center gap-1 text-[10px] sm:text-xs text-muted-foreground">
|
||||
{isRemoteServer && (
|
||||
<Server aria-label="Remote server" className="h-3 w-3 shrink-0 text-highlight" />
|
||||
)}
|
||||
{sessionBranch && <span className="font-mono sm:hidden"> · {sessionBranch}</span>}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
{sessionBranch && (
|
||||
<span className="truncate text-highlight">{projectDisplayName}</span>
|
||||
{headerBranch && (
|
||||
<span className="truncate font-mono sm:hidden"> · {headerBranch}</span>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{headerBranch && (
|
||||
<Badge
|
||||
variant="outline"
|
||||
data-testid="session-branch"
|
||||
title={`Branch: ${sessionBranch}`}
|
||||
title={`Branch: ${headerBranch}`}
|
||||
className="hidden sm:inline-flex max-w-44 shrink-0 items-center gap-1 border-border bg-card px-2 font-mono text-[11px] font-normal text-muted-foreground"
|
||||
>
|
||||
<GitBranch className="h-3 w-3 shrink-0" />
|
||||
<span className="truncate">{sessionBranch}</span>
|
||||
<span className="truncate">{headerBranch}</span>
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
@@ -862,17 +871,10 @@ export function SessionDetail() {
|
||||
)}
|
||||
<PendingActionsGroup showScheduleReports={!isRemoteServer} />
|
||||
</div>
|
||||
<ContextUsageIndicator
|
||||
directory={sessionDirectory}
|
||||
sessionID={sessionId}
|
||||
isConnected={streamConnected}
|
||||
isReconnecting={streamReconnecting}
|
||||
revertMessageID={revertMessageID}
|
||||
/>
|
||||
<SessionMoreButton />
|
||||
</Header.Actions>
|
||||
</Header>
|
||||
|
||||
<ReconnectingBanner key={sessionId} connected={streamConnected} />
|
||||
</div>
|
||||
|
||||
<div className="flex flex-1 min-h-0">
|
||||
@@ -1071,6 +1073,18 @@ export function SessionDetail() {
|
||||
}}
|
||||
/>
|
||||
|
||||
<SessionDetailsSheet
|
||||
open={sessionDetailsOpen}
|
||||
onOpenChange={setSessionDetailsOpen}
|
||||
sessionId={sessionId}
|
||||
title={session?.title}
|
||||
serverName={linkedServer?.name}
|
||||
remote={isRemoteServer}
|
||||
project={projectDisplayName}
|
||||
branch={headerBranch}
|
||||
directory={sessionDirectory}
|
||||
/>
|
||||
|
||||
{sideQuestion && sessionId && (
|
||||
<SideQuestionDialog
|
||||
key={sideQuestion.id}
|
||||
@@ -1102,7 +1116,7 @@ export function SessionDetail() {
|
||||
isOpen={!docked && fileBrowserOpen}
|
||||
onClose={handleFileBrowserClose}
|
||||
basePath={workspaceBasePath}
|
||||
repoName={workspaceDisplayName}
|
||||
repoName={projectDisplayName}
|
||||
repoId={repoId}
|
||||
initialSelectedFile={selectedFilePath}
|
||||
/>
|
||||
@@ -1160,7 +1174,7 @@ export function SessionDetail() {
|
||||
isOpen={!docked && sourceControlOpen}
|
||||
onClose={() => setSourceControlOpen(false)}
|
||||
currentBranch={repo?.currentBranch || repo?.branch || "main"}
|
||||
repoName={workspaceDisplayName}
|
||||
repoName={projectDisplayName}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -124,6 +124,7 @@ vi.mock('@/hooks/useSettingsDialog', () => ({
|
||||
vi.mock('@/hooks/useMobile', () => ({
|
||||
useMobile: mocks.useMobile,
|
||||
useSwipeBack: vi.fn(() => ({ ref: vi.fn() })),
|
||||
useSwipeDismiss: vi.fn(() => ({ bind: vi.fn(), swipeProgress: 0, swipeStyles: {} })),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useVisualViewport', () => ({
|
||||
|
||||
@@ -53,7 +53,7 @@ vi.mock('@/hooks/useModelSelection', () => ({
|
||||
vi.mock('@/hooks/useTTS', () => ({ useTTS: vi.fn(() => ({ isEnabled: false })) }))
|
||||
vi.mock('@/hooks/useSettings', () => ({ useSettings: mocks.useSettings }))
|
||||
vi.mock('@/hooks/useSettingsDialog', () => ({ useSettingsDialog: mocks.useSettingsDialog }))
|
||||
vi.mock('@/hooks/useMobile', () => ({ useMobile: mocks.useMobile }))
|
||||
vi.mock('@/hooks/useMobile', () => ({ useMobile: mocks.useMobile, useSwipeBack: vi.fn(() => ({ bind: vi.fn(), swipeProgress: 0, swipeStyles: {} })) }))
|
||||
vi.mock('@/hooks/useVisualViewport', () => ({ useVisualViewport: mocks.useVisualViewport }))
|
||||
vi.mock('@/contexts/KeyboardShortcutsContext', () => ({ useShortcutActions: mocks.useShortcutActions }))
|
||||
vi.mock('@/hooks/useAutoScroll', () => ({ useAutoScroll: mocks.useAutoScroll }))
|
||||
@@ -87,7 +87,6 @@ vi.mock('@/components/message/MessageThread', () => ({ MessageThread: mocks.Mess
|
||||
vi.mock('@/components/message/PromptInput', () => ({ PromptInput: mocks.PromptInput }))
|
||||
vi.mock('@/components/message/FloatingTTSButton', () => ({ FloatingTTSButton: () => null }))
|
||||
vi.mock('@/components/message/MessageSkeleton', () => ({ MessageSkeleton: () => null }))
|
||||
vi.mock('@/components/session/ContextUsageIndicator', () => ({ ContextUsageIndicator: () => null }))
|
||||
vi.mock('@/components/session/SessionSendErrorBanner', () => ({ SessionSendErrorBanner: () => null }))
|
||||
vi.mock('@/components/session/BackgroundWorkBar', () => ({ BackgroundWorkBar: () => null }))
|
||||
vi.mock('@/components/session/SessionGoalBar', () => ({ SessionGoalBar: () => null }))
|
||||
|
||||
@@ -8,7 +8,6 @@ import { SwipeNavigationProvider, useSwipeNavigation } from '@/contexts/SwipeNav
|
||||
import { getServerProjectPath } from '@/lib/navigation'
|
||||
import { LocationCatcher } from '@/test/test-utils'
|
||||
import { MessageThread } from '@/components/message/MessageThread'
|
||||
import { ContextUsageIndicator } from '@/components/session/ContextUsageIndicator'
|
||||
import { SessionSendErrorBanner } from '@/components/session/SessionSendErrorBanner'
|
||||
import { PendingActionsGroup } from '@/components/notifications/PendingActionsGroup'
|
||||
import { SessionDetail } from '../SessionDetail'
|
||||
@@ -133,7 +132,6 @@ vi.mock('@/components/message/MessageThread', () => ({
|
||||
vi.mock('@/components/message/PromptInput', () => ({ PromptInput: vi.fn(() => null) }))
|
||||
vi.mock('@/components/message/FloatingTTSButton', () => ({ FloatingTTSButton: vi.fn(() => null) }))
|
||||
vi.mock('@/components/message/MessageSkeleton', () => ({ MessageSkeleton: vi.fn(() => null) }))
|
||||
vi.mock('@/components/session/ContextUsageIndicator', () => ({ ContextUsageIndicator: vi.fn(() => null) }))
|
||||
vi.mock('@/components/session/SessionSendErrorBanner', () => ({ SessionSendErrorBanner: vi.fn(() => null) }))
|
||||
vi.mock('@/components/session/BackgroundWorkBar', () => ({ BackgroundWorkBar: vi.fn(() => null) }))
|
||||
vi.mock('@/components/session/SessionGoalBar', () => ({ SessionGoalBar: mocks.SessionGoalBar }))
|
||||
@@ -279,20 +277,21 @@ describe('SessionDetail remote server mode', () => {
|
||||
expect(mocks.useRepoSiblings).toHaveBeenCalledWith(undefined)
|
||||
})
|
||||
|
||||
it('titles the header with the server name and session directory', async () => {
|
||||
it('shows the remote project in the header without the server name', async () => {
|
||||
renderRemoteSession()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Kitchen')).toHaveClass('text-info')
|
||||
expect(screen.getByLabelText('Remote server')).toBeInTheDocument()
|
||||
})
|
||||
expect(screen.getByText('Kitchen').parentElement).toHaveTextContent('Kitchen · app')
|
||||
expect(screen.getByText('app')).toBeInTheDocument()
|
||||
expect(screen.queryByText(/Kitchen/)).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('returns to the project page from the header back button', async () => {
|
||||
const { capturedPathname, capturedSearch } = renderRemoteSession()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Kitchen').parentElement).toHaveTextContent('Kitchen · app')
|
||||
expect(screen.getByLabelText('Remote server')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Go back' }))
|
||||
@@ -452,9 +451,6 @@ describe('SessionDetail remote server mode', () => {
|
||||
expect(screen.getByTestId('message-thread')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(vi.mocked(ContextUsageIndicator).mock.calls.at(-1)?.[0]).toEqual(
|
||||
expect.objectContaining({ isConnected: false, isReconnecting: true }),
|
||||
)
|
||||
expect(vi.mocked(SessionSendErrorBanner).mock.calls.at(-1)?.[0]).toEqual(
|
||||
expect.objectContaining({ isConnected: false, isReconnecting: true }),
|
||||
)
|
||||
@@ -467,9 +463,6 @@ describe('SessionDetail remote server mode', () => {
|
||||
expect(screen.getByTestId('message-thread')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(vi.mocked(ContextUsageIndicator).mock.calls.at(-1)?.[0]).toEqual(
|
||||
expect.objectContaining({ isConnected: true, isReconnecting: false }),
|
||||
)
|
||||
expect(vi.mocked(SessionSendErrorBanner).mock.calls.at(-1)?.[0]).toEqual(
|
||||
expect.objectContaining({ isConnected: true, isReconnecting: false }),
|
||||
)
|
||||
@@ -484,11 +477,34 @@ describe('SessionDetail remote server mode', () => {
|
||||
expect(screen.getByTestId('message-thread')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(vi.mocked(ContextUsageIndicator).mock.calls.at(-1)?.[0]).toEqual(
|
||||
expect(vi.mocked(SessionSendErrorBanner).mock.calls.at(-1)?.[0]).toEqual(
|
||||
expect.objectContaining({ isConnected: false, isReconnecting: true }),
|
||||
)
|
||||
})
|
||||
|
||||
it('navigates to the parent session from the header pill', async () => {
|
||||
mocks.useSession.mockReturnValue({
|
||||
data: { ...remoteSession, parentID: 'ses_parent' },
|
||||
isLoading: false,
|
||||
error: undefined,
|
||||
})
|
||||
|
||||
const { capturedPathname } = renderRemoteSession()
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Parent session' }))
|
||||
|
||||
expect(capturedPathname.current).toBe('/servers/srv_kitchen/sessions/ses_parent')
|
||||
})
|
||||
|
||||
it('opens the session details sheet from the header title', async () => {
|
||||
renderRemoteSession()
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Session details' }))
|
||||
|
||||
expect(await screen.findByRole('dialog')).toHaveAccessibleName('Session details')
|
||||
expect(screen.getByText('/home/me/app')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('navigates child sessions within the linked server route', async () => {
|
||||
const { capturedPathname } = renderRemoteSession()
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ vi.mock('@/hooks/useSettingsDialog', () => ({
|
||||
vi.mock('@/hooks/useMobile', () => ({
|
||||
useMobile: mocks.useMobile,
|
||||
useSwipeBack: vi.fn(() => ({ ref: vi.fn() })),
|
||||
useSwipeDismiss: vi.fn(() => ({ bind: vi.fn(), swipeProgress: 0, swipeStyles: {} })),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useVisualViewport', () => ({
|
||||
|
||||
Reference in new issue
Block a user