Require loop parameter key (#907)

This commit is contained in:
Kerem Yilmaz
2024-10-04 09:21:57 -07:00
committed by GitHub
parent b664dada75
commit 17ed1c90f2
2 changed files with 30 additions and 0 deletions

View File

@@ -62,6 +62,7 @@ import {
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { ReloadIcon } from "@radix-ui/react-icons";
import { isLoopNode, LoopNode } from "./nodes/LoopNode/types";
function convertToParametersYAML(
parameters: ParametersState,
@@ -414,6 +415,18 @@ function FlowRenderer({
},
};
}
if (node.type === "loop") {
return {
...node,
data: {
...node.data,
loopValue:
node.data.loopValue === getOutputParameterKey(deletedNodeLabel)
? ""
: node.data.loopValue,
},
};
}
return node;
});
setHasChanges(true);
@@ -538,6 +551,19 @@ function FlowRenderer({
}
}}
onSave={async () => {
// TODO might need to abstract this out or find different way to handle errors
const loopNodes: Array<LoopNode> = nodes.filter(isLoopNode);
const emptyLoopNodes = loopNodes.filter(
(node: LoopNode) => node.data.loopValue === "",
);
if (emptyLoopNodes.length > 0) {
toast({
title: "Can not save workflow because of errors",
description: `${emptyLoopNodes.map((node) => node.data.label).join(", ")}: Loop value cannot be empty`,
variant: "destructive",
});
return;
}
await handleSave();
}}
/>

View File

@@ -13,3 +13,7 @@ export const loopNodeDefaultData: LoopNodeData = {
label: "",
loopValue: "",
} as const;
export function isLoopNode(node: Node): node is LoopNode {
return node.type === "loop";
}