/* ┌──────────────────────────────────────────────────────────────────────────────┐ │ @author: Davidson Gomes │ │ @file: /app/agents/workflows/nodes/components/condition/ConditionDialog.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 { useState } from "react"; import { v4 as uuidv4 } from "uuid"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "@/components/ui/dialog"; import { ConditionType, ConditionTypeEnum } from "../../nodeFunctions"; import { Button } from "@/components/ui/button"; import { Filter, ArrowRight } from "lucide-react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Badge } from "@/components/ui/badge"; const conditionTypes = [ { id: "previous-output", name: "Previous output", description: "Validate the result returned by the previous node", icon: , color: "bg-blue-900/30 border-blue-700/50", }, ]; const operators = [ { value: "is_defined", label: "is defined" }, { value: "is_not_defined", label: "is not defined" }, { value: "equals", label: "is equal to" }, { value: "not_equals", label: "is not equal to" }, { value: "contains", label: "contains" }, { value: "not_contains", label: "does not contain" }, { value: "starts_with", label: "starts with" }, { value: "ends_with", label: "ends with" }, { value: "greater_than", label: "is greater than" }, { value: "greater_than_or_equal", label: "is greater than or equal to" }, { value: "less_than", label: "is less than" }, { value: "less_than_or_equal", label: "is less than or equal to" }, { value: "matches", label: "matches the regex" }, { value: "not_matches", label: "does not match the regex" }, ]; const outputFields = [ { value: "content", label: "Content" }, { value: "status", label: "Status" }, ]; function ConditionDialog({ open, onOpenChange, selectedNode, handleUpdateNode, }: { open: boolean; onOpenChange: (open: boolean) => void; selectedNode: any; handleUpdateNode: any; }) { const [selectedType, setSelectedType] = useState("previous-output"); const [selectedField, setSelectedField] = useState(outputFields[0].value); const [selectedOperator, setSelectedOperator] = useState(operators[0].value); const [comparisonValue, setComparisonValue] = useState(""); const handleConditionSave = (condition: ConditionType) => { const newConditions = selectedNode.data.conditions ? [...selectedNode.data.conditions] : []; newConditions.push(condition); const updatedNode = { ...selectedNode, data: { ...selectedNode.data, conditions: newConditions, }, }; handleUpdateNode(updatedNode); onOpenChange(false); }; const getOperatorLabel = (value: string) => { return operators.find(op => op.value === value)?.label || value; }; const getFieldLabel = (value: string) => { return outputFields.find(field => field.value === value)?.label || value; }; return ( Add New Condition
{conditionTypes.map((type) => (
setSelectedType(type.id)} >
{type.icon}

{type.name}

{type.description}

{selectedType === type.id && ( Selected )}
))}
{selectedType === "previous-output" && (
Output field Operator {!["is_defined", "is_not_defined"].includes(selectedOperator) && ( <> Value )}
)}
{selectedType === "previous-output" && (
{!["is_defined", "is_not_defined"].includes(selectedOperator) && (
setComparisonValue(e.target.value)} className="bg-neutral-700 border-neutral-600" />
)}
Preview
{getFieldLabel(selectedField)} {" "} {getOperatorLabel(selectedOperator)} {" "} {!["is_defined", "is_not_defined"].includes(selectedOperator) && ( "{comparisonValue || "(empty)"}" )}
)}
); } export { ConditionDialog };