Skip to content

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

TypeScript

fix(gfs-ui): refuse no-op moves, dedupe the shared root, and refresh listings

M93d86a37b9a2
diff --git a/control-ui/components/GfsMoveDialog/index.tsx b/control-ui/components/GfsMoveDialog/index.tsx
index a43770b1b..bece8f862 100644
--- a/control-ui/components/GfsMoveDialog/index.tsx
+++ b/control-ui/components/GfsMoveDialog/index.tsx
@@ -12,6 +12,9 @@ type MoveFolder = {
resourceId: string
name: string
kind: string
+ /** Present on browser rows — used to refuse a no-op move into the folder
+ * that already contains the target. */
+ parentResourceId?: string | null
}
type MoveCrumb = {
@@ -196,17 +199,24 @@ export function GfsMoveDialog({
onClose,
onMove,
}: GfsMoveDialogProps) {
- const initialDestination = [...initialCrumbs]
+ // The nearest crumb that is not the target itself is the folder that
+ // already contains it (both entry paths end there). Selecting it is a
+ // no-op the server accepts while visibly changing nothing, so it must not
+ // be preselected and must not be committable.
+ const currentParent = [...initialCrumbs]
.reverse()
.find(crumb => crumb.id && crumb.id !== target.resourceId)
- const [selected, setSelected] = useState<SelectedDestination | null>(() =>
- initialDestination?.id
- ? {
- resourceId: initialDestination.id,
- name: initialDestination.name === '/' ? DRIVE : initialDestination.name,
- }
+ const currentParentId =
+ typeof target.parentResourceId === 'string'
+ ? target.parentResourceId
+ : (currentParent?.id ?? null)
+ const currentParentName =
+ currentParent && currentParent.id === currentParentId
+ ? currentParent.name === '/'
+ ? DRIVE
+ : currentParent.name
: null
- )
+ const [selected, setSelected] = useState<SelectedDestination | null>(null)
const [expandedIds, setExpandedIds] = useState<Set<string>>(
() => new Set(initialCrumbs.flatMap(crumb => (crumb.id ? [crumb.id] : [])))
)
@@ -276,6 +286,8 @@ export function GfsMoveDialog({
}
}
+ const isNoOpDestination = Boolean(selected && selected.resourceId === currentParentId)
+
return (
<div
className="cu-modal-backdrop cu-gfs-move-modal"
@@ -311,7 +323,7 @@ export function GfsMoveDialog({
<span>Current location:</span>
<span className="cu-gfs-move-dialog__location-pill">
<IconFolder />
- <strong>{selected?.name ?? 'Choose a folder'}</strong>
+ <strong>{currentParentName ?? (currentParentId ? 'another folder' : DRIVE)}</strong>
</span>
</div>
@@ -372,7 +384,7 @@ export function GfsMoveDialog({
</Button>
<Button
aria-label={selected ? `Move here (${selected.name})` : 'Move'}
- disabled={!selected}
+ disabled={!selected || isNoOpDestination}
loading={busy}
onClick={() => void commit()}
variant="primary"
@@ -381,6 +393,12 @@ export function GfsMoveDialog({
</Button>
</span>
</footer>
+ {isNoOpDestination ? (
+ <p className="cu-gfs-move-dialog__notice">
+ {target.name} is already in {currentParentName ?? 'the folder you selected'} — pick a
+ different destination.
+ </p>
+ ) : null}
</section>
</div>
)
diff --git a/control-ui/components/__tests__/GfsMoveDialog.test.tsx b/control-ui/components/__tests__/GfsMoveDialog.test.tsx
index 4213cedff..2c8dfa55d 100644
--- a/control-ui/components/__tests__/GfsMoveDialog.test.tsx
+++ b/control-ui/components/__tests__/GfsMoveDialog.test.tsx
@@ -49,13 +49,60 @@ describe('GfsMoveDialog', () => {
const archive = await within(dialog).findByRole('button', { name: 'Archive' })
expect(archive.classList.contains('cu-gfs-move-dialog__tree-select')).toBe(true)
+
+ // The location pill reports the folder that CONTAINS the target (from the
+ // crumbs) — never the pending selection.
+ expect(within(dialog).getAllByText('Product', { selector: 'strong' })).toHaveLength(1)
fireEvent.click(archive)
await waitFor(() => {
- expect(within(dialog).getAllByText('Archive', { selector: 'strong' })).toHaveLength(2)
+ expect(within(dialog).getAllByText('Archive', { selector: 'strong' })).toHaveLength(1)
+ })
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Archive)' }))
+
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith('archive-1', 'Archive'))
+ })
+
+ it('refuses a no-op move into the folder that already contains the target', async () => {
+ mockApiGet.mockImplementation(async path => {
+ if (path === '/api/v1/gfs/tree') {
+ return {
+ items: [
+ { resourceId: 'product-1', name: 'Product', kind: 'directory' },
+ { resourceId: 'archive-1', name: 'Archive', kind: 'directory' },
+ ],
+ nextCursor: null,
+ }
+ }
+ return { items: [], nextCursor: null }
})
+ const onMove = vi.fn(async () => undefined)
+
+ render(
+ <GfsMoveDialog
+ initialCrumbs={[{ id: 'product-1', name: 'Product' }]}
+ onClose={vi.fn()}
+ onMove={onMove}
+ target={{ resourceId: 'file-1', name: 'notes.txt', kind: 'file' }}
+ />
+ )
+
+ const dialog = screen.getByRole('dialog', { name: 'Move file notes.txt' })
+ // The current parent is never preselected.
+ expect(within(dialog).getByText('Select a destination folder')).toBeTruthy()
+
+ const product = await within(dialog).findByRole('button', { name: 'Product' })
+ fireEvent.click(product)
+ const noOpButton = within(dialog).getByRole('button', {
+ name: 'Move here (Product)',
+ }) as HTMLButtonElement
+ expect(noOpButton.disabled).toBe(true)
+ expect(within(dialog).getByText(/is already in Product/)).toBeTruthy()
+
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Archive' }))
fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Archive)' }))
await waitFor(() => expect(onMove).toHaveBeenCalledWith('archive-1', 'Archive'))
+ expect(onMove).toHaveBeenCalledTimes(1)
})
})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index c4955757e..50ce100e7 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.507",
+ "version": "0.1.508",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.507",
+ "version": "0.1.508",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 2efc57da5..b25028709 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.507",
+ "version": "0.1.508",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/desktop-app/ui/src/gfs/__tests__/moveDialog.test.tsx b/desktop-app/ui/src/gfs/__tests__/moveDialog.test.tsx
index 271b1536c..05885915f 100644
--- a/desktop-app/ui/src/gfs/__tests__/moveDialog.test.tsx
+++ b/desktop-app/ui/src/gfs/__tests__/moveDialog.test.tsx
@@ -194,3 +194,59 @@ describe('GfsMoveDialog pagination', () => {
expect(within(dialog).queryByRole('button', { name: 'Load more' })).toBeNull()
})
})
+
+describe('GfsMoveDialog no-op destination guard', () => {
+ it('does not preselect the current parent and reports the real current location', async () => {
+ const listAccessible = vi.fn(async () => ({
+ items: [folder('folder-1', 'Product'), folder('arch-1', 'Archive')],
+ nextCursor: null,
+ }))
+
+ renderDialog({ listAccessible }, { initialCrumbs: [parentCrumb] })
+
+ const dialog = await screen.findByRole('dialog', { name: 'Move file notes.txt' })
+ // The location pill names the folder that CONTAINS the target (the last
+ // crumb), never the selection — and the old trap preselected exactly it.
+ expect(within(dialog).getByText('Product', { selector: 'strong' })).toBeTruthy()
+ expect(within(dialog).getByText('Select a destination folder')).toBeTruthy()
+ const moveButton = within(dialog).getByRole('button', { name: 'Move' }) as HTMLButtonElement
+ expect(moveButton.disabled).toBe(true)
+ })
+
+ it('refuses a no-op move into the folder that already contains the target', async () => {
+ const onMove = vi.fn(async () => undefined)
+ const listAccessible = vi.fn(async () => ({
+ items: [folder('folder-1', 'Product'), folder('arch-1', 'Archive')],
+ nextCursor: null,
+ }))
+
+ // Row-style target carrying its real parent id (e.g. a root-listed file
+ // that actually lives in a shared folder).
+ renderDialog(
+ { listAccessible },
+ {
+ onMove,
+ target: { ...target, parentResourceId: 'folder-1' },
+ initialCrumbs: [],
+ }
+ )
+
+ const dialog = await screen.findByRole('dialog', { name: 'Move file notes.txt' })
+ // No breadcrumb context: the pill is honest about the unknown name.
+ expect(within(dialog).getByText('another shared folder')).toBeTruthy()
+
+ const productRow = await within(dialog).findByRole('button', { name: 'Product' })
+ await fireEvent.click(productRow)
+ const noOpButton = within(dialog).getByRole('button', {
+ name: 'Move here (Product)',
+ }) as HTMLButtonElement
+ expect(noOpButton.disabled).toBe(true)
+ expect(within(dialog).getByText(/is already in/)).toBeTruthy()
+
+ // A different destination still commits normally.
+ await fireEvent.click(within(dialog).getByRole('button', { name: 'Archive' }))
+ await fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Archive)' }))
+ expect(onMove).toHaveBeenCalledWith('arch-1', 'Archive')
+ expect(onMove).toHaveBeenCalledTimes(1)
+ })
+})
diff --git a/desktop-app/ui/src/gfs/moveDialog.tsx b/desktop-app/ui/src/gfs/moveDialog.tsx
index a94e99d7d..b774e73e7 100644
--- a/desktop-app/ui/src/gfs/moveDialog.tsx
+++ b/desktop-app/ui/src/gfs/moveDialog.tsx
@@ -183,13 +183,34 @@ export function GfsMoveDialog({
onAuthorityFailure,
}: GfsMoveDialogProps) {
const initialDestination = initialCrumbs[initialCrumbs.length - 1]
+ // The folder that already contains the target. Row moves carry the real
+ // parent id; for the current resource the sliced crumbs end at its parent.
+ // Selecting it as the destination is a no-op the server accepts (it bumps
+ // the version and changes nothing), so the dialog must refuse it instead
+ // of confirming a "successful" move that visibly changed nothing.
+ const currentParentId =
+ typeof target.parentResourceId === 'string'
+ ? target.parentResourceId
+ : initialDestination && initialDestination.resourceId !== target.resourceId
+ ? initialDestination.resourceId
+ : null
+ const currentParentName =
+ initialDestination && initialDestination.resourceId === currentParentId
+ ? initialDestination.name
+ : null
const [expandedFolderIds, setExpandedFolderIds] = useState<Set<string>>(
() => new Set(initialCrumbs.map(crumb => crumb.resourceId))
)
- const [selectedDestination, setSelectedDestination] = useState<SelectedDestination | null>(() =>
- initialDestination && initialDestination.resourceId !== target.resourceId
- ? { resourceId: initialDestination.resourceId, name: initialDestination.name }
- : null
+ const [selectedDestination, setSelectedDestination] = useState<SelectedDestination | null>(
+ // Never preselect the target's own folder — in every entry path the last
+ // crumb IS the current parent, so the old preselect only ever armed the
+ // no-op move described above.
+ () =>
+ initialDestination &&
+ initialDestination.resourceId !== target.resourceId &&
+ initialDestination.resourceId !== currentParentId
+ ? { resourceId: initialDestination.resourceId, name: initialDestination.name }
+ : null
)
const [error, setError] = useState<string | null>(null)
const scope = sessionScope ?? 'anonymous'
@@ -239,6 +260,9 @@ export function GfsMoveDialog({
const pathPassesThroughTarget =
initialCrumbs.some(crumb => crumb.resourceId === target.resourceId) ||
selectedDestination?.resourceId === target.resourceId
+ const isNoOpDestination = Boolean(
+ selectedDestination && selectedDestination.resourceId === currentParentId
+ )
// Destination listings are session-scoped GFS reads: an authority failure
// here must reach the same fail-closed boundary as the page's queries (the
@@ -311,7 +335,10 @@ export function GfsMoveDialog({
<span>Current location:</span>
<span className="da-gfs-move-dialog__location-pill">
<IconContexts />
- <strong>{selectedDestination?.name ?? 'Choose a folder'}</strong>
+ <strong>
+ {currentParentName ??
+ (currentParentId ? 'another shared folder' : 'Shared with me')}
+ </strong>
</span>
</div>
<div className="da-gfs-move-dialog__tree-heading">
@@ -380,7 +407,7 @@ export function GfsMoveDialog({
aria-label={
selectedDestination ? `Move here (${selectedDestination.name})` : 'Move'
}
- disabled={!selectedDestination || pathPassesThroughTarget}
+ disabled={!selectedDestination || pathPassesThroughTarget || isNoOpDestination}
loading={busy}
onClick={() => void commit()}
type="button"
@@ -392,6 +419,12 @@ export function GfsMoveDialog({
{pathPassesThroughTarget ? (
<p className="muted">A folder can’t be moved into its own subtree.</p>
) : null}
+ {isNoOpDestination ? (
+ <p className="muted">
+ {target.name} is already in {currentParentName ?? 'the folder you selected'} — pick a
+ different destination.
+ </p>
+ ) : null}
</div>
</section>
</div>
diff --git a/desktop-app/ui/src/gfs/moveDialog.types.ts b/desktop-app/ui/src/gfs/moveDialog.types.ts
index cfe218f3d..ed0170476 100644
--- a/desktop-app/ui/src/gfs/moveDialog.types.ts
+++ b/desktop-app/ui/src/gfs/moveDialog.types.ts
@@ -1,8 +1,15 @@
import type { GfsCrumb } from '@hooks/domain/useGfsBrowserController'
export type GfsMoveDialogProps = {
- /** The resource being moved (kind powers the dialog title + cycle guard). */
- target: { resourceId: string; name: string; kind: 'file' | 'directory' }
+ /** The resource being moved (kind powers the dialog title + cycle guard).
+ * `parentResourceId`, when known (list rows carry it), lets the dialog
+ * disable a no-op move into the folder that already contains the target. */
+ target: {
+ resourceId: string
+ name: string
+ kind: 'file' | 'directory'
+ parentResourceId?: string | null
+ }
/** Cache scope from useGfsBrowserController — shares the page's gfs queries. */
sessionScope?: string
/** Dialog-local starting path (typically the page crumbs, minus the target). */
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
index 4d080f60f..e53dcaa8c 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -2,7 +2,7 @@
import { type ReactNode, useState } from 'react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { AuthContext, type AuthContextValue } from '@contexts/AuthContext'
-import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { QueryClient, QueryClientProvider, focusManager } from '@tanstack/react-query'
import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
import { desktopQueryDefaults } from '@lib/queryClient'
import { desktopQueryKeys } from '../queryKeys'
@@ -519,6 +519,201 @@ describe('useGfsBrowserController', () => {
await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('team-folder'))
})
+ it('suppresses directly-shared files that live inside accessible folders (virtual-root hygiene)', async () => {
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ gfs: {
+ listAccessible: vi.fn(async () => ({
+ items: [
+ {
+ resourceId: 'marketing',
+ rid: 'marketing',
+ gfsUri: 'gfs://main/marketing',
+ drive: 'main',
+ parentResourceId: null,
+ name: 'Marketing',
+ kind: 'directory',
+ path: '/Marketing',
+ version: 1,
+ bytes: 0,
+ sources: ['grant'],
+ permissions: ['read'],
+ coversDescendants: true,
+ },
+ {
+ resourceId: 'shared-file',
+ rid: 'sharedfile',
+ gfsUri: 'gfs://main/sharedfile',
+ drive: 'main',
+ parentResourceId: 'marketing',
+ name: 'enterprise-ai-agents-mockup.txt',
+ kind: 'file',
+ path: '/Marketing/enterprise-ai-agents-mockup.txt',
+ version: 1,
+ bytes: 7633,
+ sources: ['grant'],
+ permissions: ['read', 'share'],
+ coversDescendants: false,
+ },
+ {
+ // Nested under an accessible folder even though its immediate
+ // parent is not itself directly listed.
+ resourceId: 'nested-file',
+ rid: 'nestedfile',
+ gfsUri: 'gfs://main/nestedfile',
+ drive: 'main',
+ parentResourceId: 'not-listed-subfolder',
+ name: 'nested.txt',
+ kind: 'file',
+ path: '/Marketing/Assets/nested.txt',
+ version: 1,
+ bytes: 12,
+ sources: ['share'],
+ permissions: ['read'],
+ coversDescendants: false,
+ },
+ {
+ // Orphan share: location not reachable — must stay listed.
+ resourceId: 'orphan-file',
+ rid: 'orphanfile',
+ gfsUri: 'gfs://main/orphanfile',
+ drive: 'main',
+ parentResourceId: null,
+ name: 'lonely.md',
+ kind: 'file',
+ path: '/lonely.md',
+ version: 1,
+ bytes: 8,
+ sources: ['share'],
+ permissions: ['read'],
+ coversDescendants: false,
+ },
+ ],
+ nextCursor: null,
+ })),
+ resolve: vi.fn(),
+ listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
+ affordances: vi.fn(async () => ({
+ held: [],
+ canDelegate: false,
+ grantableBits: [],
+ canCreateShare: false,
+ })),
+ },
+ },
+ })
+
+ render(<Probe />, { wrapper: Harness })
+
+ // The Marketing folder and the unreachable orphan stay; the two files
+ // reachable by navigating into Marketing are suppressed from the root.
+ await waitFor(() => expect(screen.getByTestId('accessible-count').textContent).toBe('2'))
+ expect(screen.getByRole('button', { name: 'open Marketing' })).toBeTruthy()
+ expect(screen.getByRole('button', { name: 'open lonely.md' })).toBeTruthy()
+ expect(
+ screen.queryByRole('button', { name: 'open enterprise-ai-agents-mockup.txt' })
+ ).toBeNull()
+ expect(screen.queryByRole('button', { name: 'open nested.txt' })).toBeNull()
+ })
+
+ it('revalidates folder listings on revisit and window focus under production cache defaults', async () => {
+ const marketingFolder = {
+ resourceId: 'folder-a',
+ rid: 'foldera',
+ gfsUri: 'gfs://main/foldera',
+ drive: 'main',
+ parentResourceId: null,
+ name: 'Marketing',
+ kind: 'directory' as const,
+ path: '/Marketing',
+ version: 1,
+ bytes: 0,
+ sources: ['grant'],
+ permissions: ['read'],
+ coversDescendants: true,
+ }
+ const financeFolder = {
+ ...marketingFolder,
+ resourceId: 'folder-b',
+ rid: 'folderb',
+ gfsUri: 'gfs://main/folderb',
+ name: 'Finance',
+ path: '/Finance',
+ }
+ const file = (id: string, name: string) => ({
+ resourceId: id,
+ rid: id,
+ gfsUri: `gfs://main/${id}`,
+ drive: 'main',
+ parentResourceId: 'folder-a',
+ name,
+ kind: 'file' as const,
+ path: `/Marketing/${name}`,
+ version: 1,
+ bytes: 10,
+ })
+ // The out-of-band writer (an agent with a host grant, or an operator).
+ let marketingItems = [file('file-1', 'report.txt')]
+ const listChildren = vi.fn(async (resourceId: string) =>
+ resourceId === 'folder-a'
+ ? { items: marketingItems, nextCursor: null }
+ : { items: [], nextCursor: null }
+ )
+ Object.defineProperty(window, 'clerum', {
+ configurable: true,
+ value: {
+ gfs: {
+ listAccessible: vi.fn(async () => ({
+ items: [marketingFolder, financeFolder],
+ nextCursor: null,
+ })),
+ listChildren,
+ affordances: vi.fn(async () => ({
+ held: [],
+ canDelegate: false,
+ grantableBits: [],
+ canCreateShare: false,
+ })),
+ resolve: vi.fn(),
+ },
+ },
+ })
+
+ render(<Probe />, { wrapper: ProductionHarness })
+
+ await waitFor(() => expect(screen.getByRole('button', { name: 'open Marketing' })).toBeTruthy())
+ await act(async () => {
+ screen.getByRole('button', { name: 'open Marketing' }).click()
+ })
+ await waitFor(() => expect(screen.getByTestId('items-count').textContent).toBe('1'))
+
+ // An agent creates a second file while the app is open.
+ marketingItems = [file('file-1', 'report.txt'), file('file-2', 'northstar.md')]
+
+ // Navigating away and back revalidates — no hard reload needed.
+ await act(async () => {
+ screen.getByRole('button', { name: 'open Finance' }).click()
+ })
+ await waitFor(() => expect(screen.getByTestId('items-count').textContent).toBe('0'))
+ await act(async () => {
+ screen.getByRole('button', { name: 'open Marketing' }).click()
+ })
+ await waitFor(() => expect(screen.getByTestId('items-count').textContent).toBe('2'))
+
+ // Focusing the window while the folder stays open revalidates in place.
+ marketingItems = [
+ file('file-1', 'report.txt'),
+ file('file-2', 'northstar.md'),
+ file('file-3', 'northstar-wordmark.svg'),
+ ]
+ await act(async () => {
+ focusManager.setFocused(false)
+ focusManager.setFocused(true)
+ })
+ await waitFor(() => expect(screen.getByTestId('items-count').textContent).toBe('3'))
+ })
+
it('hydrates readable parent folders for a directly opened file', async () => {
const rootId = '00000000-0000-0000-0000-000000000001'
const projectsId = '00000000-0000-0000-0000-000000000002'
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index 03b6d701b..aea7d5be0 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -69,6 +69,47 @@ function normalizeAccessibleResource(
}
}
+type NavigableShareRow = {
+ resourceId: string
+ kind: 'file' | 'directory'
+ path: string | null
+ parentResourceId: string | null
+}
+
+/**
+ * Virtual-root hygiene for the "Shared with me" surface. The server lists
+ * EVERY resource carrying a direct grant — including files that live inside
+ * folders the caller can already navigate into. Surfacing those twice (a
+ * loose root item with no location, plus the real folder child) hides where
+ * the file actually lives and invites acting on a different copy than
+ * intended. Suppress a file from the virtual root when an accessible folder
+ * covers it (path prefix, falling back to a direct parent match when the
+ * server omits paths). Orphan shares — files whose location is NOT otherwise
+ * reachable — stay listed; that is this surface's purpose. The filter only
+ * sees already-loaded pages, so a folder on a later page suppresses its
+ * files once that page loads.
+ */
+export function suppressNavigableShares<T extends NavigableShareRow>(rows: T[]): T[] {
+ const folderPathPrefixes = new Set(
+ rows
+ .filter(
+ (row): row is T & { path: string } =>
+ row.kind === 'directory' && typeof row.path === 'string' && row.path.length > 1
+ )
+ .map(row => (row.path.endsWith('/') ? row.path : `${row.path}/`))
+ )
+ const folderIds = new Set(rows.filter(row => row.kind === 'directory').map(row => row.resourceId))
+ return rows.filter(row => {
+ if (row.kind !== 'file') return true
+ if (typeof row.path === 'string' && row.path.length > 1) {
+ for (const prefix of folderPathPrefixes) {
+ if (row.path.startsWith(prefix)) return false
+ }
+ }
+ return !(row.parentResourceId && folderIds.has(row.parentResourceId))
+ })
+}
+
export interface GfsCrumb {
resourceId: string
gfsUri: string
@@ -204,6 +245,10 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
// Infinity-cached list must not survive a Files remount without a server
// check — even though the app-level client defaults disable refetching.
refetchOnMount: 'always',
+ // Grants are often made from another surface (control-ui, an operator,
+ // another user) while this window stays open; focusing the app must
+ // surface the new shares without a hard reload.
+ refetchOnWindowFocus: 'always',
initialPageParam: undefined as string | undefined,
getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,
})
@@ -232,6 +277,12 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
window.clerum.gfs.listChildren(current!.resourceId, DRIVE, pageParam),
enabled:
Boolean(sessionScope) && Boolean(current) && currentIsDirectory && accessState === 'active',
+ // Folder contents change out-of-band: agents with host grants, other
+ // sessions, and operator writes never pass through this client. Revisit
+ // and window focus must revalidate — an Infinity-fresh cached listing
+ // otherwise hides new files until a hard app reload.
+ refetchOnMount: 'always',
+ refetchOnWindowFocus: 'always',
initialPageParam: undefined as string | undefined,
getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,
})
@@ -537,8 +588,10 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
() =>
authorityPending
? []
- : (accessibleQuery.data?.pages ?? []).flatMap(page =>
- page.items.map(normalizeAccessibleResource)
+ : suppressNavigableShares(
+ (accessibleQuery.data?.pages ?? []).flatMap(page =>
+ page.items.map(normalizeAccessibleResource)
+ )
),
[accessibleQuery.data, authorityPending]
)
@@ -643,38 +696,74 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
onError: failClosedOnMutationError,
})
- const openChild = useCallback((child: GfsBrowserChild) => {
- if (child.kind !== 'directory') return
- setCrumbs(prev => [
- ...prev,
- {
- resourceId: child.resourceId,
- gfsUri: child.gfsUri,
- name: child.name,
- kind: 'directory',
- version: child.version,
- bytes: child.bytes,
- },
- ])
- }, [])
+ /**
+ * Revalidate a folder's children listing as navigation enters it. Folder
+ * contents change out-of-band (agents with host grants, other sessions,
+ * operator writes) and TanStack does not refetch on a live observer's
+ * query-key switch, so revisit would otherwise serve the Infinity-cached
+ * page until a hard app reload. `refetchType: 'all'` also refreshes the
+ * currently-inactive query so fresh data lands as the crumbs update.
+ */
+ const revalidateChildren = useCallback(
+ (resourceId: string) => {
+ if (!sessionScope) return
+ void queryClient.invalidateQueries({
+ exact: true,
+ queryKey: desktopQueryKeys.gfsChildren(sessionScope, resourceId, DRIVE),
+ refetchType: 'all',
+ })
+ },
+ [queryClient, sessionScope]
+ )
- const openResource = useCallback((resource: GfsBrowserChild) => {
- setOpenError(null)
- setCrumbs([
- {
- resourceId: resource.resourceId,
- gfsUri: resource.gfsUri,
- name: resource.name,
- kind: resource.kind === 'directory' ? 'directory' : 'file',
- version: resource.version,
- bytes: resource.bytes,
- },
- ])
- }, [])
+ const openChild = useCallback(
+ (child: GfsBrowserChild) => {
+ if (child.kind !== 'directory') return
+ revalidateChildren(child.resourceId)
+ setCrumbs(prev => [
+ ...prev,
+ {
+ resourceId: child.resourceId,
+ gfsUri: child.gfsUri,
+ name: child.name,
+ kind: 'directory',
+ version: child.version,
+ bytes: child.bytes,
+ },
+ ])
+ },
+ [revalidateChildren]
+ )
- const goToCrumb = useCallback((index: number) => {
- setCrumbs(prev => prev.slice(0, index + 1))
- }, [])
+ const openResource = useCallback(
+ (resource: GfsBrowserChild) => {
+ setOpenError(null)
+ if (resource.kind === 'directory') revalidateChildren(resource.resourceId)
+ setCrumbs([
+ {
+ resourceId: resource.resourceId,
+ gfsUri: resource.gfsUri,
+ name: resource.name,
+ kind: resource.kind === 'directory' ? 'directory' : 'file',
+ version: resource.version,
+ bytes: resource.bytes,
+ },
+ ])
+ },
+ [revalidateChildren]
+ )
+
+ const goToCrumb = useCallback(
+ (index: number) => {
+ setCrumbs(prev => {
+ const next = prev.slice(0, index + 1)
+ const target = next[index]
+ if (target?.kind === 'directory') revalidateChildren(target.resourceId)
+ return next
+ })
+ },
+ [revalidateChildren]
+ )
/** Restore an exact browser location after a transient resource selection
* (for example, opening a row's Manage dialog). */
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index f742dc89f..b82ba70f0 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -2,6 +2,7 @@ import {
type DragEvent as ReactDragEvent,
useCallback,
useEffect,
+ useId,
useMemo,
useRef,
useState,
@@ -162,6 +163,9 @@ const GFS_UPLOAD_NAME_RETRY_LIMIT = 100
* guard). */
type GfsActionTarget = Pick<GfsDriveResource, 'resourceId' | 'name' | 'version'> & {
kind: 'file' | 'directory'
+ /** Present on list rows (GfsBrowserChild) — the move dialog uses it to
+ * refuse a no-op move into the folder that already contains the target. */
+ parentResourceId?: string | null
}
type GfsInlineRenameProps = {
@@ -232,6 +236,7 @@ function GfsInlineRename({
export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }: FilesPageProps) {
const [createFolderName, setCreateFolderName] = useState('')
const [createFolderOpen, setCreateFolderOpen] = useState(false)
+ const [createFolderError, setCreateFolderError] = useState<string | null>(null)
const [renameName, setRenameName] = useState('')
const [renameOpen, setRenameOpen] = useState(false)
const [deleteOpen, setDeleteOpen] = useState(false)
@@ -258,6 +263,9 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
const manageReturnCrumbsRef = useRef<GfsCrumb[] | null>(null)
const uploadInputRef = useRef<HTMLInputElement | null>(null)
const uploadNameReservationsRef = useRef(new Map<string, Set<string>>())
+ const createFolderTitleId = useId()
+ const createFolderDescriptionId = useId()
+ const createFolderInputId = useId()
const queryClient = useQueryClient()
const ctrl = useGfsBrowserController({ grantsListEnabled: manageOpen })
const {
@@ -353,6 +361,32 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
manageReturnCrumbsRef.current = null
if (returnCrumbs) ctrl.restoreCrumbs(returnCrumbs)
}, [ctrl.restoreCrumbs])
+ const closeCreateFolder = useCallback(() => {
+ setCreateFolderOpen(false)
+ setCreateFolderName('')
+ setCreateFolderError(null)
+ const returnCrumbs = manageReturnCrumbsRef.current
+ manageReturnCrumbsRef.current = null
+ if (returnCrumbs) ctrl.restoreCrumbs(returnCrumbs)
+ }, [ctrl.restoreCrumbs])
+ const openCreateFolder = useCallback(() => {
+ setCreateFolderName('')
+ setCreateFolderError(null)
+ setRenameOpen(false)
+ setDeleteOpen(false)
+ setShareDetailsOpen(false)
+ setManageOpen(false)
+ setCreateFolderOpen(true)
+ }, [])
+
+ useEffect(() => {
+ if (!createFolderOpen) return
+ const handleKeyDown = (event: KeyboardEvent) => {
+ if (event.key === 'Escape' && !ctrl.mutating) closeCreateFolder()
+ }
+ window.addEventListener('keydown', handleKeyDown)
+ return () => window.removeEventListener('keydown', handleKeyDown)
+ }, [closeCreateFolder, createFolderOpen, ctrl.mutating])
const accessRevoked = ctrl.accessState === 'revoked'
// R4 spec §1: on an authority failure every local surface that could show
// or act on stale GFS data must close — preview bytes, Manage, Move, rename,
@@ -600,15 +634,15 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
const handleCreateFolder = async () => {
const requestedName = createFolderName.trim()
if (!requestedName) return
+ setCreateFolderError(null)
try {
const name = await normalizeGfsResourceName(requestedName)
await ctrl.createFolder(name)
- setCreateFolderName('')
- setCreateFolderOpen(false)
+ closeCreateFolder()
pushToast?.(`Folder ${name} created`, 'success')
} catch (createError) {
if (failClosedOnAuthorizationError(createError)) return
- pushToast?.(createError instanceof Error ? createError.message : String(createError), 'error')
+ setCreateFolderError(createError instanceof Error ? createError.message : String(createError))
}
}
@@ -1149,17 +1183,7 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
</div>
{currentIsFolder && canWriteCurrent ? (
<div className="da-gfs-drive__header-actions">
- <Button
- disabled={ctrl.mutating}
- onClick={() => {
- setCreateFolderName('')
- setCreateFolderOpen(true)
- setRenameOpen(false)
- setDeleteOpen(false)
- setManageOpen(true)
- }}
- size="sm"
- >
+ <Button disabled={ctrl.mutating} onClick={openCreateFolder} size="sm">
<IconContexts width={16} height={16} />
New folder
</Button>
@@ -1589,13 +1613,7 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
resourceName={current.name}
onCopyLink={() => void handleCopyLink(current.gfsUri)}
onCreateFolder={
- currentIsFolder && canWriteCurrent
- ? () => {
- setCreateFolderName('')
- setCreateFolderOpen(true)
- setDeleteOpen(false)
- }
- : undefined
+ currentIsFolder && canWriteCurrent ? openCreateFolder : undefined
}
onDelete={
canDeleteCurrent
@@ -1649,45 +1667,6 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
</header>
<div className="da-gfs-manage-dialog__body">
- {currentIsFolder && canWriteCurrent && createFolderOpen ? (
- <form
- className="da-gfs-inline-form da-gfs-create-folder-form"
- aria-label="Create folder"
- onSubmit={event => {
- event.preventDefault()
- void handleCreateFolder()
- }}
- >
- <div className="da-gfs-create-folder-form__heading">
- <h4>New folder</h4>
- <p className="muted">Create a folder in {current.name}.</p>
- </div>
- <label className="da-gfs-inline-form__field da-gfs-create-folder-form__field">
- <span>Folder name</span>
- <TextInput
- autoFocus
- value={createFolderName}
- onChange={event => setCreateFolderName(event.currentTarget.value)}
- />
- </label>
- <div className="da-gfs-create-folder-form__actions">
- <Button
- onClick={() => {
- setCreateFolderName('')
- setCreateFolderOpen(false)
- }}
- size="sm"
- type="button"
- variant="ghost"
- >
- Cancel
- </Button>
- <Button loading={ctrl.mutating} size="sm" type="submit">
- Create folder
- </Button>
- </div>
- </form>
- ) : null}
{canDeleteCurrent && deleteOpen ? (
<div className="da-gfs-inline-form" role="alertdialog" aria-label="Delete resource">
<span className="da-gfs-inline-form__copy">Delete {current.name}?</span>
@@ -1771,6 +1750,69 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
</div>
) : null}
+ {createFolderOpen && currentIsFolder && canWriteCurrent ? (
+ <div
+ className="da-gfs-manage-modal da-gfs-new-folder-modal"
+ role="presentation"
+ onMouseDown={event => {
+ if (event.target === event.currentTarget && !ctrl.mutating) closeCreateFolder()
+ }}
+ >
+ <section
+ aria-describedby={createFolderDescriptionId}
+ aria-labelledby={createFolderTitleId}
+ aria-modal="true"
+ className="da-gfs-new-folder-dialog"
+ onMouseDown={event => event.stopPropagation()}
+ role="dialog"
+ >
+ <header className="da-gfs-new-folder-dialog__header">
+ <h3 id={createFolderTitleId}>New folder</h3>
+ </header>
+ <p className="da-gfs-new-folder-dialog__copy" id={createFolderDescriptionId}>
+ Create a new folder in {current.name}.
+ </p>
+ <form
+ aria-label="Create folder"
+ className="da-gfs-new-folder-dialog__form"
+ onSubmit={event => {
+ event.preventDefault()
+ void handleCreateFolder()
+ }}
+ >
+ <label className="da-gfs-new-folder-dialog__field" htmlFor={createFolderInputId}>
+ <span>Folder name</span>
+ <TextInput
+ aria-label="Folder name"
+ autoComplete="off"
+ autoFocus
+ disabled={ctrl.mutating}
+ id={createFolderInputId}
+ placeholder="e.g. research-notes"
+ spellCheck={false}
+ value={createFolderName}
+ onChange={event => setCreateFolderName(event.currentTarget.value)}
+ />
+ </label>
+ {createFolderError ? <StatusBanner tone="error" text={createFolderError} /> : null}
+ <footer className="da-gfs-new-folder-dialog__actions">
+ <Button
+ disabled={ctrl.mutating}
+ onClick={closeCreateFolder}
+ type="button"
+ variant="ghost"
+ >
+ Cancel
+ </Button>
+ <Button disabled={!createFolderName.trim()} loading={ctrl.mutating} type="submit">
+ Create folder
+ </Button>
+ </footer>
+ </form>
+ </section>
+ </div>
+ ) : null}
+
{filePreview?.kind === 'image' ? (
<GfsImagePreview
byteLength={filePreview.bytes}
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
index f30a7a31f..a985278ef 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
@@ -589,12 +589,16 @@ describe('FilesPage', () => {
await openManageDialog('Team folder')
expect(screen.queryByText('Manage folder')).toBeNull()
await chooseManageAction('Team folder', 'New folder')
+ const newFolderDialog = screen.getByRole('dialog', { name: 'New folder' })
const createFolderForm = screen.getByRole('form', { name: 'Create folder' })
+ expect(within(newFolderDialog).queryByText('People with access')).toBeNull()
+ expect(within(newFolderDialog).queryByText(/Add people/)).toBeNull()
await act(async () => {
fireEvent.change(screen.getByLabelText('Folder name'), { target: { value: 'new-folder' } })
fireEvent.click(createFolderForm.querySelector('button[type="submit"]')!)
})
+ await openManageDialog('Team folder')
await chooseManageAction('Team folder', 'Rename')
const renameForm = screen.getByRole('form', { name: 'Rename resource' })
await act(async () => {
@@ -648,9 +652,13 @@ describe('FilesPage', () => {
fireEvent.click(screen.getByRole('button', { name: 'Close GFS link dialog' }))
fireEvent.click(newFolderButton)
+ const newFolderDialog = screen.getByRole('dialog', { name: 'New folder' })
const createFolderForm = screen.getByRole('form', { name: 'Create folder' })
- expect(within(createFolderForm).getByRole('heading', { name: 'New folder' })).toBeTruthy()
- expect(createFolderForm.querySelector('.da-gfs-create-folder-form__actions')).not.toBeNull()
+ expect(within(newFolderDialog).getByRole('heading', { name: 'New folder' })).toBeTruthy()
+ expect(newFolderDialog.classList.contains('da-gfs-new-folder-dialog')).toBe(true)
+ expect(within(newFolderDialog).queryByText('People with access')).toBeNull()
+ expect(createFolderForm.querySelector('.da-gfs-new-folder-dialog__actions')).not.toBeNull()
+ fireEvent.click(within(createFolderForm).getByRole('button', { name: 'Cancel' }))
const upload = new File(['desktop file'], 'notes.md', { type: 'text/markdown' })
await act(async () => {
@@ -2421,12 +2429,29 @@ describe('FilesPage', () => {
expect(await within(dialog).findByRole('button', { name: 'Subfolder' })).toBeTruthy()
expect(within(dialog).queryByRole('button', { name: 'notes.txt' })).toBeNull()
+ // The current parent is never preselected, and selecting it explicitly is
+ // refused — that "move" is a server-accepted no-op that would toast
+ // success while changing nothing.
await act(async () => {
- fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Product)' }))
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Product' }))
})
+ const noOpButton = within(dialog).getByRole('button', {
+ name: 'Move here (Product)',
+ }) as HTMLButtonElement
+ expect(noOpButton.disabled).toBe(true)
+ expect(within(dialog).getByText(/is already in Product/)).toBeTruthy()
- expect(moveResource).toHaveBeenCalledWith('child-1', 'folder-1', 3)
- expect(pushToast).toHaveBeenCalledWith('Moved notes.txt to Product', 'success')
+ // A real destination commits and toasts.
+ await act(async () => {
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Subfolder' }))
+ })
+ await act(async () => {
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Subfolder)' }))
+ })
+
+ expect(moveResource).toHaveBeenCalledWith('child-1', 'sub-1', 3)
+ expect(moveResource).toHaveBeenCalledTimes(1)
+ expect(pushToast).toHaveBeenCalledWith('Moved notes.txt to Subfolder', 'success')
})
it('moves a dragged file onto a folder only after confirming destination write access', async () => {
@@ -3243,7 +3268,7 @@ describe('FilesPage', () => {
name: 'Cancel',
})
)
- await chooseManageAction('Product', 'New folder')
+ fireEvent.click(screen.getByRole('button', { name: 'New folder' }))
expect((screen.getByLabelText('Folder name') as HTMLInputElement).value).toBe('')
})