Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions wework/src/App.plugins.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ describe('App plugins route', () => {
localStorage.clear()
vi.stubEnv('DEV', false)
mockViewport.isMobile = false
workbenchValue.state.runtimeWork = null
workbenchValue.state.currentRuntimeTask = null
vi.mocked(workbenchValue.openRuntimeTask).mockReset().mockResolvedValue(undefined)
mockSystemSkillsFetch()
})

Expand All @@ -599,6 +602,50 @@ describe('App plugins route', () => {

await waitFor(() => expect(window.location.pathname).toBe('/plugins'))
expect(await screen.findByTestId('plugins-workspace')).toBeInTheDocument()
expect(screen.queryByTestId('plugins-sidebar-placeholder')).not.toBeInTheDocument()
})

test('opens a runtime task from the plugins sidebar and leaves the plugins route', async () => {
const workspacePath = '/Users/alice/Documents/Codex/plugin-task'
workbenchValue.state.runtimeWork = {
projects: [],
chats: [
{
deviceId: 'local-device',
deviceName: 'Local Mac',
deviceStatus: 'online',
available: true,
workspacePath,
workspaceKind: 'chat',
tasks: [
{
taskId: 'plugin-task',
workspacePath,
workspaceKind: 'chat',
title: 'Return to task',
runtime: 'codex',
},
],
},
],
totalTasks: 1,
}
window.history.pushState({}, '', '/plugins')

render(<App />)

await userEvent.click(await screen.findByTestId('runtime-local-task-row-plugin-task'))

await waitFor(() => {
expect(workbenchValue.openRuntimeTask).toHaveBeenCalledWith({
deviceId: 'local-device',
workspacePath,
taskId: 'plugin-task',
})
expect(window.location.pathname).toBe('/runtime-tasks')
})
expect(window.location.search).toBe('?deviceId=local-device&taskId=plugin-task')
expect(screen.queryByTestId('plugins-workspace')).not.toBeInTheDocument()
})

test('preserves the workbench composer while visiting plugins', async () => {
Expand Down
26 changes: 24 additions & 2 deletions wework/src/components/common/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface ActionMenuProps {
icon?: ComponentType<{ className?: string }>
variant?: 'horizontal' | 'vertical'
triggerClassName?: string
placement?: 'side' | 'bottom-end'
contextMenuPosition?: MenuPosition | null
onContextMenuClose?: () => void
}
Expand All @@ -39,6 +40,7 @@ export function ActionMenu({
icon: Icon = MoreHorizontal,
variant = 'horizontal',
triggerClassName,
placement = 'side',
contextMenuPosition,
onContextMenuClose,
}: ActionMenuProps) {
Expand Down Expand Up @@ -99,6 +101,18 @@ export function ActionMenu({
const trigger = containerRef.current
if (!trigger) return
const triggerRect = trigger.getBoundingClientRect()
if (placement === 'bottom-end') {
const belowTop = triggerRect.bottom + MENU_GAP
const aboveTop = triggerRect.top - menuHeight - MENU_GAP
const top =
belowTop + menuHeight <= viewportHeight - VIEWPORT_PADDING
? belowTop
: Math.max(VIEWPORT_PADDING, aboveTop)
const left = Math.max(VIEWPORT_PADDING, Math.min(triggerRect.right - menuWidth, maxLeft))
setMenuPosition({ left, top })
return
}

const rightSideLeft = triggerRect.right + MENU_GAP
const leftSideLeft = triggerRect.left - menuWidth - MENU_GAP
const hasRoomOnRight = rightSideLeft + menuWidth <= viewportWidth - VIEWPORT_PADDING
Expand All @@ -116,7 +130,7 @@ export function ActionMenu({
window.removeEventListener('resize', updatePosition)
window.removeEventListener('scroll', updatePosition, true)
}
}, [contextMenuPosition, menuOpen])
}, [contextMenuPosition, menuOpen, placement])

useEffect(() => {
if (!menuOpen) return
Expand All @@ -127,9 +141,16 @@ export function ActionMenu({
closeMenu()
}
}
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') closeMenu()
}

document.addEventListener('pointerdown', handlePointerDown)
return () => document.removeEventListener('pointerdown', handlePointerDown)
document.addEventListener('keydown', handleKeyDown)
return () => {
document.removeEventListener('pointerdown', handlePointerDown)
document.removeEventListener('keydown', handleKeyDown)
}
}, [closeMenu, menuOpen])

return (
Expand All @@ -148,6 +169,7 @@ export function ActionMenu({
}
aria-label={ariaLabel}
aria-expanded={menuOpen}
aria-haspopup="menu"
>
<Icon className={variant === 'vertical' ? 'h-4 w-4 rotate-90' : 'h-4 w-4'} />
</button>
Expand Down
Loading
Loading