Show empty project worktrees (#4628)
* Show empty project worktrees Render ungrouped project repositories without active worktrees as sidebar placeholders, keep repo filtering behavior intact, and cover grouping/filtering with focused tests. Design doc: docs/display-empty-project-worktree-card.md * rm design doc
This commit is contained in:
@@ -385,6 +385,65 @@ function setProjectGroupWithoutWorktreeRowsState(filterRepoIds: string[] = []):
|
||||
}
|
||||
}
|
||||
|
||||
function setEmptyUngroupedProjectState(filterRepoIds: string[] = []): void {
|
||||
const repo: Repo = {
|
||||
...makeRepo(),
|
||||
displayName: 'empty-project'
|
||||
}
|
||||
|
||||
mockStore.state = {
|
||||
activeModal: '',
|
||||
activeView: 'terminal',
|
||||
activeWorktreeId: null,
|
||||
agentStatusEpoch: 0,
|
||||
agentStatusByPaneKey: {},
|
||||
browserTabsByWorktree: {},
|
||||
clearPendingRevealWorktreeId: vi.fn(),
|
||||
collapsedGroups: new Set<string>(),
|
||||
deleteStateByWorktreeId: {},
|
||||
filterRepoIds,
|
||||
groupBy: 'repo',
|
||||
hideDefaultBranchWorkspace: false,
|
||||
issueCache: {},
|
||||
migrationUnsupportedByPtyId: {},
|
||||
openModal: vi.fn(),
|
||||
pendingRevealWorktree: null,
|
||||
prCache: {},
|
||||
prVisibleRefreshGeneration: 0,
|
||||
projectGroups: [],
|
||||
ptyIdsByTabId: {},
|
||||
reorderRepos: vi.fn(),
|
||||
reportVisibleGitHubPRRefreshCandidates: vi.fn(),
|
||||
retainedAgentsByPaneKey: {},
|
||||
repos: [repo],
|
||||
runtimePaneTitlesByTabId: {},
|
||||
setFilterRepoIds: vi.fn(),
|
||||
setHideDefaultBranchWorkspace: vi.fn(),
|
||||
setRenamingWorktreeId: vi.fn(),
|
||||
setShowSleepingWorkspaces: vi.fn(),
|
||||
setSortBy: vi.fn(),
|
||||
settings: null,
|
||||
renamingWorktreeId: null,
|
||||
showSleepingWorkspaces: true,
|
||||
sortBy: 'recent',
|
||||
sortEpoch: 0,
|
||||
sshConnectedGeneration: 0,
|
||||
sshConnectionStates: new Map(),
|
||||
sshTargetLabels: new Map(),
|
||||
tabsByWorktree: {},
|
||||
terminalLayoutsByTabId: {},
|
||||
toggleCollapsedGroup: vi.fn(),
|
||||
updateWorktreeMeta: vi.fn(),
|
||||
updateWorktreesMeta: vi.fn(),
|
||||
workspaceStatuses: [],
|
||||
worktreeCardProperties: ['status', 'inline-agents'],
|
||||
worktreeLineageById: {},
|
||||
worktreesByRepo: {
|
||||
[repo.id]: []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function renderWorktreeListMarkup(): Promise<string> {
|
||||
return renderToStaticMarkup(
|
||||
React.createElement(WorktreeList, {
|
||||
@@ -416,6 +475,23 @@ describe('WorktreeList lineage child card renderer', () => {
|
||||
expect(markup).not.toContain('Imported Services')
|
||||
})
|
||||
|
||||
it('renders an empty ungrouped project instead of the empty workspace state', async () => {
|
||||
setEmptyUngroupedProjectState()
|
||||
const markup = await renderWorktreeListMarkup()
|
||||
|
||||
expect(markup).toContain('empty-project')
|
||||
expect(markup).not.toContain('No workspaces found')
|
||||
})
|
||||
|
||||
it('shows Clear Filters when repo filters exclude an empty ungrouped project', async () => {
|
||||
setEmptyUngroupedProjectState(['another-repo'])
|
||||
const markup = await renderWorktreeListMarkup()
|
||||
|
||||
expect(markup).toContain('No workspaces found')
|
||||
expect(markup).toContain('Clear Filters')
|
||||
expect(markup).not.toContain('empty-project')
|
||||
})
|
||||
|
||||
it('renders nested inline agent rows before the nested child-count toggle', async () => {
|
||||
setLineageFixtureState()
|
||||
const markup = await renderWorktreeListMarkup()
|
||||
|
||||
@@ -106,6 +106,7 @@ import {
|
||||
setVisibleWorktreeIds,
|
||||
sidebarHasActiveFilters
|
||||
} from './visible-worktrees'
|
||||
import { getEmptyProjectPlaceholderRepoIds } from './empty-project-placeholder-repos'
|
||||
import {
|
||||
getVisibleWorktreeBrowserActivityTabs,
|
||||
getVisibleWorktreeTerminalActivityTabs,
|
||||
@@ -3982,17 +3983,8 @@ const WorktreeList = React.memo(function WorktreeList({
|
||||
})
|
||||
}, [detectedWorktreesByRepo, filterRepoIds, importedWorktreeCardActionState, repos])
|
||||
const placeholderRepoIds = useMemo(() => {
|
||||
if (groupBy !== 'repo' || projectGroups.length === 0) {
|
||||
return new Set<string>()
|
||||
}
|
||||
const filterSet = filterRepoIds.length > 0 ? new Set(filterRepoIds) : null
|
||||
return new Set(
|
||||
repos
|
||||
.filter((repo) => (worktreesByRepo[repo.id]?.length ?? 0) === 0)
|
||||
.filter((repo) => filterSet === null || filterSet.has(repo.id))
|
||||
.map((repo) => repo.id)
|
||||
)
|
||||
}, [filterRepoIds, groupBy, projectGroups.length, repos, worktreesByRepo])
|
||||
return getEmptyProjectPlaceholderRepoIds({ groupBy, repos, worktreesByRepo, filterRepoIds })
|
||||
}, [filterRepoIds, groupBy, repos, worktreesByRepo])
|
||||
const allRepoIds = useMemo(() => repos.map((r) => r.id), [repos])
|
||||
const reorderReposAction = useAppStore((s) => s.reorderRepos)
|
||||
const projectGroupOrdering = getProjectGroupOrdering(groupBy, sortBy)
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Repo, Worktree } from '../../../../shared/types'
|
||||
import { getEmptyProjectPlaceholderRepoIds } from './empty-project-placeholder-repos'
|
||||
|
||||
const repo: Repo = {
|
||||
id: 'repo-1',
|
||||
path: '/repo',
|
||||
displayName: 'Project',
|
||||
badgeColor: '#000000',
|
||||
addedAt: 1
|
||||
}
|
||||
|
||||
const worktree: Worktree = {
|
||||
id: 'wt-1',
|
||||
repoId: repo.id,
|
||||
path: '/repo/wt-1',
|
||||
displayName: 'main',
|
||||
branch: 'refs/heads/main',
|
||||
head: 'abc123',
|
||||
isBare: false,
|
||||
isMainWorktree: true,
|
||||
comment: '',
|
||||
linkedIssue: null,
|
||||
linkedPR: null,
|
||||
linkedLinearIssue: null,
|
||||
isArchived: false,
|
||||
isUnread: false,
|
||||
isPinned: false,
|
||||
sortOrder: 0,
|
||||
lastActivityAt: 0
|
||||
}
|
||||
|
||||
describe('getEmptyProjectPlaceholderRepoIds', () => {
|
||||
it('returns empty repo placeholders in repo grouping without project groups', () => {
|
||||
expect(
|
||||
Array.from(
|
||||
getEmptyProjectPlaceholderRepoIds({
|
||||
groupBy: 'repo',
|
||||
repos: [repo],
|
||||
worktreesByRepo: { [repo.id]: [] },
|
||||
filterRepoIds: []
|
||||
})
|
||||
)
|
||||
).toEqual([repo.id])
|
||||
})
|
||||
|
||||
it('treats missing worktreesByRepo keys as empty for the current render', () => {
|
||||
expect(
|
||||
Array.from(
|
||||
getEmptyProjectPlaceholderRepoIds({
|
||||
groupBy: 'repo',
|
||||
repos: [repo],
|
||||
worktreesByRepo: {},
|
||||
filterRepoIds: []
|
||||
})
|
||||
)
|
||||
).toEqual([repo.id])
|
||||
})
|
||||
|
||||
it('applies repo filters to empty placeholder candidates', () => {
|
||||
const selectedRepo = { ...repo, id: 'repo-selected' }
|
||||
const hiddenRepo = { ...repo, id: 'repo-hidden' }
|
||||
|
||||
expect(
|
||||
Array.from(
|
||||
getEmptyProjectPlaceholderRepoIds({
|
||||
groupBy: 'repo',
|
||||
repos: [selectedRepo, hiddenRepo],
|
||||
worktreesByRepo: { [selectedRepo.id]: [], [hiddenRepo.id]: [] },
|
||||
filterRepoIds: [selectedRepo.id]
|
||||
})
|
||||
)
|
||||
).toEqual([selectedRepo.id])
|
||||
})
|
||||
|
||||
it('does not create placeholders outside repo grouping', () => {
|
||||
expect(
|
||||
getEmptyProjectPlaceholderRepoIds({
|
||||
groupBy: 'none',
|
||||
repos: [repo],
|
||||
worktreesByRepo: { [repo.id]: [] },
|
||||
filterRepoIds: []
|
||||
}).size
|
||||
).toBe(0)
|
||||
})
|
||||
|
||||
it('does not treat non-empty repos as empty when workspace filters hide their rows', () => {
|
||||
expect(
|
||||
getEmptyProjectPlaceholderRepoIds({
|
||||
groupBy: 'repo',
|
||||
repos: [repo],
|
||||
worktreesByRepo: { [repo.id]: [worktree] },
|
||||
filterRepoIds: []
|
||||
}).size
|
||||
).toBe(0)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { Repo, Worktree } from '../../../../shared/types'
|
||||
import type { WorktreeGroupBy } from './worktree-list-groups'
|
||||
|
||||
export function getEmptyProjectPlaceholderRepoIds(args: {
|
||||
groupBy: WorktreeGroupBy
|
||||
repos: readonly Repo[]
|
||||
worktreesByRepo: Readonly<Record<string, readonly Worktree[] | undefined>>
|
||||
filterRepoIds: readonly string[]
|
||||
}): Set<string> {
|
||||
if (args.groupBy !== 'repo') {
|
||||
return new Set()
|
||||
}
|
||||
|
||||
const filterSet = args.filterRepoIds.length > 0 ? new Set(args.filterRepoIds) : null
|
||||
const placeholderRepoIds = new Set<string>()
|
||||
for (const repo of args.repos) {
|
||||
if (filterSet && !filterSet.has(repo.id)) {
|
||||
continue
|
||||
}
|
||||
if ((args.worktreesByRepo[repo.id]?.length ?? 0) === 0) {
|
||||
placeholderRepoIds.add(repo.id)
|
||||
}
|
||||
}
|
||||
return placeholderRepoIds
|
||||
}
|
||||
@@ -341,6 +341,56 @@ describe('buildRows with pinned worktrees', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('emits an empty ungrouped repo placeholder before imported cards are merged', () => {
|
||||
const rows = buildRows(
|
||||
'repo',
|
||||
[],
|
||||
repoMap,
|
||||
null,
|
||||
new Set(),
|
||||
new Map([[repo.id, 0]]),
|
||||
undefined,
|
||||
'manual',
|
||||
{},
|
||||
new Map(),
|
||||
false,
|
||||
undefined,
|
||||
[],
|
||||
new Set([repo.id]),
|
||||
new Map([[repo.id, { repo, hiddenWorktrees: [makeDetectedWorktree()] }]])
|
||||
)
|
||||
|
||||
expect(rows).toMatchObject([
|
||||
{ type: 'header', key: 'repo:repo-1', label: 'orca', count: 0 },
|
||||
{
|
||||
type: 'imported-worktrees-card',
|
||||
key: 'imported-worktrees-card:repo-group:repo-1',
|
||||
placement: 'repo-group'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('skips stale empty placeholder repo ids that are absent from repoMap', () => {
|
||||
const rows = buildRows(
|
||||
'repo',
|
||||
[],
|
||||
new Map(),
|
||||
null,
|
||||
new Set(),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{},
|
||||
new Map(),
|
||||
false,
|
||||
undefined,
|
||||
[],
|
||||
new Set([repo.id])
|
||||
)
|
||||
|
||||
expect(rows).toEqual([])
|
||||
})
|
||||
|
||||
it('does not emit unpinned imported worktree cards outside repo grouping', () => {
|
||||
const rows = buildRows(
|
||||
'workspace-status',
|
||||
@@ -792,6 +842,12 @@ describe('project groups', () => {
|
||||
key: 'project-group:group-1',
|
||||
count: 1
|
||||
})
|
||||
expect(rows[1]).toMatchObject({
|
||||
type: 'header',
|
||||
key: 'repo:repo-1',
|
||||
projectGroupDepth: 1,
|
||||
count: 0
|
||||
})
|
||||
})
|
||||
|
||||
it('does not resurrect filtered repos as empty Project Group headers', () => {
|
||||
|
||||
@@ -482,14 +482,17 @@ export function buildRows(
|
||||
}
|
||||
grouped.get(key)!.items.push(w)
|
||||
}
|
||||
if (groupBy === 'repo' && projectGroups.length > 0) {
|
||||
if (groupBy === 'repo') {
|
||||
for (const repoId of placeholderRepoIds) {
|
||||
const repo = repoMap.get(repoId)
|
||||
if (!repo) {
|
||||
continue
|
||||
}
|
||||
const key = `repo:${repoId}`
|
||||
if (!grouped.has(key)) {
|
||||
// Why: nested repo imports can persist repos before their worktree rows
|
||||
// are available, but filters must not resurrect hidden repo headers.
|
||||
grouped.set(key, { label: repo?.displayName ?? 'Unknown', items: [], repo })
|
||||
// Why: repos can arrive before worktree scans, but stale IDs passed by
|
||||
// older snapshots must not render an "Unknown" project header.
|
||||
grouped.set(key, { label: repo.displayName, items: [], repo })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user