mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(activity): surface active work across the session picker, tool rail and mobile
This commit is contained in:
1 parent
be874ee07c
commit
d8f2fcf29c
46 files changed
+3120
-277
No files matched your search
@@ -97,6 +97,10 @@ vi.mock('@/contexts/EventContext', () => ({
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useRepoActivityState: () => null,
|
||||
}))
|
||||
|
||||
function createRepo(overrides: Partial<Repo> & { id: number; fullPath: string }): Repo {
|
||||
return {
|
||||
localPath: `repos/${overrides.id}`,
|
||||
|
||||
@@ -90,6 +90,7 @@ function SessionSearchResults({
|
||||
{matchingGroups.map((group) => (
|
||||
<RepoNavGroup
|
||||
key={group.repo.id}
|
||||
repo={group.repo}
|
||||
name={group.label}
|
||||
branch={group.branchLabel}
|
||||
isWorktree={group.repo.isWorktree}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { MoreDrawer } from './MoreDrawer'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { getRepo } from '@/api/repos'
|
||||
import type { ActiveWorkItem } from '@/lib/activeWork'
|
||||
|
||||
vi.mock('@/hooks/useAuth')
|
||||
vi.mock('@/hooks/useServerHealth')
|
||||
@@ -20,6 +21,61 @@ vi.mock('react-router-dom', async () => {
|
||||
}
|
||||
})
|
||||
|
||||
const activityMocks = vi.hoisted(() => ({
|
||||
useActiveWork: vi.fn(),
|
||||
useActivityWindowMs: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useActiveWork: activityMocks.useActiveWork,
|
||||
useActivityWindowMs: activityMocks.useActivityWindowMs,
|
||||
useRepoActivityState: () => null,
|
||||
}))
|
||||
|
||||
function createActiveWorkItem(): ActiveWorkItem {
|
||||
const now = Date.now()
|
||||
return {
|
||||
key: '1:s1',
|
||||
state: 'recent',
|
||||
path: '/repos/1/sessions/s1',
|
||||
session: {
|
||||
id: 's1',
|
||||
projectID: 'proj-1',
|
||||
title: 'Session s1',
|
||||
time: { created: now - 10_000, updated: now },
|
||||
location: { directory: '/path/to/repo1' },
|
||||
cost: 0,
|
||||
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
||||
},
|
||||
repo: {
|
||||
id: 1,
|
||||
name: 'repo1',
|
||||
fullPath: '/path/to/repo1',
|
||||
localPath: '/path/to/repo1',
|
||||
defaultBranch: 'main',
|
||||
currentBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function setActivityGroups(groups: {
|
||||
needsInput?: ActiveWorkItem[]
|
||||
running?: ActiveWorkItem[]
|
||||
recent?: ActiveWorkItem[]
|
||||
}) {
|
||||
activityMocks.useActiveWork.mockReturnValue({
|
||||
groups: {
|
||||
needsInput: groups.needsInput ?? [],
|
||||
running: groups.running ?? [],
|
||||
recent: groups.recent ?? [],
|
||||
},
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
})
|
||||
}
|
||||
|
||||
const mockAuth = (logout = vi.fn()) => {
|
||||
vi.mocked(useAuth).mockReturnValue({
|
||||
user: null,
|
||||
@@ -99,6 +155,8 @@ describe('MoreDrawer', () => {
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
})
|
||||
activityMocks.useActivityWindowMs.mockReturnValue(30 * 60_000)
|
||||
setActivityGroups({})
|
||||
})
|
||||
|
||||
it('renders Settings and Logout menu items', () => {
|
||||
@@ -264,4 +322,41 @@ describe('MoreDrawer', () => {
|
||||
|
||||
expect(screen.queryByRole('button', { name: 'Assistant' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the Activity section above the menu when there are items', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId' })
|
||||
|
||||
const heading = screen.getByRole('heading', { name: 'Activity' })
|
||||
const firstMenuRow = screen.getByText('Files')
|
||||
expect(screen.getByText('Session s1')).toBeInTheDocument()
|
||||
expect(heading.compareDocumentPosition(firstMenuRow) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
||||
})
|
||||
|
||||
it('hides the Activity section when there are no items', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({})
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId' })
|
||||
|
||||
expect(screen.queryByRole('heading', { name: 'Activity' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Session s1')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('navigates to the activity item and closes the drawer when a row is clicked', () => {
|
||||
const navigateMock = vi.fn()
|
||||
vi.mocked(useNavigate).mockReturnValue(navigateMock)
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
const handleClose = vi.fn()
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId', onClose: handleClose })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /Session s1/ }))
|
||||
|
||||
expect(navigateMock).toHaveBeenCalledWith('/repos/1/sessions/s1')
|
||||
expect(handleClose).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -8,6 +8,7 @@ import { useQuery } from '@tanstack/react-query'
|
||||
import { getRepo } from '@/api/repos'
|
||||
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
|
||||
import { SideDrawer, SideDrawerContent } from '@/components/ui/side-drawer'
|
||||
import { CompactActivityList } from '@/components/activity/CompactActivityList'
|
||||
import { buildMoreItems, buildNavModel, isSessionDetailPath, type MoreDrawerItem } from './moreDrawerItems'
|
||||
import { useSwipeBack } from '@/hooks/useMobile'
|
||||
import { cn, getRepoDisplayName } from '@/lib/utils'
|
||||
@@ -183,6 +184,14 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
)}
|
||||
</div>
|
||||
<SideDrawerContent className="flex flex-col gap-4 pb-3">
|
||||
{isOpen && (
|
||||
<CompactActivityList
|
||||
onNavigate={(path) => {
|
||||
navigate(path)
|
||||
onClose()
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<MenuSection>
|
||||
{isSessionDetail && (
|
||||
<MenuRow icon={FolderGit2} label="Repos" onClick={() => openMobileSheet('repos')} trailing />
|
||||
|
||||
@@ -6,6 +6,7 @@ import { RepoQuickSwitchSheet } from './RepoQuickSwitchSheet'
|
||||
import { listRepos } from '@/api/repos'
|
||||
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
||||
import { ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils'
|
||||
import type { ActiveWorkItem } from '@/lib/activeWork'
|
||||
|
||||
type SessionFixture = {
|
||||
id: string
|
||||
@@ -32,6 +33,17 @@ const { sessionsData, sessionsHookCalls, permissionSessions, createSessionDirect
|
||||
createSessionDirectories: [] as string[],
|
||||
}))
|
||||
|
||||
const activityMocks = vi.hoisted(() => ({
|
||||
useActiveWork: vi.fn(),
|
||||
useActivityWindowMs: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useActiveWork: activityMocks.useActiveWork,
|
||||
useActivityWindowMs: activityMocks.useActivityWindowMs,
|
||||
useRepoActivityState: () => null,
|
||||
}))
|
||||
|
||||
vi.mock('@/api/repos')
|
||||
|
||||
vi.mock('@/contexts/EventContext', () => ({
|
||||
@@ -92,6 +104,32 @@ function createRepo(id: number, name: string, fullPath: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function createActiveWorkItem(): ActiveWorkItem {
|
||||
return {
|
||||
key: '1:s1',
|
||||
state: 'recent',
|
||||
path: '/repos/1/sessions/s1',
|
||||
session: createSession('s1', Date.now(), '/path/to/repo1'),
|
||||
repo: createRepo(1, 'repo1', '/path/to/repo1'),
|
||||
}
|
||||
}
|
||||
|
||||
function setActivityGroups(groups: {
|
||||
needsInput?: ActiveWorkItem[]
|
||||
running?: ActiveWorkItem[]
|
||||
recent?: ActiveWorkItem[]
|
||||
}) {
|
||||
activityMocks.useActiveWork.mockReturnValue({
|
||||
groups: {
|
||||
needsInput: groups.needsInput ?? [],
|
||||
running: groups.running ?? [],
|
||||
recent: groups.recent ?? [],
|
||||
},
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
})
|
||||
}
|
||||
|
||||
function createWrapper() {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -130,6 +168,8 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
sessionsData.splice(0, sessionsData.length)
|
||||
sessionsHookCalls.splice(0, sessionsHookCalls.length)
|
||||
permissionSessions.current.clear()
|
||||
activityMocks.useActivityWindowMs.mockReturnValue(30 * 60_000)
|
||||
setActivityGroups({})
|
||||
})
|
||||
|
||||
it('renders with loading state', async () => {
|
||||
@@ -783,6 +823,79 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
expect(document.body.querySelector('[aria-hidden="true"].h-16')).not.toBeNull()
|
||||
})
|
||||
|
||||
it('renders the Activity section above the repo list when there are items', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
|
||||
render(<RepoQuickSwitchSheet isOpen onClose={vi.fn()} />, { wrapper: createWrapper() })
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
const heading = screen.getByRole('heading', { name: 'Activity' })
|
||||
const repo = screen.getByText('repo1')
|
||||
expect(screen.getByText('Session s1')).toBeInTheDocument()
|
||||
expect(heading.compareDocumentPosition(repo) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
||||
})
|
||||
|
||||
it('hides the Activity section when there are no items', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
setActivityGroups({})
|
||||
|
||||
render(<RepoQuickSwitchSheet isOpen onClose={vi.fn()} />, { wrapper: createWrapper() })
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('heading', { name: 'Activity' })).toBeNull()
|
||||
expect(screen.queryByText('Session s1')).toBeNull()
|
||||
})
|
||||
|
||||
it('hides the Activity section while a search query is entered', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
|
||||
render(<RepoQuickSwitchSheet isOpen onClose={vi.fn()} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Activity' })).toBeInTheDocument()
|
||||
|
||||
fireEvent.change(screen.getByPlaceholderText('Search projects...'), { target: { value: 'repo' } })
|
||||
|
||||
expect(screen.queryByRole('heading', { name: 'Activity' })).toBeNull()
|
||||
expect(screen.queryByText('Session s1')).toBeNull()
|
||||
})
|
||||
|
||||
it('navigates to the item path and closes the sheet when an activity row is clicked', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
const handleClose = vi.fn()
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<MemoryRouter initialEntries={['/repos/1']}>
|
||||
<Routes>
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<>
|
||||
<RepoQuickSwitchSheet isOpen onClose={handleClose} />
|
||||
<LocationSpy />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: /Session s1/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/sessions/s1')
|
||||
expect(handleClose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('starts a new session in a repo, opens it and closes the sheet', async () => {
|
||||
createSessionDirectories.splice(0, createSessionDirectories.length)
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { BottomSheet, BottomSheetHeader, BottomSheetContent } from '@/components/ui/bottom-sheet'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { CompactActivityList } from '@/components/activity/CompactActivityList'
|
||||
import { getRepoDisplayName } from '@/lib/utils'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { FolderGit2, Plus } from 'lucide-react'
|
||||
@@ -95,6 +96,9 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
</div>
|
||||
</BottomSheetHeader>
|
||||
<BottomSheetContent className="flex flex-col px-0 pt-0 gap-0">
|
||||
{isOpen && !searchQuery.trim() && (
|
||||
<CompactActivityList onNavigate={(path) => navigateAndClose(path)} />
|
||||
)}
|
||||
{isLoading ? (
|
||||
<div className="flex flex-col gap-2 px-4 pt-3">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useState, type CSSProperties, type ReactNode } from
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { Bell, ChevronDown, ChevronRight, HelpCircle, Loader2, Pin, Plus, X } from 'lucide-react'
|
||||
import { SessionStatusIndicator } from '@/components/ui/session-status-indicator'
|
||||
import { RepoActivityIndicator } from '@/components/activity/RepoActivityIndicator'
|
||||
import { useForms, usePermissions } from '@/contexts/EventContext'
|
||||
import { useCreateSession } from '@/hooks/useOpenCode'
|
||||
import { useSidebarRepoGroups } from '@/hooks/useSidebarRepoGroups'
|
||||
@@ -23,6 +24,7 @@ function OpenRepoRail() {
|
||||
}
|
||||
|
||||
interface RepoNavGroupProps {
|
||||
repo: Repo
|
||||
name: string
|
||||
branch?: string | null
|
||||
isWorktree?: boolean
|
||||
@@ -35,6 +37,7 @@ interface RepoNavGroupProps {
|
||||
}
|
||||
|
||||
export function RepoNavGroup({
|
||||
repo,
|
||||
name,
|
||||
branch,
|
||||
isWorktree,
|
||||
@@ -76,8 +79,11 @@ export function RepoNavGroup({
|
||||
onToggle ? 'pl-0' : 'pl-4',
|
||||
)}
|
||||
>
|
||||
<span className="truncate text-[15px] font-bold tracking-tight text-highlight">
|
||||
{name}
|
||||
<span className="flex min-w-0 items-center gap-1.5">
|
||||
<span className="truncate text-[15px] font-bold tracking-tight text-highlight">
|
||||
{name}
|
||||
</span>
|
||||
<RepoActivityIndicator repo={repo} />
|
||||
</span>
|
||||
{branch && (
|
||||
<span
|
||||
@@ -237,6 +243,7 @@ export function RepoSessionNavList({
|
||||
return (
|
||||
<RepoNavGroup
|
||||
key={repo.id}
|
||||
repo={repo}
|
||||
name={getRepoDisplayName(repo)}
|
||||
branch={getRepoBranchLabel(repo)}
|
||||
isWorktree={repo.isWorktree}
|
||||
|
||||
@@ -1,12 +1,26 @@
|
||||
import { describe, expect, it, vi, afterEach } from 'vitest'
|
||||
import { render, screen, waitFor } from '@testing-library/react'
|
||||
import { describe, expect, it, vi, afterEach, beforeEach } from 'vitest'
|
||||
import { render, screen, waitFor, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { ReactNode } from 'react'
|
||||
import { MemoryRouter, useLocation } from 'react-router-dom'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import type { ActiveWorkItem } from '@/lib/activeWork'
|
||||
import { stubMatchMedia } from '@/test/test-utils'
|
||||
import { ToolSidePanel } from './ToolSidePanel'
|
||||
import { useToolPanel } from '@/hooks/useToolPanel'
|
||||
|
||||
const activityMocks = vi.hoisted(() => ({
|
||||
useActiveWork: vi.fn(),
|
||||
useActiveWorkCounts: vi.fn(),
|
||||
useActivityWindowMs: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useActiveWork: activityMocks.useActiveWork,
|
||||
useActiveWorkCounts: activityMocks.useActiveWorkCounts,
|
||||
useActivityWindowMs: activityMocks.useActivityWindowMs,
|
||||
}))
|
||||
|
||||
vi.mock('@/components/file-browser/FileBrowser', () => ({
|
||||
FileBrowser: ({ initialSelectedFile }: { initialSelectedFile?: string }) => <div>files-tool {initialSelectedFile}</div>,
|
||||
}))
|
||||
@@ -77,6 +91,54 @@ function search(): URLSearchParams {
|
||||
return new URLSearchParams(screen.getByTestId('search').textContent ?? '')
|
||||
}
|
||||
|
||||
const WINDOW_MS = 30 * 60_000
|
||||
const NOW = Date.now()
|
||||
|
||||
function createSession(id: string, title: string, updated = NOW - 60_000): Session {
|
||||
return {
|
||||
id,
|
||||
projectID: 'proj-1',
|
||||
title,
|
||||
time: { created: updated - 10000, updated },
|
||||
location: { directory: `/repos/${id}` },
|
||||
cost: 0,
|
||||
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
||||
}
|
||||
}
|
||||
|
||||
function createRepo(id: number, name: string): Repo {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
fullPath: `/repos/${id}`,
|
||||
localPath: `/repos/${id}`,
|
||||
defaultBranch: 'main',
|
||||
currentBranch: 'feature/x',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: 0,
|
||||
}
|
||||
}
|
||||
|
||||
function createActivityItem(id: string, title: string, repoId: number, repoName: string): ActiveWorkItem {
|
||||
const session = createSession(id, title)
|
||||
const repo = createRepo(repoId, repoName)
|
||||
return {
|
||||
key: `${repoId}:${id}`,
|
||||
session,
|
||||
repo,
|
||||
state: 'recent',
|
||||
path: `/repos/${repoId}/sessions/${id}`,
|
||||
}
|
||||
}
|
||||
|
||||
function setActivityGroups(items: ActiveWorkItem[] = []) {
|
||||
activityMocks.useActiveWork.mockReturnValue({
|
||||
groups: { needsInput: [], running: [], recent: items },
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
})
|
||||
}
|
||||
|
||||
function HomeHarness() {
|
||||
const panel = useToolPanel(true)
|
||||
return (
|
||||
@@ -87,6 +149,13 @@ function HomeHarness() {
|
||||
)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
activityMocks.useActiveWorkCounts.mockReturnValue({ needsInput: 0, running: 0 })
|
||||
activityMocks.useActivityWindowMs.mockReturnValue(WINDOW_MS)
|
||||
setActivityGroups()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Reflect.deleteProperty(window, 'matchMedia')
|
||||
})
|
||||
@@ -252,4 +321,46 @@ describe('ToolSidePanel', () => {
|
||||
await waitFor(() => expect(search().has('panel')).toBe(false))
|
||||
expect(screen.getByLabelText('prompt')).toHaveFocus()
|
||||
})
|
||||
|
||||
it('lists the Activity tool first in the rail', () => {
|
||||
renderAt('')
|
||||
|
||||
const rail = screen.getByRole('navigation', { name: 'Tools' })
|
||||
const buttons = within(rail).getAllByRole('button')
|
||||
expect(buttons[0]).toHaveAccessibleName('Activity')
|
||||
})
|
||||
|
||||
it('opens the Activity panel with rows and the window label when clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
setActivityGroups([createActivityItem('other', 'Other Session', 2, 'Beta')])
|
||||
renderAt('')
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Activity' }))
|
||||
|
||||
expect(await screen.findByText('Other Session')).toBeInTheDocument()
|
||||
expect(search().get('panel')).toBe('activity')
|
||||
expect(screen.getByRole('complementary', { name: 'Activity' })).toHaveClass('w-80')
|
||||
expect(screen.getByText('Last 30 minutes')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keeps the Activity panel open when a row navigates to a session', async () => {
|
||||
const user = userEvent.setup()
|
||||
setActivityGroups([createActivityItem('other', 'Other Session', 2, 'Beta')])
|
||||
renderAt('')
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Activity' }))
|
||||
await user.click(await screen.findByRole('button', { name: /Other Session/ }))
|
||||
|
||||
await waitFor(() => expect(screen.getByTestId('pathname').textContent).toBe('/repos/2/sessions/other'))
|
||||
expect(search().get('panel')).toBe('activity')
|
||||
})
|
||||
|
||||
it('shows an Activity count pill and extends the accessible name', () => {
|
||||
activityMocks.useActiveWorkCounts.mockReturnValue({ needsInput: 1, running: 2 })
|
||||
renderAt('')
|
||||
|
||||
const button = screen.getByRole('button', { name: 'Activity, 1 needs input, 2 running' })
|
||||
const pill = within(button).getByText('3')
|
||||
expect(pill.className).toContain('bg-warning')
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
import { X } from 'lucide-react'
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { FileBrowser } from '@/components/file-browser/FileBrowser'
|
||||
import { SourceControlContent } from '@/components/source-control'
|
||||
import { TerminalWorkspace } from '@/components/terminal/TerminalPanel'
|
||||
@@ -23,10 +24,43 @@ import type { ModelRef } from '@opencode-manager/shared/opencode'
|
||||
import { buildToolItems, toolKeyOf, type MoreDrawerItem } from '@/components/navigation/moreDrawerItems'
|
||||
import { isPanelTool, type ToolPanelState, type PanelTool } from '@/hooks/useToolPanel'
|
||||
import { useOpenNavItem } from '@/hooks/useOpenNavItem'
|
||||
import { ActivityList } from '@/components/activity/ActivityList'
|
||||
import { ActivityCountPill } from '@/components/activity/ActivityCountPill'
|
||||
import { useActiveWorkCounts, useActivityWindowMs } from '@/hooks/useActiveWork'
|
||||
import { formatActivityWindow } from '@/lib/activeWork'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { restoreOverlayFocus } from '@/lib/overlayFocus'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const MS_PER_MINUTE = 60_000
|
||||
|
||||
const PANEL_WIDTH_CLASSES: Partial<Record<PanelTool, string>> = {
|
||||
activity: 'w-80',
|
||||
}
|
||||
|
||||
function ActivityWindowLabel() {
|
||||
const windowMs = useActivityWindowMs()
|
||||
return (
|
||||
<span className="shrink-0 text-xs text-muted-foreground">
|
||||
Last {formatActivityWindow(Math.round(windowMs / MS_PER_MINUTE))}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function ActivityPanelBody() {
|
||||
const navigate = useNavigate()
|
||||
const windowMs = useActivityWindowMs()
|
||||
|
||||
return (
|
||||
<div className="min-h-0 flex-1 overflow-y-auto">
|
||||
<ActivityList
|
||||
windowMs={windowMs}
|
||||
onNavigate={(item) => navigate({ pathname: item.path, search: '?panel=activity' })}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface ToolSidePanelProps {
|
||||
panel: ToolPanelState
|
||||
filesBasePath: string | undefined
|
||||
@@ -47,9 +81,11 @@ interface RailButtonProps {
|
||||
item: MoreDrawerItem
|
||||
active: boolean
|
||||
onClick: () => void
|
||||
ariaLabel?: string
|
||||
indicator?: ReactNode
|
||||
}
|
||||
|
||||
function RailButton({ item, active, onClick }: RailButtonProps) {
|
||||
function RailButton({ item, active, onClick, ariaLabel, indicator }: RailButtonProps) {
|
||||
const Icon = item.icon
|
||||
return (
|
||||
<Tooltip delayDuration={0}>
|
||||
@@ -57,10 +93,10 @@ function RailButton({ item, active, onClick }: RailButtonProps) {
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
aria-label={item.label}
|
||||
aria-label={ariaLabel ?? item.label}
|
||||
aria-pressed={active}
|
||||
className={cn(
|
||||
'rounded-md p-2 transition-colors',
|
||||
'relative rounded-md p-2 transition-colors',
|
||||
active
|
||||
? 'bg-accent text-foreground'
|
||||
: item.danger
|
||||
@@ -69,6 +105,7 @@ function RailButton({ item, active, onClick }: RailButtonProps) {
|
||||
)}
|
||||
>
|
||||
<Icon className="h-4 w-4" />
|
||||
{indicator}
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="left" align="center">
|
||||
@@ -100,6 +137,7 @@ export function ToolSidePanel({
|
||||
const { activeTool, toggleTool, closePanel } = panel
|
||||
const location = useLocation()
|
||||
const openNavItem = useOpenNavItem()
|
||||
const { needsInput, running } = useActiveWorkCounts()
|
||||
const railRef = useRef<HTMLElement>(null)
|
||||
const previousActiveToolRef = useRef(activeTool)
|
||||
|
||||
@@ -122,6 +160,18 @@ export function ToolSidePanel({
|
||||
}
|
||||
const activeLabel = panelTools.find(({ tool }) => tool === activeTool)?.item.label
|
||||
|
||||
const activityTotal = needsInput + running
|
||||
const activityAriaLabel =
|
||||
activityTotal > 0 ? `Activity, ${needsInput} needs input, ${running} running` : undefined
|
||||
const activityIndicator =
|
||||
activityTotal > 0 ? (
|
||||
<ActivityCountPill
|
||||
needsInput={needsInput}
|
||||
running={running}
|
||||
className="absolute -right-0.5 -top-0.5"
|
||||
/>
|
||||
) : undefined
|
||||
|
||||
if (panelTools.length === 0 && actionItems.length === 0) return null
|
||||
|
||||
const renderTool = (tool: PanelTool) => {
|
||||
@@ -139,6 +189,7 @@ export function ToolSidePanel({
|
||||
if (tool === 'preview') return <PreviewWorkspace isOpen directory={directory} compact />
|
||||
if (tool === 'mcp') return repoDirectory ? <RepoMcpContent open directory={repoDirectory} /> : null
|
||||
if (tool === 'walkthrough') return sessionId ? <ChangesWalkthroughView /> : null
|
||||
if (tool === 'activity') return <ActivityPanelBody />
|
||||
if (repoId === undefined) return null
|
||||
switch (tool) {
|
||||
case 'sourceControl':
|
||||
@@ -169,10 +220,16 @@ export function ToolSidePanel({
|
||||
activeTool && activeLabel ? (
|
||||
<aside
|
||||
aria-label={activeLabel}
|
||||
className="flex w-[min(600px,45vw)] shrink-0 flex-col border-l border-border bg-background"
|
||||
className={cn(
|
||||
'flex shrink-0 flex-col border-l border-border bg-background',
|
||||
PANEL_WIDTH_CLASSES[activeTool] ?? 'w-[min(600px,45vw)]',
|
||||
)}
|
||||
>
|
||||
<div className="flex shrink-0 items-center gap-2 border-b border-border px-3 py-2">
|
||||
<h2 className="min-w-0 flex-1 truncate text-sm font-semibold text-foreground">{activeLabel}</h2>
|
||||
<div className="flex min-w-0 flex-1 items-baseline gap-2">
|
||||
<h2 className="min-w-0 truncate text-sm font-semibold text-foreground">{activeLabel}</h2>
|
||||
{activeTool === 'activity' ? <ActivityWindowLabel /> : null}
|
||||
</div>
|
||||
{activeTool === 'walkthrough' ? (
|
||||
<>
|
||||
<ChangesWalkthroughSourcePicker />
|
||||
@@ -215,7 +272,14 @@ export function ToolSidePanel({
|
||||
<TooltipProvider>
|
||||
<nav ref={railRef} aria-label="Tools" className="flex w-11 shrink-0 flex-col items-center gap-1 overflow-y-auto border-l border-border bg-background py-2">
|
||||
{panelTools.map(({ item, tool }) => (
|
||||
<RailButton key={item.key} item={item} active={tool === activeTool} onClick={() => toggleTool(tool)} />
|
||||
<RailButton
|
||||
key={item.key}
|
||||
item={item}
|
||||
active={tool === activeTool}
|
||||
onClick={() => toggleTool(tool)}
|
||||
ariaLabel={tool === 'activity' ? activityAriaLabel : undefined}
|
||||
indicator={tool === 'activity' ? activityIndicator : undefined}
|
||||
/>
|
||||
))}
|
||||
{actionItems.length > 0 ? <div className="my-1 h-px w-6 shrink-0 bg-border" role="separator" /> : null}
|
||||
{actionItems.map((item) => (
|
||||
|
||||
@@ -139,8 +139,18 @@ describe('buildMoreItems', () => {
|
||||
})
|
||||
|
||||
describe('buildToolItems', () => {
|
||||
it('leads every route with the Activity tool', () => {
|
||||
for (const path of ['/', '/repos/42', '/repos/42/sessions/abc', '/assistant', '/schedules']) {
|
||||
const [first] = buildToolItems(path)
|
||||
expect(first.key).toBe('activity')
|
||||
expect(first.label).toBe('Activity')
|
||||
expect(first.panelTool).toBe('activity')
|
||||
}
|
||||
})
|
||||
|
||||
it('returns the session route items without home and account entries', () => {
|
||||
expect(buildToolItems('/repos/42/sessions/abc').map((item) => item.key)).toEqual([
|
||||
'activity',
|
||||
'files',
|
||||
'mcp',
|
||||
'skills',
|
||||
@@ -155,15 +165,15 @@ describe('buildToolItems', () => {
|
||||
})
|
||||
|
||||
it('returns the home route tools', () => {
|
||||
expect(buildToolItems('/').map((item) => item.key)).toEqual(['all-schedules', 'files'])
|
||||
expect(buildToolItems('/').map((item) => item.key)).toEqual(['activity', 'all-schedules', 'files'])
|
||||
})
|
||||
|
||||
it.each(['/repos/42', '/assistant'])('opens schedules in the panel on %s', (path) => {
|
||||
expect(buildToolItems(path).find((item) => item.key === 'schedules')?.panelTool).toBe('schedules')
|
||||
})
|
||||
|
||||
it.each(['/schedules', '/repos/42/schedules'])('returns nothing on %s', (path) => {
|
||||
expect(buildToolItems(path)).toEqual([])
|
||||
it.each(['/schedules', '/repos/42/schedules'])('returns only the Activity tool on %s', (path) => {
|
||||
expect(buildToolItems(path).map((item) => item.key)).toEqual(['activity'])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { BookOpen, Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, SquareTerminal, Settings, LogOut, Bot, Folder, Home, Play, Globe } from 'lucide-react'
|
||||
import { Activity, BookOpen, Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, SquareTerminal, Settings, LogOut, Bot, Folder, Home, Play, Globe } from 'lucide-react'
|
||||
import { ASSISTANT_REPO_ID } from '@opencode-manager/shared/utils'
|
||||
import { getAssistantPath, isAssistantPath } from '@/lib/navigation'
|
||||
|
||||
@@ -57,7 +57,8 @@ const NON_TOOL_ITEM_KEYS = new Set(['home', 'settings', 'logout'])
|
||||
|
||||
/** Route-scoped tool items, shown in the desktop tool rail instead of the sidebar. */
|
||||
export function buildToolItems(pathname: string): MoreDrawerItem[] {
|
||||
return buildNavModel(pathname).items.filter((item) => !NON_TOOL_ITEM_KEYS.has(item.key))
|
||||
const routeItems = buildNavModel(pathname).items.filter((item) => !NON_TOOL_ITEM_KEYS.has(item.key))
|
||||
return [{ key: 'activity', label: 'Activity', icon: Activity, panelTool: 'activity' }, ...routeItems]
|
||||
}
|
||||
|
||||
/** The `?panel=`/`?dialog=` tool identifier an item targets, preferring its panel tool. */
|
||||
|
||||
@@ -50,6 +50,22 @@ export function buildRepoByDirectory(repos: Repo[]): Map<string, Repo> {
|
||||
return new Map(repos.map((repo) => [repo.fullPath, repo]))
|
||||
}
|
||||
|
||||
function normalizeDirectory(directory?: string | null): string | null {
|
||||
return directory?.replace(/\/+$/, '') ?? null
|
||||
}
|
||||
|
||||
export function repoMatchesDirectory(repo: Repo, directory?: string | null): boolean {
|
||||
const normalizedDirectory = normalizeDirectory(directory)
|
||||
if (!normalizedDirectory) return false
|
||||
|
||||
return [repo.fullPath, repo.localPath, repo.sourcePath]
|
||||
.some((path) => normalizeDirectory(path) === normalizedDirectory)
|
||||
}
|
||||
|
||||
export function findRepoForDirectory(repos: Repo[], directory?: string | null): Repo | undefined {
|
||||
return repos.find((repo) => repoMatchesDirectory(repo, directory))
|
||||
}
|
||||
|
||||
export function buildSidebarRepoGroups(input: {
|
||||
repos: Repo[]
|
||||
sessions: Session[]
|
||||
|
||||
Reference in new issue
Block a user