mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix(navigation): show Assistant sessions in the sidebar and repo switcher (#368)
This commit is contained in:
1 parent
a1b7f58aae
commit
e80016cc22
11 files changed
+69
-26
No files matched your search
@@ -13,6 +13,7 @@ import {
|
||||
SessionNavStatus,
|
||||
} from '@/components/navigation/RepoSessionNav'
|
||||
import { getActiveRepoId, isCurrentSessionItem, isRepoReady } from '@/components/navigation/sidebar-session-tree'
|
||||
import { getRepoPath } from '@/lib/navigation'
|
||||
|
||||
function SessionSearchInput({
|
||||
hasActiveSearch,
|
||||
@@ -78,7 +79,7 @@ function SessionSearchResults({ repos, search }: { repos: Repo[]; search: string
|
||||
isWorktree={group.repo.isWorktree}
|
||||
isOpen
|
||||
isCurrent={group.repo.id === getActiveRepoId(location.pathname)}
|
||||
onOpenRepo={() => navigate(`/repos/${group.repo.id}`)}
|
||||
onOpenRepo={() => navigate(getRepoPath(group.repo.id))}
|
||||
actions={<NewSessionButton repo={group.repo} onOpenSession={navigate} />}
|
||||
>
|
||||
{group.items.map((item) => (
|
||||
@@ -121,7 +122,7 @@ export function DesktopSessionTree() {
|
||||
repos={repos}
|
||||
activeRepoId={getActiveRepoId(location.pathname)}
|
||||
isVisible
|
||||
onOpenRepo={(repoId) => navigate(`/repos/${repoId}`)}
|
||||
onOpenRepo={(repoId) => navigate(getRepoPath(repoId))}
|
||||
onSelectSession={navigate}
|
||||
renderActions={(repo) => <NewSessionButton repo={repo} onOpenSession={navigate} />}
|
||||
/>
|
||||
|
||||
@@ -243,7 +243,7 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('does not show assistant as a repo option', async () => {
|
||||
it('shows assistant as the first repo option', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
{
|
||||
id: ASSISTANT_REPO_ID,
|
||||
@@ -276,7 +276,8 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(screen.queryByText('Assistant')).not.toBeInTheDocument()
|
||||
const repoNames = screen.getAllByText(/^(Assistant|repo1)$/).map((node) => node.textContent)
|
||||
expect(repoNames).toEqual(['Assistant', 'repo1'])
|
||||
})
|
||||
|
||||
it('navigates on repo click and closes sheet', async () => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { getRepoDisplayName } from '@/lib/utils'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { FolderGit2, Plus } from 'lucide-react'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { getAssistantPath } from '@/lib/navigation'
|
||||
import { getAssistantPath, getRepoPath } from '@/lib/navigation'
|
||||
import { NewSessionButton, RepoSessionNavList, SearchClearButton } from '@/components/navigation/RepoSessionNav'
|
||||
import { getActiveRepoId } from '@/components/navigation/sidebar-session-tree'
|
||||
import { useNavigableRepos } from '@/hooks/useSidebarRepoGroups'
|
||||
@@ -58,7 +58,7 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
return
|
||||
}
|
||||
|
||||
navigateAndClose(`/repos/${id}`, { replace: true })
|
||||
navigateAndClose(getRepoPath(id), { replace: true })
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useForms, usePermissions } from '@/contexts/EventContext'
|
||||
import { useCreateSession } from '@/hooks/useOpenCode'
|
||||
import { useSidebarRepoGroups } from '@/hooks/useSidebarRepoGroups'
|
||||
import { cn, formatShortRelativeTime, getRepoBranchLabel, getRepoDisplayName } from '@/lib/utils'
|
||||
import { getSessionPath } from '@/lib/navigation'
|
||||
import { getRepoPath, getSessionPath } from '@/lib/navigation'
|
||||
import {
|
||||
isCurrentSessionItem,
|
||||
isRepoReady,
|
||||
@@ -200,7 +200,7 @@ function RepoSessionList({ repo, onSelectSession }: RepoSessionListProps) {
|
||||
/>
|
||||
))}
|
||||
{hasMore && (
|
||||
<SessionNavLink onClick={() => onSelectSession(`/repos/${repo.id}`)}>All sessions</SessionNavLink>
|
||||
<SessionNavLink onClick={() => onSelectSession(getRepoPath(repo.id))}>All sessions</SessionNavLink>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -44,10 +44,14 @@ describe('getActiveRepoId', () => {
|
||||
expect(getActiveRepoId('/repos/3/sessions/abc')).toBe(3)
|
||||
})
|
||||
|
||||
it('returns null outside a repo and on assistant routes', () => {
|
||||
it('returns null outside a repo', () => {
|
||||
expect(getActiveRepoId('/')).toBeNull()
|
||||
expect(getActiveRepoId('/assistant')).toBeNull()
|
||||
expect(getActiveRepoId('/repos/1/assistant')).toBeNull()
|
||||
})
|
||||
|
||||
it('returns the assistant repo id on assistant routes', () => {
|
||||
expect(getActiveRepoId('/assistant')).toBe(0)
|
||||
expect(getActiveRepoId('/repos/1/assistant')).toBe(0)
|
||||
expect(getActiveRepoId('/repos/0/sessions/abc')).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -76,14 +80,14 @@ describe('isRepoReady', () => {
|
||||
})
|
||||
|
||||
describe('selectNavigableRepos', () => {
|
||||
it('excludes the assistant repo but keeps repos that are not ready', () => {
|
||||
it('pins the assistant repo first and keeps repos that are not ready', () => {
|
||||
const repos = [
|
||||
createRepo({ id: 0, fullPath: '/assistant' }),
|
||||
createRepo({ id: 1, fullPath: '/repos/a' }),
|
||||
createRepo({ id: 1, fullPath: '/repos/a', lastAccessedAt: 20 }),
|
||||
createRepo({ id: 2, fullPath: '/repos/b', cloneStatus: 'cloning' }),
|
||||
createRepo({ id: 0, fullPath: '/assistant', lastAccessedAt: 10 }),
|
||||
]
|
||||
|
||||
expect(selectNavigableRepos(repos).map((repo) => repo.id)).toEqual([1, 2])
|
||||
expect(selectNavigableRepos(repos).map((repo) => repo.id)).toEqual([0, 1, 2])
|
||||
})
|
||||
|
||||
it('sorts by last access, newest first, with never-accessed repos last', () => {
|
||||
@@ -173,6 +177,17 @@ describe('buildSidebarRepoGroups', () => {
|
||||
expect(item.path).toBe('/repos/3/sessions/w1')
|
||||
})
|
||||
|
||||
it('labels assistant sessions and links them in assistant mode', () => {
|
||||
const assistant = createRepo({ id: 0, fullPath: '/assistant', localPath: 'assistant' })
|
||||
const sessions = [createSession('s1', atStartOfDay(1000), '/assistant')]
|
||||
|
||||
const [group] = buildSidebarRepoGroups({ repos: [assistant], sessions, pinnedKeys: new Set(), now: NOW })
|
||||
|
||||
expect(group.label).toBe('Assistant')
|
||||
expect(group.items[0].path).toBe('/repos/0/sessions/s1?assistant=1')
|
||||
expect(isCurrentSessionItem(group.items[0], '/repos/0/sessions/s1')).toBe(true)
|
||||
})
|
||||
|
||||
it('falls back to repo.branch when currentBranch is absent', () => {
|
||||
const repo = createRepo({ id: 4, fullPath: '/repos/d', branch: 'main' })
|
||||
const sessions = [createSession('d1', atStartOfDay(1000), '/repos/d')]
|
||||
|
||||
@@ -31,7 +31,7 @@ export function isCurrentSessionItem(item: SidebarSessionItem, pathname: string)
|
||||
}
|
||||
|
||||
export function getActiveRepoId(pathname: string): number | null {
|
||||
if (isAssistantPath(pathname)) return null
|
||||
if (isAssistantPath(pathname)) return ASSISTANT_REPO_ID
|
||||
return parseRepoRoute(pathname).repoId
|
||||
}
|
||||
|
||||
@@ -40,9 +40,10 @@ export function isRepoReady(repo: Repo): boolean {
|
||||
}
|
||||
|
||||
export function selectNavigableRepos(repos: Repo[]): Repo[] {
|
||||
return repos
|
||||
.filter((repo) => repo.id !== ASSISTANT_REPO_ID)
|
||||
.sort((a, b) => (b.lastAccessedAt ?? 0) - (a.lastAccessedAt ?? 0))
|
||||
const isAssistant = (repo: Repo) => Number(repo.id === ASSISTANT_REPO_ID)
|
||||
return [...repos].sort(
|
||||
(a, b) => isAssistant(b) - isAssistant(a) || (b.lastAccessedAt ?? 0) - (a.lastAccessedAt ?? 0),
|
||||
)
|
||||
}
|
||||
|
||||
export function buildSidebarRepoGroups(input: {
|
||||
|
||||
Reference in new issue
Block a user