feat(docs): export data dictionary as PDF

This commit is contained in:
onenewcode authored and GitHub committed 2026-09-24 19:53:58 +08:00
1 parent 2d4ee24660
commit b140f84ac4
28 files changed
+3108 -3

No files matched your search

@@ -8,6 +8,7 @@ function setup(node: Partial<TreeNode>, options: { treeNodes?: TreeNode[]; selec
const activeNode = shallowRef({ id: "n-1", label: "node", children: [], ...node } as TreeNode);
const connectionStore = {
docsSource: null as unknown,
dataDictionarySource: null as unknown,
diagramSource: null as unknown,
databaseExportSource: null as unknown,
mongoImportSource: undefined as unknown,
@@ -27,6 +28,53 @@ function setup(node: Partial<TreeNode>, options: { treeNodes?: TreeNode[]; selec
return { connectionStore, runtime };
}
describe("useSidebarTreeToolRuntime openDataDictionary", () => {
it("documents every schema when invoked on a database node", () => {
const { connectionStore, runtime } = setup({ type: "database", label: "shop", connectionId: "conn-1", database: "shop" });
runtime.openDataDictionary();
expect(connectionStore.dataDictionarySource).toEqual({ connectionId: "conn-1", database: "shop", schema: undefined });
});
it("narrows to a schema node", () => {
const { connectionStore, runtime } = setup({ type: "schema", label: "public", connectionId: "conn-1", database: "shop", schema: "public" });
runtime.openDataDictionary();
expect(connectionStore.dataDictionarySource).toEqual({ connectionId: "conn-1", database: "shop", schema: "public" });
});
it("exports the selected same-schema tables and views", () => {
const publicUsers: TreeNode = { id: "t1", label: "users", type: "table", connectionId: "c1", database: "db", schema: "public" };
const publicOrders: TreeNode = { id: "t2", label: "orders", type: "table", connectionId: "c1", database: "db", schema: "public" };
const publicView: TreeNode = { id: "v1", label: "active_users", type: "view", connectionId: "c1", database: "db", schema: "public" };
const salesUsers: TreeNode = { id: "t3", label: "users", type: "table", connectionId: "c1", database: "db", schema: "sales" };
const group: TreeNode = { id: "group", label: "Tables", type: "group-tables", children: [publicUsers, publicOrders, publicView, salesUsers] };
const { connectionStore, runtime } = setup(publicUsers, {
treeNodes: [group],
selectedTreeNodeIds: [publicOrders.id, publicUsers.id, publicView.id, salesUsers.id],
});
runtime.openDataDictionary();
expect(connectionStore.dataDictionarySource).toEqual({
connectionId: "c1",
database: "db",
schema: "public",
tableNames: ["users", "orders", "active_users"],
});
});
it("does nothing when the node carries no database", () => {
const { connectionStore, runtime } = setup({ type: "connection", label: "local", connectionId: "conn-1" });
runtime.openDataDictionary();
expect(connectionStore.dataDictionarySource).toBeNull();
});
});
describe("useSidebarTreeToolRuntime openDocs", () => {
it("documents the whole database when invoked on a database node", () => {
const { connectionStore, runtime } = setup({ type: "database", label: "shop", connectionId: "conn-1", database: "shop" });
@@ -14,6 +14,7 @@ const showDataCompareDialog = ref(false);
const showSqlFileDialog = ref(false);
const showDiagramDialog = ref(false);
const showDocsDialog = ref(false);
const showDataDictionaryDialog = ref(false);
const showTableImportDialog = ref(false);
const showMongoImportDialog = ref(false);
const showMongoDatabaseDumpDialog = ref(false);
@@ -71,6 +72,10 @@ const diagramFocusTableNames = ref<string[]>([]);
const docsPrefillConnectionId = ref("");
const docsPrefillDatabase = ref("");
const docsPrefillSchema = ref("");
const dataDictionaryPrefillConnectionId = ref("");
const dataDictionaryPrefillDatabase = ref("");
const dataDictionaryPrefillSchema = ref("");
const dataDictionaryPrefillTableNames = ref<string[]>([]);
const tableImportPrefillConnectionId = ref("");
const tableImportPrefillDatabase = ref("");
const tableImportPrefillSchema = ref("");
@@ -246,6 +251,20 @@ export function useDialogSources() {
},
);
watch(
() => connectionStore.dataDictionarySource,
(v) => {
if (v) {
dataDictionaryPrefillConnectionId.value = v.connectionId;
dataDictionaryPrefillDatabase.value = v.database;
dataDictionaryPrefillSchema.value = v.schema ?? "";
dataDictionaryPrefillTableNames.value = v.tableNames ?? [];
showDataDictionaryDialog.value = true;
connectionStore.dataDictionarySource = null;
}
},
);
watch(
() => connectionStore.tableImportSource,
(v) => {
@@ -539,6 +558,7 @@ export function useDialogSources() {
showSqlFileDialog,
showDiagramDialog,
showDocsDialog,
showDataDictionaryDialog,
showTableImportDialog,
showMongoImportDialog,
showMongoDatabaseDumpDialog,
@@ -592,6 +612,10 @@ export function useDialogSources() {
docsPrefillConnectionId,
docsPrefillDatabase,
docsPrefillSchema,
dataDictionaryPrefillConnectionId,
dataDictionaryPrefillDatabase,
dataDictionaryPrefillSchema,
dataDictionaryPrefillTableNames,
tableImportPrefillConnectionId,
tableImportPrefillDatabase,
tableImportPrefillSchema,
@@ -95,6 +95,28 @@ export function useSidebarTreeToolRuntime(options: SidebarTreeToolRuntimeOptions
};
}
function openDataDictionary() {
const node = activeNode.value;
if (!node.connectionId || !node.database) return;
if (node.type === "table" || node.type === "view" || node.type === "materialized_view") {
const targets = selectedSameSchemaStructureTargets().filter((target) => target.type === "table" || target.type === "view" || target.type === "materialized_view");
const tableNames = targets.length > 1 ? targets.map((target) => target.label) : [node.label];
connectionStore.dataDictionarySource = {
connectionId: node.connectionId,
database: node.database,
schema: node.schema,
tableNames,
};
return;
}
connectionStore.dataDictionarySource = {
connectionId: node.connectionId,
database: node.database,
// A database node has no schema, so the collector documents every schema.
schema: node.type === "schema" ? node.schema : undefined,
};
}
function openDatabaseSearch() {
const node = activeNode.value;
if (!node.connectionId || !node.database) return;
@@ -193,6 +215,7 @@ export function useSidebarTreeToolRuntime(options: SidebarTreeToolRuntimeOptions
openDataCompare,
openDatabaseExport,
openDatabaseSearch,
openDataDictionary,
openDiagram,
openDocs,
openFieldLineage,