/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/agents/workflows/nodes/components/condition/ConditionNode.tsx │ │ Developed by: Davidson Gomes │ │ Creation date: May 13, 2025 │ │ Contact: contato@evolution-api.com │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @copyright © Evolution API 2025. All rights reserved. │ │ Licensed under the Apache License, Version 2.0 │ │ │ │ You may not use this file except in compliance with the License. │ │ You may obtain a copy of the License at │ │ │ │ http://www.apache.org/licenses/LICENSE-2.0 │ │ │ │ Unless required by applicable law or agreed to in writing, software │ │ distributed under the License is distributed on an "AS IS" BASIS, │ │ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ├──────────────────────────────────────────────────────────────────────────────┤ │ @important │ │ For any future changes to the code in this file, it is recommended to │ │ include, together with the modification, the information of the developer │ │ who changed it and the date of modification. │ └──────────────────────────────────────────────────────────────────────────────┘ */ /* eslint-disable no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Handle, Node, NodeProps, Position, useEdges } from "@xyflow/react"; import { FilterIcon, ArrowRight } from "lucide-react"; import { cn } from "@/lib/utils"; import { BaseNode } from "../../BaseNode"; import { ConditionType, ConditionTypeEnum } from "../../nodeFunctions"; export type ConditionNodeType = Node< { label?: string; type?: "and" | "or"; conditions?: ConditionType[]; }, "condition-node" >; export type OperatorType = | "is_defined" | "is_not_defined" | "equals" | "not_equals" | "contains" | "not_contains" | "starts_with" | "ends_with" | "greater_than" | "greater_than_or_equal" | "less_than" | "less_than_or_equal" | "matches" | "not_matches"; const operatorText: Record = { equals: "is equal to", not_equals: "is not equal to", contains: "contains", not_contains: "does not contain", starts_with: "starts with", ends_with: "ends with", greater_than: "is greater than", greater_than_or_equal: "is greater than or equal to", less_than: "is less than", less_than_or_equal: "is less than or equal to", matches: "matches the pattern", not_matches: "does not match the pattern", is_defined: "is defined", is_not_defined: "is not defined", }; export function ConditionNode(props: NodeProps) { const { selected, data } = props; const edges = useEdges(); const isExecuting = data.isExecuting as boolean | undefined; const typeText = { and: "all of the following conditions", or: "any of the following conditions", }; const isHandleConnected = (handleId: string) => { return edges.some( (edge) => edge.source === props.id && edge.sourceHandle === handleId, ); }; const isBottomHandleConnected = isHandleConnected("bottom-handle"); const conditions: ConditionType[] = data.conditions as ConditionType[]; // const statistics: StatisticType = data.statistics as StatisticType; const renderCondition = (condition: ConditionType) => { const isConnected = isHandleConnected(condition.id); if (condition.type === ConditionTypeEnum.PREVIOUS_OUTPUT) { return (

O campo{" "} {condition.data.field} {" "} {operatorText[condition.data.operator as OperatorType]} {" "} {!["is_defined", "is_not_defined"].includes( condition.data.operator, ) && ( "{condition.data.value}" )}

); } return null; }; return (

{data.label as string}

Matches {typeText[(data.type as "and" | "or") || "and"]}

{conditions && conditions.length > 0 && Array.isArray(conditions) ? ( conditions.map((condition) => (
{renderCondition(condition)}
)) ) : (

No conditions configured

Click to add a condition

)}
Next step
); }