The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): drag gateway/profile groups by their header, not only the hidden handle
teknium16bc3628ce810
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.tsxnew file mode 100644index 00000000000..68dc2e85e75--- /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(+ <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']))+})diff --git a/apps/desktop/src/app/chat/sidebar/gateway-groups.tsx b/apps/desktop/src/app/chat/sidebar/gateway-groups.tsxindex 82281dcd412..331d43ef679 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 (<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}/>diff --git a/apps/desktop/src/app/chat/sidebar/reorderable-list.tsx b/apps/desktop/src/app/chat/sidebar/reorderable-list.tsxindex 736096572e7..62d1ed1cda4 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<HTMLElement> = { ...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.mdindex e8c3ddcafb4..81e45bf801d 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 sectionsare remembered on this desktop. Collapsing a gateway preserves its profiles'individual collapse states. Each profile's new-session action targets thatprofile on its owning gateway.