import { Database, Circle, Key } from 'lucide-react'; import { Handle, Position } from '@xyflow/react'; import { TableSchema } from '@insforge/shared-schemas'; interface TableNodeProps { data: { table: TableSchema; referencedColumns?: string[]; // List of column names that are referenced by other tables showRecordCount?: boolean; // Control whether to show record count }; } export function TableNode({ data }: TableNodeProps) { const { table, referencedColumns = [], showRecordCount = true } = data; const getColumnIcon = (isReferenced: boolean = false) => { // If column is referenced by another table (has incoming connections) // Show outer gray diamond with inner white diamond if (isReferenced) { return (
{/* Outer gray diamond */}
{/* Inner white diamond */}
); } return (
{/* Outer gray diamond */}
); }; return (
{/* Table Header */}

{table.tableName}

{showRecordCount && (

{table.recordCount !== undefined ? `${table.recordCount.toLocaleString()} data` : '0 data'}

)}
{/*
*/}
{/* Columns */}
{table.columns.map((column) => (
{/* Source handle for foreign key columns - invisible and non-interactive */} {column.foreignKey && ( )} {/* Target handle for columns that can be referenced - invisible and non-interactive */} {referencedColumns.includes(column.columnName) && ( )}
{getColumnIcon(referencedColumns.includes(column.columnName))} {column.columnName} {column.isPrimaryKey && ( )}
{column.type}
{/* Show white dot with outer circle for foreign key columns, gray circle for others */} {column.foreignKey ? (
) : ( )}
))} {/* Empty state */} {!table.columns.length && (

No columns defined

)}
); }