import { Handle, type Node, type NodeProps, Position } from "@xyflow/react"; import type { TAppDataEntity } from "data/data-schema"; import { useState } from "react"; import { TbDiamonds, TbKey } from "react-icons/tb"; import { twMerge } from "tailwind-merge"; import { DefaultNode } from "ui/components/canvas/components/nodes/DefaultNode"; export type TableProps = { name: string; type?: string; fields: TableField[]; }; export type TableField = { name: string; type: string; primary?: boolean; foreign?: boolean; indexed?: boolean; }; function NodeComponent(props: NodeProps>) { const [hovered, setHovered] = useState(false); const { data } = props; const fields = props.data.fields ?? {}; const field_count = Object.keys(fields).length; return (
{Object.entries(fields).map(([name, field], index) => ( ))}
); } const handleStyle = { background: "transparent", border: "none", }; const TableRow = ({ field, table, index, onHover, last, }: { field: TableField; table: string; index: number; last?: boolean; onHover?: (hovered: boolean) => void; }) => { const handleTop = HEIGHTS.header + HEIGHTS.row * index + HEIGHTS.row / 2; const handles = true; const handleId = `${table}:${field.name}`; return (
{handles && ( )}
{field.type === "primary" && } {field.type === "relation" && }
{field.name}
{field.type}
{handles && ( )}
); }; export const HEIGHTS = { header: 30, row: 32.5, }; export const EntityTableNode = { Component: NodeComponent, getSize: (data: TAppDataEntity) => { const fields = data.fields ?? {}; const field_count = Object.keys(fields).length; return { width: 320, height: HEIGHTS.header + HEIGHTS.row * field_count, }; }, };