mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
refactor: add desktop sidebar navigation and consolidate header actions (#199)
* refactor: add desktop sidebar navigation and consolidate header actions - Add DesktopSidebar component with collapsible navigation - Add useDesktop and useSidebarAction hooks for sidebar state management - Add useSidebarCollapsed hook with localStorage persistence and error handling - Integrate sidebar into App layout with tooltip support - Remove repoUrl and isRepoWorktree props from SourceControlPanel - BranchesTab now fetches repo data internally using getRepo query - Remove unused to prop from SidebarItem - Simplify RepoList conditional rendering - Add comprehensive test coverage for new components * refactor: remove LSP status button and memory plugin status hook - Delete LspStatusButton component and its test file - Remove unused useMemoryPluginStatus hook from RepoDetail - Clean up dead code as part of desktop header refactor
This commit is contained in:
1 parent
3776a7036a
commit
1212e6c6fb
28 files changed
+1286
-612
No files matched your search
@@ -18,6 +18,7 @@ import { VersionNotifier } from './components/VersionNotifier'
|
||||
import { PwaUpdatePrompt } from '@/components/PwaUpdatePrompt'
|
||||
import { MobileTabBar } from '@/components/navigation/MobileTabBar'
|
||||
import { MobileSheetHost } from '@/components/navigation/MobileSheetHost'
|
||||
import { DesktopSidebar } from '@/components/navigation/DesktopSidebar'
|
||||
import { useTheme } from './hooks/useTheme'
|
||||
import { useSwipeBack } from './hooks/useMobile'
|
||||
import { TTSProvider } from './contexts/TTSContext'
|
||||
@@ -143,8 +144,11 @@ function AppShell() {
|
||||
return (
|
||||
<AuthProvider>
|
||||
<EventProvider>
|
||||
<div ref={rootRef} className="contents">
|
||||
<Outlet />
|
||||
<div ref={rootRef} className="flex h-dvh w-full min-w-0">
|
||||
<DesktopSidebar />
|
||||
<div className="flex-1 min-w-0 min-h-0 flex flex-col">
|
||||
<Outlet />
|
||||
</div>
|
||||
</div>
|
||||
<MobileTabBar />
|
||||
<MobileSheetHost />
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function fetchFileRange(path: string, startLine: number, endLine: n
|
||||
}
|
||||
|
||||
export async function applyFilePatches(path: string, patches: PatchOperation[]): Promise<{ success: boolean; totalLines: number }> {
|
||||
return fetchWrapper(getFileApiUrl(path), {
|
||||
return fetchWrapper(getFileApiUrl(path, { route: 'patches' }), {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ patches }),
|
||||
|
||||
@@ -0,0 +1,232 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { MemoryRouter, useLocation } from 'react-router-dom'
|
||||
import { DesktopSidebar } from './DesktopSidebar'
|
||||
import * as useDesktopModule from '@/hooks/useDesktop'
|
||||
import * as useSidebarCollapsedModule from '@/hooks/useSidebarCollapsed'
|
||||
import * as useMemoryPluginStatusModule from '@/hooks/useMemoryPluginStatus'
|
||||
import * as useAuthModule from '@/hooks/useAuth'
|
||||
|
||||
vi.mock('@/hooks/useDesktop')
|
||||
vi.mock('@/hooks/useSidebarCollapsed')
|
||||
vi.mock('@/hooks/useMemoryPluginStatus')
|
||||
vi.mock('@/hooks/useAuth')
|
||||
|
||||
function LocationDisplay() {
|
||||
const location = useLocation()
|
||||
|
||||
return <div data-testid="location">{location.pathname}{location.search}</div>
|
||||
}
|
||||
|
||||
describe('DesktopSidebar', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('returns null when user is not authenticated', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(false)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: false,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<DesktopSidebar />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null when auth state is loading', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(false)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: true,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<DesktopSidebar />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null when not desktop', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(false)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
const { container } = render(
|
||||
<MemoryRouter>
|
||||
<DesktopSidebar />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders primary CTA for root path', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<DesktopSidebar />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
expect(screen.getByText('New Repo')).toBeInTheDocument()
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders primary CTAs for repo detail', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/repos/5']}>
|
||||
<DesktopSidebar />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
expect(screen.getByText('New Session')).toBeInTheDocument()
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders primary CTA for session detail', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/repos/5/sessions/abc']}>
|
||||
<DesktopSidebar />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders primary CTA for schedules routes', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/schedules']}>
|
||||
<DesktopSidebar />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
expect(screen.getByText('New Schedule')).toBeInTheDocument()
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('dispatches oc:sidebar:action event when primary CTA is clicked', () => {
|
||||
const dispatchEventSpy = vi.spyOn(window, 'dispatchEvent')
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/repos/5']}>
|
||||
<DesktopSidebar />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByText('New Session'))
|
||||
|
||||
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'oc:sidebar:action',
|
||||
detail: { action: 'new-session' },
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('opens dialog items by updating the dialog query param', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/repos/5/sessions/abc?assistant=1']}>
|
||||
<DesktopSidebar />
|
||||
<LocationDisplay />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByText('Files'))
|
||||
|
||||
expect(screen.getByTestId('location').textContent).toBe('/repos/5/sessions/abc?assistant=1&dialog=files')
|
||||
})
|
||||
|
||||
it('opens settings by updating settings query params', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useMemoryPluginStatusModule, 'useMemoryPluginStatus').mockReturnValue({ memoryPluginEnabled: false })
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/?dialog=files']}>
|
||||
<DesktopSidebar />
|
||||
<LocationDisplay />
|
||||
</MemoryRouter>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByText('Settings'))
|
||||
|
||||
expect(screen.getByTestId('location').textContent).toBe('/?dialog=files&settings=open&tab=account')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,111 @@
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { useDesktop } from '@/hooks/useDesktop'
|
||||
import { useSidebarCollapsed } from '@/hooks/useSidebarCollapsed'
|
||||
import { useMemoryPluginStatus } from '@/hooks/useMemoryPluginStatus'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { buildNavModel } from '@/components/navigation/moreDrawerItems'
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarSection,
|
||||
SidebarItem,
|
||||
SidebarCollapseToggle,
|
||||
} from '@/components/ui/sidebar'
|
||||
import { LayoutGrid } from 'lucide-react'
|
||||
|
||||
export function DesktopSidebar() {
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const [collapsed, toggle] = useSidebarCollapsed()
|
||||
const { memoryPluginEnabled } = useMemoryPluginStatus()
|
||||
const { isAuthenticated, isLoading, logout } = useAuth()
|
||||
|
||||
const isDesktop = useDesktop()
|
||||
|
||||
if (isLoading || !isAuthenticated) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (!isDesktop) {
|
||||
return null
|
||||
}
|
||||
|
||||
const { primary, items } = buildNavModel(location.pathname, { memoryPluginEnabled })
|
||||
|
||||
const handlePrimaryClick = (item: (typeof primary)[number]) => {
|
||||
if (item.to) {
|
||||
navigate(item.to)
|
||||
} else if (item.onSelect) {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('oc:sidebar:action', {
|
||||
detail: { action: item.onSelect },
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const handleItemClick = (item: (typeof items)[number]) => {
|
||||
if (item.to) {
|
||||
navigate(item.to)
|
||||
} else if (item.dialog) {
|
||||
const params = new URLSearchParams(location.search)
|
||||
params.set('dialog', item.dialog)
|
||||
params.delete('mobileTab')
|
||||
navigate({ search: params.toString() }, { replace: true })
|
||||
} else if (item.key === 'logout') {
|
||||
logout()
|
||||
} else if (item.key === 'settings') {
|
||||
const params = new URLSearchParams(location.search)
|
||||
params.set('settings', 'open')
|
||||
params.set('tab', 'account')
|
||||
navigate({ search: params.toString() }, { replace: true })
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Sidebar collapsed={collapsed} onToggle={toggle}>
|
||||
<div className="flex items-center justify-between p-2 border-b border-border">
|
||||
{!collapsed && (
|
||||
<span className="text-sm font-semibold px-2">OpenCode</span>
|
||||
)}
|
||||
{collapsed && (
|
||||
<div className="w-full flex justify-center">
|
||||
<LayoutGrid className="h-5 w-5" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{primary.length > 0 && (
|
||||
<SidebarSection collapsed={collapsed}>
|
||||
{primary.map((item) => (
|
||||
<SidebarItem
|
||||
key={item.key}
|
||||
icon={item.icon}
|
||||
label={item.label}
|
||||
collapsed={collapsed}
|
||||
onClick={() => handlePrimaryClick(item)}
|
||||
asPrimary
|
||||
variant={item.variant}
|
||||
/>
|
||||
))}
|
||||
</SidebarSection>
|
||||
)}
|
||||
|
||||
<SidebarSection label="Navigation" collapsed={collapsed}>
|
||||
{items.map((item) => (
|
||||
<SidebarItem
|
||||
key={item.key}
|
||||
icon={item.icon}
|
||||
label={item.label}
|
||||
collapsed={collapsed}
|
||||
onClick={() => handleItemClick(item)}
|
||||
danger={item.danger}
|
||||
/>
|
||||
))}
|
||||
</SidebarSection>
|
||||
|
||||
<div className="mt-auto">
|
||||
<SidebarCollapseToggle collapsed={collapsed} onToggle={toggle} />
|
||||
</div>
|
||||
</Sidebar>
|
||||
)
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { buildMoreItems } from './moreDrawerItems'
|
||||
import { buildMoreItems, buildNavModel } from './moreDrawerItems'
|
||||
|
||||
describe('buildMoreItems', () => {
|
||||
it('returns only Settings + Logout for root path', () => {
|
||||
it('returns Settings + Logout + All Schedules + Files for root path', () => {
|
||||
const items = buildMoreItems('/')
|
||||
expect(items).toHaveLength(2)
|
||||
expect(items[0].key).toBe('settings')
|
||||
expect(items[1].key).toBe('logout')
|
||||
expect(items).toHaveLength(4)
|
||||
expect(items[0].key).toBe('all-schedules')
|
||||
expect(items[1].key).toBe('files')
|
||||
expect(items[2].key).toBe('settings')
|
||||
expect(items[3].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('returns repo-specific items with memory when plugin enabled for /repos/:id', () => {
|
||||
@@ -62,6 +64,22 @@ describe('buildMoreItems', () => {
|
||||
expect(items[1].key).toBe('mcp')
|
||||
})
|
||||
|
||||
it('returns assistant workspace items for /repos/:id/assistant', () => {
|
||||
const items = buildMoreItems('/repos/42/assistant', { memoryPluginEnabled: true })
|
||||
expect(items).toHaveLength(9)
|
||||
expect(items[0].key).toBe('files')
|
||||
expect(items[0].dialog).toBe('files')
|
||||
expect(items[1].key).toBe('memory')
|
||||
expect(items[1].to).toBe('/repos/42/memories')
|
||||
expect(items[2].key).toBe('mcp')
|
||||
expect(items[3].key).toBe('skills')
|
||||
expect(items[4].key).toBe('reset-permissions')
|
||||
expect(items[5].key).toBe('schedules')
|
||||
expect(items[6].key).toBe('source-control')
|
||||
expect(items[7].key).toBe('settings')
|
||||
expect(items[8].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('returns only Settings + Logout for /repos/:id/memories', () => {
|
||||
const items = buildMoreItems('/repos/42/memories')
|
||||
expect(items).toHaveLength(2)
|
||||
@@ -90,3 +108,75 @@ describe('buildMoreItems', () => {
|
||||
expect(items[1].key).toBe('logout')
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildNavModel', () => {
|
||||
it('returns new-repo primary CTA for root path', () => {
|
||||
const model = buildNavModel('/')
|
||||
expect(model.primary).toHaveLength(2)
|
||||
expect(model.primary[0].key).toBe('new-repo')
|
||||
expect(model.primary[0].onSelect).toBe('new-repo')
|
||||
expect(model.primary[1].key).toBe('assistant')
|
||||
expect(model.primary[1].to).toBe('/assistant')
|
||||
})
|
||||
|
||||
it('returns new-session and assistant primary CTAs for repo detail', () => {
|
||||
const model = buildNavModel('/repos/5')
|
||||
expect(model.primary).toHaveLength(2)
|
||||
expect(model.primary[0].key).toBe('new-session')
|
||||
expect(model.primary[0].onSelect).toBe('new-session')
|
||||
expect(model.primary[1].key).toBe('assistant')
|
||||
expect(model.primary[1].to).toBe('/repos/5/assistant')
|
||||
})
|
||||
|
||||
it('returns assistant-only primary CTA for session detail', () => {
|
||||
const model = buildNavModel('/repos/5/sessions/abc')
|
||||
expect(model.primary).toHaveLength(1)
|
||||
expect(model.primary[0].key).toBe('assistant')
|
||||
expect(model.primary[0].to).toBe('/repos/5/assistant')
|
||||
expect(model.primary[0].variant).toBe('primary')
|
||||
})
|
||||
|
||||
it('returns assistant primary CTA for assistant workspace', () => {
|
||||
const model = buildNavModel('/repos/5/assistant')
|
||||
expect(model.primary).toHaveLength(1)
|
||||
expect(model.primary[0].key).toBe('assistant')
|
||||
expect(model.primary[0].to).toBe('/repos/5/assistant')
|
||||
expect(model.primary[0].variant).toBe('primary')
|
||||
})
|
||||
|
||||
it('returns new-schedule primary CTA for schedules routes', () => {
|
||||
const model1 = buildNavModel('/schedules')
|
||||
expect(model1.primary).toHaveLength(2)
|
||||
expect(model1.primary[0].key).toBe('new-schedule')
|
||||
expect(model1.primary[0].onSelect).toBe('new-schedule')
|
||||
expect(model1.primary[1].key).toBe('assistant')
|
||||
expect(model1.primary[1].to).toBe('/assistant')
|
||||
|
||||
const model2 = buildNavModel('/repos/5/schedules')
|
||||
expect(model2.primary).toHaveLength(2)
|
||||
expect(model2.primary[0].key).toBe('new-schedule')
|
||||
expect(model2.primary[0].onSelect).toBe('new-schedule')
|
||||
expect(model2.primary[1].key).toBe('assistant')
|
||||
expect(model2.primary[1].to).toBe('/repos/5/assistant')
|
||||
})
|
||||
|
||||
it('returns empty primary for memories routes', () => {
|
||||
const model = buildNavModel('/repos/5/memories')
|
||||
expect(model.primary).toHaveLength(1)
|
||||
expect(model.primary[0].key).toBe('assistant')
|
||||
expect(model.primary[0].to).toBe('/repos/5/assistant')
|
||||
})
|
||||
|
||||
it('returns assistant primary for unknown routes', () => {
|
||||
const model = buildNavModel('/unknown/path')
|
||||
expect(model.primary).toHaveLength(1)
|
||||
expect(model.primary[0].key).toBe('assistant')
|
||||
expect(model.primary[0].to).toBe('/assistant')
|
||||
})
|
||||
|
||||
it('preserves backwards compatibility with buildMoreItems', () => {
|
||||
const model = buildNavModel('/repos/42', { memoryPluginEnabled: true })
|
||||
const items = buildMoreItems('/repos/42', { memoryPluginEnabled: true })
|
||||
expect(model.items).toEqual(items)
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { FolderOpen, Brain, Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Code2, Settings, LogOut } from 'lucide-react'
|
||||
import { Brain, Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Code2, Settings, LogOut, Plus, Bot, Folder, Clock, SquarePlus } from 'lucide-react'
|
||||
|
||||
export interface MoreDrawerItem {
|
||||
key: string
|
||||
@@ -10,28 +10,54 @@ export interface MoreDrawerItem {
|
||||
danger?: boolean
|
||||
}
|
||||
|
||||
export interface NavPrimaryCta {
|
||||
key: string
|
||||
label: string
|
||||
icon: LucideIcon
|
||||
to?: string
|
||||
onSelect?: 'new-session' | 'new-repo' | 'new-schedule'
|
||||
variant?: 'primary' | 'secondary'
|
||||
}
|
||||
|
||||
export interface NavModel {
|
||||
primary: NavPrimaryCta[]
|
||||
items: MoreDrawerItem[]
|
||||
}
|
||||
|
||||
export interface BuildMoreItemsOptions {
|
||||
memoryPluginEnabled?: boolean
|
||||
}
|
||||
|
||||
export function buildMoreItems(pathname: string, options: BuildMoreItemsOptions = {}): MoreDrawerItem[] {
|
||||
const { memoryPluginEnabled = false } = options
|
||||
const baseItems: MoreDrawerItem[] = [
|
||||
export type BuildNavOptions = BuildMoreItemsOptions
|
||||
|
||||
function getAssistantNavItem(pathname: string, variant: NavPrimaryCta['variant'] = 'secondary'): NavPrimaryCta {
|
||||
const repoMatch = /^\/repos\/(\d+)/.exec(pathname)
|
||||
|
||||
return {
|
||||
key: 'assistant',
|
||||
label: 'Assistant',
|
||||
icon: Bot,
|
||||
to: repoMatch ? `/repos/${repoMatch[1]}/assistant` : '/assistant',
|
||||
variant,
|
||||
}
|
||||
}
|
||||
|
||||
function getBaseItems(): MoreDrawerItem[] {
|
||||
return [
|
||||
{ key: 'settings', label: 'Settings', icon: Settings },
|
||||
{ key: 'logout', label: 'Logout', icon: LogOut },
|
||||
]
|
||||
}
|
||||
|
||||
// Root path - no route-specific items
|
||||
if (pathname === '/') {
|
||||
return baseItems
|
||||
}
|
||||
export function buildNavModel(pathname: string, options: BuildNavOptions = {}): NavModel {
|
||||
const { memoryPluginEnabled = false } = options
|
||||
const baseItems = getBaseItems()
|
||||
|
||||
// RepoDetail: /repos/:id
|
||||
const repoDetailMatch = /^\/repos\/(\d+)$/.exec(pathname)
|
||||
if (repoDetailMatch) {
|
||||
const id = repoDetailMatch[1]
|
||||
return [
|
||||
{ key: 'files', label: 'Files', icon: FolderOpen, dialog: 'files' },
|
||||
const items: MoreDrawerItem[] = [
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
...(memoryPluginEnabled
|
||||
? [{ key: 'memory', label: 'Memory', icon: Brain, to: `/repos/${id}/memories` }]
|
||||
: []),
|
||||
@@ -42,14 +68,21 @@ export function buildMoreItems(pathname: string, options: BuildMoreItemsOptions
|
||||
{ key: 'source-control', label: 'Source Control', icon: GitCommitHorizontal, dialog: 'sourceControl' },
|
||||
...baseItems,
|
||||
]
|
||||
|
||||
return {
|
||||
primary: [
|
||||
{ key: 'new-session', label: 'New Session', icon: SquarePlus, onSelect: 'new-session', variant: 'primary' },
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
items,
|
||||
}
|
||||
}
|
||||
|
||||
// SessionDetail: /repos/:id/sessions/:sid
|
||||
const sessionDetailMatch = /^\/repos\/(\d+)\/sessions\/[^/]+$/.exec(pathname)
|
||||
if (sessionDetailMatch) {
|
||||
const id = sessionDetailMatch[1]
|
||||
return [
|
||||
{ key: 'files', label: 'Files', icon: FolderOpen, dialog: 'files' },
|
||||
const items: MoreDrawerItem[] = [
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
...(memoryPluginEnabled
|
||||
? [{ key: 'memory', label: 'Memory', icon: Brain, to: `/repos/${id}/memories` }]
|
||||
: []),
|
||||
@@ -60,18 +93,80 @@ export function buildMoreItems(pathname: string, options: BuildMoreItemsOptions
|
||||
{ key: 'source-control', label: 'Source Control', icon: GitCommitHorizontal, dialog: 'sourceControl' },
|
||||
...baseItems,
|
||||
]
|
||||
|
||||
return {
|
||||
primary: [
|
||||
getAssistantNavItem(pathname, 'primary'),
|
||||
],
|
||||
items,
|
||||
}
|
||||
}
|
||||
|
||||
// Memories: /repos/:id/memories - no extra items
|
||||
if (/^\/repos\/\d+\/memories$/.test(pathname)) {
|
||||
return baseItems
|
||||
const assistantMatch = /^\/repos\/(\d+)\/assistant$/.exec(pathname)
|
||||
if (assistantMatch) {
|
||||
const id = assistantMatch[1]
|
||||
const items: MoreDrawerItem[] = [
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
...(memoryPluginEnabled
|
||||
? [{ key: 'memory', label: 'Memory', icon: Brain, to: `/repos/${id}/memories` }]
|
||||
: []),
|
||||
{ key: 'mcp', label: 'MCP', icon: Plug, dialog: 'mcp' },
|
||||
{ key: 'skills', label: 'Skills', icon: Sparkles, dialog: 'skills' },
|
||||
{ key: 'reset-permissions', label: 'Reset Permissions', icon: ShieldOff, dialog: 'resetPermissions', danger: true },
|
||||
{ key: 'schedules', label: 'Schedules', icon: CalendarClock, to: `/repos/${id}/schedules` },
|
||||
{ key: 'source-control', label: 'Source Control', icon: GitCommitHorizontal, dialog: 'sourceControl' },
|
||||
...baseItems,
|
||||
]
|
||||
|
||||
return {
|
||||
primary: [
|
||||
getAssistantNavItem(pathname, 'primary'),
|
||||
],
|
||||
items,
|
||||
}
|
||||
}
|
||||
|
||||
// Schedules routes - no extra items
|
||||
if (pathname === '/schedules' || /^\/repos\/\d+\/schedules$/.test(pathname)) {
|
||||
return baseItems
|
||||
return {
|
||||
primary: [
|
||||
{ key: 'new-schedule', label: 'New Schedule', icon: Clock, onSelect: 'new-schedule', variant: 'primary' },
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
items: baseItems,
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown path - return base items only
|
||||
return baseItems
|
||||
if (pathname === '/') {
|
||||
return {
|
||||
primary: [
|
||||
{ key: 'new-repo', label: 'New Repo', icon: Plus, onSelect: 'new-repo', variant: 'primary' },
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
items: [
|
||||
{ key: 'all-schedules', label: 'All Schedules', icon: CalendarClock, to: '/schedules' },
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
...baseItems,
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
if (/^\/repos\/\d+\/memories$/.test(pathname)) {
|
||||
return {
|
||||
primary: [
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
items: baseItems,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
primary: [
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
items: baseItems,
|
||||
}
|
||||
}
|
||||
|
||||
export function buildMoreItems(pathname: string, options: BuildMoreItemsOptions = {}): MoreDrawerItem[] {
|
||||
return buildNavModel(pathname, options).items
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { LspStatusButton } from './LspStatusButton'
|
||||
import type { LspStatus } from '@/api/opencode'
|
||||
import { useLSPStatus } from '@/hooks/useLSPStatus'
|
||||
|
||||
vi.mock('@/hooks/useLSPStatus')
|
||||
|
||||
describe('LspStatusButton', () => {
|
||||
const mockOnClick = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should render button with LSP text', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: undefined } as any)
|
||||
|
||||
render(<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />)
|
||||
|
||||
expect(screen.getByText('LSP')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should call onClick when clicked', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: undefined } as any)
|
||||
|
||||
render(<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />)
|
||||
|
||||
const button = screen.getByRole('button')
|
||||
fireEvent.click(button)
|
||||
|
||||
expect(mockOnClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should show green icon when has active servers', () => {
|
||||
const mockData: LspStatus[] = [
|
||||
{ id: '1', name: 'typescript-language-server', status: 'connected', root: '/project' }
|
||||
]
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: mockData } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const icon = container.querySelector('.text-green-500')
|
||||
expect(icon).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show default icon when no active servers', () => {
|
||||
const mockData: LspStatus[] = [
|
||||
{ id: '1', name: 'typescript-language-server', status: 'error', root: '/project' }
|
||||
]
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: mockData } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const icon = container.querySelector('.text-green-500')
|
||||
expect(icon).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show default icon when data is empty', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: [] } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const icon = container.querySelector('.text-green-500')
|
||||
expect(icon).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show default icon when data is undefined', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: undefined } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const icon = container.querySelector('.text-green-500')
|
||||
expect(icon).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should handle multiple servers with mixed statuses', () => {
|
||||
const mockData: LspStatus[] = [
|
||||
{ id: '1', name: 'typescript-language-server', status: 'connected', root: '/project' },
|
||||
{ id: '2', name: 'python-lsp-server', status: 'error', root: '/project' }
|
||||
]
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: mockData } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const icon = container.querySelector('.text-green-500')
|
||||
expect(icon).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should hide on mobile screens (hidden md:flex)', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: undefined } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const button = container.querySelector('button')
|
||||
expect(button).toHaveClass('hidden')
|
||||
expect(button).toHaveClass('md:flex')
|
||||
})
|
||||
|
||||
it('should apply correct variant and size classes', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: undefined } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const button = container.querySelector('button')
|
||||
expect(button).toHaveClass('border')
|
||||
expect(button).toHaveClass('bg-background')
|
||||
})
|
||||
|
||||
it('should apply transition and hover classes', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: undefined } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const button = container.querySelector('button')
|
||||
expect(button).toHaveClass('transition-all')
|
||||
expect(button).toHaveClass('duration-200')
|
||||
expect(button).toHaveClass('hover:scale-105')
|
||||
})
|
||||
|
||||
it('should render Code icon', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: undefined } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const svg = container.querySelector('svg')
|
||||
expect(svg).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should hide LSP text on small screens', () => {
|
||||
vi.mocked(useLSPStatus).mockReturnValue({ data: undefined } as any)
|
||||
|
||||
const { container } = render(
|
||||
<LspStatusButton opcodeUrl="http://localhost:5551" directory="/test" onClick={mockOnClick} />
|
||||
)
|
||||
|
||||
const textSpan = container.querySelector('.hidden.sm\\:inline')
|
||||
expect(textSpan).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Code } from 'lucide-react'
|
||||
import { useLSPStatus } from '@/hooks/useLSPStatus'
|
||||
|
||||
interface LspStatusButtonProps {
|
||||
opcodeUrl: string | null | undefined
|
||||
directory?: string
|
||||
onClick: () => void
|
||||
}
|
||||
|
||||
export function LspStatusButton({ opcodeUrl, directory, onClick }: LspStatusButtonProps) {
|
||||
const { data } = useLSPStatus(opcodeUrl, directory)
|
||||
|
||||
const hasActiveServers = data && data.length > 0 && data.some(server => server.status === 'connected')
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={onClick}
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Code className={`w-4 h-4 sm:mr-2 ${hasActiveServers ? 'text-green-500' : ''}`} />
|
||||
<span className="hidden sm:inline">LSP</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -303,46 +303,53 @@ export function RepoList() {
|
||||
|
||||
}
|
||||
|
||||
if (isLoading && !repos) {
|
||||
return (
|
||||
<div className="px-0 md:p-4 h-full flex flex-col">
|
||||
<div className="px-2 md:px-0">
|
||||
<div className="h-10 bg-muted/50 animate-pulse rounded w-full" />
|
||||
</div>
|
||||
<div className="mx-2 md:mx-0 flex-1 min-h-0">
|
||||
<div className="h-full overflow-y-auto pt-4 pb-2 md:pb-0">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-2 gap-3 md:gap-4 w-full">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className="md:pl-8">
|
||||
<RepoCardSkeleton />
|
||||
const renderContent = () => {
|
||||
switch (true) {
|
||||
case isLoading && !repos:
|
||||
return (
|
||||
<div className="px-0 md:p-4 h-full flex flex-col">
|
||||
<div className="px-2 md:px-0">
|
||||
<div className="h-10 bg-muted/50 animate-pulse rounded w-full" />
|
||||
</div>
|
||||
<div className="mx-2 md:mx-0 flex-1 min-h-0">
|
||||
<div className="h-full overflow-y-auto pt-4 pb-2 md:pb-0">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-2 gap-3 md:gap-4 w-full">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className="md:pl-8">
|
||||
<RepoCardSkeleton />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
|
||||
case !!error:
|
||||
return (
|
||||
<div className="text-center p-8 text-destructive">
|
||||
Failed to load repositories:{" "}
|
||||
{error instanceof Error ? error.message : "Unknown error"}
|
||||
</div>
|
||||
)
|
||||
|
||||
case !repos || repos.length === 0:
|
||||
return (
|
||||
<div className="text-center p-12">
|
||||
<GitBranch className="w-12 h-12 mx-auto mb-4 text-zinc-600" />
|
||||
<p className="text-zinc-500">
|
||||
No repositories yet. Add one to get started.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<div className="text-center p-8 text-destructive">
|
||||
Failed to load repositories:{" "}
|
||||
{error instanceof Error ? error.message : "Unknown error"}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!repos || repos.length === 0) {
|
||||
return (
|
||||
<div className="text-center p-12">
|
||||
<GitBranch className="w-12 h-12 mx-auto mb-4 text-zinc-600" />
|
||||
<p className="text-zinc-500">
|
||||
No repositories yet. Add one to get started.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const content = renderContent()
|
||||
if (content) return content
|
||||
|
||||
const handleSelectRepo = (id: number, selected: boolean) => {
|
||||
const newSelected = new Set(selectedRepos)
|
||||
@@ -409,71 +416,82 @@ export function RepoList() {
|
||||
|
||||
<div className="mx-2 md:mx-0 flex-1 min-h-0">
|
||||
<div className="h-full overflow-y-auto pt-4 md:pb-0 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">
|
||||
{sortedViewModels.length === 0 ? (
|
||||
<div className="text-center p-12">
|
||||
<Search className="w-12 h-12 mx-auto mb-4 text-zinc-600" />
|
||||
<p className="text-zinc-500">
|
||||
{sections[0]?.emptyMessage || `No repositories found${searchQuery ? ` matching "${searchQuery}"` : ''}`}
|
||||
</p>
|
||||
</div>
|
||||
) : isDragEnabled ? (
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext items={sortedViewModels.map((r) => r.id)} strategy={verticalListSortingStrategy}>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-2 gap-3 md:gap-4 w-full md:pb-0">
|
||||
{sortedViewModels.map((repo) => (
|
||||
<SortableRepoCard
|
||||
key={repo.id}
|
||||
repo={repo}
|
||||
onDelete={(id) => {
|
||||
setRepoToDelete(id)
|
||||
setDeleteDialogOpen(true)
|
||||
}}
|
||||
isDeleting={
|
||||
deleteMutation.isPending && repoToDelete === repo.id
|
||||
}
|
||||
isSelected={selectedRepos.has(repo.id)}
|
||||
onSelect={handleSelectRepo}
|
||||
gitStatus={gitStatuses?.get(repo.id)}
|
||||
manageMode={isSelectionActive}
|
||||
isMobile={isMobile}
|
||||
isManualSort={isManualSort}
|
||||
activityLabel={formatActivityLabel(repo.activityTimestamp)}
|
||||
hasSelectedRepos={selectedRepos.size > 0}
|
||||
selectionMode={selectionMode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-2 gap-3 md:gap-4 w-full md:pb-0">
|
||||
{sortedViewModels.map((repo) => (
|
||||
<StaticRepoCard
|
||||
key={repo.id}
|
||||
repo={repo}
|
||||
onDelete={(id) => {
|
||||
setRepoToDelete(id)
|
||||
setDeleteDialogOpen(true)
|
||||
}}
|
||||
isDeleting={
|
||||
deleteMutation.isPending && repoToDelete === repo.id
|
||||
}
|
||||
isSelected={selectedRepos.has(repo.id)}
|
||||
onSelect={handleSelectRepo}
|
||||
gitStatus={gitStatuses?.get(repo.id)}
|
||||
manageMode={isSelectionActive}
|
||||
isMobile={isMobile}
|
||||
activityLabel={formatActivityLabel(repo.activityTimestamp)}
|
||||
hasSelectedRepos={selectedRepos.size > 0}
|
||||
selectionMode={selectionMode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{(() => {
|
||||
switch (true) {
|
||||
case sortedViewModels.length === 0:
|
||||
return (
|
||||
<div className="text-center p-12">
|
||||
<Search className="w-12 h-12 mx-auto mb-4 text-zinc-600" />
|
||||
<p className="text-zinc-500">
|
||||
{sections[0]?.emptyMessage || `No repositories found${searchQuery ? ` matching "${searchQuery}"` : ''}`}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
|
||||
case isDragEnabled:
|
||||
return (
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext items={sortedViewModels.map((r) => r.id)} strategy={verticalListSortingStrategy}>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-2 gap-3 md:gap-4 w-full md:pb-0">
|
||||
{sortedViewModels.map((repo) => (
|
||||
<SortableRepoCard
|
||||
key={repo.id}
|
||||
repo={repo}
|
||||
onDelete={(id) => {
|
||||
setRepoToDelete(id)
|
||||
setDeleteDialogOpen(true)
|
||||
}}
|
||||
isDeleting={
|
||||
deleteMutation.isPending && repoToDelete === repo.id
|
||||
}
|
||||
isSelected={selectedRepos.has(repo.id)}
|
||||
onSelect={handleSelectRepo}
|
||||
gitStatus={gitStatuses?.get(repo.id)}
|
||||
manageMode={isSelectionActive}
|
||||
isMobile={isMobile}
|
||||
isManualSort={isManualSort}
|
||||
activityLabel={formatActivityLabel(repo.activityTimestamp)}
|
||||
hasSelectedRepos={selectedRepos.size > 0}
|
||||
selectionMode={selectionMode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
)
|
||||
|
||||
default:
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-2 gap-3 md:gap-4 w-full md:pb-0">
|
||||
{sortedViewModels.map((repo) => (
|
||||
<StaticRepoCard
|
||||
key={repo.id}
|
||||
repo={repo}
|
||||
onDelete={(id) => {
|
||||
setRepoToDelete(id)
|
||||
setDeleteDialogOpen(true)
|
||||
}}
|
||||
isDeleting={
|
||||
deleteMutation.isPending && repoToDelete === repo.id
|
||||
}
|
||||
isSelected={selectedRepos.has(repo.id)}
|
||||
onSelect={handleSelectRepo}
|
||||
gitStatus={gitStatuses?.get(repo.id)}
|
||||
manageMode={isSelectionActive}
|
||||
isMobile={isMobile}
|
||||
activityLabel={formatActivityLabel(repo.activityTimestamp)}
|
||||
hasSelectedRepos={selectedRepos.size > 0}
|
||||
selectionMode={selectionMode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -137,8 +137,6 @@ export function RepoRowActions({
|
||||
onActionsOpenChange?.(false)
|
||||
}}
|
||||
currentBranch={branchToDisplay || ''}
|
||||
repoUrl={repo.repoUrl}
|
||||
isRepoWorktree={repo.isWorktree}
|
||||
repoName={repoName}
|
||||
/>
|
||||
<DownloadDialog
|
||||
@@ -213,8 +211,6 @@ export function RepoRowActions({
|
||||
isOpen={showSourceControl}
|
||||
onClose={() => { setShowSourceControl(false); onActionsOpenChange?.(false); }}
|
||||
currentBranch={branchToDisplay || ''}
|
||||
repoUrl={repo.repoUrl}
|
||||
isRepoWorktree={repo.isWorktree}
|
||||
repoName={repoName}
|
||||
/>
|
||||
<DownloadDialog
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState } from 'react'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { listBranches, switchBranch, GitAuthError } from '@/api/repos'
|
||||
import { listBranches, switchBranch, GitAuthError, getRepo } from '@/api/repos'
|
||||
import { useGitStatus } from '@/api/git'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
@@ -14,11 +14,9 @@ import { CreateWorktreeDialog } from '@/components/repo/CreateWorktreeDialog'
|
||||
interface BranchesTabProps {
|
||||
repoId: number
|
||||
currentBranch: string
|
||||
repoUrl?: string | null
|
||||
isRepoWorktree?: boolean
|
||||
}
|
||||
|
||||
export function BranchesTab({ repoId, currentBranch, repoUrl, isRepoWorktree }: BranchesTabProps) {
|
||||
export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) {
|
||||
const queryClient = useQueryClient()
|
||||
const [newBranchName, setNewBranchName] = useState('')
|
||||
const [isCreating, setIsCreating] = useState(false)
|
||||
@@ -33,6 +31,15 @@ export function BranchesTab({ repoId, currentBranch, repoUrl, isRepoWorktree }:
|
||||
staleTime: 30000,
|
||||
})
|
||||
|
||||
const { data: repo } = useQuery({
|
||||
queryKey: ['repo', repoId],
|
||||
queryFn: () => getRepo(repoId),
|
||||
staleTime: 30000,
|
||||
})
|
||||
|
||||
const repoUrl = repo?.repoUrl ?? null
|
||||
const isRepoWorktree = repo?.isWorktree ?? false
|
||||
|
||||
const switchBranchMutation = useMutation({
|
||||
mutationFn: (branch: string) => switchBranch(repoId, branch),
|
||||
onSuccess: (updatedRepo) => {
|
||||
|
||||
@@ -32,8 +32,6 @@ interface SourceControlPanelProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
currentBranch: string
|
||||
repoUrl?: string | null
|
||||
isRepoWorktree?: boolean
|
||||
repoName?: string
|
||||
}
|
||||
|
||||
@@ -45,8 +43,6 @@ export function SourceControlPanel({
|
||||
isOpen,
|
||||
onClose,
|
||||
currentBranch,
|
||||
repoUrl,
|
||||
isRepoWorktree,
|
||||
repoName,
|
||||
}: SourceControlPanelProps) {
|
||||
const [activeTab, setActiveTab] = useState<Tab>('changes')
|
||||
@@ -224,7 +220,7 @@ export function SourceControlPanel({
|
||||
<CommitsTab repoId={repoId} onSelectCommit={handleSelectCommit} />
|
||||
)}
|
||||
{activeTab === 'branches' && currentView === 'default' && (
|
||||
<BranchesTab repoId={repoId} currentBranch={currentBranch} repoUrl={repoUrl} isRepoWorktree={isRepoWorktree} />
|
||||
<BranchesTab repoId={repoId} currentBranch={currentBranch} />
|
||||
)}
|
||||
|
||||
{currentView === 'commit-detail' && selectedCommit && (
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { Sidebar, SidebarSection, SidebarItem, SidebarCollapseToggle } from './sidebar'
|
||||
import { TooltipProvider } from './tooltip'
|
||||
import { Folder } from 'lucide-react'
|
||||
|
||||
describe('Sidebar', () => {
|
||||
it('renders children', () => {
|
||||
render(
|
||||
<Sidebar collapsed={false} onToggle={vi.fn()}>
|
||||
<div data-testid="child">Content</div>
|
||||
</Sidebar>
|
||||
)
|
||||
|
||||
expect(screen.getByTestId('child')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('applies collapsed width class when collapsed', () => {
|
||||
const { container } = render(
|
||||
<Sidebar collapsed={true} onToggle={vi.fn()}>
|
||||
<div>Content</div>
|
||||
</Sidebar>
|
||||
)
|
||||
|
||||
expect(container.firstChild).toHaveClass('w-14')
|
||||
})
|
||||
|
||||
it('applies expanded width class when not collapsed', () => {
|
||||
const { container } = render(
|
||||
<Sidebar collapsed={false} onToggle={vi.fn()}>
|
||||
<div>Content</div>
|
||||
</Sidebar>
|
||||
)
|
||||
|
||||
expect(container.firstChild).toHaveClass('w-60')
|
||||
})
|
||||
})
|
||||
|
||||
describe('SidebarSection', () => {
|
||||
it('renders label when not collapsed', () => {
|
||||
render(
|
||||
<SidebarSection label="Test Section" collapsed={false}>
|
||||
<div>Content</div>
|
||||
</SidebarSection>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Test Section')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides label when collapsed', () => {
|
||||
render(
|
||||
<SidebarSection label="Test Section" collapsed={true}>
|
||||
<div>Content</div>
|
||||
</SidebarSection>
|
||||
)
|
||||
|
||||
expect(screen.queryByText('Test Section')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('SidebarItem', () => {
|
||||
it('fires onClick when clicked', () => {
|
||||
const handleClick = vi.fn()
|
||||
|
||||
render(
|
||||
<SidebarItem
|
||||
icon={Folder}
|
||||
label="Test Item"
|
||||
collapsed={false}
|
||||
onClick={handleClick}
|
||||
/>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button'))
|
||||
expect(handleClick).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('applies active styles when active', () => {
|
||||
render(
|
||||
<SidebarItem
|
||||
icon={Folder}
|
||||
label="Test Item"
|
||||
collapsed={false}
|
||||
active={true}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('button')).toHaveClass('bg-accent')
|
||||
})
|
||||
|
||||
it('uses title attribute when collapsed', () => {
|
||||
render(
|
||||
<TooltipProvider>
|
||||
<SidebarItem
|
||||
icon={Folder}
|
||||
label="Test Item"
|
||||
collapsed={true}
|
||||
/>
|
||||
</TooltipProvider>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('button')).toHaveAttribute('title', 'Test Item')
|
||||
})
|
||||
})
|
||||
|
||||
describe('SidebarCollapseToggle', () => {
|
||||
it('calls onToggle when clicked', () => {
|
||||
const handleToggle = vi.fn()
|
||||
|
||||
render(
|
||||
<SidebarCollapseToggle collapsed={false} onToggle={handleToggle} />
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByRole('button'))
|
||||
expect(handleToggle).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,136 @@
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { ChevronLeft, ChevronRight } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
|
||||
export interface SidebarProps {
|
||||
collapsed: boolean
|
||||
onToggle: () => void
|
||||
widthClass?: string
|
||||
collapsedWidthClass?: string
|
||||
className?: string
|
||||
children: React.ReactNode
|
||||
ariaLabel?: string
|
||||
}
|
||||
|
||||
export function Sidebar({
|
||||
collapsed,
|
||||
widthClass = 'w-60',
|
||||
collapsedWidthClass = 'w-14',
|
||||
className,
|
||||
children,
|
||||
ariaLabel = 'Sidebar',
|
||||
}: SidebarProps) {
|
||||
return (
|
||||
<aside
|
||||
className={cn(
|
||||
'flex-shrink-0 border-r border-border bg-card/50 backdrop-blur-sm h-dvh flex flex-col pt-safe pb-safe transition-[width] duration-200',
|
||||
collapsed ? collapsedWidthClass : widthClass,
|
||||
className
|
||||
)}
|
||||
aria-label={ariaLabel}
|
||||
>
|
||||
{children}
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
|
||||
export interface SidebarSectionProps {
|
||||
label?: string
|
||||
collapsed: boolean
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export function SidebarSection({ label, collapsed, children }: SidebarSectionProps) {
|
||||
return (
|
||||
<div className={cn('flex flex-col gap-1 p-2', !label && 'pt-0')}>
|
||||
{label && !collapsed && (
|
||||
<div className="px-2 py-1.5 text-xs font-medium text-muted-foreground uppercase tracking-wider">
|
||||
{label}
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export interface SidebarItemProps {
|
||||
icon: LucideIcon
|
||||
label: string
|
||||
active?: boolean
|
||||
danger?: boolean
|
||||
collapsed: boolean
|
||||
onClick?: () => void
|
||||
asPrimary?: boolean
|
||||
variant?: 'default' | 'primary' | 'secondary' | 'danger'
|
||||
}
|
||||
|
||||
export function SidebarItem({
|
||||
icon: Icon,
|
||||
label,
|
||||
active = false,
|
||||
collapsed,
|
||||
onClick,
|
||||
asPrimary = false,
|
||||
variant = 'default',
|
||||
}: SidebarItemProps) {
|
||||
|
||||
const baseClasses = cn(
|
||||
'flex items-center gap-3 rounded-md transition-colors duration-150',
|
||||
'focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:ring-offset-background',
|
||||
asPrimary ? 'p-3 text-sm font-medium' : 'p-2.5 text-sm',
|
||||
variant === 'primary' && 'bg-primary text-primary-foreground hover:bg-primary/90',
|
||||
variant === 'secondary' && 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
||||
variant === 'danger' && 'text-destructive hover:bg-destructive/10',
|
||||
variant === 'default' && active && 'bg-accent text-accent-foreground',
|
||||
variant === 'default' && !active && 'hover:bg-accent/50 text-foreground',
|
||||
collapsed && 'justify-center'
|
||||
)
|
||||
|
||||
const content = (
|
||||
<button
|
||||
type="button"
|
||||
className={baseClasses}
|
||||
onClick={onClick}
|
||||
title={collapsed ? label : undefined}
|
||||
>
|
||||
<Icon className={cn('h-5 w-5', 'flex-shrink-0')} />
|
||||
{!collapsed && <span className="truncate">{label}</span>}
|
||||
{collapsed && <span className="sr-only">{label}</span>}
|
||||
</button>
|
||||
)
|
||||
|
||||
if (collapsed) {
|
||||
return (
|
||||
<Tooltip delayDuration={0}>
|
||||
<TooltipTrigger asChild>{content}</TooltipTrigger>
|
||||
<TooltipContent side="right" align="center">
|
||||
{label}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
export interface SidebarCollapseToggleProps {
|
||||
collapsed: boolean
|
||||
onToggle: () => void
|
||||
}
|
||||
|
||||
export function SidebarCollapseToggle({ collapsed, onToggle }: SidebarCollapseToggleProps) {
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onToggle}
|
||||
className="w-full rounded-none border-t border-border"
|
||||
title={collapsed ? 'Expand sidebar' : 'Collapse sidebar'}
|
||||
>
|
||||
{collapsed ? <ChevronRight className="h-4 w-4" /> : <ChevronLeft className="h-4 w-4" />}
|
||||
<span className="sr-only">{collapsed ? 'Expand' : 'Collapse'}</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import * as React from 'react'
|
||||
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const TooltipProvider = TooltipPrimitive.Provider
|
||||
|
||||
const Tooltip = TooltipPrimitive.Root
|
||||
|
||||
const TooltipTrigger = TooltipPrimitive.Trigger
|
||||
|
||||
const TooltipContent = React.forwardRef<
|
||||
React.ElementRef<typeof TooltipPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||
<TooltipPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
'z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
TooltipContent.displayName = TooltipPrimitive.Content.displayName
|
||||
|
||||
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { renderHook, act } from '@testing-library/react'
|
||||
import { useDesktop } from './useDesktop'
|
||||
|
||||
describe('useDesktop', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('returns true for width >= 768px', () => {
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: 1024,
|
||||
})
|
||||
|
||||
const { result } = renderHook(() => useDesktop())
|
||||
|
||||
expect(result.current).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false for width < 768px', () => {
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: 500,
|
||||
})
|
||||
|
||||
const { result } = renderHook(() => useDesktop())
|
||||
|
||||
expect(result.current).toBe(false)
|
||||
})
|
||||
|
||||
it('updates when window is resized', () => {
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: 500,
|
||||
})
|
||||
|
||||
const { result } = renderHook(() => useDesktop())
|
||||
|
||||
expect(result.current).toBe(false)
|
||||
|
||||
act(() => {
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: 1024,
|
||||
})
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
|
||||
expect(result.current).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,14 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
export function useDesktop() {
|
||||
const [isDesktop, setIsDesktop] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const check = () => setIsDesktop(window.innerWidth >= 768)
|
||||
check()
|
||||
window.addEventListener('resize', check)
|
||||
return () => window.removeEventListener('resize', check)
|
||||
}, [])
|
||||
|
||||
return isDesktop
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import { useSidebarAction } from './useSidebarAction'
|
||||
|
||||
describe('useSidebarAction', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('calls handler when matching event is dispatched', () => {
|
||||
const handler = vi.fn()
|
||||
|
||||
renderHook(() => useSidebarAction('new-session', handler))
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('oc:sidebar:action', {
|
||||
detail: { action: 'new-session' },
|
||||
})
|
||||
)
|
||||
|
||||
expect(handler).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('does not call handler for non-matching action', () => {
|
||||
const handler = vi.fn()
|
||||
|
||||
renderHook(() => useSidebarAction('new-session', handler))
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('oc:sidebar:action', {
|
||||
detail: { action: 'new-repo' },
|
||||
})
|
||||
)
|
||||
|
||||
expect(handler).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('cleans up event listener on unmount', () => {
|
||||
const handler = vi.fn()
|
||||
const { unmount } = renderHook(() => useSidebarAction('new-session', handler))
|
||||
|
||||
unmount()
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('oc:sidebar:action', {
|
||||
detail: { action: 'new-session' },
|
||||
})
|
||||
)
|
||||
|
||||
expect(handler).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import { useEffect } from 'react'
|
||||
|
||||
type SidebarActionKey = 'new-session' | 'new-repo' | 'new-schedule'
|
||||
|
||||
export function useSidebarAction(action: SidebarActionKey, handler: () => void) {
|
||||
useEffect(() => {
|
||||
const listener = (event: Event) => {
|
||||
const detail = (event as CustomEvent<{ action?: SidebarActionKey }>).detail
|
||||
if (detail?.action === action) {
|
||||
handler()
|
||||
}
|
||||
}
|
||||
window.addEventListener('oc:sidebar:action', listener)
|
||||
return () => window.removeEventListener('oc:sidebar:action', listener)
|
||||
}, [action, handler])
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { renderHook, act } from '@testing-library/react'
|
||||
import { useSidebarCollapsed } from './useSidebarCollapsed'
|
||||
|
||||
describe('useSidebarCollapsed', () => {
|
||||
const localStorageMock = {
|
||||
getItem: vi.fn(),
|
||||
setItem: vi.fn(),
|
||||
removeItem: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
Object.defineProperty(global, 'localStorage', {
|
||||
value: localStorageMock,
|
||||
writable: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('returns false by default when no stored value', () => {
|
||||
localStorageMock.getItem.mockReturnValue(null)
|
||||
|
||||
const { result } = renderHook(() => useSidebarCollapsed())
|
||||
|
||||
expect(result.current[0]).toBe(false)
|
||||
})
|
||||
|
||||
it('returns stored value from localStorage', () => {
|
||||
localStorageMock.getItem.mockReturnValue('true')
|
||||
|
||||
const { result } = renderHook(() => useSidebarCollapsed())
|
||||
|
||||
expect(result.current[0]).toBe(true)
|
||||
})
|
||||
|
||||
it('toggles collapsed state and persists to localStorage', () => {
|
||||
localStorageMock.getItem.mockReturnValue(null)
|
||||
|
||||
const { result } = renderHook(() => useSidebarCollapsed())
|
||||
|
||||
expect(result.current[0]).toBe(false)
|
||||
|
||||
act(() => {
|
||||
result.current[1]()
|
||||
})
|
||||
|
||||
expect(result.current[0]).toBe(true)
|
||||
expect(localStorageMock.setItem).toHaveBeenCalledWith('oc:sidebar:collapsed', 'true')
|
||||
})
|
||||
|
||||
it('returns false when stored value is malformed JSON', () => {
|
||||
localStorageMock.getItem.mockReturnValue('not-json{{')
|
||||
|
||||
const { result } = renderHook(() => useSidebarCollapsed())
|
||||
|
||||
expect(result.current[0]).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when stored value is JSON but not a boolean', () => {
|
||||
localStorageMock.getItem.mockReturnValue('"some string"')
|
||||
|
||||
const { result } = renderHook(() => useSidebarCollapsed())
|
||||
|
||||
expect(result.current[0]).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useState, useCallback } from 'react'
|
||||
|
||||
const STORAGE_KEY = 'oc:sidebar:collapsed'
|
||||
|
||||
export function useSidebarCollapsed(): [boolean, () => void] {
|
||||
const [collapsed, setCollapsed] = useState(() => {
|
||||
if (typeof window === 'undefined') {
|
||||
return false
|
||||
}
|
||||
const stored = localStorage.getItem(STORAGE_KEY)
|
||||
if (stored === null) {
|
||||
return false
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(stored)
|
||||
return typeof parsed === 'boolean' ? parsed : false
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
const toggle = useCallback(() => {
|
||||
setCollapsed((prev: boolean) => {
|
||||
const newValue = !prev
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(newValue))
|
||||
}
|
||||
return newValue
|
||||
})
|
||||
}, [])
|
||||
|
||||
return [collapsed, toggle]
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
import { ErrorBoundary } from '@/components/ui/error-boundary'
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import { registerServiceWorker } from './lib/serviceWorker'
|
||||
|
||||
registerServiceWorker()
|
||||
@@ -10,7 +11,9 @@ registerServiceWorker()
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<ErrorBoundary>
|
||||
<App />
|
||||
<TooltipProvider>
|
||||
<App />
|
||||
</TooltipProvider>
|
||||
</ErrorBoundary>
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -5,7 +5,6 @@ import { getRepo, initializeAssistantMode, listRepos } from "@/api/repos"
|
||||
import { useAssistantSessionLauncher } from "@/hooks/useAssistantSessionLauncher"
|
||||
import { useCreateSession } from "@/hooks/useOpenCode"
|
||||
import { useDialogParam } from "@/hooks/useDialogParam"
|
||||
import { useMemoryPluginStatus } from "@/hooks/useMemoryPluginStatus"
|
||||
import { useSSE } from "@/hooks/useSSE"
|
||||
import { OPENCODE_API_ENDPOINT } from "@/config"
|
||||
import { Button } from "@/components/ui/button"
|
||||
@@ -19,7 +18,7 @@ import { ResetPermissionsDialog } from "@/components/repo/ResetPermissionsDialog
|
||||
import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup"
|
||||
import { invalidateConfigCaches } from "@/lib/queryInvalidation"
|
||||
import { SwitchConfigDialog } from "@/components/repo/SwitchConfigDialog"
|
||||
import { Brain, CalendarClock, FolderOpen, GitCommitHorizontal, Loader2, Plug, Plus, ShieldOff, Sparkles } from "lucide-react"
|
||||
import { Loader2, Plus } from "lucide-react"
|
||||
|
||||
export function AssistantRedirect() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
@@ -38,8 +37,6 @@ export function AssistantRedirect() {
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null)
|
||||
|
||||
const opcodeUrl = OPENCODE_API_ENDPOINT
|
||||
const { memoryPluginEnabled } = useMemoryPluginStatus()
|
||||
|
||||
const { data: repo } = useQuery({
|
||||
queryKey: ["repo", repoId],
|
||||
queryFn: () => getRepo(repoId),
|
||||
@@ -119,36 +116,6 @@ export function AssistantRedirect() {
|
||||
<div className="flex items-center gap-1">
|
||||
<PendingActionsGroup />
|
||||
</div>
|
||||
<Button variant="outline" onClick={() => setMcpDialogOpen(true)} size="sm" className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105">
|
||||
<Plug className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">MCP</span>
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setSkillsDialogOpen(true)} size="sm" className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105">
|
||||
<Sparkles className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Skills</span>
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setSourceControlOpen(true)} size="sm" className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105">
|
||||
<GitCommitHorizontal className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Source</span>
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setFileBrowserOpen(true)} size="sm" className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105">
|
||||
<FolderOpen className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Files</span>
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setResetPermissionsOpen(true)} size="sm" className="hidden lg:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105">
|
||||
<ShieldOff className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Reset Permissions</span>
|
||||
</Button>
|
||||
{memoryPluginEnabled && (
|
||||
<Button variant="outline" onClick={() => navigate(`/repos/${repoId}/memories`)} size="sm" className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105">
|
||||
<Brain className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Memory</span>
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="outline" onClick={() => navigate(`/repos/${repoId}/schedules`)} size="sm" className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105">
|
||||
<CalendarClock className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Schedules</span>
|
||||
</Button>
|
||||
<Button onClick={() => handleCreateSession()} disabled={!opcodeUrl || !assistantDirectory || createSessionMutation.isPending} size="sm" className="hidden sm:inline-flex bg-blue-600 hover:bg-blue-700 text-white transition-all duration-200 hover:scale-105">
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
<span>New Session</span>
|
||||
@@ -176,7 +143,7 @@ export function AssistantRedirect() {
|
||||
<FileBrowserSheet isOpen={fileBrowserOpen} onClose={() => setFileBrowserOpen(false)} basePath={assistantFileBasePath} repoName="Assistant" repoId={repoId} />
|
||||
<RepoMcpDialog open={mcpDialogOpen} onOpenChange={setMcpDialogOpen} directory={assistantDirectory} />
|
||||
<RepoSkillsDialog open={skillsDialogOpen} onOpenChange={setSkillsDialogOpen} repoId={repoId} />
|
||||
<SourceControlPanel repoId={repoId} isOpen={sourceControlOpen} onClose={() => setSourceControlOpen(false)} currentBranch={repo?.currentBranch || repo?.branch || "main"} repoUrl={repo?.repoUrl} isRepoWorktree={repo?.isWorktree} repoName="Assistant" />
|
||||
<SourceControlPanel repoId={repoId} isOpen={sourceControlOpen} onClose={() => setSourceControlOpen(false)} currentBranch={repo?.currentBranch || repo?.branch || "main"} repoName="Assistant" />
|
||||
<ResetPermissionsDialog open={resetPermissionsOpen} onOpenChange={setResetPermissionsOpen} repoId={repoId} repoDirectory={assistantDirectory} />
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -8,20 +8,21 @@ import { Header } from "@/components/ui/header";
|
||||
import { SwitchConfigDialog } from "@/components/repo/SwitchConfigDialog";
|
||||
import { RepoMcpDialog } from "@/components/repo/RepoMcpDialog";
|
||||
import { RepoSkillsDialog } from "@/components/repo/RepoSkillsDialog";
|
||||
import { CreateWorktreeDialog } from "@/components/repo/CreateWorktreeDialog";
|
||||
import { SourceControlPanel } from "@/components/source-control";
|
||||
import { useCreateSession } from "@/hooks/useOpenCode";
|
||||
import { useRepoActivity } from "@/hooks/useRepoActivity";
|
||||
import { useMemoryPluginStatus } from "@/hooks/useMemoryPluginStatus";
|
||||
import { useSSE } from "@/hooks/useSSE";
|
||||
import { useDialogParam } from "@/hooks/useDialogParam";
|
||||
import { OPENCODE_API_ENDPOINT } from "@/config";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Plug, FolderOpen, Plus, GitBranch, GitBranchPlus, GitCommitHorizontal, ShieldOff, Brain, Loader2, CalendarClock, Sparkles, Bot } from "lucide-react";
|
||||
import { GitBranch, Plus, Loader2 } from "lucide-react";
|
||||
import { ResetPermissionsDialog } from "@/components/repo/ResetPermissionsDialog";
|
||||
import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup";
|
||||
import { invalidateConfigCaches } from "@/lib/queryInvalidation";
|
||||
import { getRepoDisplayName } from "@/lib/utils";
|
||||
import { useSidebarAction } from "@/hooks/useSidebarAction";
|
||||
|
||||
export function RepoDetail() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
@@ -33,7 +34,6 @@ export function RepoDetail() {
|
||||
const [skillsDialogOpen, setSkillsDialogOpen] = useDialogParam('skills');
|
||||
const [sourceControlOpen, setSourceControlOpen] = useDialogParam('sourceControl');
|
||||
const [resetPermissionsOpen, setResetPermissionsOpen] = useDialogParam('resetPermissions');
|
||||
const [worktreeDialogOpen, setWorktreeDialogOpen] = useDialogParam('createWorktree');
|
||||
|
||||
const { data: repo, isLoading: repoLoading } = useQuery({
|
||||
queryKey: ["repo", repoId],
|
||||
@@ -43,8 +43,6 @@ export function RepoDetail() {
|
||||
|
||||
useRepoActivity(repoId, Boolean(repo));
|
||||
|
||||
const { memoryPluginEnabled } = useMemoryPluginStatus();
|
||||
|
||||
const opcodeUrl = OPENCODE_API_ENDPOINT;
|
||||
|
||||
const repoDirectory = repo?.fullPath;
|
||||
@@ -68,6 +66,10 @@ export function RepoDetail() {
|
||||
navigate(`/repos/${repoId}/sessions/${sessionId}`);
|
||||
};
|
||||
|
||||
useSidebarAction('new-session', () => {
|
||||
handleCreateSession();
|
||||
});
|
||||
|
||||
if (repoLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen bg-background">
|
||||
@@ -104,7 +106,6 @@ export function RepoDetail() {
|
||||
const displayName = branchToDisplay ? `${repoName} (${branchToDisplay})` : repoName;
|
||||
const currentBranch = repo.currentBranch || repo.branch || "main";
|
||||
const isWorktree = repo.isWorktree || false;
|
||||
const canCreateWorktree = !isWorktree && Boolean(repo.repoUrl);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -121,152 +122,10 @@ export function RepoDetail() {
|
||||
</Badge>
|
||||
) : null}
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setMcpDialogOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Plug className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">MCP</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setSkillsDialogOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Sparkles className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Skills</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setSourceControlOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<GitCommitHorizontal className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Source</span>
|
||||
</Button>
|
||||
{canCreateWorktree && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setWorktreeDialogOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
title="Create Worktree"
|
||||
>
|
||||
<GitBranchPlus className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Worktree</span>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setFileBrowserOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<FolderOpen className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Files</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setResetPermissionsOpen(true)}
|
||||
size="sm"
|
||||
className="hidden lg:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<ShieldOff className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Reset Permissions</span>
|
||||
</Button>
|
||||
<Header.Actions>
|
||||
{memoryPluginEnabled && (
|
||||
<>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setMcpDialogOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Plug className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">MCP</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setSkillsDialogOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Sparkles className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Skills</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setSourceControlOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<GitCommitHorizontal className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Source</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setFileBrowserOpen(true)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<FolderOpen className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Files</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setResetPermissionsOpen(true)}
|
||||
size="sm"
|
||||
className="hidden lg:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<ShieldOff className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Reset Permissions</span>
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{memoryPluginEnabled && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => navigate(`/repos/${repoId}/memories`)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Brain className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Memory</span>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => navigate(`/repos/${repoId}/schedules`)}
|
||||
size="sm"
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<CalendarClock className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Schedules</span>
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => navigate(`/repos/${repoId}/assistant`)}
|
||||
disabled={!opcodeUrl}
|
||||
size="sm"
|
||||
className="hidden sm:inline-flex bg-purple-600 hover:bg-purple-700 text-white transition-all duration-200 hover:scale-105"
|
||||
aria-label="Open Assistant"
|
||||
>
|
||||
<Bot className="w-4 h-4 mr-2" />
|
||||
<span>Assistant</span>
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => handleCreateSession()}
|
||||
disabled={!opcodeUrl || createSessionMutation.isPending}
|
||||
size="sm"
|
||||
className="hidden sm:inline-flex bg-blue-600 hover:bg-blue-700 text-white transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
<span>New Session</span>
|
||||
</Button>
|
||||
<div className="flex items-center gap-1">
|
||||
<PendingActionsGroup />
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => handleCreateSession()}
|
||||
disabled={!opcodeUrl || createSessionMutation.isPending}
|
||||
@@ -314,8 +173,6 @@ export function RepoDetail() {
|
||||
isOpen={sourceControlOpen}
|
||||
onClose={() => setSourceControlOpen(false)}
|
||||
currentBranch={currentBranch}
|
||||
repoUrl={repo.repoUrl}
|
||||
isRepoWorktree={repo.isWorktree}
|
||||
repoName={repoName}
|
||||
/>
|
||||
|
||||
@@ -341,14 +198,6 @@ export function RepoDetail() {
|
||||
repoId={repoId}
|
||||
repoDirectory={repoDirectory}
|
||||
/>
|
||||
|
||||
<CreateWorktreeDialog
|
||||
open={worktreeDialogOpen}
|
||||
onOpenChange={setWorktreeDialogOpen}
|
||||
repoId={repoId}
|
||||
repoUrl={repo.repoUrl}
|
||||
defaultBaseBranch={currentBranch}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,16 +7,22 @@ import { Header } from "@/components/ui/header";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Plus, FolderOpen, CalendarClock } from "lucide-react";
|
||||
import { PendingActionsGroup } from "@/components/notifications/PendingActionsGroup";
|
||||
import { useSidebarAction } from "@/hooks/useSidebarAction";
|
||||
import { useDialogParam } from "@/hooks/useDialogParam";
|
||||
|
||||
export function Repos() {
|
||||
const navigate = useNavigate();
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false);
|
||||
const [fileBrowserOpen, setFileBrowserOpen] = useState(false);
|
||||
const [fileBrowserOpen, setFileBrowserOpen] = useDialogParam('files');
|
||||
|
||||
const handleCloseFileBrowser = () => {
|
||||
setFileBrowserOpen(false);
|
||||
};
|
||||
|
||||
useSidebarAction('new-repo', () => {
|
||||
setAddRepoOpen(true);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="h-dvh max-h-dvh overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col">
|
||||
<Header>
|
||||
@@ -31,7 +37,7 @@ export function Repos() {
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => setFileBrowserOpen(true)}
|
||||
className="hidden sm:flex text-muted-foreground hover:text-foreground hover:bg-accent transition-all duration-200 h-8 w-8"
|
||||
className="text-muted-foreground hover:text-foreground hover:bg-accent transition-all duration-200 h-8 w-8"
|
||||
>
|
||||
<FolderOpen className="w-4 h-4" />
|
||||
</Button>
|
||||
@@ -44,15 +50,11 @@ export function Repos() {
|
||||
<CalendarClock className="w-4 h-4 mr-2" />
|
||||
All Schedules
|
||||
</Button>
|
||||
<Button onClick={() => setAddRepoOpen(true)} size="sm" className="hidden sm:inline-flex">
|
||||
<Button onClick={() => setAddRepoOpen(true)} size="sm">
|
||||
<Plus className="w-4 h-4 mr-1" />
|
||||
Repo
|
||||
</Button>
|
||||
<Button onClick={() => setAddRepoOpen(true)} size="sm" className="sm:hidden">
|
||||
<Plus className="w-4 h-4 mr-1" />
|
||||
Repo
|
||||
</Button>
|
||||
<span className="hidden sm:block">
|
||||
<span>
|
||||
<Header.Settings />
|
||||
</span>
|
||||
</Header.Actions>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getRepo, initializeAssistantMode } from "@/api/repos";
|
||||
import { MessageThread } from "@/components/message/MessageThread";
|
||||
import { PromptInput, type PromptInputHandle } from "@/components/message/PromptInput";
|
||||
import { FloatingTTSButton } from '@/components/message/FloatingTTSButton'
|
||||
import { X, FolderOpen, Plug, Settings, CornerUpLeft, GitCommitHorizontal, Brain, ShieldOff, Sparkles } from "lucide-react";
|
||||
import { X, CornerUpLeft } from "lucide-react";
|
||||
import { ModelSelectDialog } from "@/components/model/ModelSelectDialog";
|
||||
import { Header } from "@/components/ui/header";
|
||||
import { SessionList } from "@/components/session/SessionList";
|
||||
@@ -36,7 +36,6 @@ import { showToast } from "@/lib/toast";
|
||||
import { getRepoDisplayName } from "@/lib/utils";
|
||||
import { RepoMcpDialog } from "@/components/repo/RepoMcpDialog";
|
||||
import { ResetPermissionsDialog } from "@/components/repo/ResetPermissionsDialog";
|
||||
import { LspStatusButton } from "@/components/repo/LspStatusButton";
|
||||
import { RepoLspDialog } from "@/components/repo/RepoLspDialog";
|
||||
import { RepoSkillsDialog } from "@/components/repo/RepoSkillsDialog";
|
||||
import { createOpenCodeClient } from "@/api/opencode";
|
||||
@@ -50,7 +49,6 @@ import { SourceControlPanel } from "@/components/source-control";
|
||||
import { SessionTodoDisplay } from "@/components/message/SessionTodoDisplay";
|
||||
import { useDialogParam } from "@/hooks/useDialogParam";
|
||||
import { SessionMoreButton } from "@/components/navigation/SessionMoreButton";
|
||||
import { useMemoryPluginStatus } from "@/hooks/useMemoryPluginStatus";
|
||||
|
||||
const compareMessageIds = (id1: string, id2: string): number => {
|
||||
const num1 = parseInt(id1, 10)
|
||||
@@ -119,8 +117,6 @@ export function SessionDetail() {
|
||||
|
||||
useRepoActivity(repoId, Boolean(repo));
|
||||
|
||||
const { memoryPluginEnabled } = useMemoryPluginStatus();
|
||||
|
||||
const opcodeUrl = OPENCODE_API_ENDPOINT;
|
||||
|
||||
const repoDirectory = isAssistantSession ? assistantMode?.directory : repo?.fullPath;
|
||||
@@ -422,78 +418,6 @@ export function SessionDetail() {
|
||||
isConnected={isConnected}
|
||||
isReconnecting={isReconnecting}
|
||||
/>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setFileBrowserOpen(true)}
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<FolderOpen className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Files</span>
|
||||
</Button>
|
||||
<div className="hidden md:flex">
|
||||
<LspStatusButton
|
||||
opcodeUrl={opcodeUrl}
|
||||
directory={repoDirectory}
|
||||
onClick={() => setLspDialogOpen(true)}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setSkillsDialogOpen(true)}
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Sparkles className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Skills</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setMcpDialogOpen(true)}
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Plug className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">MCP</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setSourceControlOpen(true)}
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<GitCommitHorizontal className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Source</span>
|
||||
</Button>
|
||||
{memoryPluginEnabled && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => navigate(`/repos/${repoId}/memories`)}
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Brain className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Memory</span>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => setResetPermissionsOpen(true)}
|
||||
className="hidden lg:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<ShieldOff className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Reset Permissions</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={openSettings}
|
||||
className="hidden md:flex text-foreground border-border hover:bg-accent transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Settings className="w-4 h-4 sm:mr-2" />
|
||||
<span className="hidden sm:inline">Settings</span>
|
||||
</Button>
|
||||
<SessionMoreButton />
|
||||
</Header.Actions>
|
||||
</Header>
|
||||
@@ -651,8 +575,6 @@ export function SessionDetail() {
|
||||
isOpen={sourceControlOpen}
|
||||
onClose={() => setSourceControlOpen(false)}
|
||||
currentBranch={repo.currentBranch || repo.branch || "main"}
|
||||
repoUrl={repo.repoUrl}
|
||||
isRepoWorktree={repo.isWorktree}
|
||||
repoName={workspaceDisplayName}
|
||||
/>
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"concurrently": "^9.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@radix-ui/react-tooltip": "^1.2.8",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"dotenv": "^17.2.3"
|
||||
}
|
||||
|
||||
Generated
+36
@@ -8,6 +8,9 @@ importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
'@radix-ui/react-tooltip':
|
||||
specifier: ^1.2.8
|
||||
version: 1.2.8(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
|
||||
class-variance-authority:
|
||||
specifier: ^0.7.1
|
||||
version: 0.7.1
|
||||
@@ -1189,6 +1192,19 @@ packages:
|
||||
'@types/react-dom':
|
||||
optional: true
|
||||
|
||||
'@radix-ui/react-tooltip@1.2.8':
|
||||
resolution: {integrity: sha512-tY7sVt1yL9ozIxvmbtN5qtmH2krXcBCfjEiCgKGLqunJHvgvZG2Pcl2oQ3kbcZARb1BGEHdkLzcYGO8ynVlieg==}
|
||||
peerDependencies:
|
||||
'@types/react': '*'
|
||||
'@types/react-dom': '*'
|
||||
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
||||
react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
|
||||
peerDependenciesMeta:
|
||||
'@types/react':
|
||||
optional: true
|
||||
'@types/react-dom':
|
||||
optional: true
|
||||
|
||||
'@radix-ui/react-use-callback-ref@1.1.1':
|
||||
resolution: {integrity: sha512-FkBMwD+qbGQeMu1cOHnuGB6x4yzPjho8ap5WtbEJ26umhgqVXbhekKUQO+hZEL1vU92a3wHwdp0HAcqAUF5iDg==}
|
||||
peerDependencies:
|
||||
@@ -4983,6 +4999,26 @@ snapshots:
|
||||
'@types/react': 19.2.7
|
||||
'@types/react-dom': 19.2.3(@types/react@19.2.7)
|
||||
|
||||
'@radix-ui/react-tooltip@1.2.8(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)':
|
||||
dependencies:
|
||||
'@radix-ui/primitive': 1.1.3
|
||||
'@radix-ui/react-compose-refs': 1.1.2(@types/react@19.2.7)(react@19.2.3)
|
||||
'@radix-ui/react-context': 1.1.2(@types/react@19.2.7)(react@19.2.3)
|
||||
'@radix-ui/react-dismissable-layer': 1.1.11(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
|
||||
'@radix-ui/react-id': 1.1.1(@types/react@19.2.7)(react@19.2.3)
|
||||
'@radix-ui/react-popper': 1.2.8(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
|
||||
'@radix-ui/react-portal': 1.1.9(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
|
||||
'@radix-ui/react-presence': 1.1.5(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
|
||||
'@radix-ui/react-primitive': 2.1.3(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
|
||||
'@radix-ui/react-slot': 1.2.3(@types/react@19.2.7)(react@19.2.3)
|
||||
'@radix-ui/react-use-controllable-state': 1.2.2(@types/react@19.2.7)(react@19.2.3)
|
||||
'@radix-ui/react-visually-hidden': 1.2.3(@types/react-dom@19.2.3(@types/react@19.2.7))(@types/react@19.2.7)(react-dom@19.2.3(react@19.2.3))(react@19.2.3)
|
||||
react: 19.2.3
|
||||
react-dom: 19.2.3(react@19.2.3)
|
||||
optionalDependencies:
|
||||
'@types/react': 19.2.7
|
||||
'@types/react-dom': 19.2.3(@types/react@19.2.7)
|
||||
|
||||
'@radix-ui/react-use-callback-ref@1.1.1(@types/react@19.2.7)(react@19.2.3)':
|
||||
dependencies:
|
||||
react: 19.2.3
|
||||
|
||||
Reference in new issue
Block a user