diff --git a/src/components/draw_area.jsx b/src/components/draw_area.jsx index e8b8fae..adbd136 100644 --- a/src/components/draw_area.jsx +++ b/src/components/draw_area.jsx @@ -1,12 +1,11 @@ import React, { useRef, useState } from "react"; import { useDrop } from "react-dnd"; import Rect from "./rect"; -import Node from "./node"; + export default function Canvas(props) { const [dragging, setDragging] = useState(-1); const [offset, setOffset] = useState({ x: 0, y: 0 }); - const [links, setLinks] = useState([]); const [onRect, setOnRect] = useState(false); const [panning, setPanning] = useState(false); const [panOffset, setPanOffset] = useState({ x: 0, y: 0 }); @@ -37,12 +36,7 @@ export default function Canvas(props) { })); props.setRectangles(updatedRectangles); - const updatedLinks = links.map((link) => ({ - ...link, - x: link.x + dx, - y: link.y + dy, - })); - setLinks(updatedLinks); + } else if (dragging >= 0) { const { clientX, clientY } = e; const updatedRectangles = props.rectangles.map((rect) => { @@ -52,47 +46,7 @@ export default function Canvas(props) { x: clientX - offset.x, y: clientY - offset.y, }; - const updatedLinks = links.map((link) => { - let updatedLink = link; - if (link.rect === updatedRect.id) { - switch (link.node) { - case Node.TOP: - updatedLink = { - ...link, - x: updatedRect.x + updatedRect.width / 2, - y: updatedRect.y, - }; - break; - case Node.BOTTOM: - updatedLink = { - ...link, - x: updatedRect.x + updatedRect.width / 2, - y: updatedRect.y + updatedRect.height, - }; - break; - case Node.LEFT: - updatedLink = { - ...link, - x: updatedRect.x, - y: updatedRect.y + updatedRect.height / 2, - }; - break; - case Node.RIGHT: - updatedLink = { - ...link, - x: updatedRect.x + updatedRect.width, - y: updatedRect.y + updatedRect.height / 2, - }; - break; - default: - break; - } - } - return updatedLink; - }); - - setLinks(updatedLinks); - return updatedRect; + return updatedRect; } return rect; }); @@ -201,13 +155,13 @@ export default function Canvas(props) { width={rectangle.width} height={rectangle.height} setOnRect={setOnRect} - links={links} - setLinks={setLinks} + // links={links} + // setLinks={setLinks} onMouseDown={(e) => handleMouseDownRect(e, rectangle.id)} onDelete={deleteTable} /> ))} - {links.map( + {/* {links.map( (link, index) => links.length >= 2 && index % 2 === 0 && @@ -222,7 +176,7 @@ export default function Canvas(props) { strokeDasharray="5,5" /> ) - )} + )} */} diff --git a/src/components/node.js b/src/components/node.js deleted file mode 100644 index 6aa33f5..0000000 --- a/src/components/node.js +++ /dev/null @@ -1,9 +0,0 @@ -const Node = { - NONE: "NONE", - TOP: "TOP", - LEFT: "LEFT", - RIGHT: "RIGHT", - BOTTOM: "BOTTOM", -}; - -export default Node; diff --git a/src/components/rect.jsx b/src/components/rect.jsx index b8346fb..d1516f7 100644 --- a/src/components/rect.jsx +++ b/src/components/rect.jsx @@ -1,5 +1,4 @@ import { React, useState } from "react"; -import Node from "./node"; import sqlDataTypes from "./sql_types"; import { IconEdit, @@ -20,7 +19,6 @@ import { } from "@douyinfe/semi-ui"; const Rect = (props) => { - const [node, setNode] = useState(Node.NONE); const [isHovered, setIsHovered] = useState(false); const [hoveredField, setHoveredField] = useState(-1); const [name, setName] = useState("New Table"); @@ -207,7 +205,10 @@ const Rect = (props) => { setHoveredField(-1); }} > -
{e.name}
+
+ + {e.name} +
{hoveredField === i ? (
@@ -241,82 +242,7 @@ const Rect = (props) => { })}
- { - setNode(Node.TOP); - props.setLinks([ - ...props.links, - { - rect: props.id, - node: Node.TOP, - x: props.x + props.width / 2, - y: props.y, - }, - ]); - }} - style={{ fill: node === Node.TOP ? "green" : "black" }} - /> - { - setNode(Node.LEFT); - props.setLinks([ - ...props.links, - { - rect: props.id, - node: Node.LEFT, - x: props.x, - y: props.y + height / 2, - }, - ]); - }} - style={{ fill: node === Node.LEFT ? "green" : "black" }} - /> - { - setNode(Node.RIGHT); - props.setLinks([ - ...props.links, - { - rect: props.id, - node: Node.RIGHT, - x: props.x + props.width, - y: props.y + height / 2, - }, - ]); - }} - style={{ fill: node === Node.RIGHT ? "green" : "black" }} - /> - { - setNode(Node.BOTTOM); - props.setLinks([ - ...props.links, - { - rect: props.id, - node: Node.BOTTOM, - x: props.x + props.width / 2, - y: props.y + height, - }, - ]); - }} - style={{ fill: node === Node.BOTTOM ? "green" : "black" }} - /> +