mirror of
https://github.com/stablyai/orca.git
synced 2026-09-24 16:02:41 +00:00
Keep main workspace first in project groups (#3178)
Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
This commit is contained in:
@@ -638,6 +638,39 @@ describe('buildRows project grouping order', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps the main workspace first inside its project group', () => {
|
||||
const main = {
|
||||
...wA,
|
||||
id: 'wt-a-main',
|
||||
displayName: 'main',
|
||||
isMainWorktree: true
|
||||
}
|
||||
const freshChild = {
|
||||
...wA,
|
||||
id: 'wt-a-fresh-child',
|
||||
displayName: 'fresh-child',
|
||||
isMainWorktree: false
|
||||
}
|
||||
const rows = buildRows(
|
||||
'repo',
|
||||
[freshChild, wB, main],
|
||||
map,
|
||||
null,
|
||||
new Set(),
|
||||
undefined,
|
||||
undefined,
|
||||
'visible-worktree-order'
|
||||
)
|
||||
|
||||
expect(rows).toMatchObject([
|
||||
{ type: 'header', key: 'repo:repo-a' },
|
||||
{ type: 'item', worktree: { id: 'wt-a-main' } },
|
||||
{ type: 'item', worktree: { id: 'wt-a-fresh-child' } },
|
||||
{ type: 'header', key: 'repo:repo-b' },
|
||||
{ type: 'item', worktree: { id: 'wt-b' } }
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps repoOrder for manual project group ordering', () => {
|
||||
const repoOrder = new Map([
|
||||
[repoB.id, 0],
|
||||
|
||||
@@ -381,6 +381,16 @@ function appendWorktreeRows(
|
||||
}
|
||||
}
|
||||
|
||||
function orderMainWorktreeFirst(worktrees: Worktree[]): Worktree[] {
|
||||
const mainWorktrees = worktrees.filter((worktree) => worktree.isMainWorktree)
|
||||
if (mainWorktrees.length === 0) {
|
||||
return worktrees
|
||||
}
|
||||
// Why: project groups are scanned by repo; keep the repo's canonical
|
||||
// workspace anchored even when dynamic sorts rank a child workspace first.
|
||||
return [...mainWorktrees, ...worktrees.filter((worktree) => !worktree.isMainWorktree)]
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the flat row list consumed by the virtualizer.
|
||||
* Extracted here to keep WorktreeList.tsx under the line-count lint limit.
|
||||
@@ -593,7 +603,8 @@ export function buildRows(
|
||||
result.push(buildImportedWorktreesCardRow(candidate, 'repo-group'))
|
||||
}
|
||||
}
|
||||
appendWorktreeRows(result, group.items, repoMap, lineageById, worktreeMap, {
|
||||
const items = groupBy === 'repo' ? orderMainWorktreeFirst(group.items) : group.items
|
||||
appendWorktreeRows(result, items, repoMap, lineageById, worktreeMap, {
|
||||
nestLineage,
|
||||
collapsedGroups
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user