mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(frontend): consolidate session picker navigation and remote project loading
This commit is contained in:
1 parent
81fb2d4033
commit
52aeb7780f
42 files changed
+1486
-769
No files matched your search
@@ -20,13 +20,16 @@ import {
|
||||
listPendingPermissions,
|
||||
listSessionMessages,
|
||||
listSessionPage,
|
||||
projectActivityTimestamp,
|
||||
readSessionSnapshot,
|
||||
remoteProjectName,
|
||||
renameSession,
|
||||
replyForm,
|
||||
replyPermission,
|
||||
runCommand,
|
||||
runShell,
|
||||
sendPrompt,
|
||||
sortProjectsByActivity,
|
||||
stageRevert,
|
||||
switchSessionAgent,
|
||||
switchSessionModel,
|
||||
@@ -753,3 +756,47 @@ describe('OpenCode facade', () => {
|
||||
expect(lastRequest().init.method).toBe('DELETE')
|
||||
})
|
||||
})
|
||||
|
||||
const project = (
|
||||
id: string,
|
||||
name: string | undefined,
|
||||
canonical: string,
|
||||
time: { created: number; updated: number; active?: number },
|
||||
) => ({ id, name, canonical, time, sandboxes: [] })
|
||||
|
||||
describe('project helpers', () => {
|
||||
it('prefers the activity time over the update time', () => {
|
||||
const withActivity = project('p1', 'Active', '/work/active', { created: 1, updated: 10, active: 900 })
|
||||
|
||||
expect(projectActivityTimestamp(withActivity)).toBe(900)
|
||||
})
|
||||
|
||||
it('falls back to the update time when the project was never active', () => {
|
||||
const neverActive = project('p1', 'Idle', '/work/idle', { created: 1, updated: 10, active: 0 })
|
||||
|
||||
expect(projectActivityTimestamp(neverActive)).toBe(10)
|
||||
})
|
||||
|
||||
it('orders projects by activity, most recent first, without mutating the input', () => {
|
||||
const stale = project('p_stale', 'Stale', '/work/stale', { created: 1, updated: 500, active: 100 })
|
||||
const recent = project('p_recent', 'Recent', '/work/recent', { created: 1, updated: 100, active: 900 })
|
||||
const middle = project('p_middle', 'Middle', '/work/middle', { created: 1, updated: 700 })
|
||||
const projects = [stale, recent, middle]
|
||||
|
||||
expect(sortProjectsByActivity(projects).map((entry) => entry.id)).toEqual([
|
||||
'p_recent',
|
||||
'p_middle',
|
||||
'p_stale',
|
||||
])
|
||||
expect(projects.map((entry) => entry.id)).toEqual(['p_stale', 'p_recent', 'p_middle'])
|
||||
})
|
||||
|
||||
it('names a project from its trimmed title', () => {
|
||||
expect(remoteProjectName(project('p1', ' Alpha ', '/work/alpha', { created: 1, updated: 2 }))).toBe('Alpha')
|
||||
})
|
||||
|
||||
it('names a project from its directory when it has no title', () => {
|
||||
expect(remoteProjectName(project('p1', undefined, '/work/beta', { created: 1, updated: 2 }))).toBe('beta')
|
||||
expect(remoteProjectName(project('p1', ' ', '/work/gamma', { created: 1, updated: 2 }))).toBe('gamma')
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,7 @@
|
||||
import { openCodeLocation, parseOpenCodeModelRef } from '@opencode-manager/shared/opencode'
|
||||
import { MANAGER_PROMPT_CLIENT_METADATA_KEY } from '@opencode-manager/shared/schemas'
|
||||
import { isMobileViewport } from '@/hooks/useMobile'
|
||||
import { getDirectoryName } from '@/lib/utils'
|
||||
import { callOpenCode } from './opencodeApi'
|
||||
import type {
|
||||
AgentInfo,
|
||||
@@ -37,10 +38,36 @@ export type OpenCodeLocationInfo = Awaited<ReturnType<OpenCodeApi['location']['g
|
||||
|
||||
export type OpenCodeProject = Awaited<ReturnType<OpenCodeApi['project']['list']>>[number]
|
||||
|
||||
/**
|
||||
* Returns the timestamp that represents a project's most recent activity.
|
||||
*
|
||||
* @param project Project whose activity time is read.
|
||||
* @returns The activity time, falling back to the last update when the project was never active.
|
||||
*/
|
||||
export function projectActivityTimestamp(project: OpenCodeProject): number {
|
||||
return project.time.active || project.time.updated
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders projects from the most to the least recently active.
|
||||
*
|
||||
* @param projects Projects to order.
|
||||
* @returns A new array with the projects sorted by activity; the input is left untouched.
|
||||
*/
|
||||
export function sortProjectsByActivity(projects: OpenCodeProject[]): OpenCodeProject[] {
|
||||
return [...projects].sort((a, b) => projectActivityTimestamp(b) - projectActivityTimestamp(a))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display name of a project, falling back to the name of its directory.
|
||||
*
|
||||
* @param project Project whose name is resolved.
|
||||
* @returns The trimmed project name, or the last segment of its canonical directory.
|
||||
*/
|
||||
export function remoteProjectName(project: OpenCodeProject): string {
|
||||
return project.name?.trim() || getDirectoryName(project.canonical)
|
||||
}
|
||||
|
||||
export type VcsInfo = Awaited<ReturnType<OpenCodeApi['vcs']['get']>>['data']
|
||||
|
||||
export type VcsFileStatus = Awaited<ReturnType<OpenCodeApi['vcs']['status']>>['data'][number]
|
||||
|
||||
Reference in new issue
Block a user