import { DiamondIcon, Fingerprint, Hash, Key, Table2 } from 'lucide-react' import { Handle, NodeProps } from 'reactflow' import { cn } from 'ui' // ReactFlow is scaling everything by the factor of 2 const TABLE_NODE_WIDTH = 320 const TABLE_NODE_ROW_HEIGHT = 40 export type TableNodeData = { name: string isForeign: boolean columns: { id: string isPrimary: boolean isNullable: boolean isUnique: boolean isIdentity: boolean name: string format: string }[] } const TableNode = ({ data, targetPosition, sourcePosition }: NodeProps) => { // Important styles is a nasty hack to use Handles (required for edges calculations), but do not show them in the UI. // ref: https://github.com/wbkd/react-flow/discussions/2698 const hiddenNodeConnector = '!h-px !w-px !min-w-0 !min-h-0 !cursor-grab !border-0 !opacity-0' const itemHeight = 'h-[22px]' return ( <> {data.isForeign ? (
{data.name} {targetPosition && ( )}
) : (
{data.name}
{data.columns.map((column) => (
{column.isPrimary && ( )} {column.isNullable && ( )} {!column.isNullable && ( )} {column.isUnique && ( )} {column.isIdentity && ( )}
{column.name} {column.format}
{targetPosition && ( )} {sourcePosition && ( )}
))}
)} ) } export { TABLE_NODE_ROW_HEIGHT, TABLE_NODE_WIDTH, TableNode }