Skip to content

Commit 6d5d81c

Browse files
committed
Also have right click working
1 parent 68e70f0 commit 6d5d81c

10 files changed

+736
-102
lines changed

studio-frontend/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12+
"@dorbus/flexboard": "^1.1.2",
1213
"@monaco-editor/react": "^4.5.0",
1314
"@mysten/sui.js": "^0.33.0",
1415
"@suiet/wallet-kit": "^0.2.9",
@@ -18,7 +19,7 @@
1819
"@vercel/analytics": "^1.0.1",
1920
"autoprefixer": "10.4.14",
2021
"axios": "^1.4.0",
21-
"daisyui": "^2.51.6",
22+
"daisyui": "^3.1.6",
2223
"eslint": "8.39.0",
2324
"eslint-config-next": "13.3.4",
2425
"idb": "^7.1.1",
@@ -28,6 +29,7 @@
2829
"react": "18.2.0",
2930
"react-dom": "18.2.0",
3031
"react-loading-overlay-ts": "^2.0.1",
32+
"react-resizable": "^3.0.5",
3133
"react-scripts": "^5.0.1",
3234
"react-spinners": "^0.13.8",
3335
"reactflow": "^11.7.3",

studio-frontend/src/components/DeployCanvas.tsx

+88-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import axios from 'axios';
2-
import { useCallback, useEffect, useMemo, useState } from 'react';
3-
import { DeployedPackageInfo } from '../types/project-types';
2+
import { useCallback, useEffect, useMemo, useState, useRef } from 'react';
3+
import { DeployedPackageInfo, Project } from '../types/project-types';
44
// import './DeployCanvas.css'
55
import {DeployedPackage, DeployedObject, ObjectNode, PackageNode} from './DeployedObjects'
66
import { ScaleLoader } from 'react-spinners';
77
import LoadingOverlay from 'react-loading-overlay-ts';
88
import { useWallet } from '@suiet/wallet-kit';
99

10-
import ReactFlow, { Background, Controls, MiniMap, applyEdgeChanges, applyNodeChanges } from 'reactflow';
10+
import ReactFlow, { Background, Controls, MiniMap, applyEdgeChanges, applyNodeChanges, useNodesState, useStore } from 'reactflow';
1111
import 'reactflow/dist/style.css';
12+
import DeployCanvasContextMenu from './DeployCanvasContextMenu';
1213

1314
const BACKEND_URL = process.env.REACT_APP_BACKEND_URL || 'http://localhost:80/';
1415

@@ -43,10 +44,18 @@ const BACKEND_URL = process.env.REACT_APP_BACKEND_URL || 'http://localhost:80/';
4344
// ];
4445

4546
// const initialEdges = [{ id: '1-2', source: '1', target: '2', label: 'to the', type: 'step' }];
46-
47+
let id = 0;
48+
const getId = () => `dndnode_${id++}`;
4749

