Data parsed through drop event fixed, data showing at node
This commit is contained in:
parent
cf2cdd7691
commit
30466ade93
3 changed files with 22 additions and 44 deletions
|
|
@ -9,10 +9,10 @@ import Dropdown from "../../components/dropdownComponent";
|
||||||
import Input from "../../components/inputComponent";
|
import Input from "../../components/inputComponent";
|
||||||
import { nodeColors, nodeIcons } from "../../utils";
|
import { nodeColors, nodeIcons } from "../../utils";
|
||||||
|
|
||||||
export default function GenericNode({ data, onDelete, onRun }) {
|
export default function GenericNode({ data }) {
|
||||||
const Icon = nodeIcons[data.type];
|
const Icon = nodeIcons[data.type];
|
||||||
return (
|
return (
|
||||||
<div className="prompt-node relative bg-white h-96 w-96 rounded-lg solid border flex flex-col justify-center">
|
<div className="prompt-node relative bg-white w-96 rounded-lg solid border flex flex-col justify-center">
|
||||||
<Handle
|
<Handle
|
||||||
type="source"
|
type="source"
|
||||||
position={Position.Left}
|
position={Position.Left}
|
||||||
|
|
@ -32,21 +32,21 @@ export default function GenericNode({ data, onDelete, onRun }) {
|
||||||
|
|
||||||
<div className="w-full p-5 h-full">
|
<div className="w-full p-5 h-full">
|
||||||
<div className="w-full text-gray-500 text-sm truncate">
|
<div className="w-full text-gray-500 text-sm truncate">
|
||||||
{data.description}
|
{data.node.description}
|
||||||
</div>
|
</div>
|
||||||
{data.template.map((t) => (
|
{Object.keys(data.node.template).map((t, idx) => (
|
||||||
<div className="w-full mt-5">
|
<div key={idx} className="w-full mt-5">
|
||||||
{t.type === "dropdown" ? (
|
{data.node.template[t].type === "dropdown" ? (
|
||||||
<Dropdown
|
<Dropdown
|
||||||
title={t.title}
|
title={data.node.template[t].title}
|
||||||
value={t.options[0]}
|
value={data.node.template[t].options[0]}
|
||||||
options={t.options}
|
options={data.node.template[t].options}
|
||||||
onSelect={() => {}}
|
onSelect={() => {}}
|
||||||
/>
|
/>
|
||||||
) : t.type === "input" ? (
|
) : data.node.template[t].type === "str" ? (
|
||||||
<Input
|
<Input
|
||||||
title={t.title}
|
title={t}
|
||||||
placeholder={t.placeholder}
|
placeholder="pleicerolder"
|
||||||
onChange={() => {}}
|
onChange={() => {}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -58,10 +58,10 @@ export default function GenericNode({ data, onDelete, onRun }) {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex w-full justify-between items-center bg-gray-50 gap-2 border-t text-gray-600 p-4 text-sm">
|
<div className="flex w-full justify-between items-center bg-gray-50 gap-2 border-t text-gray-600 p-4 text-sm">
|
||||||
<button onClick={onDelete}>
|
<button onClick={data.onDelete}>
|
||||||
<TrashIcon className="w-6 h-6"></TrashIcon>
|
<TrashIcon className="w-6 h-6"></TrashIcon>
|
||||||
</button>
|
</button>
|
||||||
<button onClick={onRun}>
|
<button onClick={data.onRun}>
|
||||||
<PlayIcon className="w-6 h-6"></PlayIcon>
|
<PlayIcon className="w-6 h-6"></PlayIcon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -14,29 +14,9 @@ export default function ExtraSidebar() {
|
||||||
getAll().then((d) => { setData(d.data);});
|
getAll().then((d) => { setData(d.data);});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function onDragStart(event: React.DragEvent<any>, nodeType) {
|
function onDragStart(event: React.DragEvent<any>, data) {
|
||||||
let json;
|
|
||||||
event.dataTransfer.setData("application/reactflow", nodeType);
|
|
||||||
event.dataTransfer.effectAllowed = "move";
|
event.dataTransfer.effectAllowed = "move";
|
||||||
if (nodeType === "promptNode") {
|
event.dataTransfer.setData("json", JSON.stringify(data));
|
||||||
json = JSON.stringify(prompt);
|
|
||||||
}
|
|
||||||
if (nodeType === "modelNode") {
|
|
||||||
json = JSON.stringify(llm_chain);
|
|
||||||
}
|
|
||||||
if (nodeType === "chainNode") {
|
|
||||||
json = JSON.stringify({ content: "" });
|
|
||||||
}
|
|
||||||
if (nodeType === "agentNode") {
|
|
||||||
json = JSON.stringify({ content: "" });
|
|
||||||
}
|
|
||||||
if (nodeType === "toolNode") {
|
|
||||||
json = JSON.stringify({ content: "" });
|
|
||||||
}
|
|
||||||
if (nodeType === "memoryNode") {
|
|
||||||
json = JSON.stringify({ content: "" });
|
|
||||||
}
|
|
||||||
event.dataTransfer.setData("json", json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -51,7 +31,7 @@ export default function ExtraSidebar() {
|
||||||
draggable
|
draggable
|
||||||
className={" cursor-grab border-l-8 rounded-l-md"}
|
className={" cursor-grab border-l-8 rounded-l-md"}
|
||||||
style={{ borderLeftColor: nodeColors[d] }}
|
style={{ borderLeftColor: nodeColors[d] }}
|
||||||
onDragStart={(event) => onDragStart(event, "promptNode")}
|
onDragStart={(event) => onDragStart(event, {type: d, name:t, node: data[d][t]})}
|
||||||
>
|
>
|
||||||
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
<div className="flex w-full justify-between text-sm px-4 py-3 items-center border-dashed border-gray-400 border-l-0 rounded-md rounded-l-none border-2">
|
||||||
<span className="text-black w-36 truncate">{t}</span>
|
<span className="text-black w-36 truncate">{t}</span>
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import axios from "axios";
|
||||||
import { generateUiNode } from "../../controllers/UiGenerator";
|
import { generateUiNode } from "../../controllers/UiGenerator";
|
||||||
import Chat from "../../components/chatComponent";
|
import Chat from "../../components/chatComponent";
|
||||||
import { getAll } from "../../controllers/NodesServices";
|
import { getAll } from "../../controllers/NodesServices";
|
||||||
|
import GenericNode from "../../CustomNodes/GenericNode";
|
||||||
|
|
||||||
const nodeTypes = {
|
const nodeTypes = {
|
||||||
promptNode: PromptNode,
|
promptNode: PromptNode,
|
||||||
|
|
@ -25,7 +26,8 @@ const nodeTypes = {
|
||||||
chainNode: ChainNode,
|
chainNode: ChainNode,
|
||||||
agentNode: AgentNode,
|
agentNode: AgentNode,
|
||||||
toolNode: ToolsNode,
|
toolNode: ToolsNode,
|
||||||
memoryNode:MemoryNode
|
memoryNode:MemoryNode,
|
||||||
|
genericNode:GenericNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function FlowPage() {
|
export default function FlowPage() {
|
||||||
|
|
@ -72,12 +74,8 @@ export default function FlowPage() {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
const reactflowBounds = reactFlowWrapper.current.getBoundingClientRect();
|
const reactflowBounds = reactFlowWrapper.current.getBoundingClientRect();
|
||||||
const type = event.dataTransfer.getData("application/reactflow");
|
|
||||||
let data = JSON.parse(event.dataTransfer.getData("json"));
|
let data = JSON.parse(event.dataTransfer.getData("json"));
|
||||||
// check if the dropped element is valid
|
// check if the dropped element is valid
|
||||||
if (typeof type === "undefined" || !type) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const position = reactFlowInstance.project({
|
const position = reactFlowInstance.project({
|
||||||
x: event.clientX - reactflowBounds.left,
|
x: event.clientX - reactflowBounds.left,
|
||||||
|
|
@ -85,9 +83,9 @@ export default function FlowPage() {
|
||||||
});
|
});
|
||||||
const newNode = {
|
const newNode = {
|
||||||
id: getId(),
|
id: getId(),
|
||||||
type,
|
type: 'genericNode',
|
||||||
position,
|
position,
|
||||||
data: { ...data, delete: () => console.log("asdsdsadad") },
|
data: { ...data, onDelete: () => console.log("asdsdsadad"), onRun: () => {} },
|
||||||
};
|
};
|
||||||
setNodes((nds) => nds.concat(newNode));
|
setNodes((nds) => nds.concat(newNode));
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue