fix(sidebar): keep table search results on Enter
This commit is contained in:
1 parent
acc2137cde
commit
0908a944e8
4 files changed
+77
-11
No files matched your search
+10
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createFlatTreeIndex, flattenTree, mutateFlatTreeExpansion, replaceFlatTreeChildren, type FlatTreeNode } from "@/composables/useFlatTree";
|
||||
import { createFlatTreeIndex, flatTreeRowsChanged, flattenTree, mutateFlatTreeExpansion, replaceFlatTreeChildren, type FlatTreeNode } from "@/composables/useFlatTree";
|
||||
import type { TreeNode, TreeNodeType } from "@/types/database";
|
||||
|
||||
function item(id: string, type: TreeNodeType, depth: number, children?: TreeNode[]): FlatTreeNode {
|
||||
@@ -145,6 +145,15 @@ describe("flat-tree range mutations", () => {
|
||||
});
|
||||
|
||||
describe("flat-tree render identities", () => {
|
||||
it("detects same-length table-search row replacements for #6951", () => {
|
||||
const previous = [item("table-a", "table", 1), item("table-b", "table", 1)];
|
||||
const unchanged = previous.map((entry) => ({ ...entry }));
|
||||
const next = [item("table-c", "table", 1), item("table-b", "table", 1)];
|
||||
|
||||
expect(flatTreeRowsChanged(unchanged, previous)).toBe(false);
|
||||
expect(flatTreeRowsChanged(next, previous)).toBe(true);
|
||||
});
|
||||
|
||||
it("isolates equal business ids that belong to different lineages", () => {
|
||||
const collidingId = "connection:a:b";
|
||||
const collidingSchemaId = "connection:a:b:c";
|
||||
|
||||
@@ -98,6 +98,15 @@ export function mutateFlatTreeExpansion(nodes: readonly FlatTreeNode[], parentIn
|
||||
return replaceFlatTreeChildren(nodes, parentIndex, parent);
|
||||
}
|
||||
|
||||
/** Whether the visible row identities changed enough to refresh recycled views. */
|
||||
export function flatTreeRowsChanged(nodes: readonly FlatTreeNode[], previousNodes: readonly FlatTreeNode[] | undefined): boolean {
|
||||
if (!previousNodes || nodes.length !== previousNodes.length) return true;
|
||||
return nodes.some((item, index) => {
|
||||
const previous = previousNodes[index];
|
||||
return !previous || item.renderKey !== previous.renderKey || item.poolType !== previous.poolType || item.depth !== previous.depth;
|
||||
});
|
||||
}
|
||||
|
||||
export function shouldVirtualizeFlatTree(count: number): boolean {
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user