Skip to content

Allow manual sorting of Project Groups - #7191

Merged
nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/feature-allow-manual-sorting-of-project-groups
Jul 3, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/feature-allow-manual-sorting-of-project-groups

Conversation

@nwparker

@nwparker nwparker commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #6609.

This adds manual vertical sorting for Project Group headers in the repo-grouped sidebar. Users can drag the folder icon on a Project Group header when that group has reorderable siblings, and the new order persists through the existing updateProjectGroup(groupId, { tabOrder }) path.

The implementation keeps Project Group movement sibling-only by bucketing headers by their effective parentGroupId. That means root groups can be reordered with root groups, nested groups can be reordered with siblings under the same parent, and a drag never implicitly reparents a group.

ELI5

You can now grab a Project Group folder in the sidebar and move it above or below the other groups next to it. Orca remembers that order. It will not accidentally move the group into a different parent group while you are sorting.

Trade-offs

  • Sorting uses the existing numeric ProjectGroup.tabOrder field with midpoint-style ranks, matching the lightweight ordering model already used nearby. This avoids schema/runtime changes, but it does mean repeated insert-between operations can create fractional ranks instead of compacting every sibling order.
  • Dragging is intentionally sibling-only. That is safer for a sorting feature, but it does not add drag-to-reparent behavior.
  • Evidence is focused unit/source coverage rather than an Electron mouse-drag recording. The drag logic mirrors the existing repo-header pointer/virtualizer pattern and is covered at the pure drop/commit level.

Evidence

  • Codex self-review of the final diff: no blocking findings.
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/sidebar/project-group-header-drop.test.ts src/renderer/src/components/sidebar/project-group-header-drag-commit.test.ts src/renderer/src/components/sidebar/project-group-header-dom.test.ts src/renderer/src/components/sidebar/worktree-list-groups.test.ts src/renderer/src/components/sidebar/project-header-drop.test.ts src/renderer/src/components/sidebar/project-header-drag-commit.test.ts — 6 files, 123 tests passed.
  • pnpm exec oxlint src/renderer/src/components/sidebar/WorktreeList.tsx src/renderer/src/components/sidebar/worktree-list-groups.test.ts src/renderer/src/components/sidebar/project-group-header-dom.test.ts src/renderer/src/components/sidebar/project-group-header-drag-commit.test.ts src/renderer/src/components/sidebar/project-group-header-drag-commit.ts src/renderer/src/components/sidebar/project-group-header-drag-contract.ts src/renderer/src/components/sidebar/project-group-header-drag-start.ts src/renderer/src/components/sidebar/project-group-header-drag.ts src/renderer/src/components/sidebar/project-group-header-drop.test.ts src/renderer/src/components/sidebar/project-group-header-drop.ts — passed.
  • pnpm run typecheck:web — passed.
  • git diff --check — passed.
  • Commit hook on 3101fc13e2: oxlint, oxlint --config config/oxlint-react-doctor.json, and oxfmt --write passed on staged files.

@nwparker
nwparker merged commit 0fd2d67 into stablyai:main Jul 3, 2026
2 checks passed
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extends the sidebar's existing repo-header drag/reorder system to also support Project Group headers when grouping by repo. New modules define drag contracts, DOM target detection, drop-index/bucket/tabOrder computation, session creation, and commit logic. A new useProjectGroupHeaderDrag hook implements pointer-based drag lifecycle handling (arming, promotion, autoscroll, drop preview, commit/cancel). WorktreeList.tsx wires this hook, adds lookup maps, a drop indicator, header DOM attributes, and drag-handle event routing, committing reorder results via updateProjectGroup with a new tabOrder. Corresponding unit tests were added across the new helper modules and existing grouping/DOM tests.

Changes

Cohort: Project Group header drag-and-drop reordering

  • Added drag contract types, initial state, threshold/selectors, and pointer-target detection helpers.
  • Added drop-index, bucket-key, tabOrder, and DOM-rect measurement utilities with unit tests.
  • Added session-creation gatekeeping and drop-commit logic with unit tests.
  • Added useProjectGroupHeaderDrag hook implementing full pointer drag lifecycle, autoscroll, and cursor/selection side effects.
  • Wired drag hook, commit callback, lookup maps, drop indicator, and header attributes into WorktreeList.tsx; added supporting DOM and grouping tests.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant WorktreeList
  participant useProjectGroupHeaderDrag
  participant createProjectGroupHeaderDragSession
  participant commitProjectGroupHeaderDragDrop
  participant updateProjectGroup

  User->>WorktreeList: pointerdown on drag handle
  WorktreeList->>useProjectGroupHeaderDrag: onHandlePointerDown
  useProjectGroupHeaderDrag->>createProjectGroupHeaderDragSession: create session
  createProjectGroupHeaderDragSession-->>useProjectGroupHeaderDrag: session or null
  User->>useProjectGroupHeaderDrag: pointermove (promote drag)
  useProjectGroupHeaderDrag->>useProjectGroupHeaderDrag: computeProjectGroupHeaderDropPreview
  User->>useProjectGroupHeaderDrag: pointerup
  useProjectGroupHeaderDrag->>commitProjectGroupHeaderDragDrop: commit(session, dropIndex)
  commitProjectGroupHeaderDragDrop->>WorktreeList: onCommitProjectGroupTabOrder(groupId, tabOrder)
  WorktreeList->>updateProjectGroup: updateProjectGroup(groupId, { tabOrder })
