import { useState } from "react"; import { Tab, ObjectType, tableFieldHeight, tableHeaderHeight, tableColorStripHeight, } from "../../data/constants"; import { IconEdit, IconMore, IconMinus, IconDeleteStroked, IconKeyStroked, } from "@douyinfe/semi-icons"; import { Popover, Tag, Button, SideSheet } from "@douyinfe/semi-ui"; import { useLayout, useSettings, useDiagram, useSelect } from "../../hooks"; import TableInfo from "../EditorSidePanel/TablesTab/TableInfo"; import { useTranslation } from "react-i18next"; export default function Table(props) { const [hoveredField, setHoveredField] = useState(-1); const { tableData, onPointerDown, setHoveredTable, handleGripField, setLinkingLine, } = props; const { layout } = useLayout(); const { deleteTable, deleteField } = useDiagram(); const { settings } = useSettings(); const { t } = useTranslation(); const { selectedElement, setSelectedElement } = useSelect(); const height = tableData.fields.length * tableFieldHeight + tableHeaderHeight + 7; const openEditor = () => { if (!layout.sidebar) { setSelectedElement((prev) => ({ ...prev, element: ObjectType.TABLE, id: tableData.id, open: true, })); } else { setSelectedElement((prev) => ({ ...prev, currentTab: Tab.TABLES, element: ObjectType.TABLE, id: tableData.id, open: true, })); if (selectedElement.currentTab !== Tab.TABLES) return; document .getElementById(`scroll_table_${tableData.id}`) .scrollIntoView({ behavior: "smooth" }); } }; return ( <>
{tableData.name}
} position="rightTop" showArrow trigger="click" style={{ width: "200px", wordBreak: "break-word" }} >
{tableData.fields.map((e, i) => { return settings.showFieldSummary ? (

{e.name}

{e.type}


{e.primary && ( {t("primary")} )} {e.unique && ( {t("unique")} )} {e.notNull && ( {t("not_null")} )} {e.increment && ( {t("autoincrement")} )}

{t("default_value")}: {e.default === "" ? t("not_set") : e.default}

{t("comment")}: {e.comment === "" ? t("not_set") : e.comment}

} position="right" showArrow > {field(e, i)} ) : ( field(e, i) ); })}
setSelectedElement((prev) => ({ ...prev, open: !prev.open, })) } style={{ paddingBottom: "16px" }} >
); function field(fieldData, index) { return (
{ if (!e.isPrimary) return; setHoveredField(index); setHoveredTable({ tableId: tableData.id, field: index, }); }} onPointerLeave={(e) => { if (!e.isPrimary) return; setHoveredField(-1); }} onPointerDown={(e) => { // Required for onPointerLeave to trigger when a touch pointer leaves // https://stackoverflow.com/a/70976017/1137077 e.target.releasePointerCapture(e.pointerId); }} >
{hoveredField === index ? (
); } }