diff --git a/src/components/control_panel.jsx b/src/components/control_panel.jsx index e6160e1..7f29496 100644 --- a/src/components/control_panel.jsx +++ b/src/components/control_panel.jsx @@ -35,9 +35,11 @@ export default function ControlPanel() { break; case Tool.ZOOM: setOpenZoom((prev) => !prev); + setOpenAdd(false); break; case Tool.ADD: setOpenAdd((prev) => !prev); + setOpenZoom(false); break; default: break; @@ -143,7 +145,7 @@ export default function ControlPanel() { - + diff --git a/src/components/draw_area.jsx b/src/components/draw_area.jsx index 94a08e3..fbcb857 100644 --- a/src/components/draw_area.jsx +++ b/src/components/draw_area.jsx @@ -124,19 +124,19 @@ export default function Canvas(props) { const canvasRect = canvas.current.getBoundingClientRect(); const x = offset.x - canvasRect.left - 100 * 0.5; const y = offset.y - canvasRect.top - 100 * 0.5; - const newRectangle = { + const d = { id: props.rectangles.length + 1, x, y, - width: 100, + width: 240, height: 100, label: `rect ${props.rectangles.length + 1}`, }; - props.setRectangles([...props.rectangles, newRectangle]); + props.setRectangles([...props.rectangles, d]); props.setCode((prev) => prev === "" - ? `CREATE TABLE \`${newRectangle.label}\`;` - : `${prev}\n\nCREATE TABLE \`${newRectangle.label}\`;` + ? `CREATE TABLE \`${d.label}\`;` + : `${prev}\n\nCREATE TABLE \`${d.label}\`;` ); }, collect: (monitor) => ({ diff --git a/src/components/editor_panel.jsx b/src/components/editor_panel.jsx index 81b06fe..52a87b2 100644 --- a/src/components/editor_panel.jsx +++ b/src/components/editor_panel.jsx @@ -52,7 +52,7 @@ export default function EditorPanel(props) { id: props.rectangles.length + 1, x: 0, y: 0, - width: 100, + width: 240, height: 100, label: `rect ${props.rectangles.length + 1}`, }; @@ -95,7 +95,7 @@ export default function EditorPanel(props) { id: props.rectangles.length + 1, x: 0, y: 0, - width: 100, + width: 240, height: 100, label: `rect ${props.rectangles.length + 1}`, }; diff --git a/src/components/rect.jsx b/src/components/rect.jsx index 519e46f..a63feb1 100644 --- a/src/components/rect.jsx +++ b/src/components/rect.jsx @@ -6,6 +6,33 @@ const Rect = (props) => { const [isHovered, setIsHovered] = useState(false); const [node, setNode] = useState(Node.NONE); + const table = { + name: "Students", + fields: [ + { + name: "id", + type: "uuid", + default: "", + primary: true, + unique: true, + notNull: true, + increment: false, + }, + { + name: "name", + type: "varchar(20)", + default: "n/a", + primary: false, + unique: false, + notNull: true, + increment: false, + }, + ], + }; + + const height = + table.fields.length * 36 + (table.fields.length - 1) * 2 + 40 + 4; + return ( { x={props.x} y={props.y} width={props.width} - height={props.height} + height={height} style={{ cursor: "move" }} onMouseDown={props.onMouseDown} onMouseEnter={() => { @@ -26,15 +53,27 @@ const Rect = (props) => { }} > - {props.label} - e.preventDefault()}> - - - console.log("sup")}> - sup - + + {table.name} + + {table.fields.map((e, i) => { + return ( + + {e.name} + {e.type} + + ); + })} { { setNode(Node.LEFT); @@ -69,7 +108,7 @@ const Rect = (props) => { rect: props.id, node: Node.LEFT, x: props.x, - y: props.y + props.height / 2, + y: props.y + height / 2, }, ]); }} @@ -78,7 +117,7 @@ const Rect = (props) => { { setNode(Node.RIGHT); @@ -88,7 +127,7 @@ const Rect = (props) => { rect: props.id, node: Node.RIGHT, x: props.x + props.width, - y: props.y + props.height / 2, + y: props.y + height / 2, }, ]); }} @@ -97,7 +136,7 @@ const Rect = (props) => { { setNode(Node.BOTTOM); @@ -107,7 +146,7 @@ const Rect = (props) => { rect: props.id, node: Node.BOTTOM, x: props.x + props.width / 2, - y: props.y + props.height, + y: props.y + height, }, ]); }}