import { React, useState, useContext } from "react"; import { sqlDataTypes, tableThemes, defaultTableTheme, Tab, } from "../data/data"; import { IconEdit, IconPlus, IconMore, IconMinus, IconDeleteStroked, IconKeyStroked, IconCheckboxTick, IconColorPalette, } from "@douyinfe/semi-icons"; import { Popconfirm, Select, Card, Form, Checkbox, Row, Col, Popover, Tag, Button, SideSheet, Toast, } from "@douyinfe/semi-ui"; import { LayoutContext, SettingsContext, TabContext, TableContext, } from "../pages/editor"; export default function Table(props) { const [isHovered, setIsHovered] = useState(false); const [hoveredField, setHoveredField] = useState(-1); const [visible, setVisible] = useState(false); const { layout } = useContext(LayoutContext); const { setTables } = useContext(TableContext); const { tab, setTab } = useContext(TabContext); const { settings } = useContext(SettingsContext); const height = props.tableData.fields.length * 36 + 50 + 3; const updatedField = (tid, fid, updatedValues) => { setTables((prev) => prev.map((table, i) => { if (tid === i) { return { ...table, fields: table.fields.map((field, j) => fid === j ? { ...field, ...updatedValues } : field ), }; } return table; }) ); }; const updateTable = (tid, updatedValues) => { setTables((prev) => prev.map((table, i) => { if (tid === i) { return { ...table, ...updatedValues, }; } return table; }) ); }; return ( { setIsHovered(true); }} onMouseLeave={() => { setIsHovered(false); props.setOnRect({ tableId: -1, field: -2, }); }} >
{props.tableData.name}
{isHovered && (
Comment :{" "} {props.tableData.comment === "" ? ( "No comment" ) : (
{props.tableData.comment}
)}
Indices : {" "} {props.tableData.indices.length === 0 ? ( "No indices" ) : (
{props.tableData.indices.map((index, k) => (
{index.fields.map((f) => ( {f} ))}
))}
)}
} position="rightTop" showArrow trigger="click" style={{ width: "200px" }} >
)}
{props.tableData.fields.map((e, i) => { return settings.showFieldSummary ? (

{e.name}

{e.type}


{e.primary && ( Primary )} {e.unique && ( Unique )} {e.notNull && ( Not null )} {e.increment && ( Increment )}

Default :{" "} {e.default === "" ? "Not set" : e.default}

Comment :{" "} {e.comment === "" ? "Not comment" : e.comment}

} position="right" showArrow > {field(e, i)}
) : ( field(e, i) ); })}
setVisible((prev) => !prev)} style={{ paddingBottom: "16px" }} >
updateTable(props.tableData.id, value.values)} >
{props.tableData.fields.map((f, j) => (
updatedField(props.tableData.id, j, value.values) } initValues={f} > { return { label: value, value: value, }; })} filter placeholder="Type" > updatedField(props.tableData.id, j, value.values) } >
updatedField(props.tableData.id, j, { [checkedValues.target.value]: checkedValues.target.checked, }) } >
updatedField(props.tableData.id, j, { [checkedValues.target.value]: checkedValues.target.checked, }) } >
} trigger="click" position="rightTop" showArrow > ))} {props.tableData.indices.length > 0 && (
Indices
{props.tableData.indices.map((idx, k) => (