getting connected nodes
This commit is contained in:
parent
f9ecfb5287
commit
9a770e735a
3 changed files with 17 additions and 12 deletions
|
|
@ -10,7 +10,6 @@ import { nodeColors, nodeIcons, snakeToNormalCase } from "../../utils";
|
||||||
import Tooltip from "../../components/TooltipComponent";
|
import Tooltip from "../../components/TooltipComponent";
|
||||||
|
|
||||||
export default function GenericNode({ data }) {
|
export default function GenericNode({ data }) {
|
||||||
console.log(data)
|
|
||||||
const Icon = nodeIcons[data.type];
|
const Icon = nodeIcons[data.type];
|
||||||
return (
|
return (
|
||||||
<div className="prompt-node relative bg-white 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">
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,12 @@ import ExtraSidebar from "./components/extraSidebarComponent";
|
||||||
import Chat from "../../components/chatComponent";
|
import Chat from "../../components/chatComponent";
|
||||||
import GenericNode from "../../CustomNodes/GenericNode";
|
import GenericNode from "../../CustomNodes/GenericNode";
|
||||||
import connection from "./components/connection";
|
import connection from "./components/connection";
|
||||||
|
import { getConnectedNodes } from "../../utils";
|
||||||
const nodeTypes = {
|
const nodeTypes = {
|
||||||
genericNode:GenericNode,
|
genericNode:GenericNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function FlowPage() {
|
export default function FlowPage() {
|
||||||
// getPrompts().then(result=>result.forEach(prompt=>console.log(prompt)))
|
|
||||||
// getChains().then(result=>console.log(result))
|
|
||||||
// getAgents().then(result=>console.log(result))
|
|
||||||
// getMemories().then(result=>console.log(result))
|
|
||||||
// getModels().then(result=>result.forEach(model=>console.log(model)))
|
|
||||||
|
|
||||||
// outside component to avoid render trigger
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const reactFlowWrapper = useRef(null);
|
const reactFlowWrapper = useRef(null);
|
||||||
|
|
@ -43,8 +36,13 @@ export default function FlowPage() {
|
||||||
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
|
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
|
||||||
const [reactFlowInstance, setReactFlowInstance] = useState(null);
|
const [reactFlowInstance, setReactFlowInstance] = useState(null);
|
||||||
const onConnect = useCallback(
|
const onConnect = useCallback(
|
||||||
(params) => setEdges((eds) => addEdge(params, eds)),
|
(params) => {
|
||||||
[]
|
console.log(params)
|
||||||
|
console.log(reactFlowInstance.getNodes())
|
||||||
|
console.log(getConnectedNodes(params,reactFlowInstance.getNodes()))
|
||||||
|
setEdges((eds) => addEdge({...params,style:{stroke:"red"}}, eds))
|
||||||
|
},
|
||||||
|
[reactFlowInstance]
|
||||||
);
|
);
|
||||||
const onDragOver = useCallback((event) => {
|
const onDragOver = useCallback((event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { RocketLaunchIcon, LinkIcon, CpuChipIcon, LightBulbIcon, CommandLineIcon, WrenchScrewdriverIcon } from "@heroicons/react/24/outline";
|
import { RocketLaunchIcon, LinkIcon, CpuChipIcon, LightBulbIcon, CommandLineIcon, WrenchScrewdriverIcon } from "@heroicons/react/24/outline";
|
||||||
|
import { Edge, Node } from "reactflow";
|
||||||
|
|
||||||
export function classNames(...classes) {
|
export function classNames(...classes) {
|
||||||
return classes.filter(Boolean).join(" ");
|
return classes.filter(Boolean).join(" ");
|
||||||
|
|
@ -290,4 +291,11 @@ export function classNames(...classes) {
|
||||||
export function roundNumber(x, decimals){
|
export function roundNumber(x, decimals){
|
||||||
return Math.round(x * Math.pow(10, decimals))/Math.pow(10, decimals)
|
return Math.round(x * Math.pow(10, decimals))/Math.pow(10, decimals)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function getConnectedNodes(edge:Edge,nodes:Array<Node>):Array<Node>{
|
||||||
|
const sourceId = edge.source;
|
||||||
|
const targetId = edge.target;
|
||||||
|
const connectedNodes = nodes.filter(node=>node.id===sourceId||node.id===targetId)
|
||||||
|
return connectedNodes
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue