diff --git a/space_flow/src/CustomNodes/BooleanNode/index.tsx b/space_flow/src/CustomNodes/BooleanNode/index.tsx index d068f1199..98dc6aa5a 100644 --- a/space_flow/src/CustomNodes/BooleanNode/index.tsx +++ b/space_flow/src/CustomNodes/BooleanNode/index.tsx @@ -3,17 +3,19 @@ import { Input } from "@mui/material"; import { Handle, Position } from "reactflow"; import { isValidConnection, nodeColors } from "../../utils"; import ToggleComponent from "../../components/toggleComponent"; -import { useEffect, useState } from "react"; +import { useContext, useEffect, useState } from "react"; +import { typesContext } from "../../contexts/typesContext"; export default function BooleanNode({ data }) { const [enabled, setEnabled] = useState(false); + const {types} = useContext(typesContext); return (
Boolean
@@ -26,15 +28,15 @@ export default function BooleanNode({ data }) {
- {setEnabled(x); data.enabled = x}} /> + {setEnabled(x); data.value = x}} />
isValidConnection(data,connection)} className="-mr-1 bg-transparent border-solid border-l-8 border-y-transparent border-y-8 border-r-0 rounded-none" - style={{ borderLeftColor: nodeColors[data.type] }} + style={{ borderLeftColor: nodeColors[types[data.type]] }} >
); diff --git a/space_flow/src/CustomNodes/ChatInputNode/index.tsx b/space_flow/src/CustomNodes/ChatInputNode/index.tsx index 09ad117d7..e6e4a27fd 100644 --- a/space_flow/src/CustomNodes/ChatInputNode/index.tsx +++ b/space_flow/src/CustomNodes/ChatInputNode/index.tsx @@ -3,10 +3,13 @@ import InputComponent from "../../components/inputComponent"; import { isValidConnection, nodeColors, snakeToNormalCase } from "../../utils"; import { Handle, Position } from "reactflow"; import Tooltip from "../../components/TooltipComponent"; +import { typesContext } from "../../contexts/typesContext"; +import { useContext } from "react"; export default function ChatInputNode({ data }) { + const {types} = useContext(typesContext); return ( -
+
@@ -26,10 +29,10 @@ export default function ChatInputNode({ data }) { id={'str|str|'+data.id} isValidConnection={(connection) => isValidConnection(data,connection)} className="-mr-1 bg-transparent border-solid border-l-8 border-y-transparent border-y-8 border-r-0 rounded-none" - style={{borderLeftColor: nodeColors['chat']}} + style={{borderLeftColor: nodeColors[types[data.type]]}} > -
+
Input
diff --git a/space_flow/src/CustomNodes/ChatOutputNode/index.tsx b/space_flow/src/CustomNodes/ChatOutputNode/index.tsx index 696a9b3ea..47bde0392 100644 --- a/space_flow/src/CustomNodes/ChatOutputNode/index.tsx +++ b/space_flow/src/CustomNodes/ChatOutputNode/index.tsx @@ -3,10 +3,13 @@ import { Handle, Position } from "reactflow"; import InputComponent from "../../components/inputComponent"; import { isValidConnection, nodeColors, snakeToNormalCase } from "../../utils"; import Tooltip from "../../components/TooltipComponent"; +import { useContext } from "react"; +import { typesContext } from "../../contexts/typesContext"; export default function ChatOutputNode({ data }) { + const {types} = useContext(typesContext); return ( -
+
-
+
Output
diff --git a/space_flow/src/CustomNodes/GenericNode/index.tsx b/space_flow/src/CustomNodes/GenericNode/index.tsx index 09a4315f8..29db60ef1 100644 --- a/space_flow/src/CustomNodes/GenericNode/index.tsx +++ b/space_flow/src/CustomNodes/GenericNode/index.tsx @@ -8,11 +8,11 @@ import { } from "../../utils"; import ParameterComponent from "./components/parameterComponent"; import { typesContext } from "../../contexts/typesContext"; -import { useContext } from "react"; +import { useContext, useEffect } from "react"; export default function GenericNode({ data }) { - const Icon = nodeIcons[data.type]; const {types} = useContext(typesContext); + const Icon = nodeIcons[types[data.type]]; return (
@@ -20,9 +20,9 @@ export default function GenericNode({ data }) {
-
{data.name}
+
{data.type}
); diff --git a/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx b/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx index 3d558d6e2..7d0d651dd 100644 --- a/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx +++ b/space_flow/src/pages/FlowPage/components/extraSidebarComponent/index.tsx @@ -17,18 +17,12 @@ export default function ExtraSidebar() { useEffect(() => { getAll().then((d) => { setData(d.data); - // console.log(d.data); - }); - }, []); - - useEffect(() => { - if(data){ setTypes( - Object.keys(data).reduce( + Object.keys(d.data).reduce( (acc, curr) => { - Object.keys(data[curr]).forEach((c) => { + Object.keys(d.data[curr]).forEach((c) => { acc[c] = curr; - data[curr][c].base_classes?.forEach((b) => { + d.data[curr][c].base_classes?.forEach((b) => { acc[b] = curr; }); }); @@ -43,8 +37,8 @@ export default function ExtraSidebar() { } ) ); - } - }, [data, setTypes]) + }); + }, []); function onDragStart(event: React.DragEvent, data) { event.dataTransfer.effectAllowed = "move"; @@ -67,8 +61,7 @@ export default function ExtraSidebar() { style={{ borderLeftColor: nodeColors[d] }} onDragStart={(event) => onDragStart(event, { - type: d, - name: t, + type: t, node: data[d][t], }) } @@ -94,8 +87,8 @@ export default function ExtraSidebar() { style={{ borderLeftColor: nodeColors["chat"] }} onDragStart={(event) => onDragStart(event, { - type: "chat", - name: "chatInput", + type: "chatInput", + node: {}, }) } > @@ -112,8 +105,8 @@ export default function ExtraSidebar() { style={{ borderLeftColor: nodeColors["chat"] }} onDragStart={(event) => onDragStart(event, { - type: "chat", - name: "chatOutput", + type: "chatOutput", + node: {}, }) } > @@ -136,8 +129,8 @@ export default function ExtraSidebar() { style={{ borderLeftColor: nodeColors["advanced"] }} onDragStart={(event) => onDragStart(event, { - type: "advanced", - name: "str", + type: "str", + node: {}, }) } > @@ -154,8 +147,8 @@ export default function ExtraSidebar() { style={{ borderLeftColor: nodeColors["advanced"] }} onDragStart={(event) => onDragStart(event, { - type: "advanced", - name: "bool", + type: "bool", + node: {}, }) } > diff --git a/space_flow/src/pages/FlowPage/index.tsx b/space_flow/src/pages/FlowPage/index.tsx index 622c66995..10009d942 100644 --- a/space_flow/src/pages/FlowPage/index.tsx +++ b/space_flow/src/pages/FlowPage/index.tsx @@ -80,8 +80,8 @@ export default function FlowPage() { const reactflowBounds = reactFlowWrapper.current.getBoundingClientRect(); let data = JSON.parse(event.dataTransfer.getData("json")); if ( - data.name !== "chatInput" || - (data.name === "chatInput" && + data.type !== "chatInput" || + (data.type === "chatInput" && !reactFlowInstance.getNodes().some((n) => n.type === "chatInputNode")) ) { const position = reactFlowInstance.project({ @@ -89,24 +89,24 @@ export default function FlowPage() { y: event.clientY - reactflowBounds.top, }); let newId = getId(); + const newNode = { id: newId, type: - data.name === "str" + (data.type === "str" ? "inputNode" - : data.name === "chatInput" + : (data.type === "chatInput" ? "chatInputNode" - : data.name === "chatOutput" + : (data.type === "chatOutput" ? "chatOutputNode" - : data.name === "bool" + : (data.type === "bool" ? "booleanNode" - : "genericNode", + : "genericNode")))), position, data: { ...data, id: newId, - input: "", - enabled: false, + value: null, reactFlowInstance, onDelete: () => { setNodes(