Skip to content

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

TypeScript

fix(desktop): rp-019 rp-024 fix the sidebar root drop state and the hover-expand timer

M6ee5ebd5d2d4
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 c6d2ab4de..2417cd07a 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
@@ -3,6 +3,7 @@ import { useRef, useState } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { QueryClient, QueryClientProvider, focusManager } from '@tanstack/react-query'
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import { FOLDER_HOVER_EXPAND_DELAY_MS } from '@constants/gfsBrowser'
import { useGfsBrowserController } from '@hooks/domain/useGfsBrowserController'
import { desktopQueryDefaults } from '@lib/queryClient'
import { activeWorkspaceTab, openFilesTab } from '@lib/workspaceTabs'
@@ -1397,6 +1398,109 @@ describe('FileExplorerTree — drag-and-drop moves', () => {
expect(treeItem.getAttribute('aria-expanded')).toBe('false')
})
+ it('gives the forest ROOT rows their drop state (RP-019)', async () => {
+ // The forest roots are drop targets like any nested row. Before the fix
+ // the root node never received its own `dropState`, so the verdict was
+ // painted nowhere: the drag looked dead on the very rows the user aims at.
+ const affordances = vi.fn(async (resourceId: string) => {
+ if (resourceId === 'folderb') return { held: ['read', 'write'] }
+ return { held: ['read', 'write', 'delete'] }
+ })
+ const resolve = vi.fn(async (uri: string) => {
+ const id = uri.split('/').pop()
+ return {
+ drive: 'main',
+ resourceId: id === 'grand' ? 'grand' : id,
+ parentResourceId: id === 'grand' ? null : 'grand',
+ name: id === 'foldera' ? 'A' : id === 'folderb' ? 'B' : 'Grand',
+ kind: 'directory',
+ version: id === 'foldera' ? 4 : 1,
+ }
+ })
+ installDndClerum({
+ listAccessible: vi.fn(async () =>
+ listAccessiblePage([
+ accessibleResource('foldera', 'A', 'directory', { version: 4 }),
+ accessibleResource('folderb', 'B', 'directory'),
+ ])
+ ),
+ affordances,
+ resolve,
+ moveResource: vi.fn(async () => ({ resourceId: 'foldera', version: 9 })),
+ })
+ renderTreeWithSession()
+
+ const rowA = await screen.findByRole('button', { name: 'A' })
+ const rowB = await screen.findByRole('button', { name: 'B' })
+ const dataTransfer = dragTypes()
+ const bRow = rowB.closest('[role="treeitem"]')!.querySelector('.da-file-explorer__row')!
+
+ fireEvent.dragStart(rowA, { dataTransfer })
+ fireEvent.dragOver(bRow, { dataTransfer })
+
+ // The root row carries the verdict, exactly like a nested row does.
+ expect(bRow.getAttribute('data-drop-state')).toBe('checking')
+ })
+
+ it('cancels the hover-expand timer when the drop lands on the row (RP-024)', async () => {
+ // The browser does not necessarily fire a dragleave after a drop, so the
+ // row's own hover-expand timer survived the drop: the folder expanded
+ // after the gesture ended, opening a folder the user never asked for.
+ const affordances = vi.fn(async (resourceId: string) => {
+ if (resourceId === 'folderb') return { held: ['read', 'write'] }
+ return { held: ['read', 'write', 'delete'] }
+ })
+ const resolve = vi.fn(async (uri: string) => {
+ const id = uri.split('/').pop()
+ return {
+ drive: 'main',
+ resourceId: id === 'grand' ? 'grand' : id,
+ parentResourceId: id === 'grand' ? null : 'grand',
+ name: id === 'foldera' ? 'A' : id === 'folderb' ? 'B' : 'Grand',
+ kind: 'directory',
+ version: id === 'foldera' ? 4 : 1,
+ }
+ })
+ installDndClerum({
+ listAccessible: vi.fn(async () =>
+ listAccessiblePage([
+ accessibleResource('foldera', 'A', 'directory', { version: 4 }),
+ accessibleResource('folderb', 'B', 'directory'),
+ ])
+ ),
+ affordances,
+ resolve,
+ moveResource: vi.fn(async () => ({ resourceId: 'foldera', version: 9 })),
+ })
+ renderTreeWithSession()
+
+ const rowA = await screen.findByRole('button', { name: 'A' })
+ const rowB = await screen.findByRole('button', { name: 'B' })
+ const dataTransfer = dragTypes()
+ const bRow = rowB.closest('[role="treeitem"]')!.querySelector('.da-file-explorer__row')!
+
+ // The hover-expand delay is the thing under test: fake the timers only
+ // once the rows exist, so the queries above keep their real clock.
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
+ try {
+ fireEvent.dragStart(rowA, { dataTransfer })
+ // The dwell over the collapsed folder schedules its hover-expand.
+ fireEvent.dragOver(bRow, { dataTransfer })
+ // The drop ends the gesture.
+ fireEvent.drop(bRow, { dataTransfer })
+
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(FOLDER_HOVER_EXPAND_DELAY_MS + 50)
+ })
+
+ // B is still collapsed: the user never asked to open it.
+ expect(screen.getByRole('button', { name: 'Expand B' })).toBeTruthy()
+ expect(screen.queryByRole('button', { name: 'Collapse B' })).toBeNull()
+ } finally {
+ vi.useRealTimers()
+ }
+ })
+
it('Shift+F10 opens the existing Move dialog from the tree row', async () => {
installDndClerum({
listAccessible: vi.fn(async () =>
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
index c6f447f9a..432cfa666 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
@@ -211,6 +211,18 @@ function FileExplorerNode({
const isDirectoryRow = isDirectory
const canDrag = isUnreadable !== true && movingResourceId == null
+ // Hover a collapsed directory for FOLDER_HOVER_EXPAND_DELAY_MS to expand it
+ // through its existing loader (rev-2 §4.1). The timer is owned here so a
+ // leave/drop/drag-end in this row cancels exactly its own expansion.
+ const hoverExpandTimerRef = useRef<number | null>(null)
+ const clearHoverExpand = useCallback(() => {
+ if (hoverExpandTimerRef.current !== null) {
+ clearTimeout(hoverExpandTimerRef.current)
+ hoverExpandTimerRef.current = null
+ }
+ }, [])
+ useEffect(() => clearHoverExpand, [clearHoverExpand])
+
const handleRowDragOver = useCallback(
(event: React.DragEvent<HTMLDivElement>) => {
// Nested rows live in the sibling `.da-file-explorer__group`, so a child
@@ -231,23 +243,15 @@ function FileExplorerNode({
const closestRow = event.target.closest('.da-file-explorer__row')
if (closestRow !== null && closestRow !== event.currentTarget) return
}
+ // The drop ends the gesture; the browser does not necessarily fire a
+ // dragleave afterwards, so this row's OWN hover-expand timer would still
+ // fire and expand a folder the user never asked to open (RP-024).
+ clearHoverExpand()
onNodeDrop(node, event, ancestorIds)
},
- [ancestorIds, node, onNodeDrop]
+ [ancestorIds, clearHoverExpand, node, onNodeDrop]
)
- // Hover a collapsed directory for FOLDER_HOVER_EXPAND_DELAY_MS to expand it
- // through its existing loader (rev-2 §4.1). The timer is owned here so a
- // leave/drop/drag-end in this row cancels exactly its own expansion.
- const hoverExpandTimerRef = useRef<number | null>(null)
- const clearHoverExpand = useCallback(() => {
- if (hoverExpandTimerRef.current !== null) {
- clearTimeout(hoverExpandTimerRef.current)
- hoverExpandTimerRef.current = null
- }
- }, [])
- useEffect(() => clearHoverExpand, [clearHoverExpand])
-
const handleRowDragEnterOrOver = useCallback(
(event: React.DragEvent<HTMLDivElement>) => {
handleRowDragOver(event)
@@ -667,17 +671,17 @@ export function FileExplorerTree({
source.parentKnown ? source.parentResourceId : null,
() => {
if (hoverOwnerRef.current !== source) return
- setDropStatesByResourceId(previous => {
- const fresh = adjudication.hoverVerdict(source, {
- resourceId: node.resourceId,
- name: node.name,
- kind: node.kind,
- ancestorIds,
- })
- return previous[node.resourceId] === fresh.state
+ const fresh = adjudication.hoverVerdict(source, {
+ resourceId: node.resourceId,
+ name: node.name,
+ kind: node.kind,
+ ancestorIds,
+ })
+ setDropStatesByResourceId(previous =>
+ previous[node.resourceId] === fresh.state
? previous
: { ...previous, [node.resourceId]: fresh.state }
- })
+ )
}
)
}
@@ -901,6 +905,10 @@ export function FileExplorerTree({
accessActive={ctrl.accessState === 'active'}
ancestorCrumbs={[]}
ancestorIds={node.parentResourceId != null ? [node.parentResourceId] : []}
+ // The forest roots are drop targets like any other row: their
+ // verdict belongs to them, so the root row receives its own
+ // state instead of only the map its children read (RP-019).
+ dropState={dropStatesByResourceId[node.resourceId]}
dropStatesByResourceId={dropStatesByResourceId}
expandedIds={expandedIds}
key={node.resourceId}