fix(sidebar): correct connection search activation
This commit is contained in:
1 parent
e9538ee1dd
commit
5173bbafd1
3 files changed
+153
-1
No files matched your search
+59
@@ -4,6 +4,7 @@ import { createApp, defineComponent, h, nextTick, type App } from "vue";
|
|||||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
import i18n from "@/i18n";
|
import i18n from "@/i18n";
|
||||||
import TreeItem from "@/components/sidebar/TreeItem.vue";
|
import TreeItem from "@/components/sidebar/TreeItem.vue";
|
||||||
|
import { filterSidebarTree } from "@/lib/sidebar/sidebarSearchTree";
|
||||||
import { createSidebarTreeRuntime, sidebarTreeRuntimeKey, type SidebarTreeRuntimeHost } from "@/lib/sidebar/sidebarTreeRuntime";
|
import { createSidebarTreeRuntime, sidebarTreeRuntimeKey, type SidebarTreeRuntimeHost } from "@/lib/sidebar/sidebarTreeRuntime";
|
||||||
import type { TreeNode } from "@/types/database";
|
import type { TreeNode } from "@/types/database";
|
||||||
|
|
||||||
@@ -11,9 +12,12 @@ const connectionStore = {
|
|||||||
activeConnectionId: "connection-1",
|
activeConnectionId: "connection-1",
|
||||||
connectedIds: new Set(["connection-1"]),
|
connectedIds: new Set(["connection-1"]),
|
||||||
connectingIds: new Set<string>(),
|
connectingIds: new Set<string>(),
|
||||||
|
connectionErrors: {},
|
||||||
connectionMultiSelectActive: false,
|
connectionMultiSelectActive: false,
|
||||||
connections: [],
|
connections: [],
|
||||||
getConfig: () => ({ id: "connection-1", db_type: "sqlserver" }),
|
getConfig: () => ({ id: "connection-1", db_type: "sqlserver" }),
|
||||||
|
getSidebarVisibleFilterSummary: () => null,
|
||||||
|
clearConnectionError: vi.fn(),
|
||||||
isDefaultDatabase: () => false,
|
isDefaultDatabase: () => false,
|
||||||
isDefaultSchema: () => false,
|
isDefaultSchema: () => false,
|
||||||
isPinnedTreeNodeReorderTarget: () => false,
|
isPinnedTreeNodeReorderTarget: () => false,
|
||||||
@@ -182,3 +186,58 @@ describe("TreeItem load-more activation", () => {
|
|||||||
expect(unknown.row.querySelector('[data-invalid-object-indicator="true"]')).toBeNull();
|
expect(unknown.row.querySelector('[data-invalid-object-indicator="true"]')).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("TreeItem searched connection activation", () => {
|
||||||
|
function searchedConnection(): TreeNode {
|
||||||
|
const filtered = filterSidebarTree(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
id: "connection-1",
|
||||||
|
label: "1000",
|
||||||
|
type: "connection",
|
||||||
|
connectionId: "connection-1",
|
||||||
|
isExpanded: false,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: "connection-1:__user_admin",
|
||||||
|
label: "tree.userAdmin",
|
||||||
|
type: "user-admin",
|
||||||
|
connectionId: "connection-1",
|
||||||
|
database: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"1000",
|
||||||
|
new Set(),
|
||||||
|
)[0];
|
||||||
|
if (!filtered) throw new Error("Expected the matching connection search result");
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
it("activates a connection search result on one click in single-click mode", async () => {
|
||||||
|
settingsStore.editorSettings.sidebarActivation = "single";
|
||||||
|
const node = searchedConnection();
|
||||||
|
const { row, host } = await mountTreeItem(node);
|
||||||
|
|
||||||
|
row.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 1 }));
|
||||||
|
|
||||||
|
expect(node.children).toEqual([]);
|
||||||
|
expect(node.isExpanded).toBe(false);
|
||||||
|
expect(host.handleRowClick).toHaveBeenCalledWith(node, 1);
|
||||||
|
expect(host.handleRowDoubleClick).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("waits for a double click before activating a connection search result in double-click mode", async () => {
|
||||||
|
settingsStore.editorSettings.sidebarActivation = "double";
|
||||||
|
const node = searchedConnection();
|
||||||
|
const { row, host } = await mountTreeItem(node);
|
||||||
|
|
||||||
|
row.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 1 }));
|
||||||
|
expect(host.handleRowClick).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
row.dispatchEvent(new MouseEvent("dblclick", { bubbles: true, detail: 2 }));
|
||||||
|
|
||||||
|
expect(host.handleRowDoubleClick).toHaveBeenCalledWith(node, expect.any(MouseEvent));
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2,6 +2,7 @@ import type { TreeNode, TreeNodeType } from "@/types/database";
|
|||||||
import { createSidebarLabelMatcher, type SidebarLabelMatcher } from "@/lib/sidebar/sidebarSearch";
|
import { createSidebarLabelMatcher, type SidebarLabelMatcher } from "@/lib/sidebar/sidebarSearch";
|
||||||
|
|
||||||
const preserveMatchedSubtreeTypes = new Set(["connection", "database", "schema", "table", "view", "mongo-db", "mongo-collection"]);
|
const preserveMatchedSubtreeTypes = new Set(["connection", "database", "schema", "table", "view", "mongo-db", "mongo-collection"]);
|
||||||
|
const hiddenSearchNodeTypes = new Set<TreeNodeType>(["user-admin", "dameng-job-admin"]);
|
||||||
|
|
||||||
function bestMatch(matchLabel: SidebarLabelMatcher, label: string, comment?: string | null) {
|
function bestMatch(matchLabel: SidebarLabelMatcher, label: string, comment?: string | null) {
|
||||||
const lm = matchLabel(label);
|
const lm = matchLabel(label);
|
||||||
@@ -43,10 +44,16 @@ function applySearchCollapsedState(node: TreeNode, collapsedIds: ReadonlySet<str
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function preservedSearchChildren(node: TreeNode, collapsedIds: ReadonlySet<string>): TreeNode[] | undefined {
|
||||||
|
if (!node.children) return undefined;
|
||||||
|
return node.children.filter((child) => !hiddenSearchNodeTypes.has(child.type)).map((child) => applySearchCollapsedState(child, collapsedIds));
|
||||||
|
}
|
||||||
|
|
||||||
function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabelMatcher | undefined, collapsedIds: ReadonlySet<string>, searchableNodeTypes?: ReadonlySet<TreeNodeType>): TreeNode[] {
|
function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabelMatcher | undefined, collapsedIds: ReadonlySet<string>, searchableNodeTypes?: ReadonlySet<TreeNodeType>): TreeNode[] {
|
||||||
const filteredNodes: { node: TreeNode; score: number }[] = [];
|
const filteredNodes: { node: TreeNode; score: number }[] = [];
|
||||||
|
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
|
if (matchLabel && hiddenSearchNodeTypes.has(node.type)) continue;
|
||||||
if (node.type === "object-browser" && node.hiddenChildren) {
|
if (node.type === "object-browser" && node.hiddenChildren) {
|
||||||
const matches = node.hiddenChildren.flatMap((child) => {
|
const matches = node.hiddenChildren.flatMap((child) => {
|
||||||
if (searchableNodeTypes && !searchableNodeTypes.has(child.type)) return [];
|
if (searchableNodeTypes && !searchableNodeTypes.has(child.type)) return [];
|
||||||
@@ -67,7 +74,10 @@ function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabe
|
|||||||
// A type-matched table keeps its loaded detail groups after the text query
|
// A type-matched table keeps its loaded detail groups after the text query
|
||||||
// is cleared instead of being rebuilt with an empty filtered child list.
|
// is cleared instead of being rebuilt with an empty filtered child list.
|
||||||
const preservesTypeMatchedTable = !matchLabel && !!selfMatch && node.type === "table";
|
const preservesTypeMatchedTable = !matchLabel && !!selfMatch && node.type === "table";
|
||||||
const filteredChildren = preservesSubtree ? node.children?.map((child) => applySearchCollapsedState(child, collapsedIds)) : node.children ? filterSidebarTreeWithMatcher(node.children, matchLabel, collapsedIds, searchableNodeTypes) : undefined;
|
// Connection utility entries are synthetic navigation actions, not schema
|
||||||
|
// search results. Keep real loaded descendants for connection-name matches,
|
||||||
|
// but do not let those actions make a disconnected result look expanded.
|
||||||
|
const filteredChildren = preservesSubtree ? preservedSearchChildren(node, collapsedIds) : node.children ? filterSidebarTreeWithMatcher(node.children, matchLabel, collapsedIds, searchableNodeTypes) : undefined;
|
||||||
|
|
||||||
if (selfMatch || (filteredChildren && filteredChildren.length > 0)) {
|
if (selfMatch || (filteredChildren && filteredChildren.length > 0)) {
|
||||||
if (!node.children || preservesTypeMatchedTable) {
|
if (!node.children || preservesTypeMatchedTable) {
|
||||||
|
|||||||
+83
@@ -212,6 +212,89 @@ test("preserves loaded children when the connection itself matches search", () =
|
|||||||
assert.equal(filtered[0]?.children?.[0]?.children?.[0]?.label, "products");
|
assert.equal(filtered[0]?.children?.[0]?.children?.[0]?.label, "products");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("omits synthetic connection management entries when the connection itself matches search", () => {
|
||||||
|
const nodes: TreeNode[] = [
|
||||||
|
{
|
||||||
|
id: "conn:1",
|
||||||
|
label: "1000-test",
|
||||||
|
type: "connection",
|
||||||
|
connectionId: "conn:1",
|
||||||
|
isExpanded: false,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: "conn:1:inventory",
|
||||||
|
label: "inventory",
|
||||||
|
type: "database",
|
||||||
|
connectionId: "conn:1",
|
||||||
|
database: "inventory",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "conn:1:__user_admin",
|
||||||
|
label: "tree.userAdmin",
|
||||||
|
type: "user-admin",
|
||||||
|
connectionId: "conn:1",
|
||||||
|
database: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "conn:1:__dameng_jobs",
|
||||||
|
label: "tree.damengJobAdmin",
|
||||||
|
type: "dameng-job-admin",
|
||||||
|
connectionId: "conn:1",
|
||||||
|
database: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const filtered = filterSidebarTree(nodes, "1000", new Set());
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
filtered[0]?.children?.map((child) => child.type),
|
||||||
|
["database"],
|
||||||
|
);
|
||||||
|
assert.equal(filtered[0]?.isExpanded, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("keeps a disconnected connection search result collapsed when it only has synthetic management entries", () => {
|
||||||
|
const nodes: TreeNode[] = [
|
||||||
|
{
|
||||||
|
id: "conn:1",
|
||||||
|
label: "1000",
|
||||||
|
type: "connection",
|
||||||
|
connectionId: "conn:1",
|
||||||
|
isExpanded: false,
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
id: "conn:1:__user_admin",
|
||||||
|
label: "tree.userAdmin",
|
||||||
|
type: "user-admin",
|
||||||
|
connectionId: "conn:1",
|
||||||
|
database: "",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const filtered = filterSidebarTree(nodes, "1000", new Set());
|
||||||
|
|
||||||
|
assert.deepEqual(filtered[0]?.children, []);
|
||||||
|
assert.equal(filtered[0]?.isExpanded, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("does not return synthetic connection management entries as direct text matches", () => {
|
||||||
|
const nodes: TreeNode[] = [
|
||||||
|
{
|
||||||
|
id: "conn:1:__user_admin",
|
||||||
|
label: "tree.userAdmin",
|
||||||
|
type: "user-admin",
|
||||||
|
connectionId: "conn:1",
|
||||||
|
database: "",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
assert.deepEqual(filterSidebarTree(nodes, "userAdmin", new Set()), []);
|
||||||
|
});
|
||||||
|
|
||||||
test("temporarily collapses an empty object group within a preserved search subtree", () => {
|
test("temporarily collapses an empty object group within a preserved search subtree", () => {
|
||||||
const tablesGroup: TreeNode = {
|
const tablesGroup: TreeNode = {
|
||||||
id: "conn:1:inventory:__tables",
|
id: "conn:1:inventory:__tables",
|
||||||
|
|||||||
Reference in new issue
Block a user