Skip to content

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

TypeScript

fix(desktop): add access row action menus

M514d03847796
diff --git a/desktop-app/ui/src/gfs/GfsGrantList/AccessRowMenu.tsx b/desktop-app/ui/src/gfs/GfsGrantList/AccessRowMenu.tsx
new file mode 100644
index 000000000..54a1d7cbb
--- /dev/null
+++ b/desktop-app/ui/src/gfs/GfsGrantList/AccessRowMenu.tsx
@@ -0,0 +1,121 @@
+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
+import { createPortal } from 'react-dom'
+import { IconButton, MenuItem } from '@components/Common'
+import { IconMoreVertical } from '@components/SidebarNav/icons'
+
+type AccessRowMenuProps = {
+ disabled?: boolean
+ label: string
+ onRemove: () => void | Promise<void>
+}
+
+export function AccessRowMenu({ disabled = false, label, onRemove }: AccessRowMenuProps) {
+ const [open, setOpen] = useState(false)
+ const [position, setPosition] = useState<{ left: number; top: number } | null>(null)
+ const triggerRef = useRef<HTMLButtonElement | null>(null)
+ const menuRef = useRef<HTMLDivElement | null>(null)
+ const close = useCallback((restoreFocus = false) => {
+ setOpen(false)
+ if (restoreFocus) triggerRef.current?.focus()
+ }, [])
+
+ useEffect(() => {
+ if (!open) return
+ const handlePointerDown = (event: MouseEvent) => {
+ const target = event.target as Node
+ if (!triggerRef.current?.contains(target) && !menuRef.current?.contains(target)) close()
+ }
+ const handleKeyDown = (event: KeyboardEvent) => {
+ if (event.key === 'Escape') close(true)
+ }
+ document.addEventListener('mousedown', handlePointerDown)
+ document.addEventListener('keydown', handleKeyDown)
+ return () => {
+ document.removeEventListener('mousedown', handlePointerDown)
+ document.removeEventListener('keydown', handleKeyDown)
+ }
+ }, [close, open])
+
+ useEffect(() => {
+ if (disabled && open) close()
+ }, [close, disabled, open])
+
+ const placeMenu = useCallback(() => {
+ const trigger = triggerRef.current
+ const menu = menuRef.current
+ if (!trigger || !menu) return
+ const triggerRect = trigger.getBoundingClientRect()
+ const menuRect = menu.getBoundingClientRect()
+ const inset = 8
+ const gap = 6
+ const menuWidth = menuRect.width || 184
+ const menuHeight = menuRect.height || 52
+ const left = Math.max(
+ inset,
+ Math.min(triggerRect.right - menuWidth, window.innerWidth - menuWidth - inset)
+ )
+ const opensAbove =
+ triggerRect.bottom + gap + menuHeight > window.innerHeight - inset &&
+ triggerRect.top > menuHeight
+ const top = opensAbove
+ ? Math.max(inset, triggerRect.top - menuHeight - gap)
+ : Math.min(triggerRect.bottom + gap, window.innerHeight - menuHeight - inset)
+ setPosition({ left, top: Math.max(inset, top) })
+ }, [])
+
+ useLayoutEffect(() => {
+ if (!open) {
+ setPosition(null)
+ return
+ }
+ placeMenu()
+ menuRef.current?.querySelector<HTMLButtonElement>('[role="menuitem"]')?.focus()
+ window.addEventListener('resize', placeMenu)
+ window.addEventListener('scroll', placeMenu, true)
+ return () => {
+ window.removeEventListener('resize', placeMenu)
+ window.removeEventListener('scroll', placeMenu, true)
+ }
+ }, [open, placeMenu])
+
+ return (
+ <span className="da-gfs-access-row-menu">
+ <IconButton
+ aria-expanded={open}
+ aria-haspopup="menu"
+ className="da-gfs-resource-menu__trigger"
+ disabled={disabled}
+ label={`Actions for ${label}`}
+ onClick={() => setOpen(value => !value)}
+ ref={triggerRef}
+ size="sm"
+ variant="ghost"
+ >
+ <IconMoreVertical />
+ </IconButton>
+ {open
+ ? createPortal(
+ <div
+ aria-label={`Actions for ${label}`}
+ className="da-gfs-resource-menu__panel da-gfs-access-row-menu__panel"
+ ref={menuRef}
+ role="menu"
+ style={position ?? { left: 0, top: 0, visibility: 'hidden' }}
+ >
+ <MenuItem
+ color="danger"
+ onClick={() => {
+ close(true)
+ void onRemove()
+ }}
+ role="menuitem"
+ >
+ Remove access
+ </MenuItem>
+ </div>,
+ document.body
+ )
+ : null}
+ </span>
+ )
+}
diff --git a/desktop-app/ui/src/gfs/GfsGrantList/index.tsx b/desktop-app/ui/src/gfs/GfsGrantList/index.tsx
index 91ad34ce3..6ba8afdc0 100644
--- a/desktop-app/ui/src/gfs/GfsGrantList/index.tsx
+++ b/desktop-app/ui/src/gfs/GfsGrantList/index.tsx
@@ -1,4 +1,4 @@
-import { DropdownSelect, IconButton, StatusBanner } from '@components/Common'
+import { DropdownSelect, StatusBanner } from '@components/Common'
import {
IconAgents,
IconContexts,
@@ -12,6 +12,7 @@ import type {
GfsGrantListItem,
GfsShareListItem,
} from '@/gfs/delegation.types'
+import { AccessRowMenu } from './AccessRowMenu'
import type { GfsGrantListProps } from './types'
import type { GfsAccessRole } from './types'
@@ -149,17 +150,11 @@ export function GfsGrantList({
value={roleForPermissions(item.permissions)}
/>
</span>
- <IconButton
- className="da-gfs-grant-list__revoke"
- data-testid={`gfs-revoke-grant-${item.id}`}
+ <AccessRowMenu
disabled={revoking}
- label={`Revoke access for ${label}`}
- onClick={() => void onRevoke(item, label)}
- size="xs"
- variant="ghost"
- >
- X
- </IconButton>
+ label={label}
+ onRemove={() => onRevoke(item, label)}
+ />
</li>
)
})
@@ -189,17 +184,11 @@ export function GfsGrantList({
{roleForPermissions(item.permissions) === 'editor' ? 'Editor' : 'Read'}
</span>
</span>
- <IconButton
- className="da-gfs-grant-list__revoke"
- data-testid={`gfs-revoke-share-${item.id}`}
+ <AccessRowMenu
disabled={revokingShare || !onRevokeShare}
- label={`Revoke shared access for ${label}`}
- onClick={() => void onRevokeShare?.(item, label)}
- size="xs"
- variant="ghost"
- >
- X
- </IconButton>
+ label={label}
+ onRemove={() => onRevokeShare?.(item, label)}
+ />
</li>
)
})
diff --git a/desktop-app/ui/src/gfs/__tests__/GfsGrantList.test.tsx b/desktop-app/ui/src/gfs/__tests__/GfsGrantList.test.tsx
index 38394142d..a9c154e02 100644
--- a/desktop-app/ui/src/gfs/__tests__/GfsGrantList.test.tsx
+++ b/desktop-app/ui/src/gfs/__tests__/GfsGrantList.test.tsx
@@ -73,10 +73,10 @@ describe('GfsGrantList', () => {
within(agentRow).getByRole('button', { name: 'Access role for Chat LLM' }).textContent
).toContain('Editor')
expect(within(agentRow).queryByText('Includes contents')).toBeNull()
- expect(within(agentRow).getByText('X')).toBeTruthy()
- expect(
- within(agentRow).getByRole('button', { name: 'Revoke access for Chat LLM' }).className
- ).toContain('da-gfs-grant-list__revoke')
+ expect(within(agentRow).queryByText('X')).toBeNull()
+ const actions = within(agentRow).getByRole('button', { name: 'Actions for Chat LLM' })
+ expect(actions.className).toContain('da-gfs-resource-menu__trigger')
+ expect(actions.querySelectorAll('circle')).toHaveLength(3)
const userRow = screen.getByText('Test Two').closest('li')!
expect(userRow.querySelector('[data-subject-kind="user"] svg')).not.toBeNull()
@@ -114,12 +114,15 @@ describe('GfsGrantList', () => {
expect(screen.getByText('blankdisplay')).toBeTruthy()
})
- it('fires the revoke callback from the row button with an accessible name', () => {
+ it('fires the revoke callback from the three-dot menu', () => {
const onRevoke = vi.fn()
const item = grantItem({ id: 'grant-1' })
render(<GfsGrantList agents={agents} items={[item]} onRevoke={onRevoke} subjects={subjects} />)
- fireEvent.click(screen.getByRole('button', { name: 'Revoke access for Chat LLM' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for Chat LLM' }))
+ const menu = screen.getByRole('menu', { name: 'Actions for Chat LLM' })
+ expect(menu.parentElement).toBe(document.body)
+ fireEvent.click(within(menu).getByRole('menuitem', { name: 'Remove access' }))
expect(onRevoke).toHaveBeenCalledWith(item, 'Chat LLM')
})
@@ -162,9 +165,8 @@ describe('GfsGrantList', () => {
expect(shareRow.querySelector('[data-subject-kind="team"] svg')).not.toBeNull()
expect(within(shareRow).queryByText('Share · team')).toBeNull()
expect(within(shareRow).queryByText('Includes contents')).toBeNull()
- fireEvent.click(
- within(shareRow).getByRole('button', { name: 'Revoke shared access for Core Team' })
- )
+ fireEvent.click(within(shareRow).getByRole('button', { name: 'Actions for Core Team' }))
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Remove access' }))
expect(onRevokeShare).toHaveBeenCalledWith(share, 'Core Team')
expect(onRevoke).not.toHaveBeenCalled()
@@ -188,7 +190,7 @@ describe('GfsGrantList', () => {
const banner = screen.getByText('Only people with manage access can view who has access here.')
expect(banner.closest('.status-banner')?.className).toContain('tone-info')
expect(screen.queryByRole('list')).toBeNull()
- expect(screen.queryByRole('button', { name: /Revoke access for/ })).toBeNull()
+ expect(screen.queryByRole('button', { name: /Actions for/ })).toBeNull()
})
it('renders other list failures as an error banner', () => {
@@ -237,7 +239,8 @@ describe('GfsGrantList', () => {
// …but the grant row and its revoke action stay available and work.
const grantRow = screen.getByTestId('gfs-access-row-grant-grant-1')
expect(within(grantRow).getByText('Chat LLM')).toBeTruthy()
- fireEvent.click(screen.getByRole('button', { name: 'Revoke access for Chat LLM' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for Chat LLM' }))
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Remove access' }))
expect(onRevoke).toHaveBeenCalledWith(grant, 'Chat LLM')
})
@@ -259,7 +262,8 @@ describe('GfsGrantList', () => {
expect(screen.getByText('listGrants exploded')).toBeTruthy()
const shareRow = screen.getByTestId('gfs-access-row-share-share-1')
expect(within(shareRow).getByText('Core Team')).toBeTruthy()
- fireEvent.click(screen.getByRole('button', { name: 'Revoke shared access for Core Team' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for Core Team' }))
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Remove access' }))
expect(onRevokeShare).toHaveBeenCalledWith(share, 'Core Team')
})
})
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
index 6109f8ea8..c9830e808 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
@@ -1842,7 +1842,8 @@ describe('FilesPage', () => {
renderFilesPage(pushToast)
await openManageDialog('Team folder')
- fireEvent.click(await screen.findByRole('button', { name: 'Revoke access for chatllm' }))
+ fireEvent.click(await screen.findByRole('button', { name: 'Actions for chatllm' }))
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Remove access' }))
await waitFor(() => expect(revokeGrant).toHaveBeenCalledWith('grant-1'))
await waitFor(() =>
@@ -1953,7 +1954,8 @@ describe('FilesPage', () => {
const shareRow = await screen.findByTestId('gfs-access-row-share-share-1')
expect(shareRow.textContent).not.toContain('Includes contents')
- fireEvent.click(screen.getByRole('button', { name: 'Revoke shared access for user-9' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Actions for user-9' }))
+ fireEvent.click(screen.getByRole('menuitem', { name: 'Remove access' }))
await waitFor(() => expect(revokeShare).toHaveBeenCalledWith('share-1'))
await waitFor(() =>
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index ed7697f85..c5612761e 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -16165,19 +16165,13 @@ pre {
gap: var(--space-1);
}
-.da-gfs-grant-list__revoke.ui-icon-button {
- color: var(--text);
- border-color: transparent;
- background: transparent;
- font-size: var(--font-size-sm);
- font-weight: var(--font-weight-semibold);
+.da-gfs-access-row-menu {
+ display: inline-flex;
+ flex: 0 0 auto;
}
-.da-gfs-grant-list__revoke.ui-icon-button:hover:enabled,
-.da-gfs-grant-list__revoke.ui-icon-button:focus-visible {
- border-color: transparent;
- background: transparent;
- color: var(--text);
+.da-gfs-access-row-menu__panel.da-gfs-resource-menu__panel {
+ width: min(184px, calc(100vw - (var(--space-4) * 2)));
}
@media (max-width: 940px) {