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:
parent
eaab405742
commit
2243e8df2d
3 changed files with 17 additions and 18 deletions
|
|
@ -37,7 +37,10 @@ export default function BuildTrigger({
|
|||
if (isBuilding) {
|
||||
return;
|
||||
}
|
||||
const errors = validateNodes(reactFlowInstance!);
|
||||
const errors = validateNodes(
|
||||
reactFlowInstance!.getNodes(),
|
||||
reactFlowInstance!.getEdges()
|
||||
);
|
||||
if (errors.length > 0) {
|
||||
setErrorData({
|
||||
title: "Oops! Looks like you missed something",
|
||||
|
|
|
|||
|
|
@ -356,7 +356,10 @@ export default function FormModal({
|
|||
}, [open]);
|
||||
|
||||
function sendMessage(): void {
|
||||
let nodeValidationErrors = validateNodes(reactFlowInstance!);
|
||||
let nodeValidationErrors = validateNodes(
|
||||
reactFlowInstance!.getNodes(),
|
||||
reactFlowInstance!.getEdges()
|
||||
);
|
||||
if (nodeValidationErrors.length === 0) {
|
||||
setLockChat(true);
|
||||
let inputs = tabsState[id.current].formKeysData.input_keys;
|
||||
|
|
|
|||
|
|
@ -189,10 +189,7 @@ export function buildTweaks(flow: FlowType) {
|
|||
}, {});
|
||||
}
|
||||
|
||||
export function validateNode(
|
||||
node: NodeType,
|
||||
reactFlowInstance: ReactFlowInstance
|
||||
): Array<string> {
|
||||
export function validateNode(node: NodeType, edges: Edge[]): Array<string> {
|
||||
if (!node.data?.node?.template || !Object.keys(node.data.node.template)) {
|
||||
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!",
|
||||
|
|
@ -211,13 +208,11 @@ export function validateNode(
|
|||
(template[t].value === undefined ||
|
||||
template[t].value === null ||
|
||||
template[t].value === "") &&
|
||||
!reactFlowInstance
|
||||
.getEdges()
|
||||
.some(
|
||||
(edge) =>
|
||||
edge.targetHandle?.split("|")[1] === t &&
|
||||
edge.targetHandle.split("|")[2] === node.id
|
||||
)
|
||||
!edges.some(
|
||||
(edge) =>
|
||||
edge.targetHandle?.split("|")[1] === t &&
|
||||
edge.targetHandle.split("|")[2] === node.id
|
||||
)
|
||||
) {
|
||||
errors.push(
|
||||
`${type} is missing ${
|
||||
|
|
@ -249,15 +244,13 @@ export function validateNode(
|
|||
}, [] as string[]);
|
||||
}
|
||||
|
||||
export function validateNodes(reactFlowInstance: ReactFlowInstance) {
|
||||
if (reactFlowInstance.getNodes().length === 0) {
|
||||
export function validateNodes(nodes: Node[], edges: Edge[]) {
|
||||
if (nodes.length === 0) {
|
||||
return [
|
||||
"No nodes found in the flow. Please add at least one node to the flow.",
|
||||
];
|
||||
}
|
||||
return reactFlowInstance
|
||||
.getNodes()
|
||||
.flatMap((n: NodeType) => validateNode(n, reactFlowInstance));
|
||||
return nodes.flatMap((n: NodeType) => validateNode(n, edges));
|
||||
}
|
||||
|
||||
export function addVersionToDuplicates(flow: FlowType, flows: FlowType[]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue