mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(header): move mobile reports into the More menu and compact the header
This commit is contained in:
1 parent
7f5c242fe0
commit
db40b71108
9 files changed
+232
-66
No files matched your search
@@ -7,6 +7,7 @@ import { useAuth } from '@/hooks/useAuth'
|
||||
import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { getRepo } from '@/api/repos'
|
||||
import type { ActiveWorkItem } from '@/lib/activeWork'
|
||||
import type { UnreadScheduleRun } from '@/api/schedules'
|
||||
|
||||
vi.mock('@/hooks/useAuth')
|
||||
vi.mock('@/hooks/useServerHealth')
|
||||
@@ -32,6 +33,16 @@ vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useRepoActivityState: () => null,
|
||||
}))
|
||||
|
||||
const scheduleMocks = vi.hoisted(() => ({
|
||||
useUnreadScheduleRuns: vi.fn(),
|
||||
useMarkAllScheduleRunsViewed: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSchedules', () => ({
|
||||
useUnreadScheduleRuns: scheduleMocks.useUnreadScheduleRuns,
|
||||
useMarkAllScheduleRunsViewed: scheduleMocks.useMarkAllScheduleRunsViewed,
|
||||
}))
|
||||
|
||||
function createActiveWorkItem(): ActiveWorkItem {
|
||||
const now = Date.now()
|
||||
return {
|
||||
@@ -61,6 +72,33 @@ function createActiveWorkItem(): ActiveWorkItem {
|
||||
}
|
||||
}
|
||||
|
||||
function createUnreadScheduleRun(): UnreadScheduleRun {
|
||||
const now = Date.now()
|
||||
return {
|
||||
id: 1,
|
||||
jobId: 1,
|
||||
repoId: 1,
|
||||
triggerSource: 'schedule',
|
||||
status: 'completed',
|
||||
startedAt: now - 60000,
|
||||
finishedAt: now - 30000,
|
||||
viewedAt: null,
|
||||
createdAt: now - 60000,
|
||||
sessionId: null,
|
||||
sessionTitle: null,
|
||||
logText: null,
|
||||
responseText: null,
|
||||
errorText: null,
|
||||
runBranch: null,
|
||||
commitHash: null,
|
||||
worktreePath: null,
|
||||
jobName: 'Nightly report',
|
||||
repoName: 'repo1',
|
||||
repoPath: '/path/to/repo1',
|
||||
preview: 'Report ready',
|
||||
}
|
||||
}
|
||||
|
||||
function setActivityGroups(groups: {
|
||||
needsInput?: ActiveWorkItem[]
|
||||
running?: ActiveWorkItem[]
|
||||
@@ -158,6 +196,8 @@ describe('MoreDrawer', () => {
|
||||
})
|
||||
activityMocks.useActivityWindowMinutes.mockReturnValue(30)
|
||||
setActivityGroups({})
|
||||
scheduleMocks.useUnreadScheduleRuns.mockReturnValue({ data: { runs: [], total: 0, failed: 0 } })
|
||||
scheduleMocks.useMarkAllScheduleRunsViewed.mockReturnValue({ mutate: vi.fn(), isPending: false })
|
||||
})
|
||||
|
||||
it('renders Settings and Logout menu items', () => {
|
||||
@@ -360,4 +400,21 @@ describe('MoreDrawer', () => {
|
||||
expect(navigateMock).toHaveBeenCalledWith('/repos/1/sessions/s1')
|
||||
expect(handleClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('shows unread reports and marks them all read', () => {
|
||||
const markAllReportsViewed = vi.fn()
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
scheduleMocks.useUnreadScheduleRuns.mockReturnValue({
|
||||
data: { runs: [createUnreadScheduleRun()], total: 1, failed: 0 },
|
||||
})
|
||||
scheduleMocks.useMarkAllScheduleRunsViewed.mockReturnValue({ mutate: markAllReportsViewed, isPending: false })
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId' })
|
||||
|
||||
expect(screen.getByText('Nightly report')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Mark all read' }))
|
||||
|
||||
expect(markAllReportsViewed).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@@ -9,6 +9,8 @@ import { getRepo } from '@/api/repos'
|
||||
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
|
||||
import { SideDrawer, SideDrawerContent } from '@/components/ui/side-drawer'
|
||||
import { CompactActivityList } from '@/components/activity/CompactActivityList'
|
||||
import { ScheduleReportsList } from '@/components/notifications/ScheduleReportsBell'
|
||||
import { useMarkAllScheduleRunsViewed, useUnreadScheduleRuns } from '@/hooks/useSchedules'
|
||||
import { buildMoreItems, buildNavModel, isSessionDetailPath, type MoreDrawerItem } from './moreDrawerItems'
|
||||
import { useSwipeBack } from '@/hooks/useMobile'
|
||||
import { cn, getRepoDisplayName } from '@/lib/utils'
|
||||
@@ -77,6 +79,9 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
const isAssistantRoute = isAssistantPath(location.pathname)
|
||||
const isAssistantSession = isSessionDetail && searchParams.get('assistant') === '1'
|
||||
const { open: openMobileSheet } = useMobileTabBar()
|
||||
const { data: unreadReports } = useUnreadScheduleRuns()
|
||||
const markAllReportsViewed = useMarkAllScheduleRunsViewed()
|
||||
const total = unreadReports?.total ?? 0
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && swipeRef.current) {
|
||||
@@ -184,6 +189,18 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
)}
|
||||
</div>
|
||||
<SideDrawerContent className="flex flex-col gap-4 pb-3">
|
||||
{total > 0 && (
|
||||
<div className="overflow-hidden rounded-lg border border-border">
|
||||
<ScheduleReportsList
|
||||
runs={unreadReports?.runs ?? []}
|
||||
total={total}
|
||||
rowClassName="py-3"
|
||||
onMarkAllRead={() => markAllReportsViewed.mutate()}
|
||||
markAllPending={markAllReportsViewed.isPending}
|
||||
maxHeightClass=""
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{isOpen && (
|
||||
<CompactActivityList onNavigate={(path) => navigate(path)} />
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { SessionMoreButton } from './SessionMoreButton'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
open: vi.fn(),
|
||||
useUnreadScheduleRuns: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useMobileTabBar', () => ({
|
||||
useMobileTabBar: () => ({ open: mocks.open, openSheet: null, close: vi.fn() }),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSchedules', () => ({
|
||||
useUnreadScheduleRuns: mocks.useUnreadScheduleRuns,
|
||||
}))
|
||||
|
||||
describe('SessionMoreButton', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('shows the unread report count and opens the drawer', () => {
|
||||
mocks.useUnreadScheduleRuns.mockReturnValue({ data: { runs: [], total: 4, failed: 0 } })
|
||||
render(<SessionMoreButton />)
|
||||
|
||||
const button = screen.getByRole('button', { name: 'More, 4 unread reports' })
|
||||
expect(screen.getByText('4')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(button)
|
||||
|
||||
expect(mocks.open).toHaveBeenCalledWith('more')
|
||||
})
|
||||
|
||||
it('shows no count when there are no unread reports', () => {
|
||||
mocks.useUnreadScheduleRuns.mockReturnValue({ data: { runs: [], total: 0, failed: 0 } })
|
||||
render(<SessionMoreButton />)
|
||||
|
||||
expect(screen.getByRole('button', { name: 'More' })).toBeInTheDocument()
|
||||
expect(screen.queryByText('0')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,19 +1,25 @@
|
||||
import { MoreVertical } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { ScheduleReportsBadge } from '@/components/notifications/ScheduleReportsBadge'
|
||||
import { useUnreadScheduleRuns } from '@/hooks/useSchedules'
|
||||
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
||||
|
||||
export function SessionMoreButton() {
|
||||
const { open } = useMobileTabBar()
|
||||
const { data } = useUnreadScheduleRuns()
|
||||
const total = data?.total ?? 0
|
||||
const failed = data?.failed ?? 0
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => open('more')}
|
||||
className="md:hidden h-10 w-10 p-0 text-foreground border-border hover:bg-accent"
|
||||
aria-label="More"
|
||||
className="relative md:hidden h-10 w-10 p-0 text-foreground border-border hover:bg-accent"
|
||||
aria-label={total > 0 ? `More, ${total} unread reports` : 'More'}
|
||||
>
|
||||
<MoreVertical className="w-5 h-5" />
|
||||
<ScheduleReportsBadge total={total} failed={failed} />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user