fix(sidebar): search connections by host and username

This commit is contained in:
大熊 authored and GitHub committed 2026-08-13 15:24:30 +08:00
1 parent 18d581137c
commit b5a8864220
6 files changed
+46 -7

No files matched your search

@@ -121,11 +121,16 @@ export function remapSidebarLayoutConnectionIds(layout: SidebarLayout, connectio
};
}
export function connectionSidebarSearchAliases(config: Pick<ConnectionConfig, "host" | "username">): string[] {
return [config.host, config.username].filter((value) => value.trim().length > 0);
}
function makeConnectionNode(config: ConnectionConfig, pinned: boolean): TreeNode {
return {
id: config.id,
label: config.name,
type: "connection",
searchAliases: connectionSidebarSearchAliases(config),
connectionId: config.id,
isExpanded: false,
children: [],
@@ -4,12 +4,14 @@ import { createSidebarLabelMatcher, type SidebarLabelMatcher } from "@/lib/sideb
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) {
const lm = matchLabel(label);
if (!comment) return lm;
const cm = matchLabel(comment);
if (lm && cm) return lm.score >= cm.score ? lm : cm;
return lm ?? cm;
function bestMatch(matchLabel: SidebarLabelMatcher, label: string, comment?: string | null, aliases?: readonly string[]) {
let best = matchLabel(label);
for (const candidate of [comment, ...(aliases ?? [])]) {
if (!candidate) continue;
const match = matchLabel(candidate);
if (match && (!best || match.score > best.score)) best = match;
}
return best;
}
function normalizedLabel(node: TreeNode): string {
@@ -67,7 +69,7 @@ function filterSidebarTreeWithMatcher(nodes: TreeNode[], matchLabel: SidebarLabe
const label = normalizedLabel(node);
const canSelfMatch = !searchableNodeTypes || searchableNodeTypes.has(node.type);
const selfMatch = canSelfMatch ? (matchLabel ? bestMatch(matchLabel, label, node.comment) : { score: 0 }) : null;
const selfMatch = canSelfMatch ? (matchLabel ? bestMatch(matchLabel, label, node.comment, node.searchAliases) : { score: 0 }) : null;
// Type-only filtering keeps matching rows and their ancestor path, but not
// unrelated descendants that would make the selected type appear ignored.
const preservesSubtree = !!matchLabel && !!selfMatch && preserveMatchedSubtreeTypes.has(node.type);
@@ -55,6 +55,7 @@ import {
remapSidebarLayoutConnectionIds,
reorderEntry as reorderEntryOp,
buildConnectionGroupPathMap,
connectionSidebarSearchAliases,
type DropPosition,
} from "@/lib/sidebar/sidebarLayout";
import type { SqlCompletionColumn, SqlCompletionForeignKey, SqlCompletionObject, SqlCompletionTable } from "@/lib/sql/sqlCompletion";
@@ -2882,6 +2883,7 @@ export const useConnectionStore = defineStore("connection", () => {
if (existing) {
existing.label = config.name;
existing.type = "connection";
existing.searchAliases = connectionSidebarSearchAliases(config);
existing.connectionId = id;
existing.comment = config.note || null;
existing.children = existing.children || [];
@@ -2890,6 +2892,7 @@ export const useConnectionStore = defineStore("connection", () => {
id,
label: config.name,
type: "connection",
searchAliases: connectionSidebarSearchAliases(config),
connectionId: id,
isExpanded: false,
children: [],
@@ -6917,6 +6920,7 @@ export const useConnectionStore = defineStore("connection", () => {
...existing,
label: node.label,
comment: node.comment,
searchAliases: node.searchAliases,
pinned: node.pinned,
children: withSavedSqlRoot(node.connectionId!, existing.children || [], existing),
});
+2
View File
@@ -968,6 +968,8 @@ export interface TreeNode {
id: string;
label: string;
type: TreeNodeType;
/** Additional values matched by sidebar search without rendering them. */
searchAliases?: string[];
children?: TreeNode[];
isLoading?: boolean;
isExpanded?: boolean;