More than one chat input validation done
This commit is contained in:
parent
0fa6d8346c
commit
29ca8ac732
1 changed files with 21 additions and 15 deletions
|
|
@ -17,6 +17,7 @@ import ChatInputNode from "../../CustomNodes/ChatInputNode";
|
||||||
import ChatOutputNode from "../../CustomNodes/ChatOutputNode";
|
import ChatOutputNode from "../../CustomNodes/ChatOutputNode";
|
||||||
import InputNode from "../../CustomNodes/InputNode";
|
import InputNode from "../../CustomNodes/InputNode";
|
||||||
import BooleanNode from "../../CustomNodes/BooleanNode";
|
import BooleanNode from "../../CustomNodes/BooleanNode";
|
||||||
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
const nodeTypes = {
|
const nodeTypes = {
|
||||||
genericNode:GenericNode,
|
genericNode:GenericNode,
|
||||||
inputNode: InputNode,
|
inputNode: InputNode,
|
||||||
|
|
@ -35,6 +36,7 @@ export default function FlowPage() {
|
||||||
const getId = () => `dndnode_${id++}`;
|
const getId = () => `dndnode_${id++}`;
|
||||||
|
|
||||||
const { setExtraComponent, setExtraNavigation } = useContext(locationContext);
|
const { setExtraComponent, setExtraNavigation } = useContext(locationContext);
|
||||||
|
const {setErrorData} = useContext(alertContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setExtraComponent(<ExtraSidebar />);
|
setExtraComponent(<ExtraSidebar />);
|
||||||
|
|
@ -63,8 +65,7 @@ export default function FlowPage() {
|
||||||
|
|
||||||
const reactflowBounds = reactFlowWrapper.current.getBoundingClientRect();
|
const reactflowBounds = reactFlowWrapper.current.getBoundingClientRect();
|
||||||
let data = JSON.parse(event.dataTransfer.getData("json"));
|
let data = JSON.parse(event.dataTransfer.getData("json"));
|
||||||
// check if the dropped element is valid
|
if(data.name !== 'chatInput' || (data.name === 'chatInput' && !reactFlowInstance.getNodes().some((n) => (n.type === 'chatInputNode')))){
|
||||||
|
|
||||||
const position = reactFlowInstance.project({
|
const position = reactFlowInstance.project({
|
||||||
x: event.clientX - reactflowBounds.left,
|
x: event.clientX - reactflowBounds.left,
|
||||||
y: event.clientY - reactflowBounds.top,
|
y: event.clientY - reactflowBounds.top,
|
||||||
|
|
@ -77,6 +78,11 @@ export default function FlowPage() {
|
||||||
data: { ...data, id: newId, input: '', enabled: false, reactFlowInstance, onDelete: () => {setNodes(reactFlowInstance.getNodes().filter((n)=>n.id !== newId))} },
|
data: { ...data, id: newId, input: '', enabled: false, reactFlowInstance, onDelete: () => {setNodes(reactFlowInstance.getNodes().filter((n)=>n.id !== newId))} },
|
||||||
};
|
};
|
||||||
setNodes((nds) => nds.concat(newNode));
|
setNodes((nds) => nds.concat(newNode));
|
||||||
|
} else {
|
||||||
|
setErrorData({title: 'Error creating node', list:["There can't be more than one chat input."]})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
[reactFlowInstance]
|
[reactFlowInstance]
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue