feat(grid): add table info overview tab to the info drawer

This commit is contained in:
Allen authored and GitHub committed 2026-09-21 16:58:01 +08:00
1 parent 0f8ad280c1
commit 2c4395d412
17 files changed
+200 -6

No files matched your search

@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import { findTableStatistics } from "@/lib/dataGrid/tableInfoOverview";
import type { ObjectStatistics } from "@/types/database";
const stats: ObjectStatistics[] = [
{ name: "orders", schema: "public", estimated_rows: 100, total_bytes: 4096 },
{ name: "orders", schema: "reporting", estimated_rows: 5, total_bytes: 1024 },
{ name: "users", schema: null, estimated_rows: 42, total_bytes: 2048 },
];
describe("findTableStatistics", () => {
it("prefers an exact schema match", () => {
expect(findTableStatistics(stats, "orders", "reporting")?.estimated_rows).toBe(5);
expect(findTableStatistics(stats, "orders", "public")?.estimated_rows).toBe(100);
});
it("falls back to a name-only match when the schema differs", () => {
expect(findTableStatistics(stats, "users", "public")?.estimated_rows).toBe(42);
});
it("matches by name when no schema is given", () => {
expect(findTableStatistics(stats, "orders")?.estimated_rows).toBe(100);
});
it("matches case-insensitively when drivers report inconsistent casing", () => {
const mixed: ObjectStatistics[] = [
{ name: "Orders", schema: "PUBLIC", estimated_rows: 7, total_bytes: 512 },
{ name: "Orders", schema: "reporting", estimated_rows: 9, total_bytes: 256 },
];
expect(findTableStatistics(mixed, "orders", "public")?.estimated_rows).toBe(7);
expect(findTableStatistics(mixed, "ORDERS", "REPORTING")?.estimated_rows).toBe(9);
expect(findTableStatistics(mixed, "orders")?.estimated_rows).toBe(7);
});
it("returns undefined when the table has no statistics", () => {
expect(findTableStatistics(stats, "missing", "public")).toBeUndefined();
expect(findTableStatistics([], "orders")).toBeUndefined();
});
});
@@ -0,0 +1,18 @@
import type { ObjectStatistics } from "@/types/database";
/**
* Picks the statistics entry for a table from a schema-level list. Drivers can
* report inconsistent casing between `listObjects` and `listObjectStatistics`,
* so both the schema and the name fold to lowercase — the same normalization
* the object browser's statistic keys apply. The name-only fallback stays:
* the statistics query is already scoped to one database/schema, and
* MySQL-family tables carry an empty `tableMeta.schema` while their statistics
* entries report the database as schema.
*/
export function findTableStatistics(stats: readonly ObjectStatistics[], tableName: string, schema?: string): ObjectStatistics | undefined {
if (schema !== undefined && schema !== "") {
const exact = stats.find((entry) => (entry.schema ?? "").toLowerCase() === schema.toLowerCase() && entry.name.toLowerCase() === tableName.toLowerCase());
if (exact) return exact;
}
return stats.find((entry) => entry.name.toLowerCase() === tableName.toLowerCase());
}
@@ -27,6 +27,9 @@ export function visibleTableStructureRefreshScope(activeTab: TableInfoTab): Tabl
return { columns: false, indexes: false, foreignKeys: false, constraints: false, triggers: false, partitions: true, tableComment: false };
case "ddl":
return { columns: false, indexes: false, foreignKeys: false, constraints: false, triggers: false, partitions: false, tableComment: true };
default:
// "info" is a data-grid drawer tab and has no structure-editor scope.
return { columns: false, indexes: false, foreignKeys: false, constraints: false, triggers: false, partitions: false, tableComment: false };
}
}