From 6bc3628ce8103cd481012f95a9d41ca08581814d Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Tue, 15 Sep 2026 05:09:15 -0700 Subject: [PATCH] fix(desktop): drag gateway/profile groups by their header, not only the hidden handle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../chat/sidebar/gateway-groups-drag.test.tsx | 99 +++++++++++++++++++ .../src/app/chat/sidebar/gateway-groups.tsx | 17 ++++ .../src/app/chat/sidebar/reorderable-list.tsx | 3 +- .../user-guide/multi-connection-desktop.md | 5 +- 4 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 apps/desktop/src/app/chat/sidebar/gateway-groups-drag.test.tsx diff --git a/apps/desktop/src/app/chat/sidebar/gateway-groups-drag.test.tsx b/apps/desktop/src/app/chat/sidebar/gateway-groups-drag.test.tsx new file mode 100644 index 0000000000..68dc2e85e7 --- /dev/null +++ b/apps/desktop/src/app/chat/sidebar/gateway-groups-drag.test.tsx @@ -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( + + + {}} + /> + + + ) + +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'])) +}) diff --git a/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx b/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx index 82281dcd41..331d43ef67 100644 --- a/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx +++ b/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx @@ -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 ( {group.profile && ( @@ -243,6 +251,8 @@ function GatewayProfileGroup({ } + className={cn(sortable.dragging && 'cursor-grabbing bg-(--ui-sidebar-surface-background)')} + data-glass-opaque={sortable.dragging ? '' : undefined} label={ toggleGatewayGroup(group.id)}> {label} @@ -266,6 +276,13 @@ function GatewayProfileGroup({ )} } + 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} /> diff --git a/apps/desktop/src/app/chat/sidebar/reorderable-list.tsx b/apps/desktop/src/app/chat/sidebar/reorderable-list.tsx index 736096572e..62d1ed1cda 100644 --- a/apps/desktop/src/app/chat/sidebar/reorderable-list.tsx +++ b/apps/desktop/src/app/chat/sidebar/reorderable-list.tsx @@ -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 = { ...attributes, ...listeners } return { dragging: isDragging, - dragHandleProps: { ...attributes, ...listeners }, + dragHandleProps, ref: setNodeRef, reorderable: true as const, style: { diff --git a/website/docs/user-guide/multi-connection-desktop.md b/website/docs/user-guide/multi-connection-desktop.md index e8c3ddcafb..81e45bf801 100644 --- a/website/docs/user-guide/multi-connection-desktop.md +++ b/website/docs/user-guide/multi-connection-desktop.md @@ -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.