diff --git a/frontend/src/components/navigation/DesktopSidebar.test.tsx b/frontend/src/components/navigation/DesktopSidebar.test.tsx index a7d1ace1..a9aa694e 100644 --- a/frontend/src/components/navigation/DesktopSidebar.test.tsx +++ b/frontend/src/components/navigation/DesktopSidebar.test.tsx @@ -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(, { wrapper: createWrapper(['/schedules']) }) + render(, { 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(, { 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()]) diff --git a/frontend/src/components/navigation/DesktopSidebar.tsx b/frontend/src/components/navigation/DesktopSidebar.tsx index 1a3bd34b..9e61431c 100644 --- a/frontend/src/components/navigation/DesktopSidebar.tsx +++ b/frontend/src/components/navigation/DesktopSidebar.tsx @@ -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 ( <> - {desktopPrimary.length > 0 && ( + {primary.length > 0 && ( - {desktopPrimary.map((item: NavPrimaryCta) => ( + {primary.map((item: NavPrimaryCta) => ( handlePrimaryClick(item)} + onClick={() => navigate(item.to)} asPrimary variant={item.variant} /> diff --git a/frontend/src/components/navigation/moreDrawerItems.test.ts b/frontend/src/components/navigation/moreDrawerItems.test.ts index 104ab468..353fed70 100644 --- a/frontend/src/components/navigation/moreDrawerItems.test.ts +++ b/frontend/src/components/navigation/moreDrawerItems.test.ts @@ -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') diff --git a/frontend/src/components/navigation/moreDrawerItems.ts b/frontend/src/components/navigation/moreDrawerItems.ts index 7fa438c8..7bc85911 100644 --- a/frontend/src/components/navigation/moreDrawerItems.ts +++ b/frontend/src/components/navigation/moreDrawerItems.ts @@ -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, } } diff --git a/frontend/src/components/notifications/ScheduleReportsBell.tsx b/frontend/src/components/notifications/ScheduleReportsBell.tsx index 32fc4821..ac864181 100644 --- a/frontend/src/components/notifications/ScheduleReportsBell.tsx +++ b/frontend/src/components/notifications/ScheduleReportsBell.tsx @@ -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" > - + ) diff --git a/frontend/src/components/schedules/RunHistoryTab.tsx b/frontend/src/components/schedules/RunHistoryTab.tsx index 4e18e42c..f862248b 100644 --- a/frontend/src/components/schedules/RunHistoryTab.tsx +++ b/frontend/src/components/schedules/RunHistoryTab.tsx @@ -75,8 +75,8 @@ export function RunHistoryTab({ Clear history -
-
+
+
) : (

diff --git a/frontend/src/hooks/useSidebarAction.test.tsx b/frontend/src/hooks/useSidebarAction.test.tsx deleted file mode 100644 index 5e9bb2bc..00000000 --- a/frontend/src/hooks/useSidebarAction.test.tsx +++ /dev/null @@ -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']) - }) -}) diff --git a/frontend/src/hooks/useSidebarAction.ts b/frontend/src/hooks/useSidebarAction.ts deleted file mode 100644 index 2de1188c..00000000 --- a/frontend/src/hooks/useSidebarAction.ts +++ /dev/null @@ -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() - -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]) -} diff --git a/frontend/src/pages/AssistantRedirect.tsx b/frontend/src/pages/AssistantRedirect.tsx index c7818be9..d4f05bfe 100644 --- a/frontend/src/pages/AssistantRedirect.tsx +++ b/frontend/src/pages/AssistantRedirect.tsx @@ -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 (
diff --git a/frontend/src/pages/GlobalSchedules.tsx b/frontend/src/pages/GlobalSchedules.tsx index 490be737..e6fdd966 100644 --- a/frontend/src/pages/GlobalSchedules.tsx +++ b/frontend/src/pages/GlobalSchedules.tsx @@ -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() {
-
+
{!hasJobs ? (
@@ -596,7 +590,7 @@ export function GlobalSchedules() {
) : ( -
+
-
-
+
+
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" + > + + New Session + +