fix(sidebar): avoid synchronous selection pruning

This commit is contained in:
t8y2 committed 2026-08-18 15:47:44 +08:00
1 parent 94949eb1c7
commit 0b49c5a761
4 files changed
+59 -12

No files matched your search

@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { filterSidebarModifierSelectionIds, selectedSidebarBatchTargets, supportsSidebarModifierSelection } from "@/lib/sidebar/sidebarTreeSelection";
import { describe, expect, it, vi } from "vitest";
import { filterSidebarModifierSelectionIds, pruneTreeSelectionToVisibleNodeIds, selectedSidebarBatchTargets, supportsSidebarModifierSelection } from "@/lib/sidebar/sidebarTreeSelection";
import type { TreeNode } from "@/types/database";
function node(id: string, type: TreeNode["type"]): TreeNode {
@@ -32,6 +32,28 @@ describe("sidebar modifier selection", () => {
});
});
describe("visible sidebar selection pruning", () => {
it("checks only selected identifiers against the existing visible-node index", () => {
const has = vi.fn((id: string) => id === "table-2");
expect(
pruneTreeSelectionToVisibleNodeIds(
{ has },
{
nodeIds: ["table-1", "table-2", "table-3"],
activeNodeId: "table-3",
anchorNodeId: "table-1",
},
),
).toEqual({
nodeIds: ["table-2"],
activeNodeId: "table-2",
anchorNodeId: "table-2",
});
expect(has).toHaveBeenCalledTimes(5);
});
});
describe("sidebar batch action targets", () => {
const table = (id: string, connectionId = "connection-1", database = "database-1"): TreeNode => ({
id,