Loading

Estimated code review effort: 4 (High)

Related PRs: None identified.

Suggested labels: enhancement, sidebar, needs-testing

Suggested reviewers: None identified.

🐰 A header hops and drags its feet,
bucketed neat, its order complete,
pointer down, then promoted flight,
tabOrder set with dashed delight,
carrots stacked in project rows tonight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: manual sorting for Project Groups.
Description check ✅ Passed The description is directly related to the changeset and explains the new Project Group sorting behavior.
Linked Issues check ✅ Passed The PR implements vertical manual sorting for Project Groups and persists the order through tabOrder, matching #6609.
Out of Scope Changes check ✅ Passed The added drag, drop, commit, and test changes all support Project Group sorting and appear within scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/renderer/src/components/sidebar/project-group-header-drag.ts (1)

191-223: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Unthrottled DOM measurement on every raw pointermove.

refreshHeaderRects() (querySelectorAll + getBoundingClientRect per header) runs unconditionally on every pointermove event, and is called twice in the same handler right after promotion (Line 211 and again at Line 214). For sidebars with many Project Group headers, this can cause layout thrashing/jank since pointermove can fire at very high frequency. Consider coalescing measurement to the existing requestAnimationFrame loop (runAutoscrollFrame) instead of doing it synchronously per pointer event, and dropping the redundant call on the promotion frame.

src/renderer/src/components/sidebar/WorktreeList.tsx (1)

1406-1409: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate Map construction from projectGroups.

This memo is structurally identical to projectGroupByIdForFolderPathStatus (Lines 1759-1762): both build new Map(projectGroups.map((group) => [group.id, group])). Consider reusing a single memoized map for both consumers to avoid the duplicate allocation/iteration on every projectGroups change.

♻️ Proposed consolidation
-  const projectGroupByIdForHeaderDrag = useMemo(
-    () => new Map(projectGroups.map((group) => [group.id, group])),
-    [projectGroups]
-  )
+  const projectGroupById = useMemo(
+    () => new Map(projectGroups.map((group) => [group.id, group])),
+    [projectGroups]
+  )

and reuse projectGroupById in place of both projectGroupByIdForHeaderDrag and projectGroupByIdForFolderPathStatus.

src/renderer/src/components/sidebar/project-group-header-dom.test.ts (1)

5-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Source-string matching is brittle test coverage.

This test reads WorktreeList.tsx as raw text and asserts literal substrings (e.g. exact attribute expressions, exact callback bodies). Any harmless refactor — renaming a local variable, reformatting, or restructuring the JSX without changing behavior — will break these assertions even though the actual DOM output/behavior is unaffected. Consider replacing with a render-based test (React Testing Library) that mounts the component and asserts on the rendered data-project-group-header-* attributes and the updateProjectGroup call via a mocked store, which would validate actual behavior instead of source text.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 940ee793-edeb-4666-b57e-439cf4856e9a

📥 Commits

Reviewing files that changed from the base of the PR and between 4caea00 and 3101fc1.

📒 Files selected for processing (10)
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/project-group-header-dom.test.ts
  • src/renderer/src/components/sidebar/project-group-header-drag-commit.test.ts
  • src/renderer/src/components/sidebar/project-group-header-drag-commit.ts
  • src/renderer/src/components/sidebar/project-group-header-drag-contract.ts
  • src/renderer/src/components/sidebar/project-group-header-drag-start.ts
  • src/renderer/src/components/sidebar/project-group-header-drag.ts
  • src/renderer/src/components/sidebar/project-group-header-drop.test.ts
  • src/renderer/src/components/sidebar/project-group-header-drop.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.test.ts

@@ -0,0 +1,304 @@
import { useCallback, useEffect, useRef, useState } from 'react'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
sed -n '1,5p;280,300p' src/renderer/src/components/sidebar/project-group-header-drag.ts
rg -n "^import" src/renderer/src/components/sidebar/project-group-header-drag.ts
rg -n "React\." src/renderer/src/components/sidebar/project-group-header-drag.ts

Repository: stablyai/orca

Length of output: 1978


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Re-check the target file and nearby type usage.
sed -n '1,40p;170,250p;275,300p' src/renderer/src/components/sidebar/project-group-header-drag.ts

