fix(sidebar): preserve searched database children

This commit is contained in:
t8y2 2026-05-20 16:45:35 +08:00
parent 47ec339d5a
commit d64074dbc2
2 changed files with 31 additions and 1 deletions

View File

@ -1,7 +1,7 @@
import type { TreeNode } from "@/types/database";
import { matchSidebarLabel } from "@/lib/sidebarSearch";
const preserveMatchedSubtreeTypes = new Set(["table", "view"]);
const preserveMatchedSubtreeTypes = new Set(["database", "schema", "table", "view"]);
const normalizedLabelCache = new WeakMap<TreeNode, { label: string; normalized: string }>();

View File

@ -53,3 +53,33 @@ test("preserves loaded table children when the table itself matches search", ()
assert.equal(table?.children?.[0]?.label, "tree.columns");
assert.equal(table?.children?.[0]?.children?.[0]?.label, "id");
});
test("preserves loaded schema children when the database itself matches search", () => {
const nodes: TreeNode[] = [
{
id: "conn:hdi",
label: "hdi",
type: "database",
connectionId: "conn",
database: "hdi",
isExpanded: true,
children: [
{
id: "conn:hdi:public",
label: "public",
type: "schema",
connectionId: "conn",
database: "hdi",
schema: "public",
isExpanded: false,
children: [],
},
],
},
];
const filtered = filterSidebarTree(nodes, "hdi", new Set());
assert.equal(filtered[0]?.label, "hdi");
assert.equal(filtered[0]?.children?.[0]?.label, "public");
});