mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
refactor(activity): remove the compact activity list from the mobile More drawer
This commit is contained in:
1 parent
11a2661cc6
commit
87a8a21a8d
5 files changed
+20
-331
No files matched your search
@@ -3,7 +3,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import type { Repo, Session } from '@/api/types'
|
||||
import type { ActiveWorkItem } from '@/lib/activeWork'
|
||||
import { formatShortRelativeTime } from '@/lib/utils'
|
||||
import { ActivityList } from './ActivityList'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
@@ -72,19 +71,10 @@ function setGroups(groups: {
|
||||
})
|
||||
}
|
||||
|
||||
const renderList = (
|
||||
onNavigate = vi.fn(),
|
||||
path = '/',
|
||||
props: {
|
||||
hideWhenEmpty?: boolean
|
||||
title?: string
|
||||
variant?: 'full' | 'compact'
|
||||
minutes?: number
|
||||
} = {},
|
||||
) =>
|
||||
const renderList = (onNavigate = vi.fn(), path = '/', minutes = WINDOW_MINUTES) =>
|
||||
render(
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<ActivityList minutes={WINDOW_MINUTES} onNavigate={onNavigate} {...props} />
|
||||
<ActivityList minutes={minutes} onNavigate={onNavigate} />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
@@ -130,7 +120,7 @@ describe('ActivityList', () => {
|
||||
it('renders the empty state with an hour-scale window', () => {
|
||||
setGroups({})
|
||||
|
||||
renderList(vi.fn(), '/', { minutes: 1440 })
|
||||
renderList(vi.fn(), '/', 1440)
|
||||
|
||||
expect(screen.getByText('No active or recent sessions in the last 24 hours')).toBeInTheDocument()
|
||||
})
|
||||
@@ -219,180 +209,4 @@ describe('ActivityList', () => {
|
||||
|
||||
expect(screen.getByText("Couldn't load activity.")).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders nothing when hideWhenEmpty and there are no items', () => {
|
||||
setGroups({})
|
||||
|
||||
const { container } = renderList(vi.fn(), '/', { hideWhenEmpty: true })
|
||||
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
|
||||
it('renders nothing while loading when hideWhenEmpty', () => {
|
||||
mocks.useActiveWork.mockReturnValue({
|
||||
groups: { needsInput: [], running: [], recent: [] },
|
||||
isLoading: true,
|
||||
isError: false,
|
||||
})
|
||||
|
||||
const { container } = renderList(vi.fn(), '/', { hideWhenEmpty: true })
|
||||
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
|
||||
it('renders the title only when there are items', () => {
|
||||
setGroups({
|
||||
recent: [createItem({ state: 'recent', session: createSession('c1', 'Recent'), repo: createRepo(3, 'Gamma') })],
|
||||
})
|
||||
|
||||
renderList(vi.fn(), '/', { title: 'Activity' })
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Activity' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not render the title when there are no items', () => {
|
||||
setGroups({})
|
||||
|
||||
renderList(vi.fn(), '/', { title: 'Activity' })
|
||||
|
||||
expect(screen.queryByRole('heading', { name: 'Activity' })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('ActivityList compact variant', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('renders only the section title, without group headings', () => {
|
||||
setGroups({
|
||||
needsInput: [
|
||||
createItem({ state: 'needs-input', session: createSession('n1', 'Needs work'), repo: createRepo(1, 'Alpha') }),
|
||||
],
|
||||
running: [
|
||||
createItem({ state: 'running', session: createSession('r1', 'Running task'), repo: createRepo(2, 'Beta') }),
|
||||
],
|
||||
recent: [
|
||||
createItem({ state: 'recent', session: createSession('c1', 'Recent task'), repo: createRepo(3, 'Gamma') }),
|
||||
],
|
||||
})
|
||||
|
||||
renderList(vi.fn(), '/', { variant: 'compact', title: 'Activity' })
|
||||
|
||||
expect(screen.getAllByRole('heading').map((node) => node.textContent)).toEqual(['Activity'])
|
||||
expect(screen.queryByText('Needs input')).toBeNull()
|
||||
expect(screen.queryByText('Running')).toBeNull()
|
||||
expect(screen.queryByText('Recent')).toBeNull()
|
||||
})
|
||||
|
||||
it('renders one single-line row per item in needs-input, running, recent order', () => {
|
||||
const needs = createItem({
|
||||
state: 'needs-input',
|
||||
session: createSession('n1', 'Needs work'),
|
||||
repo: createRepo(1, 'Alpha'),
|
||||
})
|
||||
const running = createItem({
|
||||
state: 'running',
|
||||
session: createSession('r1', 'Running task'),
|
||||
repo: createRepo(2, 'Beta'),
|
||||
})
|
||||
const recent = createItem({
|
||||
state: 'recent',
|
||||
session: createSession('c1', 'Recent task'),
|
||||
repo: createRepo(3, 'Gamma'),
|
||||
})
|
||||
setGroups({ needsInput: [needs], running: [running], recent: [recent] })
|
||||
|
||||
renderList(vi.fn(), '/', { variant: 'compact' })
|
||||
|
||||
const rows = screen.getAllByRole('button')
|
||||
expect(rows).toHaveLength(3)
|
||||
expect(rows[0]).toHaveTextContent('Needs work')
|
||||
expect(rows[1]).toHaveTextContent('Running task')
|
||||
expect(rows[2]).toHaveTextContent('Recent task')
|
||||
|
||||
expect(rows[0]).toHaveAccessibleName(/Needs work/)
|
||||
expect(rows[0]).toHaveAccessibleName(/Alpha/)
|
||||
expect(rows[0]).toHaveTextContent(formatShortRelativeTime(new Date(needs.session.time.updated)))
|
||||
expect(rows[0]).not.toHaveTextContent('feature/x')
|
||||
})
|
||||
|
||||
it('caps the compact list at five items, keeping needs-input and running over recent', () => {
|
||||
setGroups({
|
||||
needsInput: [1, 2].map((n): ActiveWorkItem =>
|
||||
createItem({
|
||||
state: 'needs-input',
|
||||
session: createSession(`n${n}`, `Needs work ${n}`),
|
||||
repo: createRepo(n, `Repo ${n}`),
|
||||
}),
|
||||
),
|
||||
running: [1, 2, 3].map((n): ActiveWorkItem =>
|
||||
createItem({
|
||||
state: 'running',
|
||||
session: createSession(`r${n}`, `Running task ${n}`),
|
||||
repo: createRepo(10 + n, `Repo ${10 + n}`),
|
||||
}),
|
||||
),
|
||||
recent: [1, 2, 3].map((n): ActiveWorkItem =>
|
||||
createItem({
|
||||
state: 'recent',
|
||||
session: createSession(`c${n}`, `Recent task ${n}`),
|
||||
repo: createRepo(20 + n, `Repo ${20 + n}`),
|
||||
}),
|
||||
),
|
||||
})
|
||||
|
||||
renderList(vi.fn(), '/', { variant: 'compact' })
|
||||
|
||||
const rows = screen.getAllByRole('button')
|
||||
expect(rows).toHaveLength(5)
|
||||
expect(rows[0]).toHaveTextContent('Needs work 1')
|
||||
expect(rows[4]).toHaveTextContent('Running task 3')
|
||||
expect(screen.queryByText('Recent task 1')).toBeNull()
|
||||
})
|
||||
|
||||
it('fills the remaining compact slots with recent items', () => {
|
||||
setGroups({
|
||||
running: [
|
||||
createItem({ state: 'running', session: createSession('r1', 'Running task'), repo: createRepo(1, 'Alpha') }),
|
||||
],
|
||||
recent: [1, 2, 3, 4, 5].map((n): ActiveWorkItem =>
|
||||
createItem({
|
||||
state: 'recent',
|
||||
session: createSession(`c${n}`, `Recent task ${n}`),
|
||||
repo: createRepo(10 + n, `Repo ${10 + n}`),
|
||||
}),
|
||||
),
|
||||
})
|
||||
|
||||
renderList(vi.fn(), '/', { variant: 'compact' })
|
||||
|
||||
const rows = screen.getAllByRole('button')
|
||||
expect(rows).toHaveLength(5)
|
||||
expect(rows[0]).toHaveTextContent('Running task')
|
||||
expect(rows[4]).toHaveTextContent('Recent task 4')
|
||||
expect(screen.queryByText('Recent task 5')).toBeNull()
|
||||
})
|
||||
|
||||
it('marks the currently open session with aria-current', () => {
|
||||
setGroups({
|
||||
recent: [
|
||||
createItem({ state: 'recent', session: createSession('open', 'Open session'), repo: createRepo(7, 'Gamma') }),
|
||||
createItem({ state: 'recent', session: createSession('other', 'Other session'), repo: createRepo(7, 'Gamma') }),
|
||||
],
|
||||
})
|
||||
|
||||
renderList(vi.fn(), '/repos/7/sessions/open', { variant: 'compact' })
|
||||
|
||||
expect(screen.getByRole('button', { name: /Open session/ })).toHaveAttribute('aria-current', 'true')
|
||||
expect(screen.getByRole('button', { name: /Other session/ })).not.toHaveAttribute('aria-current')
|
||||
})
|
||||
|
||||
it('renders nothing when hideWhenEmpty and there are no items', () => {
|
||||
setGroups({})
|
||||
|
||||
const { container } = renderList(vi.fn(), '/', { hideWhenEmpty: true, variant: 'compact' })
|
||||
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
})
|
||||
@@ -12,20 +12,14 @@ import {
|
||||
} from '@/lib/activeWork'
|
||||
|
||||
const UNTITLED_SESSION_TITLE = 'Untitled Session'
|
||||
const COMPACT_MAX_ITEMS = 5
|
||||
|
||||
const FULL_ICON_CLASS = 'h-4 w-4'
|
||||
const COMPACT_ICON_CLASS = 'h-3.5 w-3.5'
|
||||
|
||||
interface ActivityListProps {
|
||||
/** Activity window in minutes. */
|
||||
minutes: number
|
||||
/** Called when a row is chosen; the caller owns navigation so each surface can apply its own history and close rules. */
|
||||
onNavigate: (item: ActiveWorkItem) => void
|
||||
hideWhenEmpty?: boolean
|
||||
title?: string
|
||||
/** `compact` renders one flat, single-line list capped at {@link COMPACT_MAX_ITEMS}; `full` renders grouped rows. */
|
||||
variant?: 'full' | 'compact'
|
||||
}
|
||||
|
||||
function isCurrentItem(
|
||||
@@ -51,10 +45,9 @@ function activityItemLine(item: ActiveWorkItem): string {
|
||||
return branch ? `${getRepoDisplayName(item.repo)} · ${branch}` : getRepoDisplayName(item.repo)
|
||||
}
|
||||
|
||||
function activityRowClass(isCurrent: boolean, compact: boolean) {
|
||||
function activityRowClass(isCurrent: boolean) {
|
||||
return cn(
|
||||
'flex w-full items-center gap-2 rounded-md px-2 text-left text-sm transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
||||
compact ? 'py-1' : 'py-1.5',
|
||||
'flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
||||
isCurrent && 'bg-accent',
|
||||
)
|
||||
}
|
||||
@@ -87,7 +80,7 @@ function ActivityRow({ item, isCurrent, onSelect }: ActivityRowProps) {
|
||||
type="button"
|
||||
onClick={() => onSelect(item)}
|
||||
aria-current={isCurrent ? 'true' : undefined}
|
||||
className={activityRowClass(isCurrent, false)}
|
||||
className={activityRowClass(isCurrent)}
|
||||
>
|
||||
<span className="flex w-5 shrink-0 items-center justify-center">
|
||||
<ActivityStateIcon item={item} iconClassName={FULL_ICON_CLASS} />
|
||||
@@ -105,30 +98,6 @@ function ActivityRow({ item, isCurrent, onSelect }: ActivityRowProps) {
|
||||
)
|
||||
}
|
||||
|
||||
function CompactActivityRow({ item, isCurrent, onSelect }: ActivityRowProps) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onSelect(item)}
|
||||
aria-current={isCurrent ? 'true' : undefined}
|
||||
className={activityRowClass(isCurrent, true)}
|
||||
>
|
||||
<span className="flex w-4 shrink-0 items-center justify-center">
|
||||
<ActivityStateIcon item={item} iconClassName={COMPACT_ICON_CLASS} />
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 truncate text-foreground">
|
||||
{item.session.title || UNTITLED_SESSION_TITLE}
|
||||
</span>
|
||||
<span className="max-w-[35%] truncate text-xs text-muted-foreground">
|
||||
{activityItemLabel(item)}
|
||||
</span>
|
||||
<span className="shrink-0 text-xs text-muted-foreground">
|
||||
{formatShortRelativeTime(new Date(item.updatedAt))}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
interface ActivityGroupProps {
|
||||
heading: string
|
||||
items: ActiveWorkItem[]
|
||||
@@ -163,13 +132,7 @@ function ActivityGroup({
|
||||
)
|
||||
}
|
||||
|
||||
export function ActivityList({
|
||||
minutes,
|
||||
onNavigate,
|
||||
hideWhenEmpty = false,
|
||||
title,
|
||||
variant = 'full',
|
||||
}: ActivityListProps) {
|
||||
export function ActivityList({ minutes, onNavigate }: ActivityListProps) {
|
||||
const location = useLocation()
|
||||
const { groups, isLoading, isError } = useActiveWork(minutes * MS_PER_MINUTE)
|
||||
|
||||
@@ -178,12 +141,10 @@ export function ActivityList({
|
||||
const currentSessionID = route.sessionId ?? serverRoute?.sessionId ?? null
|
||||
|
||||
if (isLoading) {
|
||||
if (hideWhenEmpty) return null
|
||||
return <p className="p-4 text-sm text-muted-foreground">Loading activity...</p>
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
if (hideWhenEmpty) return null
|
||||
return <p className="p-4 text-sm text-destructive">Couldn't load activity.</p>
|
||||
}
|
||||
|
||||
@@ -191,57 +152,24 @@ export function ActivityList({
|
||||
groups.needsInput.length === 0 && groups.running.length === 0 && groups.recent.length === 0
|
||||
|
||||
if (isEmpty) {
|
||||
if (hideWhenEmpty) return null
|
||||
return (
|
||||
<p className="p-4 text-sm text-muted-foreground">{formatActivityEmptyMessage(minutes)}</p>
|
||||
)
|
||||
}
|
||||
|
||||
const isCompact = variant === 'compact'
|
||||
const compactItems = [...groups.needsInput, ...groups.running, ...groups.recent].slice(
|
||||
0,
|
||||
COMPACT_MAX_ITEMS,
|
||||
)
|
||||
|
||||
return (
|
||||
<section
|
||||
aria-label={title}
|
||||
className={cn('flex flex-col', isCompact ? 'pb-1' : 'pb-2', title && 'border-b border-border')}
|
||||
>
|
||||
{title && (
|
||||
<h2
|
||||
className={cn(
|
||||
'px-4 text-xs font-medium uppercase tracking-wider text-muted-foreground',
|
||||
isCompact ? 'pt-2 pb-0.5' : 'pt-3 pb-1',
|
||||
)}
|
||||
>
|
||||
{title}
|
||||
</h2>
|
||||
)}
|
||||
{isCompact ? (
|
||||
compactItems.map((item) => (
|
||||
<CompactActivityRow
|
||||
key={item.key}
|
||||
item={item}
|
||||
isCurrent={isCurrentItem(item, currentSessionID, route.repoId, serverRoute?.serverId ?? null)}
|
||||
onSelect={onNavigate}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<>
|
||||
{ACTIVE_WORK_GROUPS.map((group) => (
|
||||
<ActivityGroup
|
||||
key={group.key}
|
||||
heading={group.heading}
|
||||
items={groups[group.key]}
|
||||
currentSessionID={currentSessionID}
|
||||
currentRepoId={route.repoId}
|
||||
currentServerId={serverRoute?.serverId ?? null}
|
||||
onSelect={onNavigate}
|
||||
/>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
<section className="flex flex-col pb-2">
|
||||
{ACTIVE_WORK_GROUPS.map((group) => (
|
||||
<ActivityGroup
|
||||
key={group.key}
|
||||
heading={group.heading}
|
||||
items={groups[group.key]}
|
||||
currentSessionID={currentSessionID}
|
||||
currentRepoId={route.repoId}
|
||||
currentServerId={serverRoute?.serverId ?? null}
|
||||
onSelect={onNavigate}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import { useActivityWindowMinutes } from '@/hooks/useActiveWork'
|
||||
import { ActivityList } from '@/components/activity/ActivityList'
|
||||
|
||||
/**
|
||||
* A compact, self-titled Activity section that renders nothing when empty.
|
||||
* Reads the network through `useActiveWork`, so it must only be mounted while visible.
|
||||
*/
|
||||
export function CompactActivityList({ onNavigate }: { onNavigate: (path: string) => void }) {
|
||||
const minutes = useActivityWindowMinutes()
|
||||
|
||||
return (
|
||||
<ActivityList
|
||||
minutes={minutes}
|
||||
title="Activity"
|
||||
hideWhenEmpty
|
||||
variant="compact"
|
||||
onNavigate={(item) => onNavigate(item.path)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -367,47 +367,19 @@ describe('MoreDrawer', () => {
|
||||
expect(screen.queryByRole('button', { name: 'Assistant' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows the Activity section above the menu when there are items', () => {
|
||||
it('shows no Activity section even when there are activity items', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId' })
|
||||
|
||||
const heading = screen.getByRole('heading', { name: 'Activity' })
|
||||
const firstMenuRow = screen.getByText('Files')
|
||||
expect(screen.getByText('Session s1')).toBeInTheDocument()
|
||||
expect(heading.compareDocumentPosition(firstMenuRow) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
||||
})
|
||||
|
||||
it('hides the Activity section when there are no items', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({})
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId' })
|
||||
|
||||
expect(screen.queryByRole('heading', { name: 'Activity' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Session s1')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('navigates to the activity item without a close that would replace the new route', () => {
|
||||
const navigateMock = vi.fn()
|
||||
vi.mocked(useNavigate).mockReturnValue(navigateMock)
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
const handleClose = vi.fn()
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId', onClose: handleClose })
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /Session s1/ }))
|
||||
|
||||
expect(navigateMock).toHaveBeenCalledWith('/repos/1/sessions/s1')
|
||||
expect(handleClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('offers only the remote-capable project items on a linked-server route', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
renderMoreDrawer({
|
||||
initialEntry: '/servers/srv_kitchen/sessions/ses_remote',
|
||||
routePath: '/servers/:serverId/sessions/:sessionId',
|
||||
@@ -419,7 +391,6 @@ describe('MoreDrawer', () => {
|
||||
expect(screen.getByText('Settings')).toBeInTheDocument()
|
||||
expect(screen.getByText('Logout')).toBeInTheDocument()
|
||||
expect(screen.getByText('Terminal')).toBeInTheDocument()
|
||||
expect(screen.getByRole('heading', { name: 'Activity' })).toBeInTheDocument()
|
||||
expect(screen.getByText('Sessions')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Files')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('Source Control')).toBeInTheDocument()
|
||||
|
||||
@@ -8,7 +8,6 @@ import { useQuery } from '@tanstack/react-query'
|
||||
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, isManagerOnlyNavItem, isSessionDetailPath, type MoreDrawerItem } from './moreDrawerItems'
|
||||
@@ -206,9 +205,6 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{isOpen && (
|
||||
<CompactActivityList onNavigate={(path) => navigate(path)} />
|
||||
)}
|
||||
<MenuSection>
|
||||
{(isSessionDetail || isRemoteSessionDetail) && (
|
||||
<MenuRow icon={List} label="Sessions" onClick={() => openMobileSheet('sessions')} trailing />
|
||||
|
||||
Reference in new issue
Block a user