feat(sidebar): add local table search
This commit is contained in:
15 files changed
+421
-17
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import type { FlatTreeNode } from "@/composables/useFlatTree";
|
||||
import type { TreeNode, TreeNodeType } from "@/types/database";
|
||||
|
||||
const simpleObjectParentTypes = new Set<TreeNodeType>(["database", "schema", "linked-server-schema"]);
|
||||
const simpleObjectChildTypes = new Set<TreeNodeType>(["table", "view", "materialized_view", "procedure", "function", "sequence", "package", "package-body", "load-more"]);
|
||||
|
||||
export function isSidebarTableSearchControlNode(node: TreeNode): boolean {
|
||||
return node.type === "table-search-control";
|
||||
}
|
||||
|
||||
function tableSearchControlId(parentId: string): string {
|
||||
return `${parentId}:__table_search`;
|
||||
}
|
||||
|
||||
function parentHasDirectTableList(node: TreeNode): boolean {
|
||||
return !!node.children?.some((child) => simpleObjectChildTypes.has(child.type));
|
||||
}
|
||||
|
||||
function shouldInsertTableSearchControl(item: FlatTreeNode, sidebarObjectDisplay: "simple" | "grouped", activeQueries: Readonly<Record<string, string | undefined>>): boolean {
|
||||
const node = item.node;
|
||||
if (!node.isExpanded) return false;
|
||||
if (sidebarObjectDisplay === "grouped") {
|
||||
return node.type === "group-tables";
|
||||
}
|
||||
if (!simpleObjectParentTypes.has(node.type)) return false;
|
||||
return parentHasDirectTableList(node) || !!activeQueries[node.id]?.trim();
|
||||
}
|
||||
|
||||
function buildTableSearchControlNode(parent: TreeNode): TreeNode {
|
||||
return {
|
||||
id: tableSearchControlId(parent.id),
|
||||
label: "sidebar.searchTablesInCurrentScope",
|
||||
type: "table-search-control",
|
||||
connectionId: parent.connectionId,
|
||||
database: parent.database,
|
||||
schema: parent.schema,
|
||||
tableSearchParentId: parent.id,
|
||||
};
|
||||
}
|
||||
|
||||
export function insertSidebarTableSearchControls(
|
||||
flatNodes: readonly FlatTreeNode[],
|
||||
options: {
|
||||
enabled: boolean;
|
||||
sidebarObjectDisplay: "simple" | "grouped";
|
||||
activeQueries: Readonly<Record<string, string | undefined>>;
|
||||
},
|
||||
): FlatTreeNode[] {
|
||||
if (!options.enabled) return [...flatNodes];
|
||||
|
||||
const result: FlatTreeNode[] = [];
|
||||
for (const item of flatNodes) {
|
||||
result.push(item);
|
||||
if (!shouldInsertTableSearchControl(item, options.sidebarObjectDisplay, options.activeQueries)) continue;
|
||||
|
||||
const node = buildTableSearchControlNode(item.node);
|
||||
result.push({
|
||||
node,
|
||||
depth: item.depth + 1,
|
||||
id: node.id,
|
||||
type: node.type,
|
||||
poolType: `${node.type}:${node.id}`,
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import type { TreeNode } from "@/types/database";
|
||||
export interface SidebarTreeContext {
|
||||
getVisibleNodes: () => TreeNode[];
|
||||
getVisibleNodeIndex: (id: string) => number;
|
||||
setTableSearchQuery?: (parentNodeId: string, query: string) => void;
|
||||
}
|
||||
|
||||
export const sidebarTreeContextKey: InjectionKey<SidebarTreeContext> = Symbol("sidebar-tree-context");
|
||||
@@ -19,6 +19,7 @@ const leafTypes: Set<TreeNodeType> = new Set([
|
||||
"elasticsearch-index",
|
||||
"user-admin",
|
||||
"saved-sql-file",
|
||||
"table-search-control",
|
||||
"load-more",
|
||||
]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user