fix(buildTrigger): update validateNodes function calls to pass in nodes and edges arrays instead of reactFlowInstance

fix(formModal): update validateNodes function calls to pass in nodes and edges arrays instead of reactFlowInstance
fix(reactflowUtils): update validateNode function signature to accept edges array instead of reactFlowInstance
feat(reactflowUtils): update validateNodes function signature to accept nodes and edges arrays instead of reactFlowInstance
This commit is contained in:
anovazzi1 2023-09-27 11:39:22 -03:00
commit 2243e8df2d
3 changed files with 17 additions and 18 deletions

View file

@ -37,7 +37,10 @@ export default function BuildTrigger({
if (isBuilding) { if (isBuilding) {
return; return;
} }
const errors = validateNodes(reactFlowInstance!); const errors = validateNodes(
reactFlowInstance!.getNodes(),
reactFlowInstance!.getEdges()
);
if (errors.length > 0) { if (errors.length > 0) {
setErrorData({ setErrorData({
title: "Oops! Looks like you missed something", title: "Oops! Looks like you missed something",

View file

@ -356,7 +356,10 @@ export default function FormModal({
}, [open]); }, [open]);
function sendMessage(): void { function sendMessage(): void {
let nodeValidationErrors = validateNodes(reactFlowInstance!); let nodeValidationErrors = validateNodes(
reactFlowInstance!.getNodes(),
reactFlowInstance!.getEdges()
);
if (nodeValidationErrors.length === 0) { if (nodeValidationErrors.length === 0) {
setLockChat(true); setLockChat(true);
let inputs = tabsState[id.current].formKeysData.input_keys; let inputs = tabsState[id.current].formKeysData.input_keys;

View file

@ -189,10 +189,7 @@ export function buildTweaks(flow: FlowType) {
}, {}); }, {});
} }
export function validateNode( export function validateNode(node: NodeType, edges: Edge[]): Array<string> {
node: NodeType,
reactFlowInstance: ReactFlowInstance
): Array<string> {
if (!node.data?.node?.template || !Object.keys(node.data.node.template)) { if (!node.data?.node?.template || !Object.keys(node.data.node.template)) {
return [ return [
"We've noticed a potential issue with a node in the flow. Please review it and, if necessary, submit a bug report with your exported flow file. Thank you for your help!", "We've noticed a potential issue with a node in the flow. Please review it and, if necessary, submit a bug report with your exported flow file. Thank you for your help!",
@ -211,13 +208,11 @@ export function validateNode(
(template[t].value === undefined || (template[t].value === undefined ||
template[t].value === null || template[t].value === null ||
template[t].value === "") && template[t].value === "") &&
!reactFlowInstance !edges.some(
.getEdges() (edge) =>
.some( edge.targetHandle?.split("|")[1] === t &&
(edge) => edge.targetHandle.split("|")[2] === node.id
edge.targetHandle?.split("|")[1] === t && )
edge.targetHandle.split("|")[2] === node.id
)
) { ) {
errors.push( errors.push(
`${type} is missing ${ `${type} is missing ${
@ -249,15 +244,13 @@ export function validateNode(
}, [] as string[]); }, [] as string[]);
} }
export function validateNodes(reactFlowInstance: ReactFlowInstance) { export function validateNodes(nodes: Node[], edges: Edge[]) {
if (reactFlowInstance.getNodes().length === 0) { if (nodes.length === 0) {
return [ return [
"No nodes found in the flow. Please add at least one node to the flow.", "No nodes found in the flow. Please add at least one node to the flow.",
]; ];
} }
return reactFlowInstance return nodes.flatMap((n: NodeType) => validateNode(n, edges));
.getNodes()
.flatMap((n: NodeType) => validateNode(n, reactFlowInstance));
} }
export function addVersionToDuplicates(flow: FlowType, flows: FlowType[]) { export function addVersionToDuplicates(flow: FlowType, flows: FlowType[]) {