feat(sidebar): add new query option to saved sql context menu
This commit is contained in:
1 parent
7b47b64391
commit
500c0ae692
5 files changed
+181
-4
No files matched your search
@@ -65,6 +65,16 @@ describe("database saved SQL tree", () => {
|
||||
expect(root).toMatchObject({ id: "conn-1:app:__queries", label: "tree.queries", type: "saved-sql-root", children: [] });
|
||||
});
|
||||
|
||||
it("preserves database schema on the saved-sql-root node", () => {
|
||||
const root = buildDatabaseSavedSqlRootNode({ ...database, schema: "public" }, []);
|
||||
expect(root).toMatchObject({
|
||||
id: "conn-1:app:__queries",
|
||||
type: "saved-sql-root",
|
||||
database: "app",
|
||||
schema: "public",
|
||||
});
|
||||
});
|
||||
|
||||
it("collapses the Queries node by default when opening a connection", () => {
|
||||
expect(buildDatabaseSavedSqlRootNode(database, files)?.isExpanded).toBe(false);
|
||||
expect(buildDatabaseSavedSqlRootNode(database, [])?.isExpanded).toBe(false);
|
||||
|
||||
@@ -13,7 +13,7 @@ export function savedSqlClipboardFileIds(nodes: readonly TreeNode[]): string[] {
|
||||
}
|
||||
|
||||
export function savedSqlPasteTargetForNode(node: Pick<TreeNode, "type" | "connectionId" | "catalog" | "database" | "schema">): SavedSqlPasteTarget | null {
|
||||
if (node.type !== "database" && node.type !== "saved-sql-root" && node.type !== "saved-sql-file") return null;
|
||||
if (node.type !== "database" && node.type !== "saved-sql-root" && node.type !== "saved-sql-file" && node.type !== "saved-sql-folder") return null;
|
||||
if (!node.connectionId || node.database === undefined) return null;
|
||||
return {
|
||||
connectionId: node.connectionId,
|
||||
|
||||
@@ -60,7 +60,7 @@ function savedSqlFileNode(rootId: string, file: SavedSqlFile): TreeNode {
|
||||
};
|
||||
}
|
||||
|
||||
export function buildDatabaseSavedSqlRootNode(databaseNode: Pick<TreeNode, "id" | "connectionId" | "catalog" | "database">, source: SavedSqlDatabaseSource, existingRoot?: TreeNode): TreeNode | null {
|
||||
export function buildDatabaseSavedSqlRootNode(databaseNode: Pick<TreeNode, "id" | "connectionId" | "catalog" | "database" | "schema">, source: SavedSqlDatabaseSource, existingRoot?: TreeNode): TreeNode | null {
|
||||
if (!databaseNode.connectionId || databaseNode.database === undefined) return null;
|
||||
|
||||
const id = `${databaseNode.id}:__queries`;
|
||||
@@ -71,6 +71,7 @@ export function buildDatabaseSavedSqlRootNode(databaseNode: Pick<TreeNode, "id"
|
||||
connectionId: databaseNode.connectionId,
|
||||
catalog: databaseNode.catalog,
|
||||
database: databaseNode.database,
|
||||
schema: databaseNode.schema,
|
||||
// Default collapsed: opening a connection should not expand the Queries
|
||||
// node until the user asks for it; an existing node's state is preserved.
|
||||
isExpanded: existingRoot?.isExpanded ?? false,
|
||||
@@ -82,7 +83,7 @@ export function buildDatabaseSavedSqlRootNode(databaseNode: Pick<TreeNode, "id"
|
||||
};
|
||||
}
|
||||
|
||||
export function withDatabaseSavedSqlRoot(databaseNode: Pick<TreeNode, "id" | "connectionId" | "catalog" | "database" | "children">, children: readonly TreeNode[], source: SavedSqlDatabaseSource): TreeNode[] {
|
||||
export function withDatabaseSavedSqlRoot(databaseNode: Pick<TreeNode, "id" | "connectionId" | "catalog" | "database" | "schema" | "children">, children: readonly TreeNode[], source: SavedSqlDatabaseSource): TreeNode[] {
|
||||
const existingRoot = databaseNode.children?.find((child) => child.type === "saved-sql-root");
|
||||
const existingMetadataChildren = databaseNode.children?.filter((child) => child.type !== "saved-sql-root") ?? [];
|
||||
const metadataChildren = children.filter((child) => child.type !== "saved-sql-root");
|
||||
|
||||
Reference in new issue
Block a user