Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(gfs): portal access role menus
M1846692ab5ed
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.cssindex 32c2cbc17..3b55fa072 100644--- a/control-ui/app/globals.css+++ b/control-ui/app/globals.css@@ -6792,6 +6792,11 @@ td.cu-registry-description {box-shadow: var(--cu-shadow);}+.cu-selection-dropdown__menu--portal {+ position: fixed;+ z-index: 1000;+}+.cu-image-reference-combobox .cu-selection-dropdown__option {grid-template-columns: minmax(0, 1fr);}@@ -13476,12 +13481,14 @@ button.cu-gfs-tree__button:focus-visible,}.cu-gfs-role-select .cu-selection-dropdown__option,-.cu-gfs-existing-access__role .cu-selection-dropdown__option {+.cu-gfs-existing-access__role .cu-selection-dropdown__option,+.cu-gfs-existing-access__role-menu .cu-selection-dropdown__option {grid-template-columns: minmax(0, 1fr);}.cu-gfs-role-select .cu-selection-dropdown__option-leading,-.cu-gfs-existing-access__role .cu-selection-dropdown__option-leading {+.cu-gfs-existing-access__role .cu-selection-dropdown__option-leading,+.cu-gfs-existing-access__role-menu .cu-selection-dropdown__option-leading {display: none;}diff --git a/control-ui/components/GfsGrantPanel.tsx b/control-ui/components/GfsGrantPanel.tsxindex cda443ce5..3ee114973 100644--- a/control-ui/components/GfsGrantPanel.tsx+++ b/control-ui/components/GfsGrantPanel.tsx@@ -551,8 +551,10 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.ElemeonChange={next =>void updateAccessRole(item, (next[0] ?? 'read') as AccessRole)}+ menuClassName="cu-gfs-existing-access__role-menu"options={ROLE_OPTIONS}placeholder="Role"+ portalsearchable={false}showSelectedChips={false}value={[roleForPermissions(item.permissions)]}diff --git a/control-ui/components/SelectionDropdown/index.tsx b/control-ui/components/SelectionDropdown/index.tsxindex b8200e8d0..afb6851b4 100644--- a/control-ui/components/SelectionDropdown/index.tsx+++ b/control-ui/components/SelectionDropdown/index.tsx@@ -1,6 +1,7 @@'use client'-import React, { useEffect, useMemo, useRef, useState } from 'react'+import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'+import { createPortal } from 'react-dom'import { IconCheck, IconX } from '@components/icons'import { cn } from '@lib/cn'import type { SelectionDropdownOption, SelectionDropdownProps } from './types'@@ -21,11 +22,13 @@ export function SelectionDropdown({id,inline = false,invalid = false,+ menuClassName,multiple = true,onChange,onSearchQueryChange,options,placeholder,+ portal = false,searchable = true,searchPlaceholder = 'Search...',selectionLabel = 'Selected',@@ -34,7 +37,14 @@ export function SelectionDropdown({}: SelectionDropdownProps) {const [open, setOpen] = useState(false)const [query, setQuery] = useState('')+ const [portalPosition, setPortalPosition] = useState<{+ left: number+ top: number+ width: number+ } | null>(null)const rootRef = useRef<HTMLDivElement | null>(null)+ const buttonRef = useRef<HTMLButtonElement | null>(null)+ const menuRef = useRef<HTMLDivElement | null>(null)const searchRef = useRef<HTMLInputElement | null>(null)const selectedSet = useMemo(() => new Set(value), [value])@@ -52,7 +62,8 @@ export function SelectionDropdown({if (!open || inline) returnfunction handlePointerDown(event: MouseEvent) {- if (!rootRef.current?.contains(event.target as Node)) {+ const target = event.target as Node+ if (!rootRef.current?.contains(target) && !menuRef.current?.contains(target)) {setOpen(false)}}@@ -71,6 +82,42 @@ export function SelectionDropdown({}}, [inline, open])+ const updatePortalPosition = useCallback(() => {+ const trigger = buttonRef.current+ if (!trigger) return+ const rect = trigger.getBoundingClientRect()+ const gap = 4+ const viewportPadding = 8+ const estimatedHeight = Math.min(220, 8 + options.length * 43 + (searchable ? 48 : 0))+ const menuHeight = menuRef.current?.offsetHeight || estimatedHeight+ const roomBelow = window.innerHeight - rect.bottom - viewportPadding+ const roomAbove = rect.top - viewportPadding+ const opensAbove = menuHeight > roomBelow && roomAbove > roomBelow+ const top = opensAbove+ ? Math.max(viewportPadding, rect.top - menuHeight - gap)+ : Math.max(+ viewportPadding,+ Math.min(rect.bottom + gap, window.innerHeight - menuHeight - viewportPadding)+ )+ const width = rect.width+ const left = Math.min(+ Math.max(viewportPadding, rect.left),+ Math.max(viewportPadding, window.innerWidth - width - viewportPadding)+ )+ setPortalPosition({ left, top, width })+ }, [options.length, searchable])++ useLayoutEffect(() => {+ if (!portal || !menuVisible) return+ updatePortalPosition()+ window.addEventListener('resize', updatePortalPosition)+ window.addEventListener('scroll', updatePortalPosition, true)+ return () => {+ window.removeEventListener('resize', updatePortalPosition)+ window.removeEventListener('scroll', updatePortalPosition, true)+ }+ }, [menuVisible, portal, updatePortalPosition])+useEffect(() => {if (menuVisible && searchable) {window.setTimeout(() => searchRef.current?.focus(), 0)@@ -104,6 +151,84 @@ export function SelectionDropdown({? `${selectedOptions.length} ${selectionLabel.toLowerCase()}`: selectedOptions[0]?.label+ const menu = menuVisible ? (+ <div+ className={cn(+ 'cu-selection-dropdown__menu',+ portal && 'cu-selection-dropdown__menu--portal',+ menuClassName+ )}+ ref={menuRef}+ style={+ portal+ ? portalPosition+ ? {+ left: portalPosition.left,+ top: portalPosition.top,+ width: portalPosition.width,+ }+ : { left: 0, top: 0, visibility: 'hidden' }+ : undefined+ }+ >+ {searchable ? (+ <input+ id={inline ? id : undefined}+ ref={searchRef}+ className="cu-selection-dropdown__search"+ value={query}+ onChange={event => {+ const nextQuery = event.target.value+ setQuery(nextQuery)+ onSearchQueryChange?.(nextQuery)+ }}+ placeholder={searchPlaceholder}+ aria-label={searchPlaceholder}+ disabled={disabled}+ />+ ) : null}+ <div className="cu-selection-dropdown__list" role="listbox" aria-multiselectable={multiple}>+ {filteredOptions.length === 0 ? (+ <span className="cu-selection-dropdown__empty">{emptyLabel}</span>+ ) : (+ filteredOptions.map(option => {+ const selected = selectedSet.has(option.value)+ return (+ <button+ key={option.value}+ type="button"+ className="cu-selection-dropdown__option"+ role="option"+ aria-label={option.label}+ aria-selected={selected}+ data-selected={selected ? 'true' : undefined}+ onClick={() => toggleOption(option.value)}+ >+ <span className="cu-selection-dropdown__option-leading" aria-hidden="true">+ <span className="cu-selection-dropdown__check">+ {selected ? <IconCheck width={14} height={14} /> : null}+ </span>+ {option.icon}+ </span>+ <span className="cu-selection-dropdown__option-copy">+ <span className="cu-selection-dropdown__option-label">{option.label}</span>+ {option.description ? (+ <span className="cu-selection-dropdown__option-description">+ {option.description}+ </span>+ ) : null}+ </span>+ {option.badge ? (+ <span className="cu-selection-dropdown__badge">{option.badge}</span>+ ) : null}+ </button>+ )+ })+ )}+ </div>+ </div>+ ) : null+return (<divclassName={cn('cu-selection-dropdown', inline && 'cu-selection-dropdown--inline', className)}@@ -111,6 +236,7 @@ export function SelectionDropdown({>{inline ? null : (<button+ ref={buttonRef}id={id}type="button"className={cn(@@ -152,69 +278,7 @@ export function SelectionDropdown({</div>) : null}- {menuVisible ? (- <div className="cu-selection-dropdown__menu">- {searchable ? (- <input- id={inline ? id : undefined}- ref={searchRef}- className="cu-selection-dropdown__search"- value={query}- onChange={event => {- const nextQuery = event.target.value- setQuery(nextQuery)- onSearchQueryChange?.(nextQuery)- }}- placeholder={searchPlaceholder}- aria-label={searchPlaceholder}- disabled={disabled}- />- ) : null}- <div- className="cu-selection-dropdown__list"- role="listbox"- aria-multiselectable={multiple}- >- {filteredOptions.length === 0 ? (- <span className="cu-selection-dropdown__empty">{emptyLabel}</span>- ) : (- filteredOptions.map(option => {- const selected = selectedSet.has(option.value)- return (- <button- key={option.value}- type="button"- className="cu-selection-dropdown__option"- role="option"- aria-label={option.label}- aria-selected={selected}- data-selected={selected ? 'true' : undefined}- onClick={() => toggleOption(option.value)}- >- <span className="cu-selection-dropdown__option-leading" aria-hidden="true">- <span className="cu-selection-dropdown__check">- {selected ? <IconCheck width={14} height={14} /> : null}- </span>- {option.icon}- </span>- <span className="cu-selection-dropdown__option-copy">- <span className="cu-selection-dropdown__option-label">{option.label}</span>- {option.description ? (- <span className="cu-selection-dropdown__option-description">- {option.description}- </span>- ) : null}- </span>- {option.badge ? (- <span className="cu-selection-dropdown__badge">{option.badge}</span>- ) : null}- </button>- )- })- )}- </div>- </div>- ) : null}+ {portal && menu ? createPortal(menu, document.body) : menu}</div>)}diff --git a/control-ui/components/SelectionDropdown/types.ts b/control-ui/components/SelectionDropdown/types.tsindex 888846d02..32e4a3a85 100644--- a/control-ui/components/SelectionDropdown/types.ts+++ b/control-ui/components/SelectionDropdown/types.ts@@ -23,7 +23,10 @@ export type SelectionDropdownProps = {selectionLabel?: stringmultiple?: booleaninline?: boolean+ /** Render the menu at document.body so ancestor overflow cannot clip it. */+ portal?: booleansearchable?: booleaninvalid?: boolean+ menuClassName?: stringshowSelectedChips?: boolean}diff --git a/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx b/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsxindex f5c4f22c8..d8c9cbafa 100644--- a/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx+++ b/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx@@ -243,6 +243,7 @@ describe('GfsGrantPanel bulk access', () => {const role = await screen.findByRole('button', { name: 'Access role for Ada Lovelace' })expect(role).toHaveTextContent('Editor')fireEvent.click(role)+ expect(screen.getByRole('listbox').parentElement?.parentElement).toBe(document.body)fireEvent.click(screen.getByRole('option', { name: 'Read' }))await waitFor(() =>diff --git a/control-ui/components/__tests__/SelectionDropdown.portal.test.tsx b/control-ui/components/__tests__/SelectionDropdown.portal.test.tsxnew file mode 100644index 000000000..a03e05120--- /dev/null+++ b/control-ui/components/__tests__/SelectionDropdown.portal.test.tsx@@ -0,0 +1,51 @@+import { describe, expect, it, vi } from 'vitest'+import { fireEvent, render, screen } from '@testing-library/react'+import { SelectionDropdown } from '../SelectionDropdown'++describe('SelectionDropdown portal menu', () => {+ it('renders outside overflow ancestors and keeps selection interactive', () => {+ const onChange = vi.fn()+ render(+ <div data-testid="overflow-parent" style={{ overflow: 'auto' }}>+ <SelectionDropdown+ ariaLabel="Access role"+ multiple={false}+ onChange={onChange}+ options={[+ { label: 'Read', value: 'read' },+ { label: 'Editor', value: 'editor' },+ ]}+ placeholder="Role"+ portal+ searchable={false}+ value={['read']}+ />+ </div>+ )++ const trigger = screen.getByRole('button', { name: 'Access role' })+ vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue({+ bottom: 140,+ height: 32,+ left: 200,+ right: 312,+ top: 108,+ width: 112,+ x: 200,+ y: 108,+ toJSON: () => undefined,+ })+ fireEvent.click(trigger)++ const listbox = screen.getByRole('listbox')+ const menu = listbox.parentElement+ expect(menu?.parentElement).toBe(document.body)+ expect(menu).toHaveClass('cu-selection-dropdown__menu--portal')+ expect(menu).toHaveStyle({ left: '200px', width: '112px' })++ const editor = screen.getByRole('option', { name: 'Editor' })+ fireEvent.mouseDown(editor)+ fireEvent.click(editor)+ expect(onChange).toHaveBeenCalledWith(['editor'])+ })+})diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 0c20b72d1..bb90a9ae2 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.571",+ "version": "0.1.572","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.571",+ "version": "0.1.572","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex f81d352f2..4bdd59508 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.571",+ "version": "0.1.572","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/desktop-app/ui/src/components/Common/DropdownSelect/__tests__/DropdownSelect.test.tsx b/desktop-app/ui/src/components/Common/DropdownSelect/__tests__/DropdownSelect.test.tsxindex c574ff8b2..cd8e3428c 100644--- a/desktop-app/ui/src/components/Common/DropdownSelect/__tests__/DropdownSelect.test.tsx+++ b/desktop-app/ui/src/components/Common/DropdownSelect/__tests__/DropdownSelect.test.tsx@@ -58,4 +58,46 @@ describe('DropdownSelect', () => {fireEvent.mouseDown(document.body)expect(screen.queryByRole('listbox')).toBeNull()})++ it('can portal its menu outside an overflow ancestor', async () => {+ const onChange = vi.fn()+ render(+ <div style={{ overflow: 'auto' }}>+ <DropdownSelect+ ariaLabel="Access role"+ className="access-role"+ onChange={onChange}+ options={OPTIONS}+ placeholder="Choose a role"+ portal+ value="alpha"+ />+ </div>+ )+ const trigger = screen.getByRole('button', { name: 'Access role' })+ vi.spyOn(trigger, 'getBoundingClientRect').mockReturnValue({+ bottom: 140,+ height: 32,+ left: 200,+ right: 312,+ top: 108,+ width: 112,+ x: 200,+ y: 108,+ toJSON: () => undefined,+ })+ fireEvent.click(trigger)++ const menu = await screen.findByRole('listbox', { name: 'Access role' })+ expect(menu.parentElement).toBe(document.body)+ expect(menu.classList.contains('ui-dropdown-select__menu--portal')).toBe(true)+ expect(menu.style.left).toBe('200px')+ expect(menu.style.width).toBe('112px')+ expect(trigger.closest('.ui-dropdown-select')?.classList.contains('access-role')).toBe(true)++ const beta = screen.getByRole('option', { name: 'Beta' })+ fireEvent.mouseDown(beta)+ fireEvent.click(beta)+ expect(onChange).toHaveBeenCalledWith('beta')+ })})diff --git a/desktop-app/ui/src/components/Common/DropdownSelect/index.tsx b/desktop-app/ui/src/components/Common/DropdownSelect/index.tsxindex 202209655..8fa2391a7 100644--- a/desktop-app/ui/src/components/Common/DropdownSelect/index.tsx+++ b/desktop-app/ui/src/components/Common/DropdownSelect/index.tsx@@ -1,28 +1,80 @@-import { useCallback, useEffect, useRef, useState } from 'react'+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'import type { KeyboardEvent } from 'react'+import { createPortal } from 'react-dom'import { Button } from '@components/Common/Button'import { MenuItem } from '@components/Common/MenuItem'-import { useClickOutside } from '@hooks/useClickOutside'import type { DropdownSelectProps } from './types'export function DropdownSelect({ariaLabel,+ className,disabled = false,id,onChange,options,placeholder,+ portal = false,value,}: DropdownSelectProps) {const [open, setOpen] = useState(false)+ const [portalPosition, setPortalPosition] = useState<{+ left: number+ top: number+ width: number+ } | null>(null)const rootRef = useRef<HTMLDivElement | null>(null)const triggerRef = useRef<HTMLButtonElement | null>(null)+ const menuRef = useRef<HTMLDivElement | null>(null)const optionRefs = useRef<Array<HTMLButtonElement | null>>([])const selectedIndex = options.findIndex(option => option.value === value)const selectedOption = selectedIndex >= 0 ? options[selectedIndex] : nullconst close = useCallback(() => setOpen(false), [])- useClickOutside(rootRef, open, close)+ useEffect(() => {+ if (!open) return+ const handlePointerDown = (event: MouseEvent) => {+ const target = event.target as Node+ if (!rootRef.current?.contains(target) && !menuRef.current?.contains(target)) close()+ }+ document.addEventListener('mousedown', handlePointerDown)+ return () => document.removeEventListener('mousedown', handlePointerDown)+ }, [close, open])++ const updatePortalPosition = useCallback(() => {+ const trigger = triggerRef.current+ if (!trigger) return+ const rect = trigger.getBoundingClientRect()+ const gap = 4+ const viewportPadding = 8+ const estimatedHeight = Math.min(260, 8 + options.length * 40)+ const menuHeight = menuRef.current?.offsetHeight || estimatedHeight+ const roomBelow = window.innerHeight - rect.bottom - viewportPadding+ const roomAbove = rect.top - viewportPadding+ const opensAbove = menuHeight > roomBelow && roomAbove > roomBelow+ const top = opensAbove+ ? Math.max(viewportPadding, rect.top - menuHeight - gap)+ : Math.max(+ viewportPadding,+ Math.min(rect.bottom + gap, window.innerHeight - menuHeight - viewportPadding)+ )+ const width = rect.width+ const left = Math.min(+ Math.max(viewportPadding, rect.left),+ Math.max(viewportPadding, window.innerWidth - width - viewportPadding)+ )+ setPortalPosition({ left, top, width })+ }, [options.length])++ useLayoutEffect(() => {+ if (!portal || !open) return+ updatePortalPosition()+ window.addEventListener('resize', updatePortalPosition)+ window.addEventListener('scroll', updatePortalPosition, true)+ return () => {+ window.removeEventListener('resize', updatePortalPosition)+ window.removeEventListener('scroll', updatePortalPosition, true)+ }+ }, [open, portal, updatePortalPosition])useEffect(() => {if (!open) return@@ -65,8 +117,48 @@ export function DropdownSelect({optionRefs.current[nextIndex]?.focus()}+ const menu = open ? (+ <div+ className={`ui-dropdown-select__menu${portal ? ' ui-dropdown-select__menu--portal' : ''}`}+ ref={menuRef}+ role="listbox"+ aria-label={ariaLabel}+ style={+ portal+ ? portalPosition+ ? {+ left: portalPosition.left,+ top: portalPosition.top,+ width: portalPosition.width,+ }+ : { left: 0, top: 0, visibility: 'hidden' }+ : undefined+ }+ >+ {options.map((option, index) => (+ <MenuItem+ active={option.value === value}+ aria-selected={option.value === value}+ className="ui-dropdown-select__option"+ key={option.value}+ onClick={() => choose(option.value)}+ ref={element => {+ optionRefs.current[index] = element+ }}+ role="option"+ >+ {option.label}+ </MenuItem>+ ))}+ </div>+ ) : null+return (- <div className="ui-dropdown-select" onKeyDown={handleKeyDown} ref={rootRef}>+ <div+ className={`ui-dropdown-select${className ? ` ${className}` : ''}`}+ onKeyDown={handleKeyDown}+ ref={rootRef}+ ><Buttonalign="between"aria-expanded={open}@@ -85,25 +177,7 @@ export function DropdownSelect({</span><span className="ui-dropdown-select__chevron" aria-hidden="true" /></Button>- {open ? (- <div className="ui-dropdown-select__menu" role="listbox" aria-label={ariaLabel}>- {options.map((option, index) => (- <MenuItem- active={option.value === value}- aria-selected={option.value === value}- className="ui-dropdown-select__option"- key={option.value}- onClick={() => choose(option.value)}- ref={element => {- optionRefs.current[index] = element- }}- role="option"- >- {option.label}- </MenuItem>- ))}- </div>- ) : null}+ {portal && menu ? createPortal(menu, document.body) : menu}</div>)}diff --git a/desktop-app/ui/src/components/Common/DropdownSelect/types.ts b/desktop-app/ui/src/components/Common/DropdownSelect/types.tsindex fb86ba2c4..1dab73a54 100644--- a/desktop-app/ui/src/components/Common/DropdownSelect/types.ts+++ b/desktop-app/ui/src/components/Common/DropdownSelect/types.ts@@ -5,10 +5,13 @@ export type DropdownSelectOption = {export type DropdownSelectProps = {ariaLabel?: string+ className?: stringdisabled?: booleanid?: stringonChange: (value: string) => voidoptions: DropdownSelectOption[]placeholder: string+ /** Render the menu at document.body so ancestor overflow cannot clip it. */+ portal?: booleanvalue: string}diff --git a/desktop-app/ui/src/gfs/GfsGrantList/index.tsx b/desktop-app/ui/src/gfs/GfsGrantList/index.tsxindex 358ca3cf6..91ad34ce3 100644--- a/desktop-app/ui/src/gfs/GfsGrantList/index.tsx+++ b/desktop-app/ui/src/gfs/GfsGrantList/index.tsx@@ -145,6 +145,7 @@ export function GfsGrantList({onChange={value => void onChangeRole?.(item, label, value as GfsAccessRole)}options={ROLE_OPTIONS}placeholder="Role"+ portalvalue={roleForPermissions(item.permissions)}/></span>diff --git a/desktop-app/ui/src/gfs/__tests__/GfsGrantList.test.tsx b/desktop-app/ui/src/gfs/__tests__/GfsGrantList.test.tsxindex 4046114f6..38394142d 100644--- a/desktop-app/ui/src/gfs/__tests__/GfsGrantList.test.tsx+++ b/desktop-app/ui/src/gfs/__tests__/GfsGrantList.test.tsx@@ -138,6 +138,7 @@ describe('GfsGrantList', () => {)fireEvent.click(screen.getByRole('button', { name: 'Access role for Test Two' }))+ expect(screen.getByRole('listbox').parentElement).toBe(document.body)fireEvent.click(screen.getByRole('option', { name: 'Editor' }))expect(onChangeRole).toHaveBeenCalledWith(item, 'Test Two', 'editor')})diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex 008fd3961..82ff5c590 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -9193,6 +9193,11 @@ button.page-breadcrumb-link--plain-action:hover:enabled {scrollbar-width: thin;}+.ui-dropdown-select__menu--portal {+ position: fixed;+ z-index: calc(var(--layer-dropdown) + 40);+}+.ui-dropdown-select__option.ui-menu-item {min-height: 38px;padding-inline: var(--space-2);