From b62ca684e0396873ae443453c218816255f80614 Mon Sep 17 00:00:00 2001 From: Lazaros Toumanidis Date: Thu, 16 Jan 2025 21:39:19 +0200 Subject: [PATCH] update swarm edge styles, connect user to swarm, initial agent --- src/waldiez/containers/edges/main.tsx | 2 +- src/waldiez/containers/edges/swarm.tsx | 33 ++-- src/waldiez/containers/edges/utils.ts | 67 +++++++ src/waldiez/containers/nodes/agent/main.tsx | 178 ++++++++---------- .../nodes/agent/swarmContainer/modal/main.tsx | 6 +- .../editFlowModal/hooks/useEditFlowModal.ts | 4 +- src/waldiez/models/Stores/IAgentStore.ts | 2 + src/waldiez/models/Stores/IFlowStore.ts | 2 +- src/waldiez/store/agent.ts | 42 ++++- src/waldiez/store/edge.ts | 21 ++- src/waldiez/store/flow.ts | 12 +- src/waldiez/store/utils/agent.ts | 36 ++++ src/waldiez/store/utils/edge.ts | 64 +++---- src/waldiez/styles/overrides.css | 80 +------- src/waldiez/styles/swarm.css | 23 +++ 15 files changed, 318 insertions(+), 254 deletions(-) create mode 100644 src/waldiez/containers/edges/utils.ts diff --git a/src/waldiez/containers/edges/main.tsx b/src/waldiez/containers/edges/main.tsx index 9fd2550..540584a 100644 --- a/src/waldiez/containers/edges/main.tsx +++ b/src/waldiez/containers/edges/main.tsx @@ -75,7 +75,7 @@ const WaldiezEdgeCommon = (props: WaldiezEdgeProps) => { return ; } const isSwarmSource = () => - sourceAgent.data.agentType !== "swarm" && targetAgent?.data.agentType === "swarm_container"; + sourceAgent.data.agentType !== "swarm" && targetAgent?.data.agentType === "swarm"; if (isSwarmSource()) { return ; } diff --git a/src/waldiez/containers/edges/swarm.tsx b/src/waldiez/containers/edges/swarm.tsx index 184af59..3f1b606 100644 --- a/src/waldiez/containers/edges/swarm.tsx +++ b/src/waldiez/containers/edges/swarm.tsx @@ -1,4 +1,4 @@ -import { BaseEdge, EdgeLabelRenderer, Position, getSmoothStepPath } from "@xyflow/react"; +import { BaseEdge, EdgeLabelRenderer, getSmoothStepPath } from "@xyflow/react"; import { FaTrashAlt } from "react-icons/fa"; import { FaGear } from "react-icons/fa6"; @@ -7,6 +7,7 @@ import { GiShakingHands } from "react-icons/gi"; import { MdMessage } from "react-icons/md"; import { WaldiezEdgeProps } from "@waldiez/containers/edges/types"; +import { getEdgeTranslations } from "@waldiez/containers/edges/utils"; import { useWaldiez } from "@waldiez/store"; import { AGENT_COLORS } from "@waldiez/theme"; @@ -118,7 +119,7 @@ export const WaldiezEdgeSwarmView = ( if (label === "") { return null; } - const trimmedTo20 = label.length > 15 ? `${label.slice(0, 15)}...` : label; + const trimmedTo20 = label.length > 20 ? `${label.slice(0, 20)}...` : label; return (
diff --git a/src/waldiez/containers/edges/utils.ts b/src/waldiez/containers/edges/utils.ts new file mode 100644 index 0000000..7122860 --- /dev/null +++ b/src/waldiez/containers/edges/utils.ts @@ -0,0 +1,67 @@ +import { Position } from "@xyflow/react"; + +// eslint-disable-next-line complexity +export const getEdgeTranslations = ( + sourceX: number, + sourceY: number, + targetX: number, + targetY: number, + sourcePosition: Position, + targetPosition: Position, +) => { + const translations = { + edgeStart: `translate(-50%, 0%) translate(${sourceX}px,${sourceY}px)`, + edgeEnd: `translate(-50%, 0%) translate(${targetX}px,${targetY}px)`, + }; + if (sourcePosition === Position.Right && targetPosition === Position.Left) { + translations.edgeStart = `translate(0%, 0%) translate(${sourceX - 10}px,${sourceY - 35}px)`; + translations.edgeEnd = `translate(-100%, -100%) translate(${targetX}px,${targetY}px)`; + return translations; + } + if (sourcePosition === Position.Right && targetPosition === Position.Top) { + translations.edgeStart = `translate(0%, 0%) translate(${sourceX - 10}px,${sourceY}px)`; + translations.edgeEnd = `translate(-100%, 0%) translate(${targetX}px,${targetY}px)`; + return translations; + } + if (sourcePosition === Position.Right && targetPosition === Position.Right) { + translations.edgeStart = `translate(0%, 0%) translate(${sourceX - 10}px,${sourceY}px)`; + translations.edgeEnd = `translate(0, 0) translate(${targetX}px,${targetY}px)`; + return translations; + } + if (sourcePosition === Position.Left && targetPosition === Position.Right) { + translations.edgeStart = `translate(-100%, 0%) translate(${sourceX + 10}px,${sourceY}px)`; + translations.edgeEnd = `translate(0, 0) translate(${targetX}px,${targetY}px)`; + return translations; + } + if (sourcePosition === Position.Left && targetPosition === Position.Bottom) { + translations.edgeStart = `translate(-100%, 0%) translate(${sourceX + 10}px,${sourceY - 30}px)`; + translations.edgeEnd = `translate(0, 0) translate(${targetX}px,${targetY}px)`; + return translations; + } + if (sourcePosition === Position.Left && targetPosition === Position.Left) { + translations.edgeStart = `translate(-100%, 0%) translate(${sourceX + 10}px,${sourceY}px)`; + translations.edgeEnd = `translate(-100%, 0%) translate(${targetX}px,${targetY}px)`; + return translations; + } + if (sourcePosition === Position.Top && targetPosition === Position.Bottom) { + translations.edgeStart = `translate(-100%, 0%) translate(${sourceX}px,${sourceY - 30}px)`; + translations.edgeEnd = `translate(-100%, 0%) translate(${targetX}px,${targetY}px)`; + return translations; + } + if (sourcePosition === Position.Top && targetPosition === Position.Right) { + translations.edgeStart = `translate(-100%, 0%) translate(${sourceX}px,${sourceY - 30}px)`; + translations.edgeEnd = `translate(0, 0) translate(${targetX}px,${targetY}px)`; + return translations; + } + if (sourcePosition === Position.Bottom && targetPosition === Position.Left) { + translations.edgeStart = `translate(0%, 0%) translate(${sourceX}px,${sourceY}px)`; + translations.edgeEnd = `translate(-100%, 0%) translate(${targetX}px,${targetY - 30}px)`; + return translations; + } + if (sourcePosition === Position.Bottom && targetPosition === Position.Top) { + translations.edgeStart = `translate(0%, 0%) translate(${sourceX}px,${sourceY}px)`; + translations.edgeEnd = `translate(0%, 0%) translate(${targetX}px,${targetY - 30}px)`; + return translations; + } + return translations; +}; diff --git a/src/waldiez/containers/nodes/agent/main.tsx b/src/waldiez/containers/nodes/agent/main.tsx index 56efddd..4874ae6 100644 --- a/src/waldiez/containers/nodes/agent/main.tsx +++ b/src/waldiez/containers/nodes/agent/main.tsx @@ -39,6 +39,7 @@ export const WaldiezNodeAgentView = (props: WaldiezNodeAgentProps) => { /> ); } + const handleClassNameBase = agentType === "swarm" ? "swarm-" : data.parentId ? "hidden" : ""; return (
{!data.parentId && ( @@ -57,103 +58,86 @@ export const WaldiezNodeAgentView = (props: WaldiezNodeAgentProps) => {
)} - {agentType === "swarm" ? ( - <> - - - - - - - - - - ) : ( - <> - - - - )} + + + + + + + +