feat(diagram): show table and column comments on cards
This commit is contained in:
12 files changed
+273
-55
No files matched your search
@@ -35,7 +35,7 @@ import { saveDiagramBinaryExport, saveDiagramTextExport } from "@/lib/export/sav
|
||||
import { inferRelationships, filterByStorage } from "@/lib/diagram/match-engine";
|
||||
import { loadMatchConfirms, saveMatchConfirms, loadMatchIgnores, saveMatchIgnores, isAutoMatchEnabled } from "@/lib/diagram/match-storage";
|
||||
import { toVueFlowNodes, toVueFlowEdges, toDiagramEdges, toVueFlowLayerNodes, toAbsolutePosition, isTableCanvasVisible } from "@/lib/diagram/vue-flow-adapter";
|
||||
import { CARD_WIDTH, CARD_HEADER_HEIGHT, COLUMN_ROW_HEIGHT, CARD_BOTTOM_PADDING, GAP_X, GAP_Y, MARGIN, LAYER_CONTENT_PADDING, LAYER_HEADER_HEIGHT, DIAGRAM_HOVERED_EDGE_KEY, DIAGRAM_EDGE_OBSTACLES_KEY } from "@/lib/diagram/diagram-constants";
|
||||
import { CARD_WIDTH, CARD_HEADER_HEIGHT, COLUMN_ROW_HEIGHT, CARD_BOTTOM_PADDING, GAP_X, GAP_Y, MARGIN, LAYER_CONTENT_PADDING, LAYER_HEADER_HEIGHT, DIAGRAM_HOVERED_EDGE_KEY, DIAGRAM_EDGE_OBSTACLES_KEY, diagramTableCardHeight } from "@/lib/diagram/diagram-constants";
|
||||
import { sizeLayerToFit, findLayerAtPoint, placeNewLayer } from "@/lib/diagram/size-layer";
|
||||
import { computeLtrAutoLayout } from "@/lib/diagram/ltr-auto-layout";
|
||||
import { computeLayoutWithLayers } from "@/lib/diagram/elk-layout";
|
||||
@@ -530,7 +530,9 @@ const customRelationshipCount = computed(() => customRelationships.value.length)
|
||||
const matchRelationshipCount = computed(() => matchResult.value.relationships.length);
|
||||
|
||||
function tableHeight(table: DiagramTable): number {
|
||||
return CARD_HEADER_HEIGHT + table.columns.length * COLUMN_ROW_HEIGHT + CARD_BOTTOM_PADDING;
|
||||
// Includes the rendered table/column comment lines so canvas bounds, layers,
|
||||
// edge routing and auto layout match the card height.
|
||||
return diagramTableCardHeight(table);
|
||||
}
|
||||
|
||||
const canvasSize = computed(() => {
|
||||
@@ -1345,7 +1347,7 @@ async function setSelectedSchemas(values: string[]) {
|
||||
if (diagramReady.value) await loadDiagram();
|
||||
}
|
||||
|
||||
async function loadTableDiagramData(tableName: string, querySchema: string): Promise<DiagramTable> {
|
||||
async function loadTableDiagramData(tableName: string, querySchema: string, tableComment?: string | null): Promise<DiagramTable> {
|
||||
try {
|
||||
const [columns, foreignKeys, indexes] = await Promise.all([
|
||||
api.getColumns(connectionId.value, database.value, querySchema, tableName),
|
||||
@@ -1355,6 +1357,7 @@ async function loadTableDiagramData(tableName: string, querySchema: string): Pro
|
||||
return {
|
||||
name: tableName,
|
||||
schema: querySchema,
|
||||
comment: tableComment ?? null,
|
||||
columns,
|
||||
foreignKeys,
|
||||
indexes: indexes.map((index) => ({
|
||||
@@ -1374,7 +1377,7 @@ async function loadTableDiagramData(tableName: string, querySchema: string): Pro
|
||||
} catch (e) {
|
||||
failedTableCount.value += 1;
|
||||
console.warn(`[diagram] failed to load table metadata: ${querySchema}.${tableName}`, e);
|
||||
return { name: tableName, schema: querySchema, columns: [], foreignKeys: [], indexes: [] };
|
||||
return { name: tableName, schema: querySchema, comment: tableComment ?? null, columns: [], foreignKeys: [], indexes: [] };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1395,7 +1398,8 @@ async function loadDiagram() {
|
||||
targetSchemas.map(async (sc) => {
|
||||
try {
|
||||
const list = await api.listTables(connectionId.value, database.value, sc);
|
||||
return list.filter((table) => table.table_type !== "VIEW" && table.table_type !== "MATERIALIZED_VIEW").map((table) => ({ name: table.name, schema: sc }));
|
||||
// Keep the table comment so the card can render the table description.
|
||||
return list.filter((table) => table.table_type !== "VIEW" && table.table_type !== "MATERIALIZED_VIEW").map((table) => ({ name: table.name, schema: sc, comment: table.comment ?? null }));
|
||||
} catch (e) {
|
||||
console.warn(`[diagram] failed to list tables for schema ${sc}`, e);
|
||||
return [];
|
||||
@@ -1411,7 +1415,7 @@ async function loadDiagram() {
|
||||
const loadedTables: DiagramTable[] = [];
|
||||
for (let index = 0; index < baseTables.length; index += METADATA_BATCH_SIZE) {
|
||||
const batch = baseTables.slice(index, index + METADATA_BATCH_SIZE);
|
||||
const batchTables = await Promise.all(batch.map((item) => loadTableDiagramData(item.name, item.schema)));
|
||||
const batchTables = await Promise.all(batch.map((item) => loadTableDiagramData(item.name, item.schema, item.comment)));
|
||||
loadedTables.push(...batchTables);
|
||||
loadedTableCount.value = loadedTables.length;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import { Handle, Position } from "@vue-flow/core";
|
||||
import { Table2, KeyRound, Link2 } from "@lucide/vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import type { DiagramTable, DiagramRelationship } from "@/lib/diagram/erDiagram";
|
||||
import { isDraftTable, isDroppedColumn } from "@/lib/diagram/erDiagram";
|
||||
import { isDraftTable } from "@/lib/diagram/erDiagram";
|
||||
import type { InferredRelationship } from "@/types/diagram";
|
||||
import { useLayerStore } from "@/lib/diagram/layer-store";
|
||||
import { CARD_WIDTH, COLUMN_TYPE_WIDTH, COLUMN_NAME_MAX_CHARS, COLUMN_TYPE_MAX_CHARS, TABLE_NAME_MAX_CHARS, EDGE_HANDLE_OUTSET } from "@/lib/diagram/diagram-constants";
|
||||
import { CARD_WIDTH, COLUMN_TYPE_WIDTH, COLUMN_NAME_MAX_CHARS, COLUMN_TYPE_MAX_CHARS, TABLE_NAME_MAX_CHARS, EDGE_HANDLE_OUTSET, diagramVisibleColumns } from "@/lib/diagram/diagram-constants";
|
||||
|
||||
const layerStore = useLayerStore();
|
||||
|
||||
@@ -26,7 +26,12 @@ const emit = defineEmits<{
|
||||
const isDraft = computed(() => isDraftTable(props.data.table));
|
||||
|
||||
function visibleColumns(table: DiagramTable) {
|
||||
return table.columns.filter((column) => !isDroppedColumn(table, column.name));
|
||||
return diagramVisibleColumns(table);
|
||||
}
|
||||
|
||||
/** Comments are optional metadata; blank/whitespace-only values render nothing. */
|
||||
function commentText(value: string | null | undefined): string {
|
||||
return typeof value === "string" ? value.trim() : "";
|
||||
}
|
||||
|
||||
function isForeignKeyColumn(table: DiagramTable, columnName: string): boolean {
|
||||
@@ -86,18 +91,26 @@ const handleOffsetStyle = computed(() =>
|
||||
<Badge v-if="isDraft" variant="outline" class="h-5 shrink-0 px-1.5 text-[10px] border-amber-500/50 text-amber-700 dark:text-amber-400">Draft</Badge>
|
||||
<Badge variant="outline" class="h-5 px-1.5 text-[10px]">{{ visibleColumns(data.table).length }}</Badge>
|
||||
</div>
|
||||
<div v-if="commentText(data.table.comment)" class="flex h-4 items-center gap-1.5 border-b border-border/40 bg-muted/20 px-3">
|
||||
<span class="min-w-0 flex-1 truncate text-[10px] leading-none text-muted-foreground" :title="commentText(data.table.comment)">{{ commentText(data.table.comment) }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<div v-for="column in visibleColumns(data.table)" :key="column.name" class="flex h-6 min-w-0 items-center gap-1.5 border-b border-border/40 px-3 text-xs last:border-b-0">
|
||||
<KeyRound v-if="column.is_primary_key" class="h-3 w-3 shrink-0 text-amber-500" />
|
||||
<Link2 v-else-if="isForeignKeyColumn(data.table, column.name)" class="h-3 w-3 shrink-0 text-primary" />
|
||||
<Link2 v-else-if="isRelationshipColumn(data.table, column.name)" class="h-3 w-3 shrink-0 text-muted-foreground" />
|
||||
<span v-else class="h-3 w-3 shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate font-mono" :title="column.name">
|
||||
{{ truncateLabel(column.name, COLUMN_NAME_MAX_CHARS) }}
|
||||
</span>
|
||||
<span class="shrink-0 truncate text-right text-[10px] text-muted-foreground" :style="{ width: `${COLUMN_TYPE_WIDTH}px` }" :title="column.data_type">
|
||||
{{ truncateLabel(column.data_type, COLUMN_TYPE_MAX_CHARS) }}
|
||||
</span>
|
||||
<div v-for="column in visibleColumns(data.table)" :key="column.name" class="border-b border-border/40 last:border-b-0">
|
||||
<div class="flex h-6 min-w-0 items-center gap-1.5 px-3 text-xs">
|
||||
<KeyRound v-if="column.is_primary_key" class="h-3 w-3 shrink-0 text-amber-500" />
|
||||
<Link2 v-else-if="isForeignKeyColumn(data.table, column.name)" class="h-3 w-3 shrink-0 text-primary" />
|
||||
<Link2 v-else-if="isRelationshipColumn(data.table, column.name)" class="h-3 w-3 shrink-0 text-muted-foreground" />
|
||||
<span v-else class="h-3 w-3 shrink-0" />
|
||||
<span class="min-w-0 flex-1 truncate font-mono" :title="column.name">
|
||||
{{ truncateLabel(column.name, COLUMN_NAME_MAX_CHARS) }}
|
||||
</span>
|
||||
<span class="shrink-0 truncate text-right text-[10px] text-muted-foreground" :style="{ width: `${COLUMN_TYPE_WIDTH}px` }" :title="column.data_type">
|
||||
{{ truncateLabel(column.data_type, COLUMN_TYPE_MAX_CHARS) }}
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="commentText(column.comment)" class="flex h-4 items-center pb-0.5 pl-[18px] pr-3">
|
||||
<span class="min-w-0 flex-1 truncate text-[10px] leading-none text-muted-foreground" :title="commentText(column.comment)">{{ commentText(column.comment) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user