Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(desktop): open EvenDrive file preview on single-click

Diego Zacariasab8f81ccacb5
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
index 284bc8f92..239ff511d 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
@@ -183,16 +183,16 @@ describe('FileExplorerTree — sanitizes externally-controlled GFS names in chro
const { pushToast } = renderTree()
- fireEvent.doubleClick(await screen.findByRole('button', { name: 'archive.zip' }))
+ fireEvent.click(await screen.findByRole('button', { name: 'archive.zip' }))
await waitFor(() => expect(pushToast).toHaveBeenCalledWith('Downloaded archive.zip', 'success'))
})
})
-describe('FileExplorerTree — single-vs-double click cancels the deferred single', () => {
+describe('FileExplorerTree — folder double-click cancels the deferred toggle', () => {
// The real browser fires click → click → dblclick; a single fireEvent.doubleClick
// dispatches only dblclick, so it never exercises the setTimeout cancellation.
- // These drive the full sequence and advance the 250ms window to prove the
- // deferred single-click action was cancelled by the double-click.
+ // A folder's single-click toggle is deferred; this drives the full sequence and
+ // advances the 250ms window to prove the double-click cancels that toggle.
it('folder: the double-click opens the tab once and never runs the deferred toggle', async () => {
const listChildren = vi.fn(async () => ({
items: [node('sub-1', 'Sub', 'directory')],
@@ -230,38 +230,75 @@ describe('FileExplorerTree — single-vs-double click cancels the deferred singl
expect(treeitem.getAttribute('aria-expanded')).toBe('false')
expect(listChildren).not.toHaveBeenCalled()
})
+})
- it('file: the double-click previews once and the deferred select adds nothing', async () => {
+describe('FileExplorerTree — rapid double-click on a file', () => {
+ it('file: every click of a previewable file routes to preview with the same resource, never a download', async () => {
+ const onOpenPreview = vi.fn()
+ const download = vi.fn(async () => ({ bytes: new ArrayBuffer(8) }))
installClerum({
listAccessible: vi.fn(async () => ({
items: [node('img-1', 'photo.png', 'file')],
nextCursor: null,
})),
+ download,
})
- const { onOpenPreview } = renderTree()
+ renderTree({ onOpenPreview })
const fileButton = await screen.findByRole('button', { name: 'photo.png' })
- vi.useFakeTimers()
- try {
- fireEvent.click(fileButton)
- fireEvent.click(fileButton)
- fireEvent.doubleClick(fileButton)
- expect(onOpenPreview).toHaveBeenCalledTimes(1)
- act(() => {
- vi.advanceTimersByTime(300)
- })
- } finally {
- vi.useRealTimers()
+ // Files have no single/double-click deferral, so a real double-click
+ // (click → click → dblclick) activates more than once. Preview has no
+ // component-level in-flight guard — production idempotency comes from the host
+ // deduping preview tabs by gfsUri (covered in workspaceTabs.test.ts), so this
+ // asserts the component contract, not that host layer: under the rapid gesture
+ // the preview branch always stays ahead of the download guard, so every
+ // activation targets the same previewable resource and none falls through to a
+ // download. A regression that reordered the guard would fail here.
+ fireEvent.click(fileButton)
+ fireEvent.click(fileButton)
+ fireEvent.doubleClick(fileButton)
+
+ await waitFor(() => expect(onOpenPreview).toHaveBeenCalled())
+ for (const [preview] of onOpenPreview.mock.calls) {
+ expect(preview).toEqual(
+ expect.objectContaining({ kind: 'image', gfsUri: 'gfs://main/img-1', name: 'photo.png' })
+ )
}
+ expect(download).not.toHaveBeenCalled()
+ })
- // Advancing past the single-click window adds no second activation.
- expect(onOpenPreview).toHaveBeenCalledTimes(1)
+ it('file: a double-click on a non-previewable file downloads and toasts exactly once', async () => {
+ const download = vi.fn(async () => ({ bytes: new ArrayBuffer(8) }))
+ installClerum({
+ listAccessible: vi.fn(async () => ({
+ items: [node('zip-1', 'archive.zip', 'file')],
+ nextCursor: null,
+ })),
+ download,
+ })
+
+ const { onOpenPreview, pushToast } = renderTree()
+
+ const fileButton = await screen.findByRole('button', { name: 'archive.zip' })
+
+ // The real double-click sequence: two clicks then the dblclick, driven
+ // synchronously so the in-flight download is still running when the later
+ // events arrive. The download has no host-level dedupe (unlike preview), so
+ // without the in-flight guard this saves the file and toasts three times.
+ fireEvent.click(fileButton)
+ fireEvent.click(fileButton)
+ fireEvent.doubleClick(fileButton)
+
+ await waitFor(() => expect(pushToast).toHaveBeenCalledWith('Downloaded archive.zip', 'success'))
+ expect(download).toHaveBeenCalledTimes(1)
+ expect(pushToast).toHaveBeenCalledTimes(1)
+ expect(onOpenPreview).not.toHaveBeenCalled()
})
})
-describe('FileExplorerTree — Enter activates (§3.A.4)', () => {
+describe('FileExplorerTree — Enter activates', () => {
it('folder: Enter opens the files tab and does not expand', async () => {
const listChildren = vi.fn(async () => ({ items: [], nextCursor: null }))
installClerum({
@@ -305,8 +342,8 @@ describe('FileExplorerTree — Enter activates (§3.A.4)', () => {
})
})
-describe('FileExplorerTree — single-click never navigates', () => {
- it('selects a file on single-click without opening a preview tab', async () => {
+describe('FileExplorerTree — file single-click activates', () => {
+ it('opens the preview tab and selects a previewable file on single-click', async () => {
installClerum({
listAccessible: vi.fn(async () => ({
items: [node('img-1', 'photo.png', 'file')],
@@ -320,35 +357,18 @@ describe('FileExplorerTree — single-click never navigates', () => {
const treeitem = fileButton.closest('[role="treeitem"]') as HTMLElement
expect(treeitem.getAttribute('aria-selected')).toBe('false')
+ // A single-click activates a file immediately — no 250ms deferral.
fireEvent.click(fileButton)
- // The deferred single-click resolves to selection only (aria-selected), and
- // never to a preview tab — even after the single-vs-double window elapses.
- await waitFor(() => expect(treeitem.getAttribute('aria-selected')).toBe('true'))
- expect(onOpenPreview).not.toHaveBeenCalled()
- })
-})
-
-describe('FileExplorerTree — double-click activation', () => {
- it('opens a preview tab for a previewable file on double-click', async () => {
- installClerum({
- listAccessible: vi.fn(async () => ({
- items: [node('img-1', 'photo.png', 'file')],
- nextCursor: null,
- })),
- })
- const { onOpenPreview } = renderTree()
-
- const fileButton = await screen.findByRole('button', { name: 'photo.png' })
- fireEvent.doubleClick(fileButton)
-
expect(onOpenPreview).toHaveBeenCalledTimes(1)
expect(onOpenPreview).toHaveBeenCalledWith(
expect.objectContaining({ kind: 'image', gfsUri: 'gfs://main/img-1', name: 'photo.png' })
)
+ // Activating a file also selects it, so selection still follows a single-click.
+ await waitFor(() => expect(treeitem.getAttribute('aria-selected')).toBe('true'))
})
- it('downloads a non-previewable file on double-click and toasts success', async () => {
+ it('downloads a non-previewable file on single-click and toasts success', async () => {
const download = vi.fn(async () => ({ bytes: new ArrayBuffer(8) }))
installClerum({
listAccessible: vi.fn(async () => ({
@@ -361,7 +381,7 @@ describe('FileExplorerTree — double-click activation', () => {
const { onOpenPreview, pushToast } = renderTree()
const fileButton = await screen.findByRole('button', { name: 'archive.zip' })
- fireEvent.doubleClick(fileButton)
+ fireEvent.click(fileButton)
await waitFor(() => expect(download).toHaveBeenCalledWith('gfs://main/zip-1'))
await waitFor(() => expect(pushToast).toHaveBeenCalledWith('Downloaded archive.zip', 'success'))
@@ -369,6 +389,45 @@ describe('FileExplorerTree — double-click activation', () => {
})
})
+describe('FileExplorerTree — folder single-click toggles, not navigates', () => {
+ it('expands a folder on single-click of its label and never opens a files tab', async () => {
+ const listChildren = vi.fn(async () => ({
+ items: [node('sub-1', 'Sub', 'directory')],
+ nextCursor: null,
+ }))
+ installClerum({
+ listAccessible: vi.fn(async () => ({
+ items: [node('reports', 'Reports', 'directory')],
+ nextCursor: null,
+ })),
+ listChildren,
+ })
+
+ const { onOpenFolder } = renderTree()
+
+ const folderButton = await screen.findByRole('button', { name: 'Reports' })
+ const treeitem = folderButton.closest('[role="treeitem"]') as HTMLElement
+
+ // The folder toggle is deferred; nothing happens until the 250ms window
+ // elapses without a double-click cancelling it.
+ vi.useFakeTimers()
+ try {
+ fireEvent.click(folderButton)
+ act(() => {
+ vi.advanceTimersByTime(300)
+ })
+ } finally {
+ vi.useRealTimers()
+ }
+
+ // The single-click toggled the folder open and fetched its children — it did
+ // NOT open the folder's files tab (that stays a double-click / Enter gesture).
+ await waitFor(() => expect(treeitem.getAttribute('aria-expanded')).toBe('true'))
+ await waitFor(() => expect(listChildren).toHaveBeenCalledWith('reports', 'main', undefined))
+ expect(onOpenFolder).not.toHaveBeenCalled()
+ })
+})
+
describe('FileExplorerTree — folder activation focuses an existing files tab', () => {
// Drives the real `openFilesTab` reducer (the tab store producer) so the
// observable outcome — tab count and which tab is active — is asserted (T4),
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
index 630d7dc7e..4c31da828 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
@@ -14,9 +14,10 @@ import { sanitizeAppTabTitle } from '@lib/sanitizeAppTabTitle'
import { IconChevronRight, IconContexts } from '../icons'
import type { FileExplorerNodeProps, FileExplorerTreeProps } from './types'
-// Single-click must not act before we know a double-click is not coming
-// (spec 18 §3.A.4): a single-click's toggle/select is deferred by this window so
-// a double-click (open tab / preview) can cancel it first.
+// A folder's single-click (toggle) must not act before we know a double-click
+// (open its files tab) is not coming, so it is deferred by this window to let a
+// double-click cancel it first. Files have no such ambiguity — a single-click
+// activates them immediately — so this delay applies to folders only.
const DOUBLE_CLICK_DELAY_MS = 250
function errorMessage(error: unknown): string | null {
@@ -46,9 +47,10 @@ function sortTreeItems(items: GfsBrowserChild[]): GfsBrowserChild[] {
/**
* One node of the sidebar file explorer. Extracted from `GfsMoveTreeFolder`
* (recursion, expand `Set`, lazy per-node `gfsChildren` fetch, "Load more",
- * ARIA tree roles) but, unlike the move picker, it lists BOTH folders and files
- * (spec 18 §3.A.1). A single-click toggles a folder / selects a file; opening a
- * tab or a preview is reserved for the double-click / Enter gesture (§3.A.4).
+ * ARIA tree roles) but, unlike the move picker, it lists BOTH folders and files.
+ * Gestures differ by kind: a file activates on single-click (open its preview,
+ * or download when it is not previewable); a folder toggles expand/collapse on
+ * single-click and opens its files tab on double-click. Enter activates either.
*/
function FileExplorerNode({
node,
@@ -58,7 +60,6 @@ function FileExplorerNode({
expandedIds,
selectedId,
onToggle,
- onSelect,
onActivateFolder,
onActivateFile,
onAuthorityFailure,
@@ -89,7 +90,7 @@ function FileExplorerNode({
if (childError) onAuthorityFailure(childError)
}, [childError, onAuthorityFailure])
- // Deferred single-click: cancelled by a double-click within the window.
+ // Deferred folder toggle: cancelled by a double-click within the window.
const clickTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const clearClickTimer = useCallback(() => {
if (clickTimerRef.current !== null) {
@@ -99,11 +100,6 @@ function FileExplorerNode({
}, [])
useEffect(() => clearClickTimer, [clearClickTimer])
- const runSingleClick = useCallback(() => {
- if (isDirectory) onToggle(node.resourceId)
- else onSelect(node.resourceId)
- }, [isDirectory, node.resourceId, onSelect, onToggle])
-
const runActivate = useCallback(() => {
if (isDirectory) onActivateFolder(node)
else onActivateFile(node)
@@ -111,11 +107,21 @@ function FileExplorerNode({
const handleRowClick = useCallback(() => {
clearClickTimer()
+ // A file has no single/double-click ambiguity: single-click activates it
+ // (open preview, or download when not previewable) immediately — no delay.
+ // A double-click on a file just re-activates it idempotently. onActivateFile
+ // also selects the node, so selection still follows a file's single-click.
+ if (!isDirectory) {
+ runActivate()
+ return
+ }
+ // A folder's single-click toggles expand/collapse, but that is deferred so a
+ // double-click (open its files tab) can cancel the toggle first.
clickTimerRef.current = setTimeout(() => {
clickTimerRef.current = null
- runSingleClick()
+ onToggle(node.resourceId)
}, DOUBLE_CLICK_DELAY_MS)
- }, [clearClickTimer, runSingleClick])
+ }, [clearClickTimer, isDirectory, node.resourceId, onToggle, runActivate])
const handleRowDoubleClick = useCallback(() => {
clearClickTimer()
@@ -126,7 +132,8 @@ function FileExplorerNode({
(event: React.KeyboardEvent<HTMLButtonElement>) => {
if (event.key !== 'Enter') return
// Stop the native button click Enter would otherwise fire (which would run
- // the single-click action); Enter activates, matching double-click.
+ // the row's single-click handler — a folder's deferred toggle); Enter
+ // activates instead, matching the folder double-click / file single-click.
event.preventDefault()
clearClickTimer()
runActivate()
@@ -194,7 +201,6 @@ function FileExplorerNode({
onActivateFile={onActivateFile}
onActivateFolder={onActivateFolder}
onAuthorityFailure={onAuthorityFailure}
- onSelect={onSelect}
onToggle={onToggle}
scope={scope}
selectedId={selectedId}
@@ -250,10 +256,6 @@ export function FileExplorerTree({
})
}, [])
- const handleSelect = useCallback((resourceId: string) => {
- setSelectedId(resourceId)
- }, [])
-
const handleActivateFolder = useCallback(
(node: GfsBrowserChild) => {
onOpenFolder(node.gfsUri)
@@ -269,6 +271,14 @@ export function FileExplorerTree({
[authorityFailure]
)
+ // A file now activates on single-click, so a real double-click (or accidental
+ // rapid clicks) fires activation more than once. The preview path is naturally
+ // idempotent — the host dedupes preview tabs by gfsUri — but a download has no
+ // such guard, so repeated activations would save the file and toast N times.
+ // Track in-flight downloads by gfsUri and drop any activation for one already
+ // running, making a file's double-click idempotent on the download path too.
+ const downloadsInFlight = useRef<Set<string>>(new Set())
+
const handleActivateFile = useCallback(
(node: GfsBrowserChild) => {
setSelectedId(node.resourceId)
@@ -277,6 +287,8 @@ export function FileExplorerTree({
onOpenPreview(preview)
return
}
+ if (downloadsInFlight.current.has(node.gfsUri)) return
+ downloadsInFlight.current.add(node.gfsUri)
void (async () => {
try {
// The raw name is the real on-disk filename; the toast shows the cleaned one.
@@ -286,6 +298,8 @@ export function FileExplorerTree({
const message = error instanceof Error ? error.message : String(error)
if (authorityFailure(message, 'operation')) return
pushToast(message, 'error')
+ } finally {
+ downloadsInFlight.current.delete(node.gfsUri)
}
})()
},
@@ -316,7 +330,6 @@ export function FileExplorerTree({
onActivateFile={handleActivateFile}
onActivateFolder={handleActivateFolder}
onAuthorityFailure={handleAuthorityFailure}
- onSelect={handleSelect}
onToggle={handleToggle}
scope={ctrl.sessionScope}
selectedId={selectedId}
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/types.ts b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/types.ts
index ca3c28539..56f84a3d4 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/types.ts
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/types.ts
@@ -3,14 +3,14 @@ import type { GfsPreviewResource } from '@lib/gfsPreview'
import type { Tone } from '@/uiTypes'
/**
- * Actions the sidebar file explorer hands back to the app. Folder and file
- * activation are the DOUBLE-CLICK / Enter gestures (spec 18 §3.A.4); a
- * single-click only toggles/selects inside the tree and never reaches here.
+ * Actions the sidebar file explorer hands back to the app. A file activates on
+ * single-click; a folder opens its files tab on double-click / Enter (its
+ * single-click only toggles expand/collapse inside the tree).
*/
export interface FileExplorerTreeProps {
/** Double-click / Enter on a folder → open (or focus) its files tab. */
onOpenFolder: (gfsUri: string) => void
- /** Double-click / Enter on a previewable file → open (or focus) its preview tab. */
+ /** Single-click / Enter on a previewable file → open (or focus) its preview tab. */
onOpenPreview: (preview: GfsPreviewResource) => void
/** Transient success/error feedback for the download fallback. */
pushToast: (message: string, tone: Tone) => void
@@ -28,7 +28,6 @@ export interface FileExplorerNodeProps {
expandedIds: ReadonlySet<string>
selectedId: string | null
onToggle: (resourceId: string) => void
- onSelect: (resourceId: string) => void
onActivateFolder: (node: GfsBrowserChild) => void
onActivateFile: (node: GfsBrowserChild) => void
/** Fail-closed hook: a listing authority error revokes the session. */
diff --git a/desktop-app/ui/src/components/SidebarNav/types.ts b/desktop-app/ui/src/components/SidebarNav/types.ts
index c9fa4f2cf..372893cdd 100644
--- a/desktop-app/ui/src/components/SidebarNav/types.ts
+++ b/desktop-app/ui/src/components/SidebarNav/types.ts
@@ -12,10 +12,10 @@ export type SidebarNavProps = {
onSettingsMenuOpenChange?: (open: boolean) => void
onSelect: (item: NavItem) => void
/** Open (or focus) a files tab at a folder's gfsUri — the file explorer's
- * double-click-on-folder action (spec 18 §3.A.4). */
+ * double-click / Enter action on a folder. */
onOpenFilesSection: (gfsUri: string) => void
- /** Open (or focus) a preview tab — the file explorer's double-click on a
- * previewable file (spec 18 §3.A.4). */
+ /** Open (or focus) a preview tab — the file explorer's single-click / Enter
+ * action on a previewable file. */
onOpenPreviewSection: (preview: GfsPreviewResource) => void
/** Transient feedback for the file explorer's download fallback. */
pushToast: (message: string, tone: Tone) => void