fix(desktop): drag gateway/profile groups by their header, not only the hidden handle

The Gateway & profile sidebar sections carried dnd-kit listeners on the lead
glyph alone, and that glyph only reveals its grabber on hover — so a press on
the row's name or empty space did nothing and users fell back to the ⋯ menu's
Move up / Move down. Bind the sortable to the whole header (same shape as a
project row), with the handle and the ⋯/caret cluster keeping their own
gestures; a sub-threshold press on the label is still the fold click.

Live: Playwright pointer drag on the header label reorders sections (before:
unchanged, after: reordered); handle-drag still works. Test drives dnd-kit's
keyboard sensor on the label and is red on the old binding.
This commit is contained in:
teknium1
2026-09-15 05:09:15 -07:00
committed by Teknium
parent 78d338b9ee
commit 6bc3628ce8
4 changed files with 121 additions and 3 deletions
@@ -0,0 +1,99 @@
// @vitest-environment jsdom
import { act, cleanup, fireEvent, render, screen, within } from '@testing-library/react'
import { MemoryRouter } from 'react-router'
import { afterEach, expect, it, vi } from 'vitest'
import { SidebarProvider } from '@/components/ui/sidebar'
import { $connectionsRegistry } from '@/store/connection-registry-state'
import { setSidebarGrouping } from '@/store/layout'
import { $profiles } from '@/store/profile'
import { $sessions } from '@/store/session'
import { makeSessionInfo } from '@/test/session-info'
import { $gatewayGroupOrder } from './gateway-group-preferences'
import { ChatSidebar } from './index'
// Gateway/profile groups reorder by drag as well as by the ⋯ menu's Move
// up/down. The grab handle only reveals itself on hover, so the visible
// affordance is the header itself: a press on the label must arm the dnd
// sortable (the lead handle already did). Proven red on the version where only
// the handle carried the listeners.
const noop = () => {}
const mount = () =>
render(
<MemoryRouter>
<SidebarProvider>
<ChatSidebar
currentView="chat"
onArchiveSession={noop}
onBranchSession={noop}
onDeleteSession={noop}
onLoadMoreSessions={noop}
onManageCronJob={noop}
onNavigate={noop}
onNewSessionInWorkspace={noop}
onNewSessionSplit={noop}
onResumeSession={vi.fn()}
onTriggerCronJob={async () => {}}
/>
</SidebarProvider>
</MemoryRouter>
)
afterEach(() => {
cleanup()
$gatewayGroupOrder.set([])
})
it('reorders gateway sections by dragging the header label, not only the grab handle', async () => {
mount()
act(() => {
$connectionsRegistry.set({
version: 2,
primary: 'local',
secureTokenStorage: true,
connections: [
{ id: 'local', label: 'This device', kind: 'local', tokenSet: false, tokenPreview: null },
{ id: 'remote-1', label: 'Homelab', kind: 'remote', tokenSet: false, tokenPreview: null }
]
})
$profiles.set([{ name: 'default', is_default: true }] as typeof $profiles.value)
setSidebarGrouping('profile')
$sessions.set(
['local', 'remote-1'].map(connection_id =>
makeSessionInfo({ id: connection_id, connection_id, profile: 'default', last_active: Date.now() / 1000 })
)
)
})
const sectionIds = () =>
[...document.querySelectorAll('[data-gateway-section]')].map(node => node.getAttribute('data-gateway-section'))
const device = screen.getByText('This device').closest('[data-gateway-section]') as HTMLElement
expect(sectionIds()).toEqual([JSON.stringify(['gateway', 'remote-1']), JSON.stringify(['gateway', 'local'])])
// dnd-kit's KeyboardSensor: Space on the focused sortable arms the drag,
// ArrowUp moves it over the previous item, Space drops. Drives the same
// listeners the pointer path binds, without needing layout in jsdom.
// The fold link, not the row (which dnd-kit also names as a sortable button).
const label = within(device).getByRole('button', { expanded: true, name: 'This device' })
label.focus()
await act(async () => {
fireEvent.keyDown(label, { code: 'Space', key: ' ' })
await Promise.resolve()
})
await act(async () => {
fireEvent.keyDown(label, { code: 'ArrowUp', key: 'ArrowUp' })
await Promise.resolve()
})
await act(async () => {
fireEvent.keyDown(label, { code: 'Space', key: ' ' })
await Promise.resolve()
})
expect($gatewayGroupOrder.get()[0]).toBe(JSON.stringify(['gateway', 'local']))
expect(sectionIds()[0]).toBe(JSON.stringify(['gateway', 'local']))
})
@@ -21,6 +21,7 @@ import { ProfileGlyph } from '@/components/ui/profile-glyph'
import type { SessionInfo } from '@/hermes'
import { useI18n } from '@/i18n'
import { useStoreSelector } from '@/lib/use-session-slice'
import { cn } from '@/lib/utils'
import { $connectionsRegistry } from '@/store/connection-registry-state'
import { newSessionInAgent, newSessionInProfile } from '@/store/profile'
import { $sessionProfilesUsage } from '@/store/session'
@@ -180,12 +181,19 @@ function GatewayProfileGroup({
return (
<SidebarRowStack
className={cn(sortable.dragging && 'relative z-10')}
data-gateway-group={group.profile ? group.id : undefined}
data-gateway-section={!group.profile ? group.id : undefined}
ref={sortable.ref}
style={sortable.style}
>
<SidebarGroupRow
// The whole header is grab surface, same as a project row: the lead
// glyph only reveals its grabber on hover, so a press anywhere on the
// row must start the reorder too. The ⋯/caret cluster and the handle
// keep their own gestures; a sub-threshold press on the label is still
// the click that folds the group.
{...sortable.dragHandleProps}
actions={
<div className="flex items-center">
{group.profile && (
@@ -243,6 +251,8 @@ function GatewayProfileGroup({
</DropdownMenu>
</div>
}
className={cn(sortable.dragging && 'cursor-grabbing bg-(--ui-sidebar-surface-background)')}
data-glass-opaque={sortable.dragging ? '' : undefined}
label={
<SidebarRowLink aria-expanded={open} onClick={() => toggleGatewayGroup(group.id)}>
{label}
@@ -266,6 +276,13 @@ function GatewayProfileGroup({
)}
</SidebarRowGrab>
}
onPointerDown={event => {
if ((event.target as HTMLElement).closest('[data-reorder-handle], [data-row-actions]')) {
return
}
sortable.dragHandleProps.onPointerDown?.(event)
}}
toggle={{ ariaLabel: s.projects.toggle(label, !open), onToggle: () => toggleGatewayGroup(group.id), open }}
totals={usage ? { costUsd: usage.cost_usd, tokens: usage.tokens } : undefined}
/>
@@ -63,10 +63,11 @@ export function ReorderableList({
export function useSortableBindings(id: string) {
const { attributes, isDragging, listeners, setNodeRef, transform, transition } = useSortable({ id })
const dragHandleProps: React.HTMLAttributes<HTMLElement> = { ...attributes, ...listeners }
return {
dragging: isDragging,
dragHandleProps: { ...attributes, ...listeners },
dragHandleProps,
ref: setNodeRef,
reorderable: true as const,
style: {
@@ -92,8 +92,9 @@ headers show the profile name.
Use a gateway or profile section's menu to **Rename group**, **Reset name**, **Move up**, or
**Move down**. Renaming changes only the sidebar label, not the gateway or profile.
Gateways reorder as complete sections, and profiles reorder within their own gateway.
Drag the section's leading icon to reorder it, or focus that handle and use
Space, arrow keys, then Space to place it. Names, order, and collapsed sections
Drag the section header anywhere (its icon, its name, or the empty space) to
reorder it, or focus the header and use Space, arrow keys, then Space to place
it. Names, order, and collapsed sections
are remembered on this desktop. Collapsing a gateway preserves its profiles'
individual collapse states. Each profile's new-session action targets that
profile on its owning gateway.