diff --git a/workspaces/ballerina/bi-diagram/src/components/nodes/WhileNode/WhileNodeWidget.tsx b/workspaces/ballerina/bi-diagram/src/components/nodes/WhileNode/WhileNodeWidget.tsx index 0665dbebec3..fa499ae0da3 100644 --- a/workspaces/ballerina/bi-diagram/src/components/nodes/WhileNode/WhileNodeWidget.tsx +++ b/workspaces/ballerina/bi-diagram/src/components/nodes/WhileNode/WhileNodeWidget.tsx @@ -60,9 +60,7 @@ export namespace NodeStyles { export const StyledButton = styled(Button)` border-radius: 5px; - position: absolute; - top: -10px; - left: 52px; + flex-shrink: 0; `; export const ErrorIcon = styled.div` @@ -187,7 +185,7 @@ interface WhileNodeWidgetProps { onClick?: (node: FlowNode) => void; } -export interface NodeWidgetProps extends Omit {} +export interface NodeWidgetProps extends Omit { } export function WhileNodeWidget(props: WhileNodeWidgetProps) { const { model, engine, onClick } = props; @@ -283,6 +281,38 @@ export function WhileNodeWidget(props: WhileNodeWidgetProps) { const hasError = nodeHasError(model.node); const nodeViewState = model.node.viewState; + const description = (() => { + const conditionValue = model.node.properties?.condition?.value as string; + if (conditionValue) return conditionValue; + if (model.node.codedata.node === "FOREACH" && model.node.codedata.sourceCode) { + const match = model.node.codedata.sourceCode.match(/^foreach\s+(.+?)\s*\{/); + return match?.[1] ?? null; + } + return null; + })(); + + const renderDescription = () => { + if (!description) return null; + + if (model.node.codedata.node === "FOREACH") { + const body = description.startsWith("foreach ") ? description.slice(8) : description; + const match = body.match(/^(\S+)\s+(\S+)\s+(in)\s+(.+)$/); + if (match) { + const [, type, varName, , iterable] = match; + return ( + + {type} + {" "}{varName}{" "} + in + {" "}{iterable} + + ); + } + } + + return {description}; + }; + return ( @@ -317,22 +347,32 @@ export function WhileNodeWidget(props: WhileNodeWidgetProps) { - - {model.node.metadata.label || model.node.codedata.node} - {model.node.properties?.condition && ( - - {model.node.properties.condition?.value as ReactNode} - - )} - - setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)} > - - +
+
+
+ {model.node.metadata.label || model.node.codedata.node} + + + +
+ {renderDescription()} +
+
+ {hasError && (