mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(activity): surface active work across the session picker, tool rail and mobile
This commit is contained in:
1 parent
be874ee07c
commit
d8f2fcf29c
46 files changed
+3120
-277
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { ActivitySettings } from './ActivitySettings'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import type { UserPreferences } from '@/api/types/settings'
|
||||
import { createUseSettingsMock } from '@/test/test-utils'
|
||||
|
||||
vi.mock('@/hooks/useSettings')
|
||||
|
||||
const basePreferences: UserPreferences = {
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
autoScroll: true,
|
||||
expandDiffs: true,
|
||||
expandToolCalls: false,
|
||||
showReasoning: false,
|
||||
simpleChatMode: false,
|
||||
keyboardShortcuts: {},
|
||||
customCommands: [],
|
||||
}
|
||||
|
||||
function mockUseSettings(overrides: Partial<ReturnType<typeof useSettings>> = {}) {
|
||||
vi.mocked(useSettings).mockReturnValue(createUseSettingsMock({ preferences: basePreferences, ...overrides }))
|
||||
}
|
||||
|
||||
describe('ActivitySettings', () => {
|
||||
beforeAll(() => {
|
||||
Element.prototype.hasPointerCapture ??= () => false
|
||||
Element.prototype.setPointerCapture ??= () => {}
|
||||
Element.prototype.releasePointerCapture ??= () => {}
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('shows the default window when the preference is unset', () => {
|
||||
mockUseSettings()
|
||||
render(<ActivitySettings />)
|
||||
|
||||
expect(screen.getByRole('combobox', { name: 'Recent activity window' })).toHaveTextContent('30 minutes')
|
||||
})
|
||||
|
||||
it('shows the stored window', () => {
|
||||
mockUseSettings({ preferences: { ...basePreferences, activityWindowMinutes: 120 } })
|
||||
render(<ActivitySettings />)
|
||||
|
||||
expect(screen.getByRole('combobox', { name: 'Recent activity window' })).toHaveTextContent('2 hours')
|
||||
})
|
||||
|
||||
it('saves the chosen window in minutes', async () => {
|
||||
const user = userEvent.setup()
|
||||
const updateSettings = vi.fn()
|
||||
mockUseSettings({ updateSettings })
|
||||
render(<ActivitySettings />)
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: 'Recent activity window' }))
|
||||
await user.click(screen.getByRole('option', { name: '4 hours' }))
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledTimes(1)
|
||||
expect(updateSettings).toHaveBeenCalledWith({ activityWindowMinutes: 240 })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { ACTIVITY_WINDOW_MINUTE_OPTIONS, DEFAULT_ACTIVITY_WINDOW_MINUTES } from '@/api/types/settings'
|
||||
import { formatActivityWindow } from '@/lib/activeWork'
|
||||
|
||||
export function ActivitySettings() {
|
||||
const { preferences, updateSettings } = useSettings()
|
||||
const activityWindowMinutes = preferences?.activityWindowMinutes ?? DEFAULT_ACTIVITY_WINDOW_MINUTES
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h2 className="text-lg font-semibold text-foreground">Activity</h2>
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="activityWindowMinutes">Recent activity window</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
How far back the Activity panel lists recently active sessions.
|
||||
</p>
|
||||
</div>
|
||||
<Select
|
||||
value={String(activityWindowMinutes)}
|
||||
onValueChange={(value) => updateSettings({ activityWindowMinutes: Number(value) })}
|
||||
>
|
||||
<SelectTrigger id="activityWindowMinutes" className="w-full shrink-0 sm:w-40">
|
||||
<SelectValue placeholder="Select a window" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{ACTIVITY_WINDOW_MINUTE_OPTIONS.map((minutes) => (
|
||||
<SelectItem key={minutes} value={String(minutes)}>
|
||||
{formatActivityWindow(minutes)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { SessionAutomationSettings } from './SessionAutomationSettings'
|
||||
import { WalkthroughSettings } from './WalkthroughSettings'
|
||||
import { ActivitySettings } from './ActivitySettings'
|
||||
|
||||
export function GeneralSettings() {
|
||||
const { preferences, isLoading, updateSettings, isUpdating } = useSettings()
|
||||
@@ -199,6 +200,8 @@ export function GeneralSettings() {
|
||||
<SessionAutomationSettings />
|
||||
|
||||
<WalkthroughSettings />
|
||||
|
||||
<ActivitySettings />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user