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 (
<>
{e.name} {e.type}
{t("default_value")}:
{e.default === "" ? t("not_set") : e.default}
{t("comment")}:
{e.comment === "" ? t("not_set") : e.comment}
{e.primary && (