Repository navigation
Conversation
📝 WalkthroughWalkthroughThe sidebar now measures section-end boundaries for repo and project-group headers, uses a shared indicator component for drop previews, and moves drag activation to the full header row. Repo and project-group drag preview logic now tracks extended section bounds, with project-group reordering committing explicit tab-order updates. The PR also updates unit tests and adds an end-to-end spec for manual sorting and drag interactions. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
🧹 Nitpick comments (1)
src/renderer/src/components/sidebar/WorktreeList.tsx (1)
4191-4239: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider a short "Why" comment for the row-level drag handle.
This changes the drag handle from the icon to the entire header row while still needing the row's
onClick/collapse toggle, action buttons, and drag arming to coexist correctly (opt-outs live inproject-group-header-drag-contract.ts). A one-line comment here explaining that the whole row is now the handle (and where the action/collapse exclusions are enforced) would help future maintainers avoid re-introducing per-icon-only wiring.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. Keep comments short — one or two lines, capturing only the non-obvious reason."
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 23883017-b85f-4e98-9dff-1d45b20e4531
📥 Commits
Reviewing files that changed from the base of the PR and between 653f349 and 02a6b78778943668f54abb1fbde9248a4bac2f28.
📒 Files selected for processing (7)
src/renderer/src/components/sidebar/WorktreeList.tsxsrc/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-start.test.tssrc/renderer/src/components/sidebar/project-group-header-drop.test.tssrc/renderer/src/components/sidebar/project-group-header-drop.tstests/e2e/project-group-manual-sort.spec.ts
02a6b78 to
7f71bd9
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/e2e/project-group-manual-sort.spec.ts (1)
140-176: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate drag/measurement helpers — consider a shared generic implementation.
getProjectHeaderOrder/getProjectGroupHeaderOrderanddragProjectBefore/dragProjectGroupBeforeare each near-identical, differing only by thedata-*attribute name. Parameterizing by attribute would remove the duplication.♻️ Suggested consolidation
-async function getProjectHeaderOrder( - page: Page, - projectIds: SeededProjectHeaderSortScenario -): Promise<string[]> { - const expectedIds = new Set(Object.values(projectIds)) - return page.locator('[data-worktree-sidebar] [data-repo-header-id]').evaluateAll( - (elements, ids) => - elements - .map((element) => ({ - id: element.getAttribute('data-repo-header-id') ?? '', - top: element.getBoundingClientRect().top - })) - .filter((entry) => ids.includes(entry.id)) - .sort((left, right) => left.top - right.top) - .map((entry) => entry.id), - [...expectedIds] - ) -} - -async function getProjectGroupHeaderOrder( - page: Page, - groupIds: SeededProjectGroupSortScenario -): Promise<string[]> { - const expectedIds = new Set(Object.values(groupIds)) - return page.locator('[data-worktree-sidebar] [data-project-group-header-id]').evaluateAll( - (elements, ids) => - elements - .map((element) => ({ - id: element.getAttribute('data-project-group-header-id') ?? '', - top: element.getBoundingClientRect().top - })) - .filter((entry) => ids.includes(entry.id)) - .sort((left, right) => left.top - right.top) - .map((entry) => entry.id), - [...expectedIds] - ) -} +async function getHeaderOrder( + page: Page, + attribute: string, + ids: Record<string, string> +): Promise<string[]> { + const expectedIds = new Set(Object.values(ids)) + return page.locator(`[data-worktree-sidebar] [${attribute}]`).evaluateAll( + (elements, attr, wantedIds) => + elements + .map((element) => ({ + id: element.getAttribute(attr) ?? '', + top: element.getBoundingClientRect().top + })) + .filter((entry) => wantedIds.includes(entry.id)) + .sort((left, right) => left.top - right.top) + .map((entry) => entry.id), + attribute, + [...expectedIds] + ) +}A similar parameterization applies to
dragProjectBefore/dragProjectGroupBefore.Also applies to: 178-218
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: dc6070df-832d-4ea7-8699-00dfe6e032c0
📥 Commits
Reviewing files that changed from the base of the PR and between 02a6b78778943668f54abb1fbde9248a4bac2f28 and 7f71bd9cf4f631392a71748eeb54312f82487634.
📒 Files selected for processing (8)
src/renderer/src/components/sidebar/WorktreeList.tsxsrc/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-start.test.tssrc/renderer/src/components/sidebar/project-group-header-drop.test.tssrc/renderer/src/components/sidebar/project-group-header-drop.tssrc/renderer/src/components/sidebar/project-header-drag-start.test.tstests/e2e/project-group-manual-sort.spec.ts
🚧 Files skipped from review as they are similar to previous changes (6)
- src/renderer/src/components/sidebar/project-group-header-drag-start.test.ts
- src/renderer/src/components/sidebar/project-group-header-drag-commit.ts
- src/renderer/src/components/sidebar/project-group-header-drag-commit.test.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/WorktreeList.tsx
7f71bd9 to
338618d
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (6)
tests/e2e/project-group-manual-sort.spec.ts (2)
193-197: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExplain the magic drop-offset constants.
The
+3,* 0.75, and+32pixel offsets encode non-obvious knowledge about how the drop-preview/section-boundary logic classifies a "before" vs "body" drop. As per coding guidelines,**/*.{ts,tsx,js,jsx}: "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. Keep comments short — one or two lines, capturing only the non-obvious reason." A short comment on why these specific fractions/offsets reliably land in the intended drop zone would prevent future edits from silently breaking these tests.Example
+ // Why: a few px below the target's top edge lands in the "before" drop band, + // per the section-boundary drop-preview geometry. await args.page.mouse.move(targetBox.x + targetBox.width / 2, targetBox.y + 3, { steps: 8 })Also applies to: 214-227, 244-248
Source: Coding guidelines
178-248: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsolidate near-duplicate drag/order helpers.
dragProjectBefore/dragProjectGroupBeforeandgetProjectHeaderOrder/getProjectGroupHeaderOrderare structurally identical, differing only by the data attribute name. Extracting a single parameterized helper (attribute name as an argument) would reduce duplication and keep future geometry tweaks in one place.src/renderer/src/components/sidebar/worktree-header-section-boundaries.ts (2)
41-63: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMissing "why" comment for non-obvious section-end termination logic.
The condition
rowDepth <= depth || (!row.repo && !row.projectGroup)encodes a subtle rule (stop at a sibling/shallower header, or a non-project flat header) that isn't obvious from the code alone. A short comment explaining the intent would help future maintainers avoid regressing this boundary detection.Based on learnings, the coding guidelines require: "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."
Source: Coding guidelines
65-131: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated traversal/boundary logic between repo and project-group section-end helpers.
getRepoHeaderSectionEndByRepoIdandgetProjectGroupHeaderSectionEndByGroupIdshare nearly identical structure (row-starts computation, bucket lookup, next-sibling lookup, fallback via a "find next boundary" scan). Consider extracting a shared generic helper parameterized by a row-id extractor and a "find section end" strategy to avoid divergence between the two nearly-parallel implementations as this logic evolves.src/renderer/src/components/sidebar/project-header-drop.ts (2)
119-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNear-duplicate boundary/drop logic with
project-group-header-drop.ts.
getOptionalNumberAttributeand the entirecomputeProjectHeaderDropPreviewboundary/hovered-rect algorithm are duplicated almost verbatim inproject-group-header-drop.ts'scomputeProjectGroupHeaderDropPreview. Both files were touched together in this PR to addsectionBottom-aware handling — consider extracting the shared attribute-parsing helper and drop-preview math into a common module keyed by a generic rect shape, so future fixes (like this one) don't need to be applied twice.Also applies to: 183-250
198-211: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a short "why" comment for the
lastBoundaryBottomboundary extension.Using
Math.max(last.bottom, last.sectionBottom ?? last.bottom)as the effective bottom for boundary detection is the core fix for the duplicate-tabOrderend-of-list bug, but the rationale isn't captured in a comment — a future refactor could easily drop this and regress the fix silently.Based on learnings, the coding guidelines require: "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."
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a7a9932a-b214-4b99-8782-3dcd16bb190c
📥 Commits
Reviewing files that changed from the base of the PR and between 7f71bd9cf4f631392a71748eeb54312f82487634 and 338618dded41f273b1375016349364272d28f86f.
📒 Files selected for processing (14)
src/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/WorktreeSidebarDropIndicator.tsxsrc/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-start.test.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/project-header-drag-start.test.tssrc/renderer/src/components/sidebar/project-header-drag.tssrc/renderer/src/components/sidebar/project-header-drop.test.tssrc/renderer/src/components/sidebar/project-header-drop.tssrc/renderer/src/components/sidebar/worktree-header-section-boundaries.tstests/e2e/project-group-manual-sort.spec.ts
✅ Files skipped from review due to trivial changes (2)
- src/renderer/src/components/sidebar/WorktreeSidebarDropIndicator.tsx
- src/renderer/src/components/sidebar/project-header-drag-start.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/renderer/src/components/sidebar/project-group-header-drag-start.test.ts
- src/renderer/src/components/sidebar/project-group-header-drag-commit.test.ts
- src/renderer/src/components/sidebar/project-group-header-drop.test.ts
- src/renderer/src/components/sidebar/project-group-header-drag-commit.ts
Reindex affected Project Group siblings on drag so legacy duplicate tabOrder values can represent the requested order, allow dragging from Project Group header bodies, and allow manual project sorting from the project header row instead of only the icon. Keep project and Project Group drops constrained to real header reorder slots so dropping over a project body is a no-op, and use the same solid sidebar drop marker as card reordering. Adds unit coverage plus Electron E2E regressions for issue stablyai#6609.
338618d to
2dac556
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/renderer/src/components/sidebar/worktree-sidebar-header-drop-preview.ts (1)
34-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a short "why" comment for the
sectionBottomboundary extension.The reason the trailing boundary and fallback indicator are computed from
sectionBottom(rather than the header's ownbottom) is non-obvious: it extends the end-of-list drop slot to span the last header's expanded section so a drop below its body still lands on the header reorder slot. A one-line note here (and at Lines 70-73) would preserve that intent.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."
Also applies to: 70-73
Source: Coding guidelines
src/renderer/src/components/sidebar/project-header-drop.ts (1)
117-124: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the duplicated
getOptionalNumberAttributehelper.This helper is byte-for-byte identical to the one in
project-group-header-drop.ts(Lines 135-142). Since both files already import from./worktree-sidebar-header-drop-preview, consider hoisting it into a shared module (that file or a small DOM-attr util) and importing it in both places to avoid divergence.tests/e2e/project-group-manual-sort.spec.ts (1)
178-248: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate drag-before helper logic.
dragProjectBeforeanddragProjectGroupBeforeare identical except for the data attribute used to locate elements. Consider extracting a shared helper parameterized by selector attribute.♻️ Suggested consolidation
-async function dragProjectBefore(args: { - page: Page - draggedProjectId: string - targetProjectId: string -}): Promise<void> { - const source = args.page.locator(`[data-repo-header-id="${args.draggedProjectId}"]`) - const target = args.page.locator(`[data-repo-header-id="${args.targetProjectId}"]`) - ... -} - -async function dragProjectGroupBefore(args: { - page: Page - draggedGroupId: string - targetGroupId: string -}): Promise<void> { - const source = args.page.locator(`[data-project-group-header-id="${args.draggedGroupId}"]`) - const target = args.page.locator(`[data-project-group-header-id="${args.targetGroupId}"]`) - ... -} +async function dragHeaderBefore(args: { + page: Page + attribute: 'data-repo-header-id' | 'data-project-group-header-id' + draggedId: string + targetId: string +}): Promise<void> { + const source = args.page.locator(`[${args.attribute}="${args.draggedId}"]`) + const target = args.page.locator(`[${args.attribute}="${args.targetId}"]`) + // ... shared body +}
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 305837d3-0f80-497a-ac5b-a821dd60b50c
📥 Commits
Reviewing files that changed from the base of the PR and between 338618dded41f273b1375016349364272d28f86f and 2dac556.
📒 Files selected for processing (15)
src/renderer/src/components/sidebar/WorktreeList.tsxsrc/renderer/src/components/sidebar/WorktreeSidebarDropIndicator.tsxsrc/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-start.test.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/project-header-drag-start.test.tssrc/renderer/src/components/sidebar/project-header-drag.tssrc/renderer/src/components/sidebar/project-header-drop.test.tssrc/renderer/src/components/sidebar/project-header-drop.tssrc/renderer/src/components/sidebar/worktree-header-section-boundaries.tssrc/renderer/src/components/sidebar/worktree-sidebar-header-drop-preview.tstests/e2e/project-group-manual-sort.spec.ts
🚧 Files skipped from review as they are similar to previous changes (11)
- src/renderer/src/components/sidebar/project-group-header-drag-start.test.ts
- src/renderer/src/components/sidebar/project-group-header-drag-commit.test.ts
- src/renderer/src/components/sidebar/WorktreeSidebarDropIndicator.tsx
- src/renderer/src/components/sidebar/project-group-header-drop.test.ts
- src/renderer/src/components/sidebar/worktree-header-section-boundaries.ts
- src/renderer/src/components/sidebar/project-group-header-drag-commit.ts
- src/renderer/src/components/sidebar/project-group-header-drag.ts
- src/renderer/src/components/sidebar/project-header-drop.test.ts
- src/renderer/src/components/sidebar/project-header-drag.ts
- src/renderer/src/components/sidebar/project-header-drag-start.test.ts
- src/renderer/src/components/sidebar/WorktreeList.tsx
| await args.page.mouse.move(sourceBox.x + sourceBox.width / 2, sourceBox.y + sourceBox.height / 2) | ||
| await args.page.mouse.down() | ||
| await args.page.mouse.move(targetBox.x + targetBox.width / 2, targetBox.y + 3, { steps: 8 }) | ||
| await args.page.mouse.up() | ||
| } | ||
|
|
||
| async function dragProjectIntoProjectBody(args: { | ||
| page: Page | ||
| draggedProjectId: string | ||
| targetProjectId: string | ||
| }): Promise<void> { | ||
| const source = args.page.locator(`[data-repo-header-id="${args.draggedProjectId}"]`) | ||
| const targetHeader = args.page.locator(`[data-repo-header-id="${args.targetProjectId}"]`) | ||
| await source.scrollIntoViewIfNeeded() | ||
| await targetHeader.scrollIntoViewIfNeeded() | ||
| const sourceBox = await source.boundingBox() | ||
| const targetHeaderBox = await targetHeader.boundingBox() | ||
| if (!sourceBox || !targetHeaderBox) { | ||
| throw new Error('Project body drag bounding box was not available') | ||
| } | ||
|
|
||
| await args.page.mouse.move(sourceBox.x + sourceBox.width / 2, sourceBox.y + sourceBox.height / 2) | ||
| await args.page.mouse.down() | ||
| await args.page.mouse.move( | ||
| targetHeaderBox.x + targetHeaderBox.width / 2, | ||
| targetHeaderBox.y + targetHeaderBox.height * 0.75, | ||
| { steps: 4 } | ||
| ) | ||
| await args.page.mouse.move( | ||
| targetHeaderBox.x + targetHeaderBox.width / 2, | ||
| targetHeaderBox.y + targetHeaderBox.height + 32, | ||
| { steps: 8 } | ||
| ) | ||
| await args.page.mouse.up() | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Unexplained magic pixel offsets in drag simulation.
The + 3, * 0.75, and + 32 offsets used to land the pointer within a header vs. past it into body space aren't explained. The file already follows a "Why:" comment convention elsewhere (lines 52-53, 125-126); these hard-coded geometry assumptions about row/section height deserve the same treatment so future layout changes don't silently break the drop targeting.
Also applies to: 244-247
🧰 Tools
🪛 ast-grep (0.44.0)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFileSync } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
Source: Coding guidelines
Summary
tabOrdervalues can still represent the requested visible order.Fixes #6609. Follow-up to #7191 and #6609 (comment).
Evidence
pnpm vitest run --config config/vitest.config.ts src/renderer/src/components/sidebar/project-header-drop.test.ts src/renderer/src/components/sidebar/project-group-header-drop.test.ts src/renderer/src/components/sidebar/project-header-drag-start.test.ts src/renderer/src/components/sidebar/project-group-header-drag-start.test.ts src/renderer/src/components/sidebar/project-header-drag-commit.test.ts src/renderer/src/components/sidebar/project-group-header-drag-commit.test.ts- 6 files / 40 tests passed.pnpm run test:e2e -- tests/e2e/project-group-manual-sort.spec.ts --workers=1- rebuilt Electron E2E app; 3 tests passed in 34.7s.pnpm run typecheck- passed.pnpm run lint- passed; emitted existing warnings outside this change.git diff --check- passed.