# Show imports in the related sibling files for comparison.
sed -n '1,25p' src/renderer/src/components/sidebar/project-group-header-drag-contract.ts
sed -n '1,25p' src/renderer/src/components/sidebar/project-group-header-drag-start.ts

# Quick structural check for any React namespace import in the target file.
rg -n "^(import|type import).*React|React\." src/renderer/src/components/sidebar/project-group-header-drag.ts

Repository: stablyai/orca

Length of output: 1949


🌐 Web query:

TypeScript React.PointerEvent without importing React namespace Cannot find namespace React @types/react named import React.PointerEvent module

💡 Result:

The error occurs because React event types like PointerEvent are namespaced under the React module (e.g., React.PointerEvent) [1][2], while the global PointerEvent refers to the standard browser API [3]. To use React's specific PointerEvent type without importing the entire React namespace, you can use a named import from the 'react' package: import { PointerEvent } from 'react'; // Example usage const handlePointerDown = (event: PointerEvent) => { console.log(event.pointerId); }; Why this happens: 1. Namespace Collision: TypeScript distinguishes between the global browser interface PointerEvent (defined in your project's lib.dom.d.ts) and the React-specific interface (defined in @types/react) [1][3]. 2. React Event System: React uses SyntheticEvents, which wrap native browser events [4][5]. The React.PointerEvent type includes properties specific to React's synthetic event system (e.g., nativeEvent) and generics to type the target element, such as HTMLDivElement [1][2]. 3. Importing: If you simply use PointerEvent without an import, TypeScript defaults to the global browser interface [3]. If you try to use React.PointerEvent without having React in scope, TypeScript throws "Cannot find namespace React" [2]. If you are writing a standard React component, the named import method above is the recommended and standard approach [4][5]. If you are working with vanilla DOM event listeners (like window.addEventListener) rather than React JSX props (like onPointerDown={...}), you should use the native browser PointerEvent instead and avoid importing from 'react' [6].

Citations:


Import the React pointer event type as an alias here

React.PointerEvent is used without a React namespace import, so this module won’t type-check. Import PointerEvent from react as an alias and use that in onHandlePointerDown, while keeping the native DOM PointerEvent for the window listeners below.

Comment on lines +1628 to +1640
const commitProjectGroupHeaderOrder = useCallback(
(groupId: string, tabOrder: number) => {
if (!Number.isFinite(tabOrder)) {
return
}
const suppressUntil =
window.performance.now() + USER_SCROLL_MEASUREMENT_ADJUSTMENT_SUPPRESS_MS
suppressMeasurementAdjustmentUntilRef.current = suppressUntil
directScrollInputUntilRef.current = suppressUntil
void updateProjectGroup(groupId, { tabOrder })
},
[updateProjectGroup]
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Missing "why" comment for scroll-suppression pattern.

commitProjectGroupHeaderOrder duplicates the exact scroll-measurement-suppression technique used in commitRepoReorder (lines 1425-1436), but that block is preceded by an explicit "Why" comment explaining the non-obvious rationale (reorder relocates a group without changing totalSize, so scrollTop is already stable). The new function has no such comment, leaving the rationale undocumented at this second call site.

📝 Proposed fix
+  // Why: reordering a project group header relocates it (and its rows) without
+  // changing totalSize, so scrollTop is already the visually-stable position;
+  // suppress measurement/anchor correction so it doesn't chase the moved row.
   const commitProjectGroupHeaderOrder = useCallback(
     (groupId: string, tabOrder: number) => {

As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const commitProjectGroupHeaderOrder = useCallback(
(groupId: string, tabOrder: number) => {
if (!Number.isFinite(tabOrder)) {
return
}
const suppressUntil =
window.performance.now() + USER_SCROLL_MEASUREMENT_ADJUSTMENT_SUPPRESS_MS
suppressMeasurementAdjustmentUntilRef.current = suppressUntil
directScrollInputUntilRef.current = suppressUntil
void updateProjectGroup(groupId, { tabOrder })
},
[updateProjectGroup]
)
// Why: reordering a project group header relocates it (and its rows) without
// changing totalSize, so scrollTop is already the visually-stable position;
// suppress measurement/anchor correction so it doesn't chase the moved row.
const commitProjectGroupHeaderOrder = useCallback(
(groupId: string, tabOrder: number) => {
if (!Number.isFinite(tabOrder)) {
return
}
const suppressUntil =
window.performance.now() + USER_SCROLL_MEASUREMENT_ADJUSTMENT_SUPPRESS_MS
suppressMeasurementAdjustmentUntilRef.current = suppressUntil
directScrollInputUntilRef.current = suppressUntil
void updateProjectGroup(groupId, { tabOrder })
},
[updateProjectGroup]
)

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Allow manual sorting of Project Groups

1 participant