delete table

This commit is contained in:
1ilit 2023-09-19 15:47:26 +03:00
parent c3fa9277ef
commit 5ed62c8714
3 changed files with 14 additions and 13 deletions

View File

@ -116,6 +116,12 @@ export default function Canvas(props) {
setCursor("default"); setCursor("default");
}; };
const deleteTable = (id) => {
const updatedTables = [...props.rectangles];
updatedTables.splice(id, 1);
props.setRectangles(updatedTables);
};
const [, drop] = useDrop( const [, drop] = useDrop(
() => ({ () => ({
accept: "CARD", accept: "CARD",
@ -185,10 +191,10 @@ export default function Canvas(props) {
</defs> </defs>
<rect width="100%" height="100%" fill="url(#grid)" /> <rect width="100%" height="100%" fill="url(#grid)" />
{props.rectangles.map((rectangle) => ( {props.rectangles.map((rectangle, i) => (
<Rect <Rect
key={rectangle.id} key={rectangle.id}
id={rectangle.id} id={i}
x={rectangle.x} x={rectangle.x}
y={rectangle.y} y={rectangle.y}
label={rectangle.label} label={rectangle.label}
@ -198,6 +204,7 @@ export default function Canvas(props) {
links={links} links={links}
setLinks={setLinks} setLinks={setLinks}
onMouseDown={(e) => handleMouseDownRect(e, rectangle.id)} onMouseDown={(e) => handleMouseDownRect(e, rectangle.id)}
onDelete={deleteTable}
/> />
))} ))}
{links.map( {links.map(

View File

@ -125,7 +125,10 @@ const Rect = (props) => {
> >
<IconPlus /> <IconPlus />
</button> </button>
<button className="btn bg-red-800 text-white text-xs py-1 px-2 opacity-80"> <button
className="btn bg-red-800 text-white text-xs py-1 px-2 opacity-80"
onClick={(e) => props.onDelete(props.id)}
>
<IconDelete /> <IconDelete />
</button> </button>
</div> </div>
@ -278,6 +281,7 @@ const Rect = (props) => {
field="type" field="type"
label="Type" label="Type"
className="w-full" className="w-full"
filter
optionList={sqlDataTypes.map((value, index) => { optionList={sqlDataTypes.map((value, index) => {
return { return {
label: value, label: value,

View File

@ -7,16 +7,6 @@ import { HTML5Backend } from "react-dnd-html5-backend";
import Canvas from "../components/draw_area"; import Canvas from "../components/draw_area";
import EditorPanel from "../components/editor_panel"; import EditorPanel from "../components/editor_panel";
// class Graph {
// constructor() {
// this.nodes = [];
// }
// setNodes(nodes) {
// this.nodes = nodes;
// }
// }
export default function Editor(props) { export default function Editor(props) {
const [code, setCode] = useState(""); const [code, setCode] = useState("");
const [rectangles, setRectangles] = useState([]); const [rectangles, setRectangles] = useState([]);