Fixed adding more than one chat input

This commit is contained in:
Lucas Oliveira 2024-02-29 22:26:53 +01:00
commit d2127acf04
2 changed files with 9 additions and 0 deletions

View file

@ -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<FlowStoreType>((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 = {};

View file

@ -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) => {