mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
refactor(frontend): drop sidebar action bus and primary CTAs
This commit is contained in:
1 parent
5a8a81419c
commit
4cf69e9023
19 files changed
+51
-323
No files matched your search
@@ -149,7 +149,11 @@ describe('DesktopSidebar', () => {
|
||||
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders primary CTA for schedules routes', () => {
|
||||
it.each([
|
||||
['/schedules', 'New Schedule'],
|
||||
['/repos/5/schedules', 'New Schedule'],
|
||||
['/assistant', 'New Session'],
|
||||
])('does not duplicate the page header create action on %s', (path, headerAction) => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
vi.spyOn(useAuthModule, 'useAuth').mockReturnValue({
|
||||
@@ -158,34 +162,12 @@ describe('DesktopSidebar', () => {
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(<DesktopSidebar />, { wrapper: createWrapper(['/schedules']) })
|
||||
render(<DesktopSidebar />, { wrapper: createWrapper([path]) })
|
||||
|
||||
expect(screen.getByText('New Schedule')).toBeInTheDocument()
|
||||
expect(screen.queryByText(headerAction)).toBeNull()
|
||||
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(useAuthModule, 'useAuth').mockReturnValue({
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
logout: vi.fn(),
|
||||
} as any)
|
||||
|
||||
render(<DesktopSidebar />, { wrapper: createWrapper(['/schedules']) })
|
||||
|
||||
fireEvent.click(screen.getByText('New Schedule'))
|
||||
|
||||
expect(dispatchEventSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: 'oc:sidebar:action',
|
||||
detail: { action: 'new-schedule' },
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('opens dialog items by updating the dialog query param (push) and closes on back', () => {
|
||||
vi.spyOn(useDesktopModule, 'useDesktop').mockReturnValue(true)
|
||||
vi.spyOn(useSidebarCollapsedModule, 'useSidebarCollapsed').mockReturnValue([false, vi.fn()])
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useState } from 'react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { useDesktop } from '@/hooks/useDesktop'
|
||||
import { useSidebarCollapsed, useSidebarSections } from '@/hooks/useSidebarCollapsed'
|
||||
import { emitSidebarAction } from '@/hooks/useSidebarAction'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { buildNavModel, type MoreDrawerItem, type NavPrimaryCta } from '@/components/navigation/moreDrawerItems'
|
||||
@@ -39,15 +38,6 @@ export function DesktopSidebar() {
|
||||
}
|
||||
|
||||
const { primary, items } = buildNavModel(location.pathname)
|
||||
const desktopPrimary = primary.filter((item) => item.key !== 'new-repo')
|
||||
|
||||
const handlePrimaryClick = (item: NavPrimaryCta) => {
|
||||
if (item.to) {
|
||||
navigate(item.to)
|
||||
} else if (item.onSelect) {
|
||||
emitSidebarAction(item.onSelect)
|
||||
}
|
||||
}
|
||||
|
||||
const handleItemClick = (item: MoreDrawerItem) => {
|
||||
if (item.to) {
|
||||
@@ -85,15 +75,15 @@ export function DesktopSidebar() {
|
||||
return (
|
||||
<>
|
||||
<Sidebar collapsed={collapsed} onToggle={toggle} widthClass='w-72' className='mt-2'>
|
||||
{desktopPrimary.length > 0 && (
|
||||
{primary.length > 0 && (
|
||||
<SidebarSection collapsed={collapsed}>
|
||||
{desktopPrimary.map((item: NavPrimaryCta) => (
|
||||
{primary.map((item: NavPrimaryCta) => (
|
||||
<SidebarItem
|
||||
key={item.key}
|
||||
icon={item.icon}
|
||||
label={item.label}
|
||||
collapsed={collapsed}
|
||||
onClick={() => handlePrimaryClick(item)}
|
||||
onClick={() => navigate(item.to)}
|
||||
asPrimary
|
||||
variant={item.variant}
|
||||
/>
|
||||
|
||||
@@ -109,75 +109,23 @@ describe('buildMoreItems', () => {
|
||||
})
|
||||
|
||||
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 only the assistant primary CTA for repo detail', () => {
|
||||
const model = buildNavModel('/repos/5')
|
||||
expect(model.primary).toHaveLength(1)
|
||||
expect(model.primary[0].key).toBe('assistant')
|
||||
expect(model.primary[0].to).toBe('/assistant')
|
||||
})
|
||||
|
||||
it('returns only the assistant primary CTA for session detail', () => {
|
||||
const model = buildNavModel('/repos/5/sessions/abc')
|
||||
it.each([
|
||||
'/',
|
||||
'/repos/5',
|
||||
'/repos/5/sessions/abc',
|
||||
'/repos/5/assistant',
|
||||
'/assistant',
|
||||
'/schedules',
|
||||
'/repos/5/schedules',
|
||||
'/unknown/path',
|
||||
])('returns only the assistant primary CTA for %s', (path) => {
|
||||
const model = buildNavModel(path)
|
||||
expect(model.primary).toHaveLength(1)
|
||||
expect(model.primary[0].key).toBe('assistant')
|
||||
expect(model.primary[0].to).toBe('/assistant')
|
||||
expect(model.primary[0].variant).toBe('secondary')
|
||||
})
|
||||
|
||||
it('returns new-session and assistant primary CTAs for assistant workspace', () => {
|
||||
const model = buildNavModel('/repos/5/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')
|
||||
})
|
||||
|
||||
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')
|
||||
})
|
||||
|
||||
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('/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')
|
||||
const items = buildMoreItems('/repos/42')
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { LucideIcon } from 'lucide-react'
|
||||
import { Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Settings, LogOut, Plus, Bot, Folder, Clock, SquarePlus, Home } from 'lucide-react'
|
||||
import { Plug, Sparkles, ShieldOff, CalendarClock, GitCommitHorizontal, Settings, LogOut, Bot, Folder, Home } from 'lucide-react'
|
||||
import { getAssistantPath, isAssistantPath } from '@/lib/navigation'
|
||||
import type { SidebarActionKey } from '@/hooks/useSidebarAction'
|
||||
|
||||
export interface MoreDrawerItem {
|
||||
key: string
|
||||
@@ -16,8 +15,7 @@ export interface NavPrimaryCta {
|
||||
key: string
|
||||
label: string
|
||||
icon: LucideIcon
|
||||
to?: string
|
||||
onSelect?: SidebarActionKey
|
||||
to: string
|
||||
variant?: 'primary' | 'secondary'
|
||||
}
|
||||
|
||||
@@ -26,13 +24,13 @@ export interface NavModel {
|
||||
items: MoreDrawerItem[]
|
||||
}
|
||||
|
||||
function getAssistantNavItem(_pathname: string, variant: NavPrimaryCta['variant'] = 'secondary'): NavPrimaryCta {
|
||||
function getAssistantNavItem(): NavPrimaryCta {
|
||||
return {
|
||||
key: 'assistant',
|
||||
label: 'Assistant',
|
||||
icon: Bot,
|
||||
to: getAssistantPath(),
|
||||
variant,
|
||||
variant: 'secondary',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +62,7 @@ function buildRouteNavModel(pathname: string): NavModel {
|
||||
]
|
||||
|
||||
return {
|
||||
primary: [getAssistantNavItem(pathname)],
|
||||
primary: [getAssistantNavItem()],
|
||||
items,
|
||||
}
|
||||
}
|
||||
@@ -82,7 +80,7 @@ function buildRouteNavModel(pathname: string): NavModel {
|
||||
]
|
||||
|
||||
return {
|
||||
primary: [getAssistantNavItem(pathname)],
|
||||
primary: [getAssistantNavItem()],
|
||||
items,
|
||||
}
|
||||
}
|
||||
@@ -99,30 +97,14 @@ function buildRouteNavModel(pathname: string): NavModel {
|
||||
]
|
||||
|
||||
return {
|
||||
primary: [
|
||||
{ key: 'new-session', label: 'New Session', icon: SquarePlus, onSelect: 'new-session', variant: 'primary' },
|
||||
getAssistantNavItem(pathname, 'secondary'),
|
||||
],
|
||||
primary: [getAssistantNavItem()],
|
||||
items,
|
||||
}
|
||||
}
|
||||
|
||||
if (pathname === '/schedules' || /^\/repos\/\d+\/schedules$/.test(pathname)) {
|
||||
return {
|
||||
primary: [
|
||||
{ key: 'new-schedule', label: 'New Schedule', icon: Clock, onSelect: 'new-schedule', variant: 'primary' },
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
items: baseItems,
|
||||
}
|
||||
}
|
||||
|
||||
if (pathname === '/') {
|
||||
return {
|
||||
primary: [
|
||||
{ key: 'new-repo', label: 'New Repo', icon: Plus, onSelect: 'new-repo', variant: 'primary' },
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
primary: [getAssistantNavItem()],
|
||||
items: [
|
||||
{ key: 'all-schedules', label: 'All Schedules', icon: CalendarClock, to: '/schedules' },
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
@@ -132,9 +114,7 @@ function buildRouteNavModel(pathname: string): NavModel {
|
||||
}
|
||||
|
||||
return {
|
||||
primary: [
|
||||
getAssistantNavItem(pathname),
|
||||
],
|
||||
primary: [getAssistantNavItem()],
|
||||
items: baseItems,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,9 +136,9 @@ export function ScheduleReportsBell() {
|
||||
size="icon"
|
||||
aria-label={`Reports, ${total} unread`}
|
||||
onClick={isMobile ? () => setOpen(true) : undefined}
|
||||
className="relative h-8 w-8 text-muted-foreground transition-all duration-200 hover:bg-accent hover:text-foreground"
|
||||
className="relative h-10 w-10 text-muted-foreground transition-all duration-200 hover:bg-accent hover:text-foreground sm:h-8 sm:w-8"
|
||||
>
|
||||
<Inbox className="h-4 w-4" />
|
||||
<Inbox className="h-5 w-5 sm:h-4 sm:w-4" />
|
||||
<ScheduleReportsCount total={total} failed={failed} />
|
||||
</Button>
|
||||
)
|
||||
|
||||
@@ -75,8 +75,8 @@ export function RunHistoryTab({
|
||||
<span className="hidden sm:inline">Clear history</span>
|
||||
</Button>
|
||||
</ScheduleListToolbar>
|
||||
<div className="min-h-0 flex-1 overflow-y-auto pt-2 pb-2">
|
||||
<div className="overflow-x-auto rounded-lg border border-border/70">
|
||||
<div className="flex min-h-0 flex-1 flex-col overflow-y-auto pt-2 pb-2">
|
||||
<div className="min-h-0 overflow-auto rounded-lg border border-border/70">
|
||||
<ScheduleRunsTable
|
||||
runs={runList}
|
||||
runsLoading={runsLoading}
|
||||
|
||||
@@ -45,7 +45,7 @@ function HeaderTitle({ children, logo, className }: HeaderTitleProps) {
|
||||
<img
|
||||
src={theme === 'light' ? "/opencode-wordmark-light.svg" : "/opencode-wordmark-dark.svg"}
|
||||
alt="OpenCode"
|
||||
className="h-6 w-auto sm:h-8"
|
||||
className="ml-2 h-6 w-auto sm:ml-0 sm:h-8"
|
||||
/>
|
||||
) : (
|
||||
<h1 className="text-xl font-semibold bg-gradient-to-r from-foreground to-muted-foreground bg-clip-text text-transparent truncate">
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import { useSidebarAction, emitSidebarAction, SIDEBAR_ACTIONS } 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()
|
||||
})
|
||||
})
|
||||
|
||||
describe('emitSidebarAction', () => {
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('reaches a registered handler without warning', () => {
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
const handler = vi.fn()
|
||||
|
||||
renderHook(() => useSidebarAction('new-schedule', handler))
|
||||
emitSidebarAction('new-schedule')
|
||||
|
||||
expect(handler).toHaveBeenCalledTimes(1)
|
||||
expect(warn).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('warns when an action is dispatched with no mounted handler', () => {
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
|
||||
emitSidebarAction('new-schedule')
|
||||
|
||||
expect(warn).toHaveBeenCalledWith(expect.stringContaining('new-schedule'))
|
||||
})
|
||||
|
||||
it('warns again once the last handler unmounts', () => {
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
const { unmount } = renderHook(() => useSidebarAction('new-repo', vi.fn()))
|
||||
|
||||
emitSidebarAction('new-repo')
|
||||
expect(warn).not.toHaveBeenCalled()
|
||||
|
||||
unmount()
|
||||
emitSidebarAction('new-repo')
|
||||
|
||||
expect(warn).toHaveBeenCalledWith(expect.stringContaining('new-repo'))
|
||||
})
|
||||
|
||||
it('exposes every action the nav model can emit', () => {
|
||||
expect([...SIDEBAR_ACTIONS]).toEqual(['new-session', 'new-repo', 'new-schedule'])
|
||||
})
|
||||
})
|
||||
@@ -1,33 +0,0 @@
|
||||
import { useEffect } from 'react'
|
||||
|
||||
export const SIDEBAR_ACTIONS = ['new-session', 'new-repo', 'new-schedule'] as const
|
||||
|
||||
export type SidebarActionKey = (typeof SIDEBAR_ACTIONS)[number]
|
||||
|
||||
const SIDEBAR_ACTION_EVENT = 'oc:sidebar:action'
|
||||
|
||||
const handlerCounts = new Map<SidebarActionKey, number>()
|
||||
|
||||
export function emitSidebarAction(action: SidebarActionKey) {
|
||||
if (!handlerCounts.get(action)) {
|
||||
console.warn(`Sidebar action "${action}" was dispatched but no mounted page handles it`)
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent(SIDEBAR_ACTION_EVENT, { detail: { action } }))
|
||||
}
|
||||
|
||||
export function useSidebarAction(action: SidebarActionKey, handler: () => void) {
|
||||
useEffect(() => {
|
||||
handlerCounts.set(action, (handlerCounts.get(action) ?? 0) + 1)
|
||||
const listener = (event: Event) => {
|
||||
const detail = (event as CustomEvent<{ action?: SidebarActionKey }>).detail
|
||||
if (detail?.action === action) {
|
||||
handler()
|
||||
}
|
||||
}
|
||||
window.addEventListener(SIDEBAR_ACTION_EVENT, listener)
|
||||
return () => {
|
||||
window.removeEventListener(SIDEBAR_ACTION_EVENT, listener)
|
||||
handlerCounts.set(action, Math.max(0, (handlerCounts.get(action) ?? 1) - 1))
|
||||
}
|
||||
}, [action, handler])
|
||||
}
|
||||
@@ -3,7 +3,6 @@ import { useQuery } from "@tanstack/react-query"
|
||||
import { getRepo } from "@/api/repos"
|
||||
import { useCreateSession } from "@/hooks/useOpenCode"
|
||||
import { useDialogParam } from "@/hooks/useDialogParam"
|
||||
import { useSidebarAction } from "@/hooks/useSidebarAction"
|
||||
import { useSSE } from "@/hooks/useSSE"
|
||||
import { getSessionPath } from "@/lib/navigation"
|
||||
import { Button } from "@/components/ui/button"
|
||||
@@ -43,10 +42,6 @@ export function AssistantRedirect() {
|
||||
await createSessionMutation.mutateAsync({ agent: undefined })
|
||||
}
|
||||
|
||||
useSidebarAction('new-session', () => {
|
||||
handleCreateSession()
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="h-dvh max-h-dvh overflow-hidden bg-gradient-to-br from-background via-background to-background flex flex-col pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-0">
|
||||
<Header>
|
||||
|
||||
@@ -16,7 +16,6 @@ import { CalendarClock, Loader2, Plus, ArrowLeft, SlidersHorizontal } from 'luci
|
||||
|
||||
import { useScheduleUrlState } from '@/hooks/useScheduleUrlState'
|
||||
import type { ScheduleTab } from '@/hooks/useScheduleUrlState'
|
||||
import { useSidebarAction } from '@/hooks/useSidebarAction'
|
||||
import { useDebouncedValue } from '@/hooks/useDebouncedValue'
|
||||
|
||||
import type { ScheduleJobWithRepo, ScheduleRunWithContext } from '@/api/schedules'
|
||||
@@ -50,11 +49,6 @@ export function GlobalSchedules() {
|
||||
const cancelRunMutation = useCancelRepoScheduleRun()
|
||||
const cancelRunPending = cancelRunMutation.isPending
|
||||
|
||||
useSidebarAction('new-schedule', () => {
|
||||
openNewJob()
|
||||
setSelectedRepoId(undefined)
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
runOffsetRef.current = runOffset
|
||||
}, [runOffset])
|
||||
@@ -547,7 +541,7 @@ export function GlobalSchedules() {
|
||||
</ScheduleListToolbar>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-h-0 overflow-y-auto px-2 sm:px-4 pt-2 pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-4">
|
||||
<div className="flex-1 min-h-0 flex flex-col overflow-y-auto px-2 sm:px-4 pt-2 pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-4">
|
||||
{!hasJobs ? (
|
||||
<div className="flex min-h-full items-center justify-center">
|
||||
<Card className="max-w-md border-dashed border-border/70">
|
||||
@@ -596,7 +590,7 @@ export function GlobalSchedules() {
|
||||
</Card>
|
||||
</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto rounded-lg border border-border/70">
|
||||
<div className="min-h-0 overflow-auto rounded-lg border border-border/70">
|
||||
<ScheduleJobsTable
|
||||
jobs={filteredAndSortedJobs}
|
||||
showRepo
|
||||
@@ -721,8 +715,8 @@ export function GlobalSchedules() {
|
||||
</ScheduleListToolbar>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-h-0 overflow-y-auto px-2 sm:px-4 pt-2 pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-4">
|
||||
<div className="overflow-x-auto rounded-lg border border-border/70">
|
||||
<div className="flex-1 min-h-0 flex flex-col overflow-y-auto px-2 sm:px-4 pt-2 pb-[calc(env(safe-area-inset-bottom)+56px)] sm:pb-4">
|
||||
<div className="min-h-0 overflow-auto rounded-lg border border-border/70">
|
||||
<ScheduleRunsTable
|
||||
runs={sortedRuns}
|
||||
runsLoading={runsLoading && allRuns.length === 0}
|
||||
|
||||
@@ -206,6 +206,16 @@ export function RepoDetail() {
|
||||
onClick={() => handleCreateSession()}
|
||||
disabled={createSessionMutation.isPending}
|
||||
size="sm"
|
||||
className="hidden sm:inline-flex bg-primary hover:bg-primary-hover text-primary-foreground transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
<span>New Session</span>
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => handleCreateSession()}
|
||||
disabled={createSessionMutation.isPending}
|
||||
aria-label="New Session"
|
||||
size="sm"
|
||||
className="sm:hidden h-10 w-10 p-0 bg-primary hover:bg-primary-hover text-primary-foreground transition-all duration-200 hover:scale-105"
|
||||
>
|
||||
<Plus className="w-5 h-5" />
|
||||
|
||||
@@ -7,7 +7,6 @@ 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() {
|
||||
@@ -19,10 +18,6 @@ export function Repos() {
|
||||
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>
|
||||
|
||||
@@ -16,7 +16,6 @@ import {
|
||||
import { useRepoActivity } from '@/hooks/useRepoActivity'
|
||||
import { useScheduleTarget } from '@/hooks/useScheduleTarget'
|
||||
import { useScheduleUrlState } from '@/hooks/useScheduleUrlState'
|
||||
import { useSidebarAction } from '@/hooks/useSidebarAction'
|
||||
import { ScheduleJobDialog, ScheduleJobsTable, ScheduleListToolbar, JobDetailTab, RunHistoryTab, ScheduleTabMenu } from '@/components/schedules'
|
||||
import { matchesScheduleJobSearch, toUpdateScheduleRequest } from '@/components/schedules/schedule-utils'
|
||||
import type { ScheduleJobWithRepo } from '@/api/schedules'
|
||||
@@ -74,10 +73,6 @@ export function Schedules() {
|
||||
const [clearRunsOpen, setClearRunsOpen] = useState(false)
|
||||
const [runToDelete, setRunToDelete] = useState<number | null>(null)
|
||||
|
||||
useSidebarAction('new-schedule', () => {
|
||||
openNewJob()
|
||||
})
|
||||
|
||||
const clearableRuns = useMemo(() => (runs ?? []).filter((run) => run.status !== 'running'), [runs])
|
||||
const clearableWorktrees = useMemo(() => clearableRuns.filter((run) => run.worktreePath).length, [clearableRuns])
|
||||
const clearableBranches = useMemo(() => clearableRuns.filter((run) => run.runBranch).length, [clearableRuns])
|
||||
@@ -298,8 +293,8 @@ export function Schedules() {
|
||||
{repoScheduleTab === 'jobs' && (
|
||||
<div className="flex min-h-0 flex-1 flex-col overflow-hidden">
|
||||
<ScheduleListToolbar search={jobSearch} onSearchChange={setJobSearch} searchPlaceholder="Search jobs" />
|
||||
<div className="min-h-0 flex-1 overflow-y-auto pt-2 pb-2">
|
||||
<div className="overflow-x-auto rounded-lg border border-border/70">
|
||||
<div className="flex min-h-0 flex-1 flex-col overflow-y-auto pt-2 pb-2">
|
||||
<div className="min-h-0 overflow-auto rounded-lg border border-border/70">
|
||||
<ScheduleJobsTable
|
||||
jobs={(jobs ?? []).filter((job) => matchesScheduleJobSearch(job, jobSearch))}
|
||||
showRepo={false}
|
||||
|
||||
@@ -20,7 +20,6 @@ const mocks = vi.hoisted(() => ({
|
||||
useKeyboardShortcuts: vi.fn(),
|
||||
useAutoScroll: vi.fn(),
|
||||
useDialogParam: vi.fn(),
|
||||
useSidebarAction: vi.fn(),
|
||||
RepoSkillsDialog: vi.fn(() => null),
|
||||
}))
|
||||
|
||||
@@ -76,10 +75,6 @@ vi.mock('@/hooks/useDialogParam', () => ({
|
||||
useDialogParam: vi.fn(() => [false, vi.fn()]),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSidebarAction', () => ({
|
||||
useSidebarAction: vi.fn(() => {}),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
|
||||
getAssistantText: vi.fn(() => ''),
|
||||
getLatestPlayableAssistantMessage: vi.fn(() => null),
|
||||
@@ -202,7 +197,6 @@ describe('SessionDetail assistant loading at repoId=0', () => {
|
||||
mocks.useKeyboardShortcuts.mockReturnValue({ leaderActive: false })
|
||||
mocks.useAutoScroll.mockReturnValue({ scrollToBottom: vi.fn() })
|
||||
mocks.useDialogParam.mockReturnValue([false, vi.fn()])
|
||||
mocks.useSidebarAction.mockReturnValue(undefined)
|
||||
})
|
||||
|
||||
const createQueryClient = () =>
|
||||
|
||||
@@ -17,7 +17,6 @@ const mocks = vi.hoisted(() => ({
|
||||
useMobile: vi.fn(),
|
||||
useAutoScroll: vi.fn(),
|
||||
useDialogParam: vi.fn(),
|
||||
useSidebarAction: vi.fn(),
|
||||
useSessionStatusForSession: vi.fn(),
|
||||
listSessionMessages: vi.fn(),
|
||||
downloadMarkdown: vi.fn(),
|
||||
@@ -119,10 +118,6 @@ vi.mock('@/hooks/useDialogParam', () => ({
|
||||
useDialogParam: vi.fn(() => [false, vi.fn()]),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSidebarAction', () => ({
|
||||
useSidebarAction: vi.fn(() => {}),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
|
||||
getAssistantText: vi.fn(() => ''),
|
||||
getLatestPlayableAssistantMessage: vi.fn(() => null),
|
||||
@@ -236,7 +231,6 @@ describe('SessionDetail export history', () => {
|
||||
mocks.useMobile.mockReturnValue(false)
|
||||
mocks.useAutoScroll.mockReturnValue({ scrollToBottom: vi.fn() })
|
||||
mocks.useDialogParam.mockReturnValue([false, vi.fn()])
|
||||
mocks.useSidebarAction.mockReturnValue(undefined)
|
||||
mocks.useSessionStatusForSession.mockReturnValue({ type: 'idle' })
|
||||
mocks.downloadMarkdown.mockResolvedValue(true)
|
||||
})
|
||||
|
||||
@@ -18,7 +18,6 @@ const mocks = vi.hoisted(() => ({
|
||||
useMobile: vi.fn(),
|
||||
useAutoScroll: vi.fn(),
|
||||
useDialogParam: vi.fn(),
|
||||
useSidebarAction: vi.fn(),
|
||||
useSessionStatusForSession: vi.fn(),
|
||||
showToast: { error: vi.fn(), success: vi.fn(), info: vi.fn(), loading: vi.fn() },
|
||||
}))
|
||||
@@ -99,10 +98,6 @@ vi.mock('@/hooks/useDialogParam', () => ({
|
||||
useDialogParam: vi.fn(() => [false, vi.fn()]),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSidebarAction', () => ({
|
||||
useSidebarAction: vi.fn(() => {}),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
|
||||
getAssistantText: vi.fn(() => ''),
|
||||
getLatestPlayableAssistantMessage: vi.fn(() => null),
|
||||
@@ -252,7 +247,6 @@ describe('SessionDetail form prompt session scoping', () => {
|
||||
mocks.useMobile.mockReturnValue(false)
|
||||
mocks.useAutoScroll.mockReturnValue({ scrollToBottom: vi.fn() })
|
||||
mocks.useDialogParam.mockReturnValue([false, vi.fn()])
|
||||
mocks.useSidebarAction.mockReturnValue(undefined)
|
||||
mocks.useSessionStatusForSession.mockReturnValue({ type: 'idle' })
|
||||
})
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ const mocks = vi.hoisted(() => ({
|
||||
useKeyboardShortcuts: vi.fn(),
|
||||
useAutoScroll: vi.fn(),
|
||||
useDialogParam: vi.fn(),
|
||||
useSidebarAction: vi.fn(),
|
||||
useSessionStatusForSession: vi.fn(),
|
||||
syncPermissionsForSession: vi.fn(),
|
||||
syncFormsForSession: vi.fn(),
|
||||
@@ -78,10 +77,6 @@ vi.mock('@/hooks/useDialogParam', () => ({
|
||||
useDialogParam: vi.fn(() => [false, vi.fn()]),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSidebarAction', () => ({
|
||||
useSidebarAction: vi.fn(() => {}),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
|
||||
getAssistantText: vi.fn(() => ''),
|
||||
getLatestPlayableAssistantMessage: vi.fn(() => null),
|
||||
@@ -180,7 +175,6 @@ describe('SessionDetail pending-actions polling gating', () => {
|
||||
mocks.useKeyboardShortcuts.mockReturnValue({ leaderActive: false })
|
||||
mocks.useAutoScroll.mockReturnValue({ scrollToBottom: vi.fn() })
|
||||
mocks.useDialogParam.mockReturnValue([false, vi.fn()])
|
||||
mocks.useSidebarAction.mockReturnValue(undefined)
|
||||
mocks.useSessionStatusForSession.mockReturnValue({ type: 'idle' })
|
||||
})
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ const mocks = vi.hoisted(() => ({
|
||||
useKeyboardShortcuts: vi.fn(),
|
||||
useAutoScroll: vi.fn(),
|
||||
useDialogParam: vi.fn(),
|
||||
useSidebarAction: vi.fn(),
|
||||
useSessionStatusForSession: vi.fn(),
|
||||
PromptInput: vi.fn(),
|
||||
uiState: { isEditingMessage: false },
|
||||
@@ -93,10 +92,6 @@ vi.mock('@/hooks/useDialogParam', () => ({
|
||||
useDialogParam: vi.fn(() => [false, vi.fn()]),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSidebarAction', () => ({
|
||||
useSidebarAction: vi.fn(() => {}),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
|
||||
getAssistantText: vi.fn(() => ''),
|
||||
getLatestPlayableAssistantMessage: vi.fn(() => null),
|
||||
@@ -270,7 +265,6 @@ describe('SessionDetail scroll floating button', () => {
|
||||
mocks.useVisualViewport.mockReturnValue({ keyboardHeight: 0 })
|
||||
mocks.useKeyboardShortcuts.mockReturnValue({ leaderActive: false })
|
||||
mocks.useDialogParam.mockReturnValue([false, vi.fn()])
|
||||
mocks.useSidebarAction.mockReturnValue(undefined)
|
||||
mocks.useSessionStatusForSession.mockReturnValue({ type: 'idle' })
|
||||
mocks.PromptInput.mockImplementation(() => <div>MockedPromptInput</div>)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user