Merge pull request 'feat(sidebar): 同名 member 文件夹合并到 base 一行' (#4) from feat/merge-same-name-members into main
This commit is contained in:
commit
419b43815f
|
|
@ -1479,14 +1479,22 @@ window.__ModuleLoader__.load({
|
||||||
const labels = memberFolderLabels(entry);
|
const labels = memberFolderLabels(entry);
|
||||||
const title = workspaceTitle.trim();
|
const title = workspaceTitle.trim();
|
||||||
if (title !== "") labels.set(workspacePath, title);
|
if (title !== "") labels.set(workspacePath, title);
|
||||||
const extras = effectiveFolders(workspacePath, entry).slice(1);
|
const nameOf = (value) => value.replace(/[((][^))]*[))]/gu, "").trim();
|
||||||
|
const baseName = nameOf(title);
|
||||||
|
new Set((entry?.members ?? []).map((member) => member.path));
|
||||||
|
const mergedMembers = /* @__PURE__ */ new Set();
|
||||||
|
if (baseName !== "") {
|
||||||
|
for (const member of entry?.members ?? []) if (nameOf(labels.get(member.path) ?? folderLabel(member.path)) === baseName) mergedMembers.add(member.path);
|
||||||
|
}
|
||||||
|
const isMergedMember = (path) => [...mergedMembers].some((member) => samePath(member, path));
|
||||||
|
const extras = effectiveFolders(workspacePath, entry).slice(1).filter((path) => !isMergedMember(path));
|
||||||
if (extras.length === 0) return { sessions };
|
if (extras.length === 0) return { sessions };
|
||||||
const root = rootOf(workspacePath, entry);
|
const root = rootOf(workspacePath, entry);
|
||||||
const base = [];
|
const base = [];
|
||||||
const byFolder = /* @__PURE__ */ new Map();
|
const byFolder = /* @__PURE__ */ new Map();
|
||||||
for (const node of sessions) {
|
for (const node of sessions) {
|
||||||
const owner = folderOfCwd(list.byId[node.id]?.cwd, workspacePath, entry);
|
const owner = folderOfCwd(list.byId[node.id]?.cwd, workspacePath, entry);
|
||||||
if (samePath(owner, workspacePath)) {
|
if (samePath(owner, workspacePath) || isMergedMember(owner)) {
|
||||||
base.push(node);
|
base.push(node);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -376,14 +376,27 @@ function applyFolders(
|
||||||
// remains the directory identity for file access; only the LABEL changes.
|
// remains the directory identity for file access; only the LABEL changes.
|
||||||
const title = workspaceTitle.trim()
|
const title = workspaceTitle.trim()
|
||||||
if (title !== '') labels.set(workspacePath, title)
|
if (title !== '') labels.set(workspacePath, title)
|
||||||
const extras = effectiveFolders(workspacePath, entry).slice(1)
|
// A member whose name is the same project (allowing a qualifier such as
|
||||||
|
// "(云端)") is the same folder from the user's point of view. Fold its
|
||||||
|
// sessions into the base row instead of painting a second folder row.
|
||||||
|
const nameOf = (value: string): string => value.replace(/[((][^))]*[))]/gu, '').trim()
|
||||||
|
const baseName = nameOf(title)
|
||||||
|
const memberPaths = new Set((entry?.members ?? []).map(member => member.path))
|
||||||
|
const mergedMembers = new Set<string>()
|
||||||
|
if (baseName !== '') {
|
||||||
|
for (const member of entry?.members ?? []) {
|
||||||
|
if (nameOf(labels.get(member.path) ?? folderLabel(member.path)) === baseName) mergedMembers.add(member.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const isMergedMember = (path: string): boolean => [...mergedMembers].some(member => samePath(member, path))
|
||||||
|
const extras = effectiveFolders(workspacePath, entry).slice(1).filter(path => !isMergedMember(path))
|
||||||
if (extras.length === 0) return { sessions }
|
if (extras.length === 0) return { sessions }
|
||||||
const root = rootOf(workspacePath, entry)
|
const root = rootOf(workspacePath, entry)
|
||||||
const base: SessionNode[] = []
|
const base: SessionNode[] = []
|
||||||
const byFolder = new Map<string, SessionNode[]>()
|
const byFolder = new Map<string, SessionNode[]>()
|
||||||
for (const node of sessions) {
|
for (const node of sessions) {
|
||||||
const owner = folderOfCwd(list.byId[node.id]?.cwd, workspacePath, entry)
|
const owner = folderOfCwd(list.byId[node.id]?.cwd, workspacePath, entry)
|
||||||
if (samePath(owner, workspacePath)) {
|
if (samePath(owner, workspacePath) || isMergedMember(owner)) {
|
||||||
base.push(node)
|
base.push(node)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,38 @@ describe('category appearance on the tree nodes', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('folder rows use confirmed display names', () => {
|
describe('folder rows use confirmed display names', () => {
|
||||||
|
it('folds a same-name local member into the base row instead of a second folder', () => {
|
||||||
|
const owner = workspace('ws-remote', 'C:/mirror/w123', '云端记忆系统(云端)', ['s1'])
|
||||||
|
const member = workspace('ws-local', 'C:/Users/qyh15/云端记忆系统', '云端记忆系统', ['s2'])
|
||||||
|
const list = {
|
||||||
|
ids: ['s1', 's2'],
|
||||||
|
byId: {
|
||||||
|
s1: { ...session('s1', 'remote'), cwd: 'C:/mirror/w123' },
|
||||||
|
s2: { ...session('s2', 'local'), cwd: 'C:/Users/qyh15/云端记忆系统' },
|
||||||
|
},
|
||||||
|
current: 's1',
|
||||||
|
phase: 'ready',
|
||||||
|
subagentsByParent: {},
|
||||||
|
} as unknown as SessionListState
|
||||||
|
const folders: FoldersDocument = {
|
||||||
|
version: 1,
|
||||||
|
revision: 1,
|
||||||
|
workspaces: {
|
||||||
|
'ws-remote': {
|
||||||
|
folders: [],
|
||||||
|
members: [{ path: 'C:/Users/qyh15/云端记忆系统', workspaceId: 'ws-local', kind: 'local' }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const view = { expandedCategories: [], expandedWorkspaces: ['ws-remote'] }
|
||||||
|
const top = deriveTopLevel(list, [owner, member], [], CONFIG, view, { categories: [], assignments: {} }, new Map(), folders)
|
||||||
|
const node = top.find(item => item.workspaceId === 'ws-remote')
|
||||||
|
expect(node).toBeDefined()
|
||||||
|
// The member row is gone; both sessions live on the single base row.
|
||||||
|
expect(node?.folders).toBeUndefined()
|
||||||
|
expect(node?.sessions.map(item => item.id)).toEqual(['s1', 's2'])
|
||||||
|
})
|
||||||
|
|
||||||
it('base row shows the project title, not the local mirror basename', () => {
|
it('base row shows the project title, not the local mirror basename', () => {
|
||||||
const ws = workspace('ws-remote', 'C:/mirror/w123', '远程项目', ['s1'])
|
const ws = workspace('ws-remote', 'C:/mirror/w123', '远程项目', ['s1'])
|
||||||
const folders: FoldersDocument = {
|
const folders: FoldersDocument = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue