feat(transfer): show source/target pickers as group trees

This commit is contained in:
Allen authored and GitHub committed 2026-08-24 13:26:08 +08:00
1 parent 80240d0ba6
commit 29b527fd3a
4 files changed
+43 -38

No files matched your search

@@ -81,6 +81,17 @@ describe("buildConnectionPickerRows", () => {
expect(buildConnectionPickerRows(layout(), connections, new Set(), "不存在")).toEqual([]);
});
it("prunes groups that hold none of the given connections", () => {
const onlyC3 = connections.filter((connection) => connection.id === "c3");
expect(kinds(buildConnectionPickerRows(layout(), onlyC3, new Set(), ""))).toEqual(["connection:c3@0"]);
});
it("prunes nested groups without usable descendants even when collapsed", () => {
const onlyC2 = connections.filter((connection) => connection.id === "c2");
const rows = buildConnectionPickerRows(layout(), onlyC2, new Set(["g2"]), "");
expect(kinds(rows)).toEqual(["group:g1@0", "connection:c2@1"]);
});
it("falls back to the connection id when the name is empty", () => {
const rows = buildConnectionPickerRows({ groups: [], order: [] }, [{ id: "c9", name: "" }], new Set(), "");
expect(rows[0]?.label).toBe("c9");
@@ -18,12 +18,12 @@ describe("SearchableSelect layout", () => {
expect(searchableSelectSource).toContain("props.trimCustom ? searchText.value.trim() : searchText.value");
});
it("truncates long data transfer connection labels without shrinking their icons", () => {
const truncatedConnectionLabels = dataTransferDialogSource.match(/<span class="min-w-0 flex-1 truncate">\{\{ label \}\}<\/span>/g) ?? [];
const fixedConnectionIcons = dataTransferDialogSource.match(/class="h-3\.5 w-3\.5 shrink-0"/g) ?? [];
it("renders data transfer connection pickers as sidebar-like trees", () => {
const treeSelects = dataTransferDialogSource.match(/<ConnectionTreeSelect/g) ?? [];
expect(truncatedConnectionLabels).toHaveLength(2);
expect(fixedConnectionIcons).toHaveLength(2);
expect(treeSelects).toHaveLength(2);
expect(dataTransferDialogSource).toContain(':layout="store.sidebarLayout"');
expect(dataTransferDialogSource).not.toContain("ConnectionGroupBadge");
});
it("renders the toolbar connection picker as a sidebar-like tree", () => {
@@ -86,6 +86,17 @@ export function buildConnectionPickerRows(layout: SidebarLayout, connections: re
}
const rows: ConnectionPickerRow[] = [];
const subtreeHasConnection = (entries: SidebarOrderEntry[]): boolean => {
for (const entry of entries) {
if (entry.type === "connection") {
if (connectionById.has(entry.id)) return true;
continue;
}
if (!groupById.has(entry.id)) continue;
if (subtreeHasConnection(groupEntryChildren(entry))) return true;
}
return false;
};
const visitTree = (entries: SidebarOrderEntry[], depth: number) => {
for (const entry of entries) {
if (entry.type === "connection") {
@@ -96,6 +107,9 @@ export function buildConnectionPickerRows(layout: SidebarLayout, connections: re
}
const group = groupById.get(entry.id);
if (!group) continue;
// Skip groups that hold none of the picker's connections (e.g. when the
// caller passes a filtered list such as transfer-capable connections).
if (!subtreeHasConnection(groupEntryChildren(entry))) continue;
const collapsed = collapsedGroupIds.has(group.id);
rows.push({ key: `group:${group.id}`, kind: "group", id: group.id, label: group.name, depth, collapsed });
if (!collapsed) visitTree(groupEntryChildren(entry), depth + 1);