diff --git a/src/features/database/DatabaseView.test.tsx b/src/features/database/DatabaseView.test.tsx
index 2f56899d7..258c57793 100644
--- a/src/features/database/DatabaseView.test.tsx
+++ b/src/features/database/DatabaseView.test.tsx
@@ -107,3 +107,29 @@ describe("routine grouping", () => {
expect(tree.queryByText("functions")).toBeNull();
});
});
+
+describe("Expand All", () => {
+ it("opens every loaded node and leaves unloaded ones closed", async () => {
+ useDatabase.setState({
+ sources: [
+ { id: "pg", name: "PostgreSQL", driver: "postgres", options: { singleDatabase: true } },
+ { id: "lite", name: "SQLite", driver: "sqlite" },
+ ],
+ tables: { [tablesKey("pg", "public")]: { status: "ok", value: [{ name: "users", kind: "table" }] } },
+ treeExpanded: new Set(),
+ });
+ render();
+ await act(() => executeAction("db.expandAll"));
+ expect([...useDatabase.getState().treeExpanded].sort()).toEqual([
+ "pg",
+ "pg/public",
+ "pg/public/routines",
+ "pg/public/tables",
+ ]);
+ const tree = within(screen.getByRole("tree", { name: "Data sources" }));
+ expect(tree.getByText("refresh_data")).toBeInTheDocument();
+ // Its columns aren't loaded, and neither is the SQLite source: Expand All loads nothing.
+ expect(tree.getByText("users").closest('[role="treeitem"]')).toHaveAttribute("aria-expanded", "false");
+ expect(tree.getByText("SQLite").closest('[role="treeitem"]')).toHaveAttribute("aria-expanded", "false");
+ });
+});
diff --git a/src/features/database/DatabaseView.tsx b/src/features/database/DatabaseView.tsx
index b775e5b15..0ef2b0923 100644
--- a/src/features/database/DatabaseView.tsx
+++ b/src/features/database/DatabaseView.tsx
@@ -58,7 +58,7 @@ import {
useDatabase,
type Loaded,
} from "./store";
-import { DB_VIEW_FOCUS, openTableData } from "./treeActions";
+import { DB_VIEW_FOCUS, databaseTree, openTableData } from "./treeActions";
import { newMenu, nodeMenu } from "./treeMenu";
import styles from "./Database.module.css";
import { tx } from "@/platform/i18n";
@@ -366,6 +366,34 @@ export function DatabaseView() {
else if (n.kind === "table") await loadDetails(n.id, n.schema, n.table.name);
};
+ const expandable = (n: Node) =>
+ n.kind === "source" ||
+ n.kind === "database" ||
+ n.kind === "schema" ||
+ n.kind === "folder" ||
+ n.kind === "table" ||
+ n.kind === "group";
+
+ // Expand All opens the nodes already loaded: it connects to nothing and runs no query.
+ useEffect(() => {
+ databaseTree.expandAll = () => {
+ const next = new Set(useDatabase.getState().treeExpanded);
+ const walk = (nodes: readonly Node[]) => {
+ for (const n of nodes) {
+ const kids = expandable(n) ? children(n) : undefined;
+ if (!kids) continue;
+ next.add(n.key);
+ walk(kids);
+ }
+ };
+ walk(roots);
+ useDatabase.setState({ treeExpanded: next });
+ };
+ return () => {
+ databaseTree.expandAll = null;
+ };
+ });
+
const label = (n: Node): string => {
switch (n.kind) {
case "source":
@@ -509,14 +537,7 @@ export function DatabaseView() {
getKey={(n) => n.key}
getLabel={label}
getChildren={children}
- isExpandable={(n) =>
- n.kind === "source" ||
- n.kind === "database" ||
- n.kind === "schema" ||
- n.kind === "folder" ||
- n.kind === "table" ||
- n.kind === "group"
- }
+ isExpandable={expandable}
loadChildren={load}
getIcon={(n) => icon(n)}
getDetail={detail}
@@ -662,7 +683,12 @@ function DatabaseToolbar() {
);
}
-/** Header controls (shown on hover, like IDEA's): Collapse All. */
+/** Header controls (shown on hover, like IDEA's): Expand All, Collapse All. */
export function DatabaseHeaderActions() {
- return ;
+ return (
+ <>
+
+
+ >
+ );
}
diff --git a/src/features/database/treeActions.ts b/src/features/database/treeActions.ts
index 1c78e0b96..b9dd3a12a 100644
--- a/src/features/database/treeActions.ts
+++ b/src/features/database/treeActions.ts
@@ -44,6 +44,10 @@ import { tx } from "@/platform/i18n";
/** Context key: the Database tree has focus. */
export const DB_VIEW_FOCUS = "databaseViewFocus";
+
+/** Set while the Database view is mounted: Expand All walks its tree's loaded nodes. */
+export const databaseTree: { expandAll: (() => void) | null } = { expandAll: null };
+
const OPEN = "projectOpen";
const isNode = (v: unknown): v is DbNode => !!v && typeof v === "object" && "kind" in v && "key" in v;
@@ -481,6 +485,12 @@ export function registerDatabaseTreeActions(): () => void {
title: "Separate Procedures and Functions",
run: toggleSeparateProceduresAndFunctions,
}),
+ tree({
+ id: "db.expandAll",
+ title: "Expand All",
+ icon: "expand-all",
+ run: () => databaseTree.expandAll?.(),
+ }),
tree({
id: "db.collapseAll",
title: "Collapse All",
diff --git a/src/platform/keymaps/intellij-macos.ts b/src/platform/keymaps/intellij-macos.ts
index 2fb0beb10..2a4d4e6b8 100644
--- a/src/platform/keymaps/intellij-macos.ts
+++ b/src/platform/keymaps/intellij-macos.ts
@@ -404,6 +404,7 @@ export const intellijMacos: Record = {
"db.runSqlScript": [],
"db.sqlScript": [],
"db.goToReferencedTable": [],
+ "db.expandAll": [],
"db.collapseAll": [],
// Terminal (keyWhen: terminalFocus); after VCS Update / Go to Test so it wins there.
"terminal.new": ["Meta+T"],
diff --git a/src/platform/keymaps/intellij-windows.ts b/src/platform/keymaps/intellij-windows.ts
index 6f5ec8c4b..e2acbd37f 100644
--- a/src/platform/keymaps/intellij-windows.ts
+++ b/src/platform/keymaps/intellij-windows.ts
@@ -402,6 +402,7 @@ export const intellijWindows: Record = {
"db.runSqlScript": [],
"db.sqlScript": [],
"db.goToReferencedTable": [],
+ "db.expandAll": [],
"db.collapseAll": [],
// Terminal (keyWhen: terminalFocus); after VCS Update / Go to Test so it wins there.
"terminal.new": ["Ctrl+Shift+T"],
diff --git a/src/platform/keymaps/vscode-macos.ts b/src/platform/keymaps/vscode-macos.ts
index 9bd0729ba..c6c551f3f 100644
--- a/src/platform/keymaps/vscode-macos.ts
+++ b/src/platform/keymaps/vscode-macos.ts
@@ -392,6 +392,7 @@ export const vscodeMacos: Record = {
"db.runSqlScript": [],
"db.sqlScript": [],
"db.goToReferencedTable": [],
+ "db.expandAll": [],
"db.collapseAll": [],
// Find in Files popup (findPopupOpen): after the editor's keys, so these win while it is open.
"find.popup.nextResult": ["Meta+G"],