diff --git a/src/NodeContextMenu.tsx b/src/NodeContextMenu.tsx deleted file mode 100644 index 49a4669..0000000 --- a/src/NodeContextMenu.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import { useEffect, useState } from "react"; -import { renderToStaticMarkup } from "react-dom/server"; - -export class NodeContextMenu { - contextMenu: ContextMenuInput | null; - setContextMenu: React.Dispatch>; - - constructor(containerRef: React.RefObject) { - [this.contextMenu, this.setContextMenu] = useState(null); - - useEffect(() => { - if(!this.contextMenu){ - return; - } - const container = containerRef.current; - if (container) { - const menu = renderToStaticMarkup(this.render()); - renderTo - (container as HTMLElement).append - } - }, [this.contextMenu]); - - useEffect(() => { - const close = () => this.setContextMenu(null); - document.addEventListener('click', close); - return () => document.removeEventListener('click', close); - }, []); - } - - render() { - if (this.contextMenu) - return ( -
e.stopPropagation()} - > -
Node: {this.contextMenu.nodeId}
- - -
- ) - } -} - -export class ContextMenuInput { - x: number; - y: number; - nodeId: string; - - constructor(x: number, y: number, nodeId: string) { - this.x = x; - this.y = y; - this.nodeId = nodeId; - } -} \ No newline at end of file diff --git a/src/TODO b/src/TODO new file mode 100644 index 0000000..7d7d651 --- /dev/null +++ b/src/TODO @@ -0,0 +1,3 @@ +- add not connected node in selected rank +- connect node +- remove connection \ No newline at end of file diff --git a/src/components/Graph.tsx b/src/components/Graph.tsx index 71bba0d..c069265 100644 --- a/src/components/Graph.tsx +++ b/src/components/Graph.tsx @@ -8,6 +8,7 @@ import { Modal } from "antd"; import { Input } from "antd"; import type { BreadcrumbItemType } from "antd/es/breadcrumb/Breadcrumb"; import { cloneDeep } from "lodash"; +import NodeContextMenu from "./NodeContextMenu"; export class GraphModel { nodes: NodeModel[] = []; @@ -224,7 +225,10 @@ export default function Graph({ setGraphPath }) {
- document.body} + + + + {/* document.body} // 👇 Key part: manually position the dropdown overlayStyle={{ position: "absolute", @@ -232,7 +236,7 @@ export default function Graph({ setGraphPath }) { top: coords.y, }}> - + */} >, + contextMenuOpened: boolean + }) { + function contextMenuOpenChange(open: boolean) { + if (!open) { + openContextMenu(false) + } + } + + const onMenuClick: MenuProps['onClick'] = ({ key }) => { + switch (key) { + case 'rename': { + //openRenameModal(true); + break; + } + case 'remove': { + //removeNode(nodeId); + break; + } + case 'subgraph': { + + + break; + } + } + }; + + return ( + document.body} + // 👇 Key part: manually position the dropdown + overlayStyle={{ + position: "absolute", + left: coords.x, + top: coords.y, + }}> + + + ) +}