Repository navigation
feat(desktop): drag-and-drop pinning in the v2 sidebar - #6364
Conversation
One DndContext now spans pinned/sessions/project rows so workspaces can be dragged into, within, and out of the Pinned section. Pinned order stays pinnedAt-ascending via reorderPinnedWorkspaces (anchored rewrite + single-new- pin invariant). Drag handlers read/write container state synchronously to survive event batching under main-thread stalls; per-pointer-move state is kept out of the shared context, drop zones are leaf components, sortable row bodies are memoized, and hover cards are suppressed for the drag's duration.
…derer closestCenter over the two allowed containers (Pinned at the top, home project lower down) flips on sub-pixel movement in the gap between them — and on the layout shift each container transfer itself causes, re-firing with the pointer stationary. The resulting transfer loop remounts the row until React throws 'Maximum update depth exceeded'. Switch workspace drags to dnd-kit's multi-container strategy: pointerWithin, then rectIntersection, then the cached last hit, with a one-frame freeze after each transfer.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughThe sidebar drag-and-drop implementation now uses one shared provider and multi-container state. Projects, sections, pinned workspaces, and sessions support coordinated sorting, pinning, unpinning, overlays, persistence, rollback, and hover suppression. ChangesSidebar drag-and-drop
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant DashboardSidebar
participant DashboardSidebarDndProvider
participant useSidebarDnd
participant useDashboardSidebarState
DashboardSidebar->>DashboardSidebarDndProvider: pass sidebar collections and reorderProjects
DashboardSidebarDndProvider->>useSidebarDnd: handle drag lifecycle events
useSidebarDnd->>useDashboardSidebarState: persist project and workspace ordering
DashboardSidebarDndProvider->>DashboardSidebar: render sortable rows and drag overlay
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useSidebarDnd/useSidebarDnd.ts`:
- Around line 269-276: Remove the render-time assignments to itemsRef.current
and containerByIdRef.current, and avoid rebuilding the container map solely for
those refs. Keep both refs updated exclusively by commitDragItems, while
deriving the render-time container map from items for consumers; route any other
items replacement through commitDragItems.
- Around line 527-531: Update the useEffect that resets
recentlyMovedToNewContainerRef so it depends on items instead of using an empty
dependency array, scheduling the transfer-freeze reset after every items update
while preserving the requestAnimationFrame behavior.</code>
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/providers/DashboardSidebarDndProvider/DashboardSidebarDndProvider.tsx`:
- Around line 77-87: Update handleDragEnd and handleDragCancel in
DashboardSidebarDndProvider to wrap each handler invocation in try/finally,
ensuring endHoverCardSuppression always executes even when handlers.onDragEnd or
handlers.onDragCancel throws.
In
`@apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/providers/DashboardSidebarHoverProvider/DashboardSidebarHoverProvider.tsx`:
- Around line 221-225: Update the delayed open timer callback in
DashboardSidebarHoverProvider to re-check suppressionCountRef.current before
setting hoveredId or triggering hover-open effects; if suppression is active,
exit without opening. Preserve the existing timer behavior when suppression is
inactive.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: d899bead-030a-4f1a-9560-35828e7e238e
📒 Files selected for processing (18)
AGENTS.mdapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/DashboardSidebar.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarPinnedSection/DashboardSidebarPinnedSection.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarProjectSection/DashboardSidebarProjectSection.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarProjectSection/components/DashboardSidebarCollapsedProjectContent/DashboardSidebarCollapsedProjectContent.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarProjectSection/components/DashboardSidebarCollapsedProjectContent/components/SortableCollapsedWorkspaceItem/SortableCollapsedWorkspaceItem.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarProjectSection/components/DashboardSidebarExpandedProjectContent/DashboardSidebarExpandedProjectContent.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarSessionsSection/DashboardSidebarSessionsSection.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/SidebarDragOverlay/SidebarDragOverlay.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/SidebarDropZone/SidebarDropZone.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/SidebarDropZone/index.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/SortableWorkspaceItem/SortableWorkspaceItem.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useSidebarDnd/index.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useSidebarDnd/useSidebarDnd.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/providers/DashboardSidebarDndProvider/DashboardSidebarDndProvider.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/providers/DashboardSidebarDndProvider/index.tsapps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/providers/DashboardSidebarHoverProvider/DashboardSidebarHoverProvider.tsxapps/desktop/src/renderer/routes/_authenticated/hooks/useDashboardSidebarState/useDashboardSidebarState.ts
💤 Files with no reviewable changes (1)
- apps/desktop/src/renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarProjectSection/DashboardSidebarProjectSection.tsx
🚀 Preview Deployment🔗 Preview Links
Preview updates automatically with new commits |
There was a problem hiding this comment.
All reported issues were addressed across 18 files
You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
Architecture diagram
sequenceDiagram
participant UI as Sidebar UI Components
participant DND as DashboardSidebarDndProvider
participant SORT as Sortable Components
participant HOOK as useSidebarDnd Hook
participant STATE as useDashboardSidebarState
participant STORE as Local State Store
Note over UI,STORE: Unified Drag-and-Drop Architecture
UI->>DND: Render sidebar sections (Pinned, Sessions, Projects)
DND->>HOOK: Initialize shared DnD context
HOOK->>HOOK: Build container maps (pinned/sessions/byProject)
HOOK->>STATE: Read workspace/pinned data
Note over UI,SORT: Drag Start
UI->>SORT: Initiate drag on sortable item
SORT->>DND: onDragStart
DND->>HOOK: Register active drag
HOOK->>HOOK: Set activeId, activeType, activeContainer
Note over UI,HOOK: During Drag (Pointer Move)
UI->>SORT: Pointer movement triggers useSortable updates
SORT->>DND: onDragOver (collision detection)
DND->>HOOK: pointerWithin -> rectIntersection -> lastOverId
HOOK->>SORT: Update active container (if crossing boundary)
alt Drag within same container
HOOK->>SORT: Reorder items locally
else Drag to different container (e.g., pin/unpin)
HOOK->>HOOK: Transfer item between container lists
SORT->>SORT: One-frame freeze after transfer
end
Note over UI,SORT: Drop Zone Handling
UI->>SORT: Empty container shows SidebarDropZone
SORT->>DND: useDroppable registers drop zone
Note over UI,STORE: Drag End
UI->>SORT: Drop item
SORT->>DND: onDragEnd
DND->>HOOK: Commit drag operation
alt Drop in place (no change)
HOOK->>HOOK: Compare with drag-start snapshot
HOOK-->>UI: No-op
else Pinned reorder
HOOK->>STATE: reorderPinnedWorkspaces()
STATE->>STORE: Rewrite pinnedAt sequence (anchored)
STORE-->>HOOK: Persisted
else Unpin (drag out of pinned)
HOOK->>STATE: Commit to project/session order
STATE->>STORE: Update tabOrder/section membership
STORE-->>HOOK: Persisted
else New pin (drag into pinned)
HOOK->>STATE: Pin dragged workspace only
STATE->>STORE: Set pinnedAt, clear isHidden
STORE-->>HOOK: Persisted
end
DND-->>UI: Update rendered sidebar
Note over UI,SORT: Hover Card Suppression
DND->>UI: beginHoverCardSuppression (on drag start)
UI->>UI: Suppress hover-open side effects
DND->>UI: endHoverCardSuppression (on drag end/cancel)
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
- Re-arm the post-transfer collision freeze at the transfer site instead of a deps-only effect: biome --unsafe had stripped the [items] dependency, freezing collisions for the rest of the drag after the first container transfer (no drag-out-after-drag-in in one gesture). - Stop re-assigning the drag refs during render; commitDragItems is the only writer, so a discarded concurrent render pass can't roll them back. - Release the hover-card suppression in try/finally so a throwing persistence write can't leave hover cards permanently suppressed. - Re-check suppression when a pending hover-open timer fires.
Rebuilds folders on top of the sidebar DnD that ParadevAI#6364 landed on main instead of carrying a second DndContext beside it. - DashboardSidebar no longer owns a DndContext, sensors, collision detection, drag-end or a DragOverlay. All of that is now DashboardSidebarDndProvider's, which ParadevAI#6364 introduced for pin drag and drop; folders just pass their two extra inputs into it. - useSidebarDnd learns folders: project drags may additionally target a folder header or the root zone, and its project drag-end re-parents on those drops or adopts the target project's folder when reordering. - Collision detection for project drags goes pointer-first. A project section is measured tall at drag start, so closestCenter put its centre far from the cursor and the thin strips were near-impossible to hit. pointerWithin also ranks an ungrouped project row above the root zone that contains it, so dropping there still reorders. - RootDropZone reads the active drag type from the shared context rather than taking an isDragging prop, and now ignores workspace and section drags, which never re-parent a project.
Rebuilds folders on top of the sidebar DnD that ParadevAI#6364 landed on main instead of carrying a second DndContext beside it. - DashboardSidebar no longer owns a DndContext, sensors, collision detection, drag-end or a DragOverlay. All of that is now DashboardSidebarDndProvider's, which ParadevAI#6364 introduced for pin drag and drop; folders just pass their two extra inputs into it. - useSidebarDnd learns folders: project drags may additionally target a folder header or the root zone, and its project drag-end re-parents on those drops or adopts the target project's folder when reordering. - Collision detection for project drags goes pointer-first. A project section is measured tall at drag start, so closestCenter put its centre far from the cursor and the thin strips were near-impossible to hit. pointerWithin also ranks an ungrouped project row above the root zone that contains it, so dropping there still reorders. - RootDropZone reads the active drag type from the shared context rather than taking an isDragging prop, and now ignores workspace and section drags, which never re-parent a project.
* docs: weekly update for PRs merged 2026-08-05 to 2026-08-12 - workspaces: sessions (project-less workspaces, #6274), pin + drag-and-drop pinning (#6364), list/board views with Merged & Deleted history columns (#6296), per-project naming instructions (#6250), multi-PR links per branch with remove/restore (#5924) - automations: session automations (#6280), list health stats + Up next grouping + read-only team automations (#6291, #6276), detail page Settings/Run History tabs, inline run errors, would-run preview, RRule validation (#6305) - editor: image pane pan/pinch/zoom (#6285) - tasks: multi-repo filters, expanded task states, PR author/review filters, PR checks (#6201) - monorepos: per-project sparse checkout (#6034) - customization: project icon + color picker, v1 color carry-over (#6249) - terminal presets: built-in Superset CLI preset (#6270) - agents: resume interrupted sessions + Resume Args setting (#6253, #6265), Superset hooks toggle + scoping (#6072) - cli: interactive command browser + branded help (#6273); reference updated for session mode, --task, --skip-branch-prefix, --session (verified against packages/cli/src/commands) * docs: tighten wording and drop em dashes Shorten this week's additions per the writing guide: one thought per sentence, plainest word, no em dashes as prose punctuation. Also sweeps the three pre-existing em dashes in recipes. * docs: add screenshots from the 08-09 changelog batch cli command browser, agent resume banner, PR view with checks, and the project icon/color picker. Copied into apps/docs/public/images per the SOP rather than referenced across apps.
Links
apps/desktop/plans/done/20260725-1947-sidebar-workspace-pinning.mdSummary
DndContexts to one unified context (pinned / sessions / one container per project) — required because dnd-kit cannot drag across separate contexts.Why / Context
Pinned-section drag reorder was explicitly deferred as decision D6 in the original pinning ExecPlan ("mechanical follow-up if wanted"). It turned out to be non-mechanical: cross-boundary dragging forces the unified-context restructure, which then surfaced the perf and stability work in the later commits.
How It Works
Containers.
useSidebarDndis now a sidebar-level multi-container engine. Every workspace row lives in exactly one container:pinned,sessions, or its project id.SortableContexts stay per-section; oneDndContext(hosted by the newDashboardSidebarDndProvider) spans them all. Container-less targets (empty Pinned, empty Sessions, fully-pinned project) get a leafSidebarDropZone.Collision detection is kind-scoped (projects sort among projects, sections within their project, a workspace may only target Pinned or its home container) and uses dnd-kit's multi-container strategy for workspace drags:
pointerWithin→rectIntersection→ cachedlastOverId, plus a one-frame freeze after each transfer. BareclosestCenteris what crashed: with Pinned at the top and the home project far below, "closest" flips on sub-pixel movement in the gap — and on the layout shift a transfer itself causes — producing a transfer oscillation that remounts the row until React aborts.Persistence. Pinned order stays
pinnedAt-ascending;reorderPinnedWorkspacesrewrites the sequence anchored at the smallest existing pin time so future pins still append last. It also enforces that one drop pins at most one new workspace (the dragged one) — a corrupted caller list can never mass-pin. Unpin drops reuse the existingtabOrder/section commit path. Drop-in-place is compared against the drag-start snapshot and writes nothing.Race-proofing. Drag handlers read and write the item/container refs synchronously. Pointer events batch faster than renders under main-thread stalls; deriving containers from the last rendered state is how a drop once pinned three session rows that were never dragged.
Render fan-out rules (these are the drag-perf load-bearing invariants):
DragOverlayghost);useDroppablelives only in leaf components (its internal context updates per move — hosting it in a section re-renders that section per move);performOpeninert (hover-open side effects like the PR refresh key offhoveredIdeven when the card is hidden).Manual QA (CDP-verified end-to-end, trusted input events, dev app)
All items below were driven with real
Input.dispatchMouseEventsequences and asserted against both screenshots and the persistedv2WorkspaceLocalStatecollection:location.reload()Testing
bun run typecheckbun run lint(exits 0)bun testforDashboardSidebar+useDashboardSidebarState(74 pass)AGENTS.md(CDP rules 7–8)Design Decisions
pinnedAtvs adding an order field: reusingpinnedAtas the ordering key keeps the schema untouched (no migration, no new persisted key) and preserves the "future pins append last" property by anchoring the rewrite belowDate.now().pointerWithin-first vsclosestCenter: pointer containment can't flip in the gap between far-apart containers and removes action-at-a-distance transfers;rectIntersectioncovers keyboard drags; thelastOverIdcache keepsoverstable across disallowed territory.Known Limitations
Follow-ups
sidebar-render-perf(in progress, forked from this one): hover-open PR-refresh cool-down, collapsing ~80 per-row query subscriptions into one sidebar-level subscription, replacing per-row framer-motion wrappers.Risks / Rollout
pinnedAtvalues that the previous build already understands.Summary by cubic
Adds unified drag-and-drop in the v2 sidebar so you can drag workspaces/sessions into Pinned, reorder them, and drag them back out. Fixes a drag crash and tightens persistence to avoid accidental mass pinning.
New Features
DndContextspans Pinned, Sessions, and project lists; cross-boundary drags now work.pinnedAt-ascending; future pins still append. Drag overlay shows the predicted section accent. Sortable row bodies are memoized.Bug Fixes
commitDragItemsis the only writer, and a single drop can pin at most one new workspace.Written for commit 1aab78f. Summary will update on new commits.
Summary by CodeRabbit