Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions GUI/src/services/service-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ export function getYamlContent(
}

if (parentNode.data.stepType === StepType.Condition) {
return handleConditionStep(allRelations, parentNodeId, nodes, parentNode, finishedFlow, parentStepName);
return handleConditionStep(allRelations, parentNodeId, nodes, parentNode, finishedFlow, parentStepName, edges);
}

if (parentNode.data.stepType === StepType.Input) {
Expand Down Expand Up @@ -752,13 +752,9 @@ function handleConditionStep(
parentNode: Node<NodeDataProps>,
finishedFlow: Map<any, any>,
parentStepName: string,
edges: Edge[],
) {
const conditionRelations: string[] = allRelations.filter((r) => r.startsWith(parentNodeId));
const firstChildNode = conditionRelations[0].split(',')[1];
const secondChildNode = conditionRelations[1].split(',')[1];

const firstChild = nodes.find((node) => node.id === firstChildNode);
const secondChild = nodes.find((node) => node.id === secondChildNode);

const rulesChildren = Array.isArray(parentNode.data.rules?.children) ? parentNode.data.rules.children : [];
const invalidRulesExist = hasInvalidRules(rulesChildren);
Expand All @@ -768,15 +764,25 @@ function handleConditionStep(
throw new Error(i18next.t('toast.missing-condition-rules') ?? 'Error');
}

const outgoingEdges = edges.filter((e) => e.source === parentNodeId);
const successEdge = outgoingEdges.find((e) => e.label === 'Success') ?? outgoingEdges[0];
const failureEdge = outgoingEdges.find((e) => e.label === 'Failure') ?? outgoingEdges[1];

const successChildId = successEdge?.target ?? conditionRelations[0]?.split(',')[1];
const failureChildId = failureEdge?.target ?? conditionRelations[1]?.split(',')[1];

const successChild = nodes.find((node) => node.id === successChildId);
const failureChild = nodes.find((node) => node.id === failureChildId);

const assignedVariableNames = getAssignedVariableNames(nodes);
finishedFlow.set(parentStepName, {
switch: [
{
condition: `\${${buildConditionString(parentNode.data.rules, assignedVariableNames)}}`,
next: toSnakeCase(firstChild?.data?.label ?? '') ?? '',
next: toSnakeCase(successChild?.data?.label ?? '') ?? '',
},
],
next: toSnakeCase(secondChild?.data?.label ?? '') ?? '',
next: toSnakeCase(failureChild?.data?.label ?? '') ?? '',
});
}

Expand Down
Loading