Repository navigation
Conversation
📝 WalkthroughWalkthroughThis 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 ChangesCohort: Project Group header drag-and-drop reordering
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 })
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, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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: 2
🧹 Nitpick comments (3)
src/renderer/src/components/sidebar/project-group-header-drag.ts (1)
191-223: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winUnthrottled DOM measurement on every raw pointermove.
refreshHeaderRects()(querySelectorAll+getBoundingClientRectper header) runs unconditionally on everypointermoveevent, 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 existingrequestAnimationFrameloop (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 winDuplicate
Mapconstruction fromprojectGroups.This memo is structurally identical to
projectGroupByIdForFolderPathStatus(Lines 1759-1762): both buildnew Map(projectGroups.map((group) => [group.id, group])). Consider reusing a single memoized map for both consumers to avoid the duplicate allocation/iteration on everyprojectGroupschange.♻️ 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
projectGroupByIdin place of bothprojectGroupByIdForHeaderDragandprojectGroupByIdForFolderPathStatus.src/renderer/src/components/sidebar/project-group-header-dom.test.ts (1)
5-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoffSource-string matching is brittle test coverage.
This test reads
WorktreeList.tsxas 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 rendereddata-project-group-header-*attributes and theupdateProjectGroupcall 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
📒 Files selected for processing (10)
src/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/project-group-header-dom.test.tssrc/renderer/src/components/sidebar/project-group-header-drag-commit.test.tssrc/renderer/src/components/sidebar/project-group-header-drag-commit.tssrc/renderer/src/components/sidebar/project-group-header-drag-contract.tssrc/renderer/src/components/sidebar/project-group-header-drag-start.tssrc/renderer/src/components/sidebar/project-group-header-drag.tssrc/renderer/src/components/sidebar/project-group-header-drop.test.tssrc/renderer/src/components/sidebar/project-group-header-drop.tssrc/renderer/src/components/sidebar/worktree-list-groups.test.ts
| @@ -0,0 +1,304 @@ | |||
| import { useCallback, useEffect, useRef, useState } from 'react' | |||
There was a problem hiding this comment.
🎯 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.tsRepository: 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.tsRepository: 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:
- 1: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/c7c3b75eeed5fd5edc16914acb1e011769f9a643/types/react/index.d.ts
- 2: https://tderflinger.com/event-typings-of-react-with-type-script
- 3: window.PointerEvent is undefined microsoft/TypeScript#18756
- 4: https://react.dev/learn/typescript
- 5: https://stevekinney.com/courses/react-typescript/typing-dom-and-react-events
- 6: https://stackoverflow.com/questions/71193818/react-onclick-argument-of-type-eventtarget-is-not-assignable-to-parameter-of-t
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.
| 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] | ||
| ) |
There was a problem hiding this comment.
📐 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.
| 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
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
ProjectGroup.tabOrderfield 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.Evidence
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.3101fc13e2:oxlint,oxlint --config config/oxlint-react-doctor.json, andoxfmt --writepassed on staged files.