4850
function DeployCanvas (
4951
props: {
52+
projectList: string[],
53+
currentProject: Project | null,
54+
changeProject: (project: string) => void,
55+
publishPackage: () => void,
56+
addExistingObject: (objectId: string) => void,
57+
addFromTransactions: (transactionId: string) => void,
58+
compileError: string,
5059
// theme: string,
5160
deployedObjects: DeployedPackageInfo[],
5261
toasts: JSX.Element | undefined,
@@ -57,7 +66,8 @@ function DeployCanvas (
5766
setFailTxn: (digest: string) => void,
5867
removeDeployedObject: (id: string) => void,
5968
rearrangeDeployedObjects: (draggedId: string, draggedOverId: string) => void,
60-
useSuiVision: boolean
69+
useSuiVision: boolean,
70+
dropped: () => void
6171
}
6272
) {
6373

@@ -66,16 +76,19 @@ function DeployCanvas (
6676
const [draggedId, setDraggedId] = useState<string | undefined>(undefined)
6777
const [draggedOverId, setDraggedOverId] = useState<string | undefined>(undefined)
6878

79+
const reactFlowWrapper = useRef(null);
80+
const [reactFlowInstance, setReactFlowInstance] = useState(null);
81+
6982
const [loading, setLoading] = useState<boolean>(false);
7083

71-
const nodeTypes = useMemo(() => ({ package: PackageNode, Object: ObjectNode }), []);
72-
const [nodes, setNodes] = useState<[]>([]);
84+
const nodeTypes = useMemo(() => ({ package: PackageNode, object: ObjectNode }), []);
85+
const [nodes, setNodes, onNodesChange] = useNodesState([]);
7386
// const [edges, setEdges] = useState(initialEdges);
7487

75-
const onNodesChange = useCallback(
76-
(changes: any) => setNodes((nds) => applyNodeChanges(changes, nds) as any),
77-
[]
78-
);
88+
// const onNodesChange = useCallback(
89+
// (changes: any) => setNodes((nds) => applyNodeChanges(changes, nds) as any),
90+
// []
91+
// );
7992
// const onEdgesChange = useCallback(
8093
// (changes: any) => setEdges((eds) => applyEdgeChanges(changes, eds) as any),
8194
// []
@@ -98,6 +111,55 @@ function DeployCanvas (
98111
setLoading(false);
99112
}, [nodes])
100113

114+
const onDragOver = useCallback((event: any) => {
115+
event.preventDefault();
116+
event.dataTransfer.dropEffect = 'move';
117+
}, []);
118+
119+
// useEffect(() => {
120+
// document.addEventListener('contextmenu',(event) => {
121+
// event.preventDefault();
122+
// console.log(event.type);
123+
// });
124+
// }, []);
125+
126+
const onDrop = () => {
127+
props.dropped()
128+
}
129+
130+
131+
// const onDrop = useCallback(
132+
// (event: any) => {
133+
// event.preventDefault();
134+
135+
// if (reactFlowInstance === null || reactFlowWrapper.current === null) {
136+
// return;
137+
// }
138+
139+
// const reactFlowBounds = (reactFlowWrapper.current as any).getBoundingClientRect();
140+
// const type = event.dataTransfer.getData('application/reactflow');
141+
142+
// // check if the dropped element is valid
143+
// if (typeof type === 'undefined' || !type) {
144+
// return;
145+
// }
146+
147+
// const position = (reactFlowInstance as any).project({
148+
// x: event.clientX - reactFlowBounds.left,
149+
// y: event.clientY - reactFlowBounds.top,
150+
// });
151+
// const newNode = {
152+
// id: getId(),
153+
// type,
154+
// position,
155+
// data: { label: `${type} node` },
156+
// };
157+
158+
// setNodes((nds) => nds.concat(newNode));
159+
// },
160+
// [reactFlowInstance]
161+
// );
162+
101163
const updateDeployedObjects = async () => {
102164
props.setIsOverlayActive(true);
103165
setLoading(true);
@@ -391,14 +453,26 @@ function DeployCanvas (
391453
// // }
392454
// }}
393455
// >
394-
<div style={{ height: '100%' }}>
395-
456+
<div id='deplyAndInteractMenu' style={{ height: '100%' }}>
457+
<DeployCanvasContextMenu
458+
targetId='deplyAndInteractMenu'
459+
projectList={props.projectList}
460+
changeProject={props.changeProject}
461+
addExistingObject={props.addExistingObject}
462+
addFromTransactions={props.addFromTransactions}
463+
publishPackage={props.publishPackage}
464+
currentProject={props.currentProject}
465+
compileError={props.compileError}
466+
/>
396467
<ReactFlow
397468
nodes={nodes}
398469
onNodesChange={onNodesChange}
399470
nodeTypes={nodeTypes}
400471
// edges={edges}
401472
// onEdgesChange={onEdgesChange}
473+
onInit={setReactFlowInstance as any}
474+
onDrop={onDrop}
475+
onDragOver={onDragOver}
402476
>
403477
{/* <LoadingOverlay
404478
active={props.isOverlayActive}
@@ -419,6 +493,7 @@ function DeployCanvas (
419493
}}
420494
> */}
421495
<Background />
496+
422497
<Controls />
423498
{/* <MiniMap /> */}
424499
{/* </LoadingOverlay> */}

0 commit comments

Comments
 (0)