mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix: update settings and skills handling with assistant redirect (#220)
* fix: enable swipe-back suspension on more drawer and remove unused variable * refactor(frontend): improve dialog component and settings navigation * fix: disable route swipe suspension in MoreDrawer to prevent unintended navigation * fix(frontend): enable swipe-back suspension on more drawer route * refactor(frontend): improve mobile navigation drawer and tab bar * feat: add schedules service and workspace hook with navigation updates * chore: add workspace hook, schedules library, and tests * fix: prevent MoreDrawer sentinel from undoing navigation * feat: per-agent model selection and UI refinements (#217) * feat: per-agent model selection and UI refinements - Add agentModels store with setAgentModel/getAgentModel - PromptInput uses session model priority and stores agent model on change - useContextUsage derives model from assistant message instead of global - Migrate sub-agent/subtask badges from purple to blue with refined styling - Fix MoreDrawer sentinel to skip history-back on navigation * refactor: improve per-agent model selection and task tool call status indicators * feat: add repo management skill and internal repos API * fix: improve assistant session launcher and UI components * fix: update atomic-json test assertions * refactor: split Assistant Mode instructions between AGENTS.md and assistant.md * loop: todo-header-mobile completed after 3 iterations (#218) * loop: stt-perf-1 completed after 5 iterations * fix: load audio worklet per recording context * fix: canonicalize assistant navigation routes * fix: adjust scroll-up threshold for header visibility * fix: update settings and skills handling with assistant redirect * refactor: simplify context usage indicator and extract token sum helper * feat: add currently selected model row to popover and fix responsive truncate
This commit is contained in:
1 parent
c7291518c8
commit
74cdeb3926
73 files changed
+4073
-632
No files matched your search
@@ -27,6 +27,7 @@ import { MemoryRouter } from 'react-router-dom'
|
||||
import { MobileSheetHost } from './MobileSheetHost'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
|
||||
describe('MobileSheetHost', () => {
|
||||
beforeEach(() => {
|
||||
@@ -103,18 +104,15 @@ describe('MobileSheetHost', () => {
|
||||
expect(screen.getByTestId('notifications-sheet')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders MoreDrawer when mobileTab=more', () => {
|
||||
vi.mocked(useMobileTabBar).mockReturnValue({
|
||||
openSheet: 'more',
|
||||
open: vi.fn(),
|
||||
close: vi.fn(),
|
||||
})
|
||||
it('renders MoreDrawer when isMoreDrawerOpen is true', () => {
|
||||
useUIState.setState({ isMoreDrawerOpen: true })
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/?mobileTab=more']}>
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<MobileSheetHost />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
expect(screen.getByTestId('more-drawer')).toBeInTheDocument()
|
||||
useUIState.setState({ isMoreDrawerOpen: false })
|
||||
})
|
||||
|
||||
it('closes sheet when onClose is called', () => {
|
||||
|
||||
@@ -4,10 +4,13 @@ import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
|
||||
import { RepoQuickSwitchSheet } from '@/components/navigation/RepoQuickSwitchSheet'
|
||||
import { NotificationsSheet } from '@/components/navigation/NotificationsSheet'
|
||||
import { MoreDrawer } from '@/components/navigation/MoreDrawer'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
|
||||
export function MobileSheetHost() {
|
||||
const isMobile = useMobile()
|
||||
const { openSheet, close } = useMobileTabBar()
|
||||
const isMoreDrawerOpen = useUIState((state) => state.isMoreDrawerOpen)
|
||||
const setMoreDrawerOpen = useUIState((state) => state.setMoreDrawerOpen)
|
||||
|
||||
if (!isMobile) return null
|
||||
|
||||
@@ -24,7 +27,7 @@ export function MobileSheetHost() {
|
||||
/>
|
||||
)}
|
||||
{openSheet === 'notifications' && <NotificationsSheet isOpen onClose={close} />}
|
||||
{openSheet === 'more' && <MoreDrawer isOpen onClose={close} />}
|
||||
<MoreDrawer isOpen={isMoreDrawerOpen} onClose={() => setMoreDrawerOpen(false)} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -67,7 +67,7 @@ describe('MobileTabBar', () => {
|
||||
const queryClient = new QueryClient()
|
||||
render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MemoryRouter initialEntries={['/repos/123/assistant?view=sessions']}>
|
||||
<MemoryRouter initialEntries={['/assistant?view=sessions']}>
|
||||
<MobileTabBar />
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
@@ -77,7 +77,7 @@ describe('MobileTabBar', () => {
|
||||
expect(screen.getByText('Schedules')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('navigates to assistant route when repo id is present', async () => {
|
||||
it('navigates to /assistant when assistant is clicked from repo context', async () => {
|
||||
vi.mocked(useMobile).mockReturnValue(true)
|
||||
const queryClient = new QueryClient()
|
||||
const user = userEvent.setup()
|
||||
@@ -96,7 +96,7 @@ describe('MobileTabBar', () => {
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Assistant' }))
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/123/assistant')
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/assistant')
|
||||
})
|
||||
|
||||
it('navigates to assistant route when assistant is clicked without repo id', async () => {
|
||||
|
||||
@@ -4,6 +4,8 @@ import { FolderGit2, FolderOpen, CalendarClock, Menu, Info, History, Bot } from
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useMobile } from '@/hooks/useMobile'
|
||||
import { useMobileTabBar, useScheduleTab, type ScheduleTabKey } from '@/hooks/useMobileTabBar'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
import { getAssistantPath, isAssistantPath } from '@/lib/navigation'
|
||||
|
||||
interface TabDef {
|
||||
key: string
|
||||
@@ -23,6 +25,8 @@ interface GlobalTabsArgs {
|
||||
navigate: ReturnType<typeof useNavigate>
|
||||
isInsideRepo: boolean
|
||||
repoId: string | null
|
||||
isMoreDrawerOpen: boolean
|
||||
setMoreDrawerOpen: (open: boolean) => void
|
||||
}
|
||||
|
||||
type TabBarMode = 'hidden' | 'global' | 'schedule'
|
||||
@@ -34,11 +38,15 @@ interface MobileTabRouteState {
|
||||
}
|
||||
|
||||
function getMobileTabRouteState(pathname: string): MobileTabRouteState {
|
||||
if (isAssistantPath(pathname)) {
|
||||
return { mode: 'global', isInsideRepo: false, repoId: null }
|
||||
}
|
||||
|
||||
const repoMatch = pathname.match(/^\/repos\/(\d+)(?:\/([^/]+))?/)
|
||||
const repoId = repoMatch?.[1] ?? null
|
||||
const repoSection = repoMatch?.[2]
|
||||
|
||||
if (pathname === '/' || pathname === '/schedules' || pathname === '/assistant') {
|
||||
if (pathname === '/' || pathname === '/schedules') {
|
||||
return { mode: 'global', isInsideRepo: false, repoId: null }
|
||||
}
|
||||
|
||||
@@ -48,7 +56,6 @@ function getMobileTabRouteState(pathname: string): MobileTabRouteState {
|
||||
|
||||
switch (repoSection) {
|
||||
case undefined:
|
||||
case 'assistant':
|
||||
return { mode: 'global', isInsideRepo: true, repoId }
|
||||
case 'schedules':
|
||||
return { mode: 'schedule', isInsideRepo: true, repoId }
|
||||
@@ -57,7 +64,7 @@ function getMobileTabRouteState(pathname: string): MobileTabRouteState {
|
||||
}
|
||||
}
|
||||
|
||||
function buildGlobalTabs({ pathname, search, openSheet, open, close, navigate, isInsideRepo, repoId }: GlobalTabsArgs): TabDef[] {
|
||||
function buildGlobalTabs({ pathname, search, openSheet, open, close, navigate, isInsideRepo, repoId, isMoreDrawerOpen, setMoreDrawerOpen }: GlobalTabsArgs): TabDef[] {
|
||||
const navigateWithSearch = (params: URLSearchParams) => {
|
||||
const nextSearch = params.toString()
|
||||
navigate(nextSearch ? `${pathname}?${nextSearch}` : pathname, { replace: true })
|
||||
@@ -74,14 +81,8 @@ function buildGlobalTabs({ pathname, search, openSheet, open, close, navigate, i
|
||||
}
|
||||
|
||||
const handleAssistantClick = () => {
|
||||
if (repoId) {
|
||||
close()
|
||||
navigate(`/repos/${repoId}/assistant`)
|
||||
return
|
||||
}
|
||||
|
||||
close()
|
||||
navigate('/assistant')
|
||||
navigate(getAssistantPath())
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -104,7 +105,7 @@ function buildGlobalTabs({ pathname, search, openSheet, open, close, navigate, i
|
||||
label: 'Assistant',
|
||||
icon: Bot,
|
||||
onClick: handleAssistantClick,
|
||||
active: isInsideRepo && pathname === `/repos/${repoId}/assistant` && !openSheet,
|
||||
active: isAssistantPath(pathname) && !openSheet,
|
||||
},
|
||||
{
|
||||
key: 'schedules',
|
||||
@@ -117,8 +118,8 @@ function buildGlobalTabs({ pathname, search, openSheet, open, close, navigate, i
|
||||
key: 'more',
|
||||
label: 'More',
|
||||
icon: Menu,
|
||||
onClick: () => open('more'),
|
||||
active: openSheet === 'more',
|
||||
onClick: () => setMoreDrawerOpen(true),
|
||||
active: isMoreDrawerOpen,
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -190,6 +191,8 @@ export const MobileTabBar = memo(function MobileTabBar() {
|
||||
const { openSheet, open, close } = useMobileTabBar()
|
||||
const { scheduleTab, setScheduleTab } = useScheduleTab()
|
||||
const isMobile = useMobile()
|
||||
const isMoreDrawerOpen = useUIState((state) => state.isMoreDrawerOpen)
|
||||
const setMoreDrawerOpen = useUIState((state) => state.setMoreDrawerOpen)
|
||||
const routeState = useMemo(() => getMobileTabRouteState(pathname), [pathname])
|
||||
|
||||
const tabs = useMemo<TabDef[]>(
|
||||
@@ -204,6 +207,8 @@ export const MobileTabBar = memo(function MobileTabBar() {
|
||||
navigate,
|
||||
isInsideRepo: routeState.isInsideRepo,
|
||||
repoId: routeState.repoId,
|
||||
isMoreDrawerOpen,
|
||||
setMoreDrawerOpen,
|
||||
})),
|
||||
[
|
||||
routeState,
|
||||
@@ -215,6 +220,8 @@ export const MobileTabBar = memo(function MobileTabBar() {
|
||||
open,
|
||||
close,
|
||||
navigate,
|
||||
isMoreDrawerOpen,
|
||||
setMoreDrawerOpen,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -240,4 +240,14 @@ describe('MoreDrawer', () => {
|
||||
expect(screen.queryByText('wrong-repo')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows Assistant instead of the source repo on canonical /assistant route', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
const handleClose = vi.fn()
|
||||
renderMoreDrawer({ initialEntry: '/assistant', routePath: '/assistant', onClose: handleClose })
|
||||
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
expect(screen.queryByText('wrong-repo')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
})
|
||||
@@ -13,6 +13,7 @@ import { FileBrowserSheet } from '@/components/file-browser/FileBrowserSheet'
|
||||
import { buildMoreItems } from './moreDrawerItems'
|
||||
import { useSwipeBack } from '@/hooks/useMobile'
|
||||
import { getRepoDisplayName } from '@/lib/utils'
|
||||
import { isAssistantPath } from '@/lib/navigation'
|
||||
import type { components } from '@/api/opencode-types'
|
||||
|
||||
type CommandType = components['schemas']['Command']
|
||||
@@ -30,11 +31,12 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
const [commandsOpen, setCommandsOpen] = useState(false)
|
||||
const [mentionFileBrowserOpen, setMentionFileBrowserOpen] = useState(false)
|
||||
const swipeRef = useRef<HTMLDivElement>(null)
|
||||
const { bind } = useSwipeBack(onClose, { enabled: true, suspendsRouteSwipe: true })
|
||||
const skipHistoryBackOnCloseRef = useRef(false)
|
||||
const { bind } = useSwipeBack(onClose, { enabled: isOpen, suspendsRouteSwipe: true })
|
||||
const { logout } = useAuth()
|
||||
const { data: health } = useServerHealth()
|
||||
const isSessionDetail = /^\/repos\/\d+\/sessions\/[^/]+$/.test(location.pathname)
|
||||
const isAssistantRoute = /^\/repos\/\d+\/assistant$/.test(location.pathname)
|
||||
const isAssistantRoute = isAssistantPath(location.pathname)
|
||||
const isAssistantSession = isSessionDetail && new URLSearchParams(location.search).get('assistant') === '1'
|
||||
const { filterCommands } = useCommands(isSessionDetail ? OPENCODE_API_ENDPOINT : null)
|
||||
const activePromptFileBasePath = useUIState((state) => state.activePromptFileBasePath)
|
||||
@@ -48,6 +50,37 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
}
|
||||
}, [isOpen, bind])
|
||||
|
||||
const onCloseRef = useRef(onClose)
|
||||
useEffect(() => {
|
||||
onCloseRef.current = onClose
|
||||
}, [onClose])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return
|
||||
skipHistoryBackOnCloseRef.current = false
|
||||
let sentinelActive = true
|
||||
const baseState = window.history.state
|
||||
const baseUrl = window.location.href
|
||||
window.history.pushState({ ...(baseState ?? {}), moreDrawerSentinel: true }, '', baseUrl)
|
||||
const onPop = () => {
|
||||
if (!sentinelActive) return
|
||||
sentinelActive = false
|
||||
onCloseRef.current()
|
||||
}
|
||||
window.addEventListener('popstate', onPop)
|
||||
return () => {
|
||||
window.removeEventListener('popstate', onPop)
|
||||
// Only go back if sentinel is still active AND we haven't navigated away
|
||||
if (sentinelActive && !skipHistoryBackOnCloseRef.current) {
|
||||
sentinelActive = false
|
||||
const top = window.history.state as { moreDrawerSentinel?: boolean } | null
|
||||
if (top?.moreDrawerSentinel && window.location.href === baseUrl) {
|
||||
window.history.back()
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [isOpen])
|
||||
|
||||
const { data: repo } = useQuery({
|
||||
queryKey: ['repo', repoId],
|
||||
queryFn: () => repoId ? getRepo(repoId) : null,
|
||||
@@ -64,7 +97,9 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
newParams.delete('mobileTab')
|
||||
newParams.set('settings', 'open')
|
||||
newParams.set('tab', 'account')
|
||||
skipHistoryBackOnCloseRef.current = true
|
||||
navigate({ search: newParams.toString() }, { replace: true })
|
||||
onClose()
|
||||
}
|
||||
|
||||
const handleLogoutClick = async () => {
|
||||
@@ -77,13 +112,16 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
|
||||
const handleItemClick = (item: ReturnType<typeof buildMoreItems>[0]) => {
|
||||
if (item.to) {
|
||||
skipHistoryBackOnCloseRef.current = true
|
||||
navigate(item.to)
|
||||
} else if (item.dialog) {
|
||||
const newParams = new URLSearchParams(location.search)
|
||||
newParams.set('dialog', item.dialog)
|
||||
newParams.delete('mobileTab')
|
||||
skipHistoryBackOnCloseRef.current = true
|
||||
navigate({ search: newParams.toString() }, { replace: true })
|
||||
}
|
||||
onClose()
|
||||
}
|
||||
|
||||
const handleCommandClick = (command: CommandType) => {
|
||||
@@ -121,100 +159,102 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
|
||||
return (
|
||||
<SideDrawer isOpen={isOpen} onClose={onClose} side="right" ariaLabel="More" widthClass="w-screen sm:w-[min(90vw,420px)]">
|
||||
<div ref={swipeRef} className="flex flex-col flex-shrink-0 border-b border-border bg-background px-4 py-1.5">
|
||||
<div className="flex items-center justify-between gap-3 mb-2">
|
||||
{versionLabel && (
|
||||
<span className="truncate text-xs leading-tight text-muted-foreground">{versionLabel}</span>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="shrink-0 rounded-sm p-2 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
aria-label="Close"
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
{(repoDisplayName || currentBranch) && (
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
{repoDisplayName && (
|
||||
<span className="font-medium text-orange-600 dark:text-orange-400">{repoDisplayName}</span>
|
||||
<div ref={swipeRef} className="flex flex-col flex-1 min-h-0">
|
||||
<div className="flex flex-col flex-shrink-0 border-b border-border bg-background px-4 py-1.5">
|
||||
<div className="flex items-center justify-between gap-3 mb-2">
|
||||
{versionLabel && (
|
||||
<span className="truncate text-xs leading-tight text-muted-foreground">{versionLabel}</span>
|
||||
)}
|
||||
|
||||
{currentBranch && (
|
||||
<>
|
||||
<GitBranch className="h-3.5 w-3.5" />
|
||||
<span>{currentBranch}</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<SideDrawerContent className="flex flex-col gap-1">
|
||||
{isSessionDetail && (
|
||||
<div className="flex flex-col gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setCommandsOpen((open) => !open)}
|
||||
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
|
||||
aria-expanded={commandsOpen}
|
||||
onClick={onClose}
|
||||
className="shrink-0 rounded-sm p-2 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
aria-label="Close"
|
||||
>
|
||||
<CommandIcon className="w-5 h-5 text-muted-foreground" />
|
||||
<span className="font-medium text-foreground flex-1">Commands</span>
|
||||
{commandsOpen ? (
|
||||
<ChevronDown className="w-4 h-4 text-muted-foreground" />
|
||||
) : (
|
||||
<ChevronRight className="w-4 h-4 text-muted-foreground" />
|
||||
<X className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
{(repoDisplayName || currentBranch) && (
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
{repoDisplayName && (
|
||||
<span className="font-medium text-orange-600 dark:text-orange-400">{repoDisplayName}</span>
|
||||
)}
|
||||
</button>
|
||||
{commandsOpen && (
|
||||
<div className="-mx-4 max-h-64 overflow-y-auto border-y border-border bg-muted/30 p-1 sm:mx-0 sm:rounded-lg sm:border">
|
||||
{commands.map((command) => (
|
||||
<button
|
||||
key={command.name}
|
||||
type="button"
|
||||
onClick={() => handleCommandClick(command)}
|
||||
className="flex w-full min-w-0 items-start gap-3 rounded-md px-3 py-2 text-left transition-colors hover:bg-accent"
|
||||
>
|
||||
<span className="font-mono text-sm font-medium text-blue-600 dark:text-blue-400">{command.name}</span>
|
||||
{command.description && (
|
||||
<span className="min-w-0 flex-1 truncate text-xs text-muted-foreground">{command.description}</span>
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{currentBranch && (
|
||||
<>
|
||||
<GitBranch className="h-3.5 w-3.5" />
|
||||
<span>{currentBranch}</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<SideDrawerContent className="flex flex-col gap-1">
|
||||
{isSessionDetail && (
|
||||
<div className="flex flex-col gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setCommandsOpen((open) => !open)}
|
||||
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
|
||||
aria-expanded={commandsOpen}
|
||||
>
|
||||
<CommandIcon className="w-5 h-5 text-muted-foreground" />
|
||||
<span className="font-medium text-foreground flex-1">Commands</span>
|
||||
{commandsOpen ? (
|
||||
<ChevronDown className="w-4 h-4 text-muted-foreground" />
|
||||
) : (
|
||||
<ChevronRight className="w-4 h-4 text-muted-foreground" />
|
||||
)}
|
||||
</button>
|
||||
{commandsOpen && (
|
||||
<div className="-mx-4 max-h-64 overflow-y-auto border-y border-border bg-muted/30 p-1 sm:mx-0 sm:rounded-lg sm:border">
|
||||
{commands.map((command) => (
|
||||
<button
|
||||
key={command.name}
|
||||
type="button"
|
||||
onClick={() => handleCommandClick(command)}
|
||||
className="flex w-full min-w-0 items-start gap-3 rounded-md px-3 py-2 text-left transition-colors hover:bg-accent"
|
||||
>
|
||||
<span className="font-mono text-sm font-medium text-blue-600 dark:text-blue-400">{command.name}</span>
|
||||
{command.description && (
|
||||
<span className="min-w-0 flex-1 truncate text-xs text-muted-foreground">{command.description}</span>
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMentionFileBrowserOpen(true)}
|
||||
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
|
||||
>
|
||||
<FileText className="w-5 h-5 text-muted-foreground" />
|
||||
<span className="font-medium text-foreground flex-1">Mention File</span>
|
||||
<ChevronRight className="w-4 h-4 text-muted-foreground" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{items.map((item) => (
|
||||
<button
|
||||
key={item.key}
|
||||
type="button"
|
||||
onClick={() => setMentionFileBrowserOpen(true)}
|
||||
onClick={() => {
|
||||
if (item.key === 'settings') {
|
||||
handleSettingsClick()
|
||||
} else if (item.key === 'logout') {
|
||||
handleLogoutClick()
|
||||
} else {
|
||||
handleItemClick(item)
|
||||
}
|
||||
}}
|
||||
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
|
||||
>
|
||||
<FileText className="w-5 h-5 text-muted-foreground" />
|
||||
<span className="font-medium text-foreground flex-1">Mention File</span>
|
||||
<ChevronRight className="w-4 h-4 text-muted-foreground" />
|
||||
<item.icon className="w-5 h-5 text-muted-foreground" />
|
||||
<span className="font-medium text-foreground">{item.label}</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{items.map((item) => (
|
||||
<button
|
||||
key={item.key}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (item.key === 'settings') {
|
||||
handleSettingsClick()
|
||||
} else if (item.key === 'logout') {
|
||||
handleLogoutClick()
|
||||
} else {
|
||||
handleItemClick(item)
|
||||
}
|
||||
}}
|
||||
className="flex items-center gap-3 p-3 rounded-lg hover:bg-accent transition-colors text-left w-full"
|
||||
>
|
||||
<item.icon className="w-5 h-5 text-muted-foreground" />
|
||||
<span className="font-medium text-foreground">{item.label}</span>
|
||||
</button>
|
||||
))}
|
||||
</SideDrawerContent>
|
||||
))}
|
||||
</SideDrawerContent>
|
||||
</div>
|
||||
<FileBrowserSheet
|
||||
isOpen={mentionFileBrowserOpen}
|
||||
onClose={() => setMentionFileBrowserOpen(false)}
|
||||
|
||||
@@ -134,7 +134,7 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
expect(handleClose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('navigates directly to assistant when mobileTabAction is assistant', async () => {
|
||||
it('navigates to assistant when mobileTabAction is assistant', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
@@ -172,11 +172,53 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
|
||||
fireEvent.click(screen.getByText('repo1'))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1/assistant')
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/assistant')
|
||||
expect(handleClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('navigates from assistant to repo detail when clicking active repo', async () => {
|
||||
it('navigates from assistant to repo detail when clicking repo on canonical assistant route', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
repoUrl: 'https://github.com/test/repo1.git',
|
||||
localPath: '/path/to/repo1',
|
||||
sourcePath: null,
|
||||
currentBranch: 'main',
|
||||
isLocal: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
])
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<MemoryRouter initialEntries={['/assistant?mobileTab=repos']}>
|
||||
<Routes>
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<>
|
||||
<RepoQuickSwitchSheet isOpen onClose={handleClose} />
|
||||
<LocationSpy />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
fireEvent.click(screen.getByText('repo1'))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/repos/1')
|
||||
expect(handleClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('navigates from legacy assistant route to repo detail when clicking repo', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
@@ -218,6 +260,106 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
expect(handleClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not mark any repo active on /assistant', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
repoUrl: 'https://github.com/test/repo1.git',
|
||||
localPath: '/path/to/repo1',
|
||||
sourcePath: null,
|
||||
currentBranch: 'main',
|
||||
isLocal: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
repoUrl: 'https://github.com/test/repo2.git',
|
||||
localPath: '/path/to/repo2',
|
||||
sourcePath: null,
|
||||
currentBranch: 'main',
|
||||
isLocal: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
])
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<MemoryRouter initialEntries={['/assistant?mobileTab=repos']}>
|
||||
<Routes>
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<>
|
||||
<RepoQuickSwitchSheet isOpen onClose={handleClose} />
|
||||
<LocationSpy />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
expect(screen.getByText('repo2')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('button', { current: 'page' })).toBeNull()
|
||||
})
|
||||
|
||||
it('does not mark any repo active on legacy /repos/1/assistant', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
{
|
||||
id: 1,
|
||||
repoUrl: 'https://github.com/test/repo1.git',
|
||||
localPath: '/path/to/repo1',
|
||||
sourcePath: null,
|
||||
currentBranch: 'main',
|
||||
isLocal: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
repoUrl: 'https://github.com/test/repo2.git',
|
||||
localPath: '/path/to/repo2',
|
||||
sourcePath: null,
|
||||
currentBranch: 'main',
|
||||
isLocal: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
},
|
||||
])
|
||||
const handleClose = vi.fn()
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<MemoryRouter initialEntries={['/repos/1/assistant?mobileTab=repos']}>
|
||||
<Routes>
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<>
|
||||
<RepoQuickSwitchSheet isOpen onClose={handleClose} />
|
||||
<LocationSpy />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
expect(screen.getByText('repo2')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('button', { current: 'page' })).toBeNull()
|
||||
})
|
||||
|
||||
it('switches repos from the mobile repos sheet without navigating back to the previous repo', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ import { cn, getRepoDisplayName } from '@/lib/utils'
|
||||
import { listRepos } from '@/api/repos'
|
||||
import { AddRepoDialog } from '@/components/repo/AddRepoDialog'
|
||||
import { FolderGit2, Check, Plus } from 'lucide-react'
|
||||
import { isAssistantPath, getAssistantPath } from '@/lib/navigation'
|
||||
|
||||
interface RepoQuickSwitchSheetProps {
|
||||
isOpen: boolean
|
||||
@@ -20,10 +21,13 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [addRepoOpen, setAddRepoOpen] = useState(false)
|
||||
|
||||
const isAssistantRoute = useMemo(() => isAssistantPath(location.pathname), [location.pathname])
|
||||
|
||||
const activeRepoId = useMemo(() => {
|
||||
if (isAssistantRoute) return null
|
||||
const match = location.pathname.match(/^\/repos\/(\d+)/)
|
||||
return match ? Number(match[1]) : null
|
||||
}, [location.pathname])
|
||||
}, [location.pathname, isAssistantRoute])
|
||||
|
||||
const { data: repos, isLoading } = useQuery({
|
||||
queryKey: ['repos'],
|
||||
@@ -52,18 +56,18 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
|
||||
const handleClick = (id: number) => {
|
||||
const pendingAction = new URLSearchParams(location.search).get('mobileTabAction')
|
||||
if (pendingAction === 'assistant') {
|
||||
navigateAndClose(`/repos/${id}/assistant`)
|
||||
|
||||
if (isAssistantRoute) {
|
||||
navigateAndClose(`/repos/${id}`, { replace: true })
|
||||
return
|
||||
}
|
||||
|
||||
const isAssistantRoute = location.pathname === `/repos/${id}/assistant`
|
||||
if (id === activeRepoId) {
|
||||
if (isAssistantRoute) {
|
||||
navigateAndClose(`/repos/${id}`, { replace: true })
|
||||
return
|
||||
}
|
||||
if (pendingAction === 'assistant') {
|
||||
navigateAndClose(getAssistantPath())
|
||||
return
|
||||
}
|
||||
|
||||
if (id === activeRepoId) {
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { MoreVertical } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
|
||||
export function SessionMoreButton() {
|
||||
const { open } = useMobileTabBar()
|
||||
const setMoreDrawerOpen = useUIState((state) => state.setMoreDrawerOpen)
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => open('more')}
|
||||
onClick={() => setMoreDrawerOpen(true)}
|
||||
className="md:hidden h-10 w-10 p-0 text-foreground border-border hover:bg-accent"
|
||||
aria-label="More"
|
||||
>
|
||||
|
||||
@@ -97,7 +97,7 @@ describe('buildNavModel', () => {
|
||||
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')
|
||||
expect(model.primary[1].to).toBe('/assistant')
|
||||
})
|
||||
|
||||
it('returns new-session and assistant primary CTAs for session detail', () => {
|
||||
@@ -107,7 +107,7 @@ describe('buildNavModel', () => {
|
||||
expect(model.primary[0].onSelect).toBe('new-session')
|
||||
expect(model.primary[0].variant).toBe('primary')
|
||||
expect(model.primary[1].key).toBe('assistant')
|
||||
expect(model.primary[1].to).toBe('/repos/5/assistant')
|
||||
expect(model.primary[1].to).toBe('/assistant')
|
||||
expect(model.primary[1].variant).toBe('secondary')
|
||||
})
|
||||
|
||||
@@ -118,7 +118,18 @@ describe('buildNavModel', () => {
|
||||
expect(model.primary[0].onSelect).toBe('new-session')
|
||||
expect(model.primary[0].variant).toBe('primary')
|
||||
expect(model.primary[1].key).toBe('assistant')
|
||||
expect(model.primary[1].to).toBe('/repos/5/assistant')
|
||||
expect(model.primary[1].to).toBe('/assistant')
|
||||
expect(model.primary[1].variant).toBe('secondary')
|
||||
})
|
||||
|
||||
it('returns new-session and assistant primary CTAs for canonical /assistant', () => {
|
||||
const model = buildNavModel('/assistant')
|
||||
expect(model.primary).toHaveLength(2)
|
||||
expect(model.primary[0].key).toBe('new-session')
|
||||
expect(model.primary[0].onSelect).toBe('new-session')
|
||||
expect(model.primary[0].variant).toBe('primary')
|
||||
expect(model.primary[1].key).toBe('assistant')
|
||||
expect(model.primary[1].to).toBe('/assistant')
|
||||
expect(model.primary[1].variant).toBe('secondary')
|
||||
})
|
||||
|
||||
@@ -135,7 +146,7 @@ describe('buildNavModel', () => {
|
||||
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')
|
||||
expect(model2.primary[1].to).toBe('/assistant')
|
||||
})
|
||||
|
||||
it('returns assistant primary for unknown routes', () => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Code2, Settings, LogOut, Plus, Bot, Folder, Clock, SquarePlus } from 'lucide-react'
|
||||
import { getAssistantPath, isAssistantPath } from '@/lib/navigation'
|
||||
|
||||
export interface MoreDrawerItem {
|
||||
key: string
|
||||
@@ -24,14 +25,12 @@ export interface NavModel {
|
||||
items: MoreDrawerItem[]
|
||||
}
|
||||
|
||||
function getAssistantNavItem(pathname: string, variant: NavPrimaryCta['variant'] = 'secondary'): NavPrimaryCta {
|
||||
const repoMatch = /^\/repos\/(\d+)/.exec(pathname)
|
||||
|
||||
function getAssistantNavItem(_pathname: string, variant: NavPrimaryCta['variant'] = 'secondary'): NavPrimaryCta {
|
||||
return {
|
||||
key: 'assistant',
|
||||
label: 'Assistant',
|
||||
icon: Bot,
|
||||
to: repoMatch ? `/repos/${repoMatch[1]}/assistant` : '/assistant',
|
||||
to: getAssistantPath(),
|
||||
variant,
|
||||
}
|
||||
}
|
||||
@@ -89,15 +88,13 @@ export function buildNavModel(pathname: string): NavModel {
|
||||
}
|
||||
}
|
||||
|
||||
const assistantMatch = /^\/repos\/(\d+)\/assistant$/.exec(pathname)
|
||||
if (assistantMatch) {
|
||||
const id = assistantMatch[1]
|
||||
if (isAssistantPath(pathname)) {
|
||||
const items: MoreDrawerItem[] = [
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
{ 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: 'schedules', label: 'Schedules', icon: CalendarClock, to: '/repos/0/schedules' },
|
||||
{ key: 'source-control', label: 'Source Control', icon: GitCommitHorizontal, dialog: 'sourceControl' },
|
||||
...baseItems,
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user