Skip to content

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

TypeScript

fix(gfs): stabilize resource menu positioning

M1dc4bdc3e5ae
diff --git a/desktop-app/ui/src/components/GfsResourceMenu/GfsResourceMenu.test.tsx b/desktop-app/ui/src/components/GfsResourceMenu/GfsResourceMenu.test.tsx
index a77026fcc..28a6cb1ab 100644
--- a/desktop-app/ui/src/components/GfsResourceMenu/GfsResourceMenu.test.tsx
+++ b/desktop-app/ui/src/components/GfsResourceMenu/GfsResourceMenu.test.tsx
@@ -1,11 +1,27 @@
// @vitest-environment jsdom
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
+import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react'
import { GfsResourceMenu } from './index'
+function rect(left: number, top: number, width: number, height: number): DOMRect {
+ return {
+ bottom: top + height,
+ height,
+ left,
+ right: left + width,
+ top,
+ width,
+ x: left,
+ y: top,
+ toJSON: () => ({}),
+ }
+}
+
describe('GfsResourceMenu', () => {
afterEach(() => {
cleanup()
+ vi.restoreAllMocks()
+ vi.unstubAllGlobals()
})
it('uses a vertical kebab and presents an icon-led menu panel', () => {
@@ -64,4 +80,59 @@ describe('GfsResourceMenu', () => {
expect(onManage).toHaveBeenCalledOnce()
expect(screen.queryByRole('menu', { name: 'Actions for report.txt' })).toBeNull()
})
+
+ it.each(['Shared with me', 'Marketing'])(
+ 'keeps the %s breadcrumb menu inside the Files surface as the sidebar resizes',
+ resourceName => {
+ let sidebarExpanded = true
+ const resizeCallbacks: ResizeObserverCallback[] = []
+
+ vi.spyOn(window, 'innerWidth', 'get').mockReturnValue(918)
+ vi.spyOn(window, 'innerHeight', 'get').mockReturnValue(700)
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function () {
+ if (this.classList.contains('da-gfs-drive')) {
+ const left = sidebarExpanded ? 304 : 74
+ return rect(left, 0, 918 - left, 700)
+ }
+ if (this.classList.contains('da-gfs-resource-menu__panel')) {
+ return rect(0, 0, 360, 260)
+ }
+ if (this.getAttribute('aria-label') === `Options for ${resourceName}`) {
+ const left = sidebarExpanded ? 526 : 296
+ return rect(left, 100, 32, 32)
+ }
+ return rect(0, 0, 0, 0)
+ })
+
+ class ResizeObserverMock {
+ constructor(callback: ResizeObserverCallback) {
+ resizeCallbacks.push(callback)
+ }
+
+ disconnect() {}
+ observe() {}
+ unobserve() {}
+ }
+ vi.stubGlobal('ResizeObserver', ResizeObserverMock)
+
+ render(
+ <section className="da-gfs-drive">
+ <GfsResourceMenu resourceName={resourceName} onOpenGfsLink={vi.fn()} />
+ </section>
+ )
+
+ fireEvent.click(screen.getByRole('button', { name: `Options for ${resourceName}` }))
+ const menu = screen.getByRole('menu', { name: `Actions for ${resourceName}` })
+
+ // Right alignment would start at 198px and disappear beneath the 304px
+ // sidebar. The Files boundary clamps the whole panel to visible content.
+ expect(menu.style.left).toBe('304px')
+
+ sidebarExpanded = false
+ act(() => {
+ resizeCallbacks.forEach(callback => callback([], {} as ResizeObserver))
+ })
+ expect(menu.style.left).toBe('74px')
+ }
+ )
})
diff --git a/desktop-app/ui/src/components/GfsResourceMenu/index.tsx b/desktop-app/ui/src/components/GfsResourceMenu/index.tsx
index 13490afbb..47347181b 100644
--- a/desktop-app/ui/src/components/GfsResourceMenu/index.tsx
+++ b/desktop-app/ui/src/components/GfsResourceMenu/index.tsx
@@ -41,6 +41,26 @@ function isMenuAction(action: GfsResourceMenuAction | null): action is GfsResour
return action !== null
}
+function horizontalBounds(anchor: HTMLElement, edgeInset: number) {
+ const viewportLeft = edgeInset
+ const viewportRight = window.innerWidth - edgeInset
+ const drive = anchor.closest<HTMLElement>('.da-gfs-drive')
+ const driveRect = drive?.getBoundingClientRect()
+
+ // Breadcrumb menus live beside a persistent sidebar. Keep their portal
+ // inside the Files surface instead of allowing right-edge alignment to push
+ // the panel underneath that sidebar. Isolated consumers and zero-layout test
+ // environments fall back to the viewport.
+ if (!driveRect || driveRect.width <= 0) {
+ return { left: viewportLeft, right: viewportRight }
+ }
+
+ return {
+ left: Math.max(viewportLeft, driveRect.left),
+ right: Math.min(viewportRight, driveRect.right),
+ }
+}
+
export function GfsResourceMenu({
resourceName,
onManage,
@@ -115,12 +135,10 @@ export function GfsResourceMenu({
const panelRect = panel.getBoundingClientRect()
const edgeInset = 8
const gap = 6
- const viewportWidth = window.innerWidth
const viewportHeight = window.innerHeight
- const left = Math.min(
- Math.max(edgeInset, triggerRect.right - panelRect.width),
- Math.max(edgeInset, viewportWidth - panelRect.width - edgeInset)
- )
+ const bounds = horizontalBounds(trigger, edgeInset)
+ const maxLeft = Math.max(bounds.left, bounds.right - panelRect.width)
+ const left = Math.min(Math.max(bounds.left, triggerRect.right - panelRect.width), maxLeft)
const opensAbove =
triggerRect.bottom + gap + panelRect.height > viewportHeight - edgeInset &&
triggerRect.top - gap - panelRect.height >= edgeInset
@@ -144,9 +162,17 @@ export function GfsResourceMenu({
positionPanel()
window.addEventListener('resize', positionPanel)
window.addEventListener('scroll', positionPanel, true)
+ const resizeObserver =
+ typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(positionPanel)
+ const trigger = triggerRef.current
+ const drive = trigger?.closest<HTMLElement>('.da-gfs-drive')
+ if (trigger) resizeObserver?.observe(trigger)
+ if (drive) resizeObserver?.observe(drive)
+ if (panelRef.current) resizeObserver?.observe(panelRef.current)
return () => {
window.removeEventListener('resize', positionPanel)
window.removeEventListener('scroll', positionPanel, true)
+ resizeObserver?.disconnect()
}
}, [open, positionPanel])
@@ -159,14 +185,14 @@ export function GfsResourceMenu({
const submenuRect = submenu.getBoundingClientRect()
const edgeInset = 8
const gap = 6
- const viewportWidth = window.innerWidth
const viewportHeight = window.innerHeight
- const opensLeft = triggerRect.right + gap + submenuRect.width > viewportWidth - edgeInset
+ const bounds = horizontalBounds(triggerRef.current ?? trigger, edgeInset)
+ const opensLeft = triggerRect.right + gap + submenuRect.width > bounds.right
const preferredLeft = opensLeft
? triggerRect.left - submenuRect.width - gap
: triggerRect.right + gap
- const maxLeft = Math.max(edgeInset, viewportWidth - submenuRect.width - edgeInset)
- const left = Math.min(Math.max(edgeInset, preferredLeft), maxLeft)
+ const maxLeft = Math.max(bounds.left, bounds.right - submenuRect.width)
+ const left = Math.min(Math.max(bounds.left, preferredLeft), maxLeft)
const maxTop = Math.max(edgeInset, viewportHeight - submenuRect.height - edgeInset)
const top = Math.min(Math.max(edgeInset, triggerRect.top), maxTop)
@@ -182,11 +208,21 @@ export function GfsResourceMenu({
positionSubmenu()
window.addEventListener('resize', positionSubmenu)
window.addEventListener('scroll', positionSubmenu, true)
+ const resizeObserver =
+ typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(positionSubmenu)
+ const trigger = triggerRef.current
+ const drive = trigger?.closest<HTMLElement>('.da-gfs-drive')
+ if (trigger) resizeObserver?.observe(trigger)
+ if (drive) resizeObserver?.observe(drive)
+ if (panelRef.current) resizeObserver?.observe(panelRef.current)
+ if (shareTriggerRef.current) resizeObserver?.observe(shareTriggerRef.current)
+ if (submenuRef.current) resizeObserver?.observe(submenuRef.current)
return () => {
window.removeEventListener('resize', positionSubmenu)
window.removeEventListener('scroll', positionSubmenu, true)
+ resizeObserver?.disconnect()
}
- }, [positionSubmenu, shareOpen])
+ }, [panelPosition, positionSubmenu, shareOpen])
useEffect(() => {
if (!open) return
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index 29f86970f..05acfb1fc 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -14765,7 +14765,9 @@ pre {
.da-gfs-resource-menu__panel {
position: fixed;
- z-index: calc(var(--layer-dropdown) + 60);
+ /* The persistent sidebar owns dropdown + 1000. Resource menus are portaled
+ to body and must remain above it while the navigation expands/collapses. */
+ z-index: calc(var(--layer-dropdown) + 1100);
width: min(360px, calc(100vw - (var(--space-4) * 2)));
max-height: calc(100vh - (var(--space-4) * 2));
display: grid;
@@ -14781,7 +14783,7 @@ pre {
.da-gfs-resource-menu__submenu {
position: fixed;
- z-index: calc(var(--layer-dropdown) + 61);
+ z-index: calc(var(--layer-dropdown) + 1101);
width: min(240px, calc(100vw - (var(--space-4) * 2)));
max-height: calc(100vh - (var(--space-4) * 2));
display: grid;