From d2127acf04b67ec4063fa73c20093aaf6d42c238 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 29 Feb 2024 22:26:53 +0100 Subject: [PATCH] Fixed adding more than one chat input --- src/frontend/src/stores/flowStore.ts | 5 +++++ src/frontend/src/utils/reactflowUtils.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/frontend/src/stores/flowStore.ts b/src/frontend/src/stores/flowStore.ts index 1f4a494bb..79ac65961 100644 --- a/src/frontend/src/stores/flowStore.ts +++ b/src/frontend/src/stores/flowStore.ts @@ -30,6 +30,7 @@ import { } from "../types/zustand/flow"; import { buildVertices } from "../utils/buildUtils"; import { + checkChatInput, cleanEdges, getHandleId, getNodeId, @@ -228,6 +229,10 @@ const useFlowStore = create((set, get) => ({ ); }, paste: (selection, position) => { + if(selection.nodes.some((node) => node.data.type === "ChatInput") && checkChatInput(get().nodes)){ + useAlertStore.getState().setErrorData({title: "Error pasting components", list: ["You can only have one ChatInput component in the flow"]}); + return; + } let minimumX = Infinity; let minimumY = Infinity; let idsMap = {}; diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 7def5d274..1d9e81d94 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -44,6 +44,10 @@ import { } from "./utils"; const uid = new ShortUniqueId({ length: 5 }); +export function checkChatInput(nodes: Node[]) { + return nodes.some((node) => node.data.type === "ChatInput"); +} + export function cleanEdges(nodes: Node[], edges: Edge[]) { let newEdges = cloneDeep(edges); edges.forEach((edge) => {