Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): r2-m4 contain grants modal focus
Josué9efcdefdd738
diff --git a/control-ui/components/RecipeIntegrationsPanel/index.tsx b/control-ui/components/RecipeIntegrationsPanel/index.tsxindex 7ecb944aa..9098b19f7 100644--- a/control-ui/components/RecipeIntegrationsPanel/index.tsx+++ b/control-ui/components/RecipeIntegrationsPanel/index.tsx@@ -1,6 +1,6 @@'use client'-import { useCallback, useEffect, useMemo, useState } from 'react'+import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { DataTable } from '@clerum/frontend-table-system'import {type UserGrant,@@ -80,6 +80,43 @@ export function RecipeIntegrationsPanel({ recipe }: { recipe: WorkflowRecipeReso// Per-client user-grants state, keyed by client.idconst [userGrantsMap, setUserGrantsMap] = useState<Record<string, UserGrantsRowState>>({})const [activeGrantsClientId, setActiveGrantsClientId] = useState<string | null>(null)+ const grantsDialogRef = useRef<HTMLElement>(null)+ const grantsCloseButtonRef = useRef<HTMLButtonElement>(null)+ const grantsOpenerRef = useRef<HTMLElement | null>(null)++ useEffect(() => {+ if (!activeGrantsClientId) return+ grantsCloseButtonRef.current?.focus()+ const onKeyDown = (event: KeyboardEvent) => {+ if (event.key === 'Escape') {+ event.preventDefault()+ setActiveGrantsClientId(null)+ return+ }+ if (event.key !== 'Tab') return+ const focusable = Array.from(+ grantsDialogRef.current?.querySelectorAll<HTMLElement>(+ 'a[href], button:not(:disabled), input:not(:disabled), [tabindex]:not([tabindex="-1"])'+ ) ?? []+ )+ const first = focusable[0]+ const last = focusable.at(-1)+ if (!first || !last) return+ if (event.shiftKey && document.activeElement === first) {+ event.preventDefault()+ last.focus()+ } else if (!event.shiftKey && document.activeElement === last) {+ event.preventDefault()+ first.focus()+ }+ }+ window.addEventListener('keydown', onKeyDown)+ const opener = grantsOpenerRef.current+ return () => {+ window.removeEventListener('keydown', onKeyDown)+ opener?.focus()+ }+ }, [activeGrantsClientId])const loadStatuses = useCallback(async () => {if (!recipeName || clients.length === 0) {@@ -279,31 +316,37 @@ export function RecipeIntegrationsPanel({ recipe }: { recipe: WorkflowRecipeReso</span></td><td style={{ textAlign: 'right' }}>- <RowActionsMenu- ariaLabel={`Actions for ${client.id}`}- actions={[- {- key: 'user-grants',- label: 'Manage user grants',- disabled: !recipeName,- onClick: () => void loadUserGrants(client),- },- state === 'connected'- ? {- key: 'disconnect',- label: busy ? 'Working…' : 'Disconnect',- danger: true,- disabled: busy,- onClick: () => void handleDisconnect(client),- }- : {- key: 'connect',- label: busy ? 'Working…' : `Connect ${client.provider}`,- disabled: busy || !recipeName,- onClick: () => void handleConnect(client),- },- ]}- />+ <span+ onFocusCapture={event => {+ grantsOpenerRef.current = event.target as HTMLElement+ }}+ >+ <RowActionsMenu+ ariaLabel={`Actions for ${client.id}`}+ actions={[+ {+ key: 'user-grants',+ label: 'Manage user grants',+ disabled: !recipeName,+ onClick: () => void loadUserGrants(client),+ },+ state === 'connected'+ ? {+ key: 'disconnect',+ label: busy ? 'Working…' : 'Disconnect',+ danger: true,+ disabled: busy,+ onClick: () => void handleDisconnect(client),+ }+ : {+ key: 'connect',+ label: busy ? 'Working…' : `Connect ${client.provider}`,+ disabled: busy || !recipeName,+ onClick: () => void handleConnect(client),+ },+ ]}+ />+ </span></td></tr>)@@ -331,6 +374,7 @@ export function RecipeIntegrationsPanel({ recipe }: { recipe: WorkflowRecipeResoaria-labelledby="recipe-user-grants-title"aria-modal="true"className="cu-modal-panel cu-modal-panel--selection"+ ref={grantsDialogRef}role="dialog"><div className="cu-modal-panel__head">@@ -347,6 +391,7 @@ export function RecipeIntegrationsPanel({ recipe }: { recipe: WorkflowRecipeResoclassName="cu-btn cu-btn--ghost cu-btn--sm"disabled={Boolean(grants.busyUserId)}onClick={() => setActiveGrantsClientId(null)}+ ref={grantsCloseButtonRef}type="button">Closediff --git a/control-ui/components/__tests__/RecipeIntegrationsPanel.userGrants.test.tsx b/control-ui/components/__tests__/RecipeIntegrationsPanel.userGrants.test.tsxindex ae1ea725f..066822520 100644--- a/control-ui/components/__tests__/RecipeIntegrationsPanel.userGrants.test.tsx+++ b/control-ui/components/__tests__/RecipeIntegrationsPanel.userGrants.test.tsx@@ -165,6 +165,27 @@ describe('RecipeIntegrationsPanel — per-user grants subsection', () => {expect(screen.getByRole('dialog', { name: 'Per-user connections' })).toBeInTheDocument()})+ it('traps modal focus, closes with Escape, and restores the opener', async () => {+ const { user } = renderPanel()+ await screen.findByText('Not connected')++ const opener = screen.getByRole('button', { name: 'Actions for salesforce' })+ await user.click(opener)+ await user.click(screen.getByRole('menuitem', { name: 'Manage user grants' }))++ const close = await screen.findByRole('button', { name: 'Close user grants' })+ const refresh = screen.getByRole('button', { name: 'Refresh' })+ expect(close).toHaveFocus()+ fireEvent.keyDown(window, { key: 'Tab', shiftKey: true })+ expect(refresh).toHaveFocus()+ fireEvent.keyDown(window, { key: 'Tab' })+ expect(close).toHaveFocus()++ fireEvent.keyDown(window, { key: 'Escape' })+ expect(screen.queryByRole('dialog', { name: 'Per-user connections' })).toBeNull()+ expect(opener).toHaveFocus()+ })+it('renders the user row after adminListUserGrants resolves', async () => {await renderAndExpandGrants()diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 4ab993793..08b386750 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.491",+ "version": "0.1.492","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.491",+ "version": "0.1.492","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-table-system": "file:../packages/frontend-table-system",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 5c0fdbb67..c544ad35e 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.491",+ "version": "0.1.492","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",