fantonangeli commented on code in PR #3252:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3252#discussion_r2619587420


##########
packages/serverless-workflow-editor/src/i18n/locales/en.ts:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { en as en_common } from "@kie-tools/i18n-common-dictionary";
+import { SwfEditorI18n } from "../SwfEditorI18n";
+
+export const en: SwfEditorI18n = {
+  ...en_common,
+  autoLayout: "Autolayout (beta)",
+  close: "Close",
+  none: "None",
+  cancel: "Cancel",
+  nodes: {
+    view: "View",
+    edit: "Edit",
+    output: "OUTPUT",
+    doubleClickToName: "Double-click to name",
+    addCompensationTransitionEdge: "Add Compensation Transition",
+    addDataConditionTransitionEdge: "Add Data Condition Transition",
+    addDefaultConditionTransitionEdge: "Add Default Transition",
+    addErrorTransitionEdge: "Add Error Transition",
+    addEventConditionTransitionEdge: "Add Event Condition Transition",
+    addTransitionEdge: "Add Transition",
+    addCallbackStateNode: "Add Callback State",
+    addEventStateNode: "Add Event State",
+    addForeachStateNode: "Add ForEach State",
+    addInjectStateNode: "Add Inject State",
+    addOperationStateNode: "Add Operation State",
+    addParallelStateNode: "Add Parallel State",
+    addSleepStateNode: "Add Sleep State",
+    addSwitchStateNode: "Add Switch State",
+    emptyDiagram: "Empty Diagram",
+    swfDiagramEmpty: "This SWF Diagram is empty",
+    diagramHasNodesOrOpenAnotherFile: "Make sure the workflow has nodes or try 
opening another file",
+    startByDraggingNodes: "Start by dragging nodes from the Palette",
+    overlays: "Overlays",
+    nodesSelected: (selectedNodesCount: number) => `${selectedNodesCount} 
nodes selected`,
+    edgesSelected: (selectedEdgesCount: number) => `${selectedEdgesCount} 
edges selected`,
+    nodeSelected: (nodeCount: number) => `${nodeCount} node`,
+    edgeSelected: (edgeCount: number) => `${edgeCount} edge`,
+    nodes: (nodeCount: number) => `${nodeCount} nodes`,
+    edges: (edgeCount: number) => `${edgeCount} edges`,
+    selected: "selected",
+    addingNodesMakingChanges: "Adding nodes or making changes to the Diagram 
will automatically create a DRD for you.",
+    removeDrd: "Remove DRD",

Review Comment:
   Please review my suggestion or remove `addingNodesMakingChanges` if it's not 
used:
   ```suggestion
       addingNodesMakingChanges: "Adding nodes or making changes to the Diagram 
will automatically update the Serverless Workflow for you.",
   ```



##########
packages/serverless-workflow-editor/src/store/computed/computeIndexes.ts:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { SwfEdge, SwfEdgeTypes } from "../../diagram/graph/graph";
+import { Unpacked } from "../../tsExt/tsExt";
+import { buildEdgeId } from "../../diagram/edges/useKieEdgePath";
+
+export function computeIndexedSwf(definitions: State["swf"]["model"]) {
+  const swfEdgesBySwfRef = new Map<string, SwfEdge & { index: number }>();
+  const swfNodesByHref = new Map<string, Unpacked<Specification.States> & { 
index: number }>();
+
+  const states = definitions.states;
+
+  for (let i = 0; i < states.length; i++) {
+    const state = states[i];
+
+    // SWFShape
+    // Use state name as id once the spec 0.8 is based on unique state names
+    swfNodesByHref.set(state.name!, { ...state, index: i });
+
+    // SWFNode
+    const stateEdges = buildSwfEdgesForNode(state, i);
+
+    for (let j = 0; j < stateEdges.length; j++) {
+      swfEdgesBySwfRef.set(stateEdges[j].id!, { ...stateEdges[j], index: 
swfEdgesBySwfRef.size });
+    }
+  }
+  return {
+    swfEdgesBySwfRef,
+    swfNodesByHref,
+  };
+}
+
+function buildSwfEdgesForNode(node: Unpacked<Specification.States>, index: 
number): SwfEdge[] {
+  const edges: SwfEdge[] = [];
+
+  //compensation
+  if (node.compensatedBy) {
+    edges.push(getCompensationTrasition(index, node));

Review Comment:
   ```suggestion
       edges.push(getCompensationTransition(index, node));
   ```



##########
packages/serverless-workflow-editor/src/store/computed/computeIndexes.ts:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { SwfEdge, SwfEdgeTypes } from "../../diagram/graph/graph";
+import { Unpacked } from "../../tsExt/tsExt";
+import { buildEdgeId } from "../../diagram/edges/useKieEdgePath";
+
+export function computeIndexedSwf(definitions: State["swf"]["model"]) {
+  const swfEdgesBySwfRef = new Map<string, SwfEdge & { index: number }>();
+  const swfNodesByHref = new Map<string, Unpacked<Specification.States> & { 
index: number }>();
+
+  const states = definitions.states;
+
+  for (let i = 0; i < states.length; i++) {
+    const state = states[i];
+
+    // SWFShape
+    // Use state name as id once the spec 0.8 is based on unique state names
+    swfNodesByHref.set(state.name!, { ...state, index: i });
+
+    // SWFNode
+    const stateEdges = buildSwfEdgesForNode(state, i);
+
+    for (let j = 0; j < stateEdges.length; j++) {
+      swfEdgesBySwfRef.set(stateEdges[j].id!, { ...stateEdges[j], index: 
swfEdgesBySwfRef.size });
+    }
+  }
+  return {
+    swfEdgesBySwfRef,
+    swfNodesByHref,
+  };
+}
+
+function buildSwfEdgesForNode(node: Unpacked<Specification.States>, index: 
number): SwfEdge[] {
+  const edges: SwfEdge[] = [];
+
+  //compensation
+  if (node.compensatedBy) {
+    edges.push(getCompensationTrasition(index, node));
+  }
+
+  switch (node.type) {
+    case "sleep": {
+      const state = node as Specification.ISleepstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }
+    case "event": {
+      const state = node as Specification.IEventstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }
+    case "operation": {
+      const state = node as Specification.IOperationstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }
+    case "parallel": {
+      const state = node as Specification.Parallelstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }
+    case "switch": {
+      const state = node as Specification.Switchstate;
+
+      if ("dataConditions" in state) {
+        const switchData = state as Specification.IDatabasedswitchstate;
+        if (switchData.dataConditions) {
+          getConditionTrasitions(index, node, 
switchData.dataConditions).forEach((dataConditions) =>
+            edges.push(dataConditions)
+          );
+        }
+      } else {
+        const switchEvent = state as Specification.IEventbasedswitchstate;
+        if (switchEvent.eventConditions) {
+          getConditionTrasitions(index, node, 
switchEvent.eventConditions).forEach((eventConditions) =>
+            edges.push(eventConditions)
+          );
+        }
+      }
+
+      if (state.defaultCondition?.transition) {
+        edges.push(getDefaultTrasition(index, state, 
state.defaultCondition.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }
+    case "inject": {
+      const state = node as Specification.IInjectstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      break;
+    }
+    case "foreach": {
+      const state = node as Specification.IForeachstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      break;
+    }
+    case "callback": {
+      const state = node as Specification.ICallbackstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      break;
+    }
+    default: {
+      break;
+    }
+  }
+
+  return edges;
+}
+
+function getCompensationTrasition(index: number, node: 
Unpacked<Specification.States>): SwfEdge {
+  return buildSwfEdge(index, node, node.name!, node.compensatedBy!, 
"compensationTransition");
+}
+
+function getTransition(
+  index: number,
+  node: Unpacked<Specification.States>,
+  transition: string | Specification.ITransition
+): SwfEdge {
+  let transitionStr: string | undefined = undefined;
+  if (typeof transition === "object") {
+    transitionStr = transition.nextState;
+  } else {
+    transitionStr = transition;
+  }

Review Comment:
   I see very similar parts of this file at lines: 186, 204, 222, 245, 258.
   I would evaluate putting this logic in a reusable function.



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions
+  ackTransitionEdges(definitions.states, ackEdge);
+
+  // console.timeEnd("edges");
+
+  // nodes
+  const ackNode: AckNode = (swfObject, index) => {
+    const type = getNodeTypeFromSwfObject(swfObject);
+    if (!type) {
+      return undefined;
+    }
+
+    const nodeName = swfObject!.name!;
+
+    const data: SwfDiagramNodeData = {
+      swfObject,
+      index,
+      parentRfNode: undefined,
+    };
+
+    // if there is no position calculated for the node in the state go for x:0 
y:0
+    const i = nodeIds.indexOf(nodeName);
+    const position = nodeIds.indexOf(nodeName) === -1 ? { x: 0, y: 0 } : 
nodesPosition[i];
+    nodeIds = [...nodeIds, nodeName];
+    nodesPosition = [...nodesPosition, position];

Review Comment:
   We should avoid modifying the main function params and instead declare 2 new 
constants



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions

Review Comment:
   There are many other `trasition` in this file
   ```suggestion
     // transitions
   ```



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);

Review Comment:
   ```suggestion
       const targetAdjacencyList = swfAdjacencyList.get(target);
   ```



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions
+  ackTransitionEdges(definitions.states, ackEdge);
+
+  // console.timeEnd("edges");
+
+  // nodes
+  const ackNode: AckNode = (swfObject, index) => {
+    const type = getNodeTypeFromSwfObject(swfObject);
+    if (!type) {
+      return undefined;
+    }
+
+    const nodeName = swfObject!.name!;
+
+    const data: SwfDiagramNodeData = {
+      swfObject,
+      index,
+      parentRfNode: undefined,
+    };
+
+    // if there is no position calculated for the node in the state go for x:0 
y:0
+    const i = nodeIds.indexOf(nodeName);
+    const position = nodeIds.indexOf(nodeName) === -1 ? { x: 0, y: 0 } : 
nodesPosition[i];
+    nodeIds = [...nodeIds, nodeName];
+    nodesPosition = [...nodesPosition, position];
+
+    const bounds: RF.Rect = { ...DEFAULT_NODE_SIZES[type]({ snapGrid: 
diagram.snapGrid }), ...position };
+
+    const newNode: RF.Node<SwfDiagramNodeData> = {
+      id: nodeName,
+      type,
+      selected: selectedNodes.has(nodeName),
+      dragging: draggingNodes.has(nodeName),
+      position: snapShapePosition(diagram.snapGrid, bounds),
+      data,
+      zIndex: NODE_LAYERS.NODES,
+      style: {
+        ...snapShapeDimensions(diagram.snapGrid, bounds, 
MIN_NODE_SIZES[type]({ snapGrid: diagram.snapGrid })),
+      },
+    };
+
+    nodesById.set(newNode.id, newNode);
+    if (newNode.selected) {
+      selectedNodesById.set(newNode.id, newNode);
+      selectedNodeTypes.add(newNode.type as NodeType);
+    }
+
+    return newNode;
+  };
+
+  const nodes: RF.Node<SwfDiagramNodeData>[] = [
+    ...(definitions.states ?? []).flatMap((swfObject, index) => {
+      const newNode = ackNode(swfObject, index);
+      return newNode ? [newNode] : [];
+    }),
+  ];
+
+  // Selected edges go to the end of the array. This is necessary because 
z-index doesn't work on SVGs.
+  const sortedEdges = edges
+    .filter((e) => nodesById.has(e.source) && nodesById.has(e.target))
+    .sort((a, b) => Number(selectedEdges.has(a.id)) - 
Number(selectedEdges.has(b.id)));
+
+  // console.timeEnd("nodes");
+  if (diagram.overlays.enableNodeHierarchyHighlight) {
+    assignClassesToHighlightedHierarchyNodes(diagram._selectedNodes, 
nodesById, edgesById, swfEdges);
+  }
+
+  //clean up unused nodes position
+  if (nodesPosition) {
+    for (const id of nodeIds) {
+      if (!nodesById.get(id)) {
+        const i = nodeIds.indexOf(id);
+        if (i !== -1) {
+          nodesPosition.splice(1, i);
+          nodeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  //clean up unused edges waypoits
+  if (edgeWaypoints) {
+    for (const id of edgeIds) {
+      if (!edgesById.get(id)) {
+        const i = edgeIds.indexOf(id);
+        if (i !== -1) {
+          edgeWaypoints.splice(1, i);
+          edgeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  return {
+    swfEdges,
+    swfAdjacencyList,
+    nodes: nodes,
+    edges: sortedEdges,
+    edgesById,
+    nodesById,
+    selectedNodeTypes,
+    selectedNodesById,
+    selectedEdgesById,
+  };
+}
+
+function ackTransitionEdges(states: Specification.States, ackEdge: AckEdge) {
+  for (let i = 0; i < states.length; i++) {
+    const state = states[i];
+
+    getEdgeArgsForNode(state, i).forEach((edge) => {
+      ackEdge(edge);
+    });
+  }
+}
+
+function getEdgeArgsForNode(node: Unpacked<Specification.States>, index: 
number): EdgeArgs[] {
+  const edges: EdgeArgs[] = [];
+
+  //compensation
+  if (node.compensatedBy) {
+    edges.push(getCompensationTrasitionArgs(index, node));
+  }
+
+  switch (node.type) {
+    case "sleep": {
+      const state: Specification.ISleepstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "event": {
+      const state: Specification.IEventstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "operation": {
+      const state: Specification.IOperationstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "parallel": {
+      const state: Specification.IParallelstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "switch": {
+      const state: Specification.Switchstate = node;
+
+      if ("dataConditions" in state) {
+        const switchData: Specification.IDatabasedswitchstate = state;
+        if (switchData.dataConditions) {
+          getConditionTrasitionsArgs(index, node, 
switchData.dataConditions).forEach((dataConditions) =>
+            edges.push(dataConditions)
+          );
+        }
+      } else {
+        const switchEvent: Specification.IEventbasedswitchstate = state;
+        if (switchEvent.eventConditions) {
+          getConditionTrasitionsArgs(index, node, 
switchEvent.eventConditions).forEach((eventConditions) =>
+            edges.push(eventConditions)
+          );
+        }
+      }
+
+      if (state.defaultCondition!.transition) {
+        edges.push(getDefaultTransitionArgs(index, state, 
state.defaultCondition.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "inject": {
+      const state: Specification.IInjectstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    case "foreach": {
+      const state: Specification.IForeachstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    case "callback": {
+      const state: Specification.ICallbackstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    default: {
+      break;
+    }
+  }
+
+  return edges;
+}
+
+function getCompensationTrasitionArgs(index: number, node: 
Unpacked<Specification.States>): EdgeArgs {
+  return buildEdgeArgs(index, node, node.compensatedBy!, "edge_compensation", 
"compensationTransition");
+}
+
+function getTransitionArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  transition: string | Specification.ITransition
+): EdgeArgs {
+  let transitionStr: string | undefined = undefined;
+  if (typeof transition === "object") {
+    transitionStr = transition.nextState;
+  } else {
+    transitionStr = transition;
+  }
+
+  return buildEdgeArgs(index, node, transitionStr, "edge_transition", 
"transition");
+}
+
+function getErrorTrasitionsArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  errors: Specification.IError[]
+): EdgeArgs[] {
+  const edgeArgs: EdgeArgs[] = [];
+
+  errors.forEach((error) => {
+    let transitionStr: string | undefined = undefined;
+    if (typeof error.transition === "object") {
+      transitionStr = error.transition.nextState;
+    } else {
+      transitionStr = error.transition;
+    }
+
+    edgeArgs.push(buildEdgeArgs(index, node, transitionStr, "edge_error", 
"errorTransition"));
+  });
+
+  return edgeArgs;
+}
+
+function getDefaultTransitionArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  transition: string | Specification.ITransition
+): EdgeArgs {
+  let transitionStr: string | undefined = undefined;
+  if (typeof transition === "object") {
+    transitionStr = transition.nextState;
+  } else {
+    transitionStr = transition;
+  }
+
+  return buildEdgeArgs(index, node, transitionStr, "edge_defaultCondition", 
"defaultConditionTransition");
+}
+
+function getConditionTrasitionsArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  conditions: Specification.Datacondition[] | Specification.Eventcondition[]
+): EdgeArgs[] {
+  const conditionTransitions: EdgeArgs[] = [];
+
+  conditions.forEach((condition) => {
+    // Specification.Enddeventcondition won't be created for now

Review Comment:
   I wonder if we should create a GH Issue not to forget this.
   You can skip this suggestion if not necessary.



##########
packages/serverless-workflow-editor/src/SwfEditor.tsx:
##########
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import "@patternfly/react-core/dist/styles/base.css";
+import "reactflow/dist/style.css";
+
+import * as React from "react";
+import * as ReactDOM from "react-dom";
+import * as RF from "reactflow";
+import { ErrorBoundary, ErrorBoundaryPropsWithFallback } from 
"react-error-boundary";
+import { useCallback, useEffect, useImperativeHandle, useMemo, useRef, 
useState } from "react";
+import { original } from "immer";
+import { Diagram, DiagramRef } from "./diagram/Diagram";
+import { SwfEditorContextProvider, useSwfEditor } from "./SwfEditorContext";
+import { SwfEditorErrorFallback } from "./SwfEditorErrorFallback";
+import { ComputedStateCache } from "./store/ComputedStateCache";
+import { Computed, createSwfEditorStore, defaultStaticState } from 
"./store/Store";
+import { SwfEditorStoreApiContext, StoreApiType, useSwfEditorStore, 
useSwfEditorStoreApi } from "./store/StoreContext";
+import { SwfDiagramSvg } from "./svg/SwfDiagramSvg";
+import { useEffectAfterFirstRender } from "./useEffectAfterFirstRender";
+import { INITIAL_COMPUTED_CACHE } from "./store/computed/initial";
+import { Commands, CommandsContextProvider, useCommands } from 
"./commands/CommandsContextProvider";
+import { SwfEditorSettingsContextProvider } from 
"./settings/SwfEditorSettingsContext";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import "./SwfEditor.css"; // Leave it for last, as this overrides some of the 
PF and RF styles.
+import { swfEditorDictionaries, SwfEditorI18nContext, swfEditorI18nDefaults, 
useSwfEditorI18n } from "./i18n";
+import { I18nDictionariesProvider } from 
"@kie-tools-core/i18n/dist/react-components";
+
+const ON_MODEL_CHANGE_DEBOUNCE_TIME_IN_MS = 500;
+
+const SVG_PADDING = 20;
+
+export type SwfEditorRef = {
+  reset: (model: Specification.IWorkflow) => void;
+  getDiagramSvg: () => Promise<string | undefined>;
+  getCommands: () => Commands;
+};
+
+export type OnSwfModelChange = (model: Specification.IWorkflow) => void;
+
+export type SwfEditorProps = {
+  /**
+   * The SWF itself.
+   */
+  model: Specification.IWorkflow;
+  /**
+   * Called when a change occurs on `model`, so the controlled flow of the 
component can be done.
+   */
+  onModelChange?: OnSwfModelChange;
+  /**
+   * A link that will take users to an issue tracker so they can report 
problems they find on the SWF Editor.
+   * This is shown on the ErrorBoundary fallback component, when an uncaught 
error happens.
+   */
+  issueTrackerHref?: string;
+  /**
+   * A flag to enable read-only mode on the SWF Editor.
+   * When enabled navigation is still possible,
+   * but no changes can be made and the model itself is unaltered.
+   */
+  isReadOnly?: boolean;
+  /**
+   * Notifies the caller when the SWF Editor performs a new edit after the 
debounce time.
+   */
+  onModelDebounceStateChanged?: (changed: boolean) => void;
+
+  locale: string;
+};
+
+export const SwfEditorInternal = ({
+  model,
+  onModelChange,
+  onModelDebounceStateChanged,
+  forwardRef,
+}: SwfEditorProps & { forwardRef?: React.Ref<SwfEditorRef> }) => {
+  const { i18n } = useSwfEditorI18n();
+  const swf = useSwfEditorStore((s) => s.swf);
+  const isDiagramEditingInProgress = useSwfEditorStore((s) => 
s.computed(s).isDiagramEditingInProgress());
+  const swfEditorStoreApi = useSwfEditorStoreApi();
+  const { commandsRef } = useCommands();
+
+  const { swfModelBeforeEditingRef, swfEditorRootElementRef } = useSwfEditor();
+
+  // Refs
+  const diagramRef = useRef<DiagramRef>(null);
+  const diagramContainerRef = useRef<HTMLDivElement>(null);
+
+  // Allow imperativelly controlling the Editor.
+  useImperativeHandle(
+    forwardRef,
+    () => ({
+      reset: (model) => {
+        const state = swfEditorStoreApi.getState();
+        return state.dispatch(state).swf.reset(model);
+      },
+      getDiagramSvg: async () => {
+        const nodes = diagramRef.current?.getReactFlowInstance()?.getNodes();
+        const edges = diagramRef.current?.getReactFlowInstance()?.getEdges();
+        if (!nodes || !edges) {
+          return undefined;
+        }
+
+        const bounds = RF.getNodesBounds(nodes);
+        const state = swfEditorStoreApi.getState();
+
+        const svg = document.createElementNS("http://www.w3.org/2000/svg";, 
"svg");
+        svg.setAttribute("width", bounds.width + SVG_PADDING * 2 + "");
+        svg.setAttribute("height", bounds.height + SVG_PADDING * 2 + "");
+
+        // We're still on React 17.
+        // eslint-disable-next-line react/no-deprecated
+        ReactDOM.render(
+          // Indepdent of where the nodes are located, they'll always be 
rendered at the top-left corner of the SVG
+          <g transform={`translate(${-bounds.x + SVG_PADDING} ${-bounds.y + 
SVG_PADDING})`}>
+            <SwfDiagramSvg nodes={nodes} edges={edges} 
snapGrid={state.diagram.snapGrid} thisSwf={state.swf} />
+          </g>,
+          svg
+        );
+
+        return new XMLSerializer().serializeToString(svg);
+      },
+      getCommands: () => commandsRef.current,
+    }),
+    [swfEditorStoreApi, commandsRef]
+  );
+
+  // Make sure the SWF Editor reacts to props changing.
+  useEffectAfterFirstRender(() => {
+    swfEditorStoreApi.setState((state) => {
+      // Avoid unecessary state updates
+      if (model === original(state.swf.model)) {
+        return;
+      }
+
+      state.diagram.autoLayout.canAutoGenerate = true;
+      state.swf.model = model;
+
+      swfModelBeforeEditingRef.current = state.swf.model;
+    });
+  }, [swfEditorStoreApi, model]);
+
+  useStateAsItWasBeforeConditionBecameTrue(
+    swf.model,
+    isDiagramEditingInProgress,
+    useCallback((prev) => (swfModelBeforeEditingRef.current = prev), 
[swfModelBeforeEditingRef])
+  );
+
+  // Only notify changes when dragging/resizing operations are not happening.
+  useEffectAfterFirstRender(() => {
+    if (isDiagramEditingInProgress) {
+      return;
+    }
+    onModelDebounceStateChanged?.(false);
+
+    const timeout = setTimeout(() => {
+      // Ignore changes made outside... If the controller of the component
+      // changed its props, it knows it already, we don't need to call 
"onModelChange" again.
+      if (model === swf.model) {
+        return;
+      }
+
+      onModelDebounceStateChanged?.(true);
+      console.debug("SWF EDITOR: Model changed!");
+      onModelChange?.(swf.model);
+    }, ON_MODEL_CHANGE_DEBOUNCE_TIME_IN_MS);
+
+    return () => {
+      clearTimeout(timeout);
+    };
+  }, [isDiagramEditingInProgress, onModelChange, swf.model]);
+
+  return (
+    <div ref={swfEditorRootElementRef} className={"kie-swf-editor--root"}>
+      <>

Review Comment:
   ```suggestion
           <div
             className={"kie-tools--swf-editor--diagram-container"}
             ref={diagramContainerRef}
             data-testid={"kie-tools--swf-editor--diagram-container"}
           >
             <Diagram ref={diagramRef} container={diagramContainerRef} />
           </div>
   ```



##########
packages/serverless-workflow-editor/src/store/computed/computeIndexes.ts:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { SwfEdge, SwfEdgeTypes } from "../../diagram/graph/graph";
+import { Unpacked } from "../../tsExt/tsExt";
+import { buildEdgeId } from "../../diagram/edges/useKieEdgePath";
+
+export function computeIndexedSwf(definitions: State["swf"]["model"]) {
+  const swfEdgesBySwfRef = new Map<string, SwfEdge & { index: number }>();
+  const swfNodesByHref = new Map<string, Unpacked<Specification.States> & { 
index: number }>();
+
+  const states = definitions.states;
+
+  for (let i = 0; i < states.length; i++) {
+    const state = states[i];
+
+    // SWFShape
+    // Use state name as id once the spec 0.8 is based on unique state names
+    swfNodesByHref.set(state.name!, { ...state, index: i });
+
+    // SWFNode
+    const stateEdges = buildSwfEdgesForNode(state, i);
+
+    for (let j = 0; j < stateEdges.length; j++) {
+      swfEdgesBySwfRef.set(stateEdges[j].id!, { ...stateEdges[j], index: 
swfEdgesBySwfRef.size });
+    }
+  }
+  return {
+    swfEdgesBySwfRef,
+    swfNodesByHref,
+  };
+}
+
+function buildSwfEdgesForNode(node: Unpacked<Specification.States>, index: 
number): SwfEdge[] {
+  const edges: SwfEdge[] = [];
+
+  //compensation
+  if (node.compensatedBy) {
+    edges.push(getCompensationTrasition(index, node));
+  }
+
+  switch (node.type) {
+    case "sleep": {
+      const state = node as Specification.ISleepstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));

Review Comment:
   There are also other parts of this file with the typo `Trasition -> 
Transition`
   ```suggestion
           getErrorTransitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
   ```



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions
+  ackTransitionEdges(definitions.states, ackEdge);
+
+  // console.timeEnd("edges");
+
+  // nodes
+  const ackNode: AckNode = (swfObject, index) => {
+    const type = getNodeTypeFromSwfObject(swfObject);
+    if (!type) {
+      return undefined;
+    }
+
+    const nodeName = swfObject!.name!;
+
+    const data: SwfDiagramNodeData = {
+      swfObject,
+      index,
+      parentRfNode: undefined,
+    };
+
+    // if there is no position calculated for the node in the state go for x:0 
y:0
+    const i = nodeIds.indexOf(nodeName);
+    const position = nodeIds.indexOf(nodeName) === -1 ? { x: 0, y: 0 } : 
nodesPosition[i];

Review Comment:
   ```suggestion
       const position = i === -1 ? { x: 0, y: 0 } : nodesPosition[i];
   ```



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions
+  ackTransitionEdges(definitions.states, ackEdge);
+
+  // console.timeEnd("edges");
+
+  // nodes
+  const ackNode: AckNode = (swfObject, index) => {
+    const type = getNodeTypeFromSwfObject(swfObject);
+    if (!type) {
+      return undefined;
+    }
+
+    const nodeName = swfObject!.name!;
+
+    const data: SwfDiagramNodeData = {
+      swfObject,
+      index,
+      parentRfNode: undefined,
+    };
+
+    // if there is no position calculated for the node in the state go for x:0 
y:0
+    const i = nodeIds.indexOf(nodeName);
+    const position = nodeIds.indexOf(nodeName) === -1 ? { x: 0, y: 0 } : 
nodesPosition[i];
+    nodeIds = [...nodeIds, nodeName];
+    nodesPosition = [...nodesPosition, position];
+
+    const bounds: RF.Rect = { ...DEFAULT_NODE_SIZES[type]({ snapGrid: 
diagram.snapGrid }), ...position };
+
+    const newNode: RF.Node<SwfDiagramNodeData> = {
+      id: nodeName,
+      type,
+      selected: selectedNodes.has(nodeName),
+      dragging: draggingNodes.has(nodeName),
+      position: snapShapePosition(diagram.snapGrid, bounds),
+      data,
+      zIndex: NODE_LAYERS.NODES,
+      style: {
+        ...snapShapeDimensions(diagram.snapGrid, bounds, 
MIN_NODE_SIZES[type]({ snapGrid: diagram.snapGrid })),
+      },
+    };
+
+    nodesById.set(newNode.id, newNode);
+    if (newNode.selected) {
+      selectedNodesById.set(newNode.id, newNode);
+      selectedNodeTypes.add(newNode.type as NodeType);
+    }
+
+    return newNode;
+  };
+
+  const nodes: RF.Node<SwfDiagramNodeData>[] = [
+    ...(definitions.states ?? []).flatMap((swfObject, index) => {
+      const newNode = ackNode(swfObject, index);
+      return newNode ? [newNode] : [];
+    }),
+  ];
+
+  // Selected edges go to the end of the array. This is necessary because 
z-index doesn't work on SVGs.
+  const sortedEdges = edges
+    .filter((e) => nodesById.has(e.source) && nodesById.has(e.target))
+    .sort((a, b) => Number(selectedEdges.has(a.id)) - 
Number(selectedEdges.has(b.id)));
+
+  // console.timeEnd("nodes");
+  if (diagram.overlays.enableNodeHierarchyHighlight) {
+    assignClassesToHighlightedHierarchyNodes(diagram._selectedNodes, 
nodesById, edgesById, swfEdges);
+  }
+
+  //clean up unused nodes position
+  if (nodesPosition) {
+    for (const id of nodeIds) {
+      if (!nodesById.get(id)) {
+        const i = nodeIds.indexOf(id);
+        if (i !== -1) {
+          nodesPosition.splice(1, i);
+          nodeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  //clean up unused edges waypoits
+  if (edgeWaypoints) {
+    for (const id of edgeIds) {
+      if (!edgesById.get(id)) {
+        const i = edgeIds.indexOf(id);
+        if (i !== -1) {
+          edgeWaypoints.splice(1, i);

Review Comment:
   If I go to: 
   -"Dev - Web app"
   - upload a WF with the drag&drop ie: `jsongreet.sw.json`
   - click on Autolayout
   - upload another WF ie: `callback-state-timeouts.sw.json`
   
   I get:
   ```
   SwfEditorErrorFallback.tsx:47 TypeError: Cannot assign to read only property 
'length' of object '[object Array]'
   ```
   
   In the real use cases, the user should not reach this issue, and we can also 
fix it in a separate PR, if needed, I think



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions
+  ackTransitionEdges(definitions.states, ackEdge);
+
+  // console.timeEnd("edges");
+
+  // nodes
+  const ackNode: AckNode = (swfObject, index) => {
+    const type = getNodeTypeFromSwfObject(swfObject);
+    if (!type) {
+      return undefined;
+    }
+
+    const nodeName = swfObject!.name!;
+
+    const data: SwfDiagramNodeData = {
+      swfObject,
+      index,
+      parentRfNode: undefined,
+    };
+
+    // if there is no position calculated for the node in the state go for x:0 
y:0
+    const i = nodeIds.indexOf(nodeName);
+    const position = nodeIds.indexOf(nodeName) === -1 ? { x: 0, y: 0 } : 
nodesPosition[i];
+    nodeIds = [...nodeIds, nodeName];
+    nodesPosition = [...nodesPosition, position];
+
+    const bounds: RF.Rect = { ...DEFAULT_NODE_SIZES[type]({ snapGrid: 
diagram.snapGrid }), ...position };
+
+    const newNode: RF.Node<SwfDiagramNodeData> = {
+      id: nodeName,
+      type,
+      selected: selectedNodes.has(nodeName),
+      dragging: draggingNodes.has(nodeName),
+      position: snapShapePosition(diagram.snapGrid, bounds),
+      data,
+      zIndex: NODE_LAYERS.NODES,
+      style: {
+        ...snapShapeDimensions(diagram.snapGrid, bounds, 
MIN_NODE_SIZES[type]({ snapGrid: diagram.snapGrid })),
+      },
+    };
+
+    nodesById.set(newNode.id, newNode);
+    if (newNode.selected) {
+      selectedNodesById.set(newNode.id, newNode);
+      selectedNodeTypes.add(newNode.type as NodeType);
+    }
+
+    return newNode;
+  };
+
+  const nodes: RF.Node<SwfDiagramNodeData>[] = [
+    ...(definitions.states ?? []).flatMap((swfObject, index) => {
+      const newNode = ackNode(swfObject, index);
+      return newNode ? [newNode] : [];
+    }),
+  ];
+
+  // Selected edges go to the end of the array. This is necessary because 
z-index doesn't work on SVGs.
+  const sortedEdges = edges
+    .filter((e) => nodesById.has(e.source) && nodesById.has(e.target))
+    .sort((a, b) => Number(selectedEdges.has(a.id)) - 
Number(selectedEdges.has(b.id)));
+
+  // console.timeEnd("nodes");
+  if (diagram.overlays.enableNodeHierarchyHighlight) {
+    assignClassesToHighlightedHierarchyNodes(diagram._selectedNodes, 
nodesById, edgesById, swfEdges);
+  }
+
+  //clean up unused nodes position
+  if (nodesPosition) {
+    for (const id of nodeIds) {
+      if (!nodesById.get(id)) {
+        const i = nodeIds.indexOf(id);
+        if (i !== -1) {
+          nodesPosition.splice(1, i);
+          nodeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  //clean up unused edges waypoits

Review Comment:
   ```suggestion
     //clean up unused edges waypoints
   ```



##########
packages/serverless-workflow-editor/src/store/computed/computeIndexes.ts:
##########
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { SwfEdge, SwfEdgeTypes } from "../../diagram/graph/graph";
+import { Unpacked } from "../../tsExt/tsExt";
+import { buildEdgeId } from "../../diagram/edges/useKieEdgePath";
+
+export function computeIndexedSwf(definitions: State["swf"]["model"]) {
+  const swfEdgesBySwfRef = new Map<string, SwfEdge & { index: number }>();
+  const swfNodesByHref = new Map<string, Unpacked<Specification.States> & { 
index: number }>();
+
+  const states = definitions.states;
+
+  for (let i = 0; i < states.length; i++) {
+    const state = states[i];
+
+    // SWFShape
+    // Use state name as id once the spec 0.8 is based on unique state names
+    swfNodesByHref.set(state.name!, { ...state, index: i });
+
+    // SWFNode
+    const stateEdges = buildSwfEdgesForNode(state, i);
+
+    for (let j = 0; j < stateEdges.length; j++) {
+      swfEdgesBySwfRef.set(stateEdges[j].id!, { ...stateEdges[j], index: 
swfEdgesBySwfRef.size });
+    }
+  }
+  return {
+    swfEdgesBySwfRef,
+    swfNodesByHref,
+  };
+}
+
+function buildSwfEdgesForNode(node: Unpacked<Specification.States>, index: 
number): SwfEdge[] {
+  const edges: SwfEdge[] = [];
+
+  //compensation
+  if (node.compensatedBy) {
+    edges.push(getCompensationTrasition(index, node));
+  }
+
+  switch (node.type) {
+    case "sleep": {
+      const state = node as Specification.ISleepstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }
+    case "event": {
+      const state = node as Specification.IEventstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }
+    case "operation": {
+      const state = node as Specification.IOperationstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }
+    case "parallel": {
+      const state = node as Specification.Parallelstate;
+
+      if (state.transition) {
+        edges.push(getTransition(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitions(index, state, 
state.onErrors).forEach((errorTransitions) => edges.push(errorTransitions));
+      }
+
+      break;
+    }

Review Comment:
   I think it's worth trying to aggregate these `swith cases`?



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions
+  ackTransitionEdges(definitions.states, ackEdge);
+
+  // console.timeEnd("edges");
+
+  // nodes
+  const ackNode: AckNode = (swfObject, index) => {
+    const type = getNodeTypeFromSwfObject(swfObject);
+    if (!type) {
+      return undefined;
+    }
+
+    const nodeName = swfObject!.name!;
+
+    const data: SwfDiagramNodeData = {
+      swfObject,
+      index,
+      parentRfNode: undefined,
+    };
+
+    // if there is no position calculated for the node in the state go for x:0 
y:0
+    const i = nodeIds.indexOf(nodeName);
+    const position = nodeIds.indexOf(nodeName) === -1 ? { x: 0, y: 0 } : 
nodesPosition[i];
+    nodeIds = [...nodeIds, nodeName];
+    nodesPosition = [...nodesPosition, position];
+
+    const bounds: RF.Rect = { ...DEFAULT_NODE_SIZES[type]({ snapGrid: 
diagram.snapGrid }), ...position };
+
+    const newNode: RF.Node<SwfDiagramNodeData> = {
+      id: nodeName,
+      type,
+      selected: selectedNodes.has(nodeName),
+      dragging: draggingNodes.has(nodeName),
+      position: snapShapePosition(diagram.snapGrid, bounds),
+      data,
+      zIndex: NODE_LAYERS.NODES,
+      style: {
+        ...snapShapeDimensions(diagram.snapGrid, bounds, 
MIN_NODE_SIZES[type]({ snapGrid: diagram.snapGrid })),
+      },
+    };
+
+    nodesById.set(newNode.id, newNode);
+    if (newNode.selected) {
+      selectedNodesById.set(newNode.id, newNode);
+      selectedNodeTypes.add(newNode.type as NodeType);
+    }
+
+    return newNode;
+  };
+
+  const nodes: RF.Node<SwfDiagramNodeData>[] = [
+    ...(definitions.states ?? []).flatMap((swfObject, index) => {
+      const newNode = ackNode(swfObject, index);
+      return newNode ? [newNode] : [];
+    }),
+  ];
+
+  // Selected edges go to the end of the array. This is necessary because 
z-index doesn't work on SVGs.
+  const sortedEdges = edges
+    .filter((e) => nodesById.has(e.source) && nodesById.has(e.target))
+    .sort((a, b) => Number(selectedEdges.has(a.id)) - 
Number(selectedEdges.has(b.id)));
+
+  // console.timeEnd("nodes");
+  if (diagram.overlays.enableNodeHierarchyHighlight) {
+    assignClassesToHighlightedHierarchyNodes(diagram._selectedNodes, 
nodesById, edgesById, swfEdges);
+  }
+
+  //clean up unused nodes position
+  if (nodesPosition) {
+    for (const id of nodeIds) {
+      if (!nodesById.get(id)) {
+        const i = nodeIds.indexOf(id);
+        if (i !== -1) {
+          nodesPosition.splice(1, i);
+          nodeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  //clean up unused edges waypoits
+  if (edgeWaypoints) {
+    for (const id of edgeIds) {
+      if (!edgesById.get(id)) {
+        const i = edgeIds.indexOf(id);
+        if (i !== -1) {
+          edgeWaypoints.splice(1, i);
+          edgeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  return {
+    swfEdges,
+    swfAdjacencyList,
+    nodes: nodes,
+    edges: sortedEdges,
+    edgesById,
+    nodesById,
+    selectedNodeTypes,
+    selectedNodesById,
+    selectedEdgesById,
+  };
+}
+
+function ackTransitionEdges(states: Specification.States, ackEdge: AckEdge) {
+  for (let i = 0; i < states.length; i++) {
+    const state = states[i];
+
+    getEdgeArgsForNode(state, i).forEach((edge) => {
+      ackEdge(edge);
+    });
+  }
+}
+
+function getEdgeArgsForNode(node: Unpacked<Specification.States>, index: 
number): EdgeArgs[] {
+  const edges: EdgeArgs[] = [];
+
+  //compensation
+  if (node.compensatedBy) {
+    edges.push(getCompensationTrasitionArgs(index, node));
+  }
+
+  switch (node.type) {
+    case "sleep": {
+      const state: Specification.ISleepstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "event": {
+      const state: Specification.IEventstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "operation": {
+      const state: Specification.IOperationstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "parallel": {
+      const state: Specification.IParallelstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "switch": {
+      const state: Specification.Switchstate = node;
+
+      if ("dataConditions" in state) {
+        const switchData: Specification.IDatabasedswitchstate = state;
+        if (switchData.dataConditions) {
+          getConditionTrasitionsArgs(index, node, 
switchData.dataConditions).forEach((dataConditions) =>
+            edges.push(dataConditions)
+          );
+        }
+      } else {
+        const switchEvent: Specification.IEventbasedswitchstate = state;
+        if (switchEvent.eventConditions) {
+          getConditionTrasitionsArgs(index, node, 
switchEvent.eventConditions).forEach((eventConditions) =>
+            edges.push(eventConditions)
+          );
+        }
+      }
+
+      if (state.defaultCondition!.transition) {
+        edges.push(getDefaultTransitionArgs(index, state, 
state.defaultCondition.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "inject": {
+      const state: Specification.IInjectstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    case "foreach": {
+      const state: Specification.IForeachstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    case "callback": {
+      const state: Specification.ICallbackstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    default: {
+      break;
+    }
+  }
+
+  return edges;
+}
+
+function getCompensationTrasitionArgs(index: number, node: 
Unpacked<Specification.States>): EdgeArgs {
+  return buildEdgeArgs(index, node, node.compensatedBy!, "edge_compensation", 
"compensationTransition");
+}
+
+function getTransitionArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  transition: string | Specification.ITransition
+): EdgeArgs {
+  let transitionStr: string | undefined = undefined;
+  if (typeof transition === "object") {
+    transitionStr = transition.nextState;
+  } else {
+    transitionStr = transition;
+  }

Review Comment:
   These conditions are replicated at lines 388, 406, 424, 447, 462, in this 
file as well, and can be unified together with the point 
[here](https://github.com/apache/incubator-kie-tools/pull/3252/changes#r2619758015)



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions
+  ackTransitionEdges(definitions.states, ackEdge);
+
+  // console.timeEnd("edges");
+
+  // nodes
+  const ackNode: AckNode = (swfObject, index) => {
+    const type = getNodeTypeFromSwfObject(swfObject);
+    if (!type) {
+      return undefined;
+    }
+
+    const nodeName = swfObject!.name!;
+
+    const data: SwfDiagramNodeData = {
+      swfObject,
+      index,
+      parentRfNode: undefined,
+    };
+
+    // if there is no position calculated for the node in the state go for x:0 
y:0
+    const i = nodeIds.indexOf(nodeName);
+    const position = nodeIds.indexOf(nodeName) === -1 ? { x: 0, y: 0 } : 
nodesPosition[i];
+    nodeIds = [...nodeIds, nodeName];
+    nodesPosition = [...nodesPosition, position];
+
+    const bounds: RF.Rect = { ...DEFAULT_NODE_SIZES[type]({ snapGrid: 
diagram.snapGrid }), ...position };
+
+    const newNode: RF.Node<SwfDiagramNodeData> = {
+      id: nodeName,
+      type,
+      selected: selectedNodes.has(nodeName),
+      dragging: draggingNodes.has(nodeName),
+      position: snapShapePosition(diagram.snapGrid, bounds),
+      data,
+      zIndex: NODE_LAYERS.NODES,
+      style: {
+        ...snapShapeDimensions(diagram.snapGrid, bounds, 
MIN_NODE_SIZES[type]({ snapGrid: diagram.snapGrid })),
+      },
+    };
+
+    nodesById.set(newNode.id, newNode);
+    if (newNode.selected) {
+      selectedNodesById.set(newNode.id, newNode);
+      selectedNodeTypes.add(newNode.type as NodeType);
+    }
+
+    return newNode;
+  };
+
+  const nodes: RF.Node<SwfDiagramNodeData>[] = [
+    ...(definitions.states ?? []).flatMap((swfObject, index) => {
+      const newNode = ackNode(swfObject, index);
+      return newNode ? [newNode] : [];
+    }),
+  ];
+
+  // Selected edges go to the end of the array. This is necessary because 
z-index doesn't work on SVGs.
+  const sortedEdges = edges
+    .filter((e) => nodesById.has(e.source) && nodesById.has(e.target))
+    .sort((a, b) => Number(selectedEdges.has(a.id)) - 
Number(selectedEdges.has(b.id)));
+
+  // console.timeEnd("nodes");
+  if (diagram.overlays.enableNodeHierarchyHighlight) {
+    assignClassesToHighlightedHierarchyNodes(diagram._selectedNodes, 
nodesById, edgesById, swfEdges);
+  }
+
+  //clean up unused nodes position
+  if (nodesPosition) {
+    for (const id of nodeIds) {
+      if (!nodesById.get(id)) {
+        const i = nodeIds.indexOf(id);
+        if (i !== -1) {
+          nodesPosition.splice(1, i);
+          nodeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  //clean up unused edges waypoits
+  if (edgeWaypoints) {
+    for (const id of edgeIds) {
+      if (!edgesById.get(id)) {
+        const i = edgeIds.indexOf(id);
+        if (i !== -1) {
+          edgeWaypoints.splice(1, i);
+          edgeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  return {
+    swfEdges,
+    swfAdjacencyList,
+    nodes: nodes,
+    edges: sortedEdges,
+    edgesById,
+    nodesById,
+    selectedNodeTypes,
+    selectedNodesById,
+    selectedEdgesById,
+  };
+}
+
+function ackTransitionEdges(states: Specification.States, ackEdge: AckEdge) {
+  for (let i = 0; i < states.length; i++) {
+    const state = states[i];
+
+    getEdgeArgsForNode(state, i).forEach((edge) => {
+      ackEdge(edge);
+    });
+  }
+}
+
+function getEdgeArgsForNode(node: Unpacked<Specification.States>, index: 
number): EdgeArgs[] {
+  const edges: EdgeArgs[] = [];
+
+  //compensation
+  if (node.compensatedBy) {
+    edges.push(getCompensationTrasitionArgs(index, node));
+  }
+
+  switch (node.type) {
+    case "sleep": {
+      const state: Specification.ISleepstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "event": {
+      const state: Specification.IEventstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "operation": {
+      const state: Specification.IOperationstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "parallel": {
+      const state: Specification.IParallelstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }

Review Comment:
   I would aggregate these `cases`



##########
packages/serverless-workflow-editor/src/store/computed/computeDiagramData.ts:
##########
@@ -0,0 +1,524 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as RF from "reactflow";
+import { snapShapeDimensions, snapShapePosition } from 
"../../diagram/SnapGrid";
+import { EdgeType, NodeType } from "../../diagram/connections/graphStructure";
+import { SwfDiagramEdgeData } from "../../diagram/edges/SwfEdges";
+import {
+  SwfEdge,
+  SwfEdgeTypes,
+  SwfAdjacencyList,
+  EdgeVisitor,
+  NodeVisitor,
+  getAdjMatrix,
+  traverse,
+} from "../../diagram/graph/graph";
+import { getNodeTypeFromSwfObject } from "../../diagram/maths/SwfMaths";
+import { DEFAULT_NODE_SIZES, MIN_NODE_SIZES } from 
"../../diagram/nodes/SwfDefaultSizes";
+import { 
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches } 
from "../../diagram/nodes/SwfNodeSvgs";
+import { SwfDiagramNodeData, NodeSwfObjects } from 
"../../diagram/nodes/SwfNodes";
+import { TypeOrReturnType } from "../ComputedStateCache";
+import { Computed, State } from "../Store";
+import { Specification } from "@serverlessworkflow/sdk-typescript";
+import { Unpacked } from "../../tsExt/tsExt";
+
+export const NODE_LAYERS = {
+  NODES: 1000, // We need a difference > 1000 here, since ReactFlow will add 
1000 to the z-index when a node is selected.
+};
+
+interface EdgeArgs {
+  id: string;
+  swfObject: SwfDiagramEdgeData["swfObject"];
+  type: EdgeType;
+  source: string;
+  target: string;
+}
+
+type AckEdge = (args: EdgeArgs) => RF.Edge<SwfDiagramEdgeData>;
+
+type AckNode = (swfObject: NodeSwfObjects, index: number) => 
RF.Node<SwfDiagramNodeData> | undefined;
+
+export function computeDiagramData(
+  diagram: State["diagram"],
+  definitions: State["swf"]["model"],
+  indexedSwf: TypeOrReturnType<Computed["indexedSwf"]>,
+  nodeIds: Array<string>,
+  nodesPosition: Array<RF.XYPosition>,
+  edgeIds: Array<string>,
+  edgeWaypoints: Array<RF.XYPosition[]>,
+  requiresLayout?: boolean
+) {
+  // console.time("nodes");
+  
___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag
 =
+    
!___NASTY_HACK_FOR_SAFARI_to_force_redrawing_svgs_and_avoid_repaint_glitches.flag;
+
+  const selectedNodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const selectedEdgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const selectedNodeTypes = new Set<NodeType>();
+  const nodesById = new Map<string, RF.Node<SwfDiagramNodeData>>();
+  const edgesById = new Map<string, RF.Edge<SwfDiagramEdgeData>>();
+  const edges: RF.Edge<SwfDiagramEdgeData>[] = [];
+  const swfEdges: SwfEdge[] = [];
+  const swfAdjacencyList: SwfAdjacencyList = new Map();
+
+  if (requiresLayout && (!nodeIds || nodeIds.length == 0)) {
+    return {
+      swfEdges,
+      swfAdjacencyList,
+      nodes: [] as RF.Node<SwfDiagramNodeData>[],
+      edges,
+      edgesById,
+      nodesById,
+      selectedNodeTypes,
+      selectedNodesById,
+      selectedEdgesById,
+    };
+  }
+
+  const { selectedNodes, draggingNodes, selectedEdges } = {
+    selectedNodes: new Set(diagram._selectedNodes),
+    draggingNodes: new Set(diagram.draggingNodes),
+    selectedEdges: new Set(diagram._selectedEdges),
+  };
+
+  // console.time("edges");
+  const ackEdge: AckEdge = ({ id, type, swfObject, source, target }) => {
+    const data = {
+      swfObject,
+      swfEdge: id ? indexedSwf.swfEdgesBySwfRef.get(id) : undefined,
+      swfSource: indexedSwf.swfNodesByHref.get(source),
+      swfTarget: indexedSwf.swfNodesByHref.get(target),
+    };
+
+    const edge: RF.Edge<SwfDiagramEdgeData> = {
+      data,
+      id,
+      type,
+      source,
+      target,
+      selected: selectedEdges.has(id),
+    };
+
+    edgesById.set(edge.id, edge);
+    if (edge.selected) {
+      selectedEdgesById.set(edge.id, edge);
+    }
+
+    edges.push(edge);
+
+    swfEdges.push({ id, sourceId: source, targetId: target, swfObject });
+
+    const targetAdjancyList = swfAdjacencyList.get(target);
+    if (!targetAdjancyList) {
+      swfAdjacencyList.set(target, { dependencies: new Set([source]) });
+    } else {
+      targetAdjancyList.dependencies.add(source);
+    }
+
+    return edge;
+  };
+
+  // trasitions
+  ackTransitionEdges(definitions.states, ackEdge);
+
+  // console.timeEnd("edges");
+
+  // nodes
+  const ackNode: AckNode = (swfObject, index) => {
+    const type = getNodeTypeFromSwfObject(swfObject);
+    if (!type) {
+      return undefined;
+    }
+
+    const nodeName = swfObject!.name!;
+
+    const data: SwfDiagramNodeData = {
+      swfObject,
+      index,
+      parentRfNode: undefined,
+    };
+
+    // if there is no position calculated for the node in the state go for x:0 
y:0
+    const i = nodeIds.indexOf(nodeName);
+    const position = nodeIds.indexOf(nodeName) === -1 ? { x: 0, y: 0 } : 
nodesPosition[i];
+    nodeIds = [...nodeIds, nodeName];
+    nodesPosition = [...nodesPosition, position];
+
+    const bounds: RF.Rect = { ...DEFAULT_NODE_SIZES[type]({ snapGrid: 
diagram.snapGrid }), ...position };
+
+    const newNode: RF.Node<SwfDiagramNodeData> = {
+      id: nodeName,
+      type,
+      selected: selectedNodes.has(nodeName),
+      dragging: draggingNodes.has(nodeName),
+      position: snapShapePosition(diagram.snapGrid, bounds),
+      data,
+      zIndex: NODE_LAYERS.NODES,
+      style: {
+        ...snapShapeDimensions(diagram.snapGrid, bounds, 
MIN_NODE_SIZES[type]({ snapGrid: diagram.snapGrid })),
+      },
+    };
+
+    nodesById.set(newNode.id, newNode);
+    if (newNode.selected) {
+      selectedNodesById.set(newNode.id, newNode);
+      selectedNodeTypes.add(newNode.type as NodeType);
+    }
+
+    return newNode;
+  };
+
+  const nodes: RF.Node<SwfDiagramNodeData>[] = [
+    ...(definitions.states ?? []).flatMap((swfObject, index) => {
+      const newNode = ackNode(swfObject, index);
+      return newNode ? [newNode] : [];
+    }),
+  ];
+
+  // Selected edges go to the end of the array. This is necessary because 
z-index doesn't work on SVGs.
+  const sortedEdges = edges
+    .filter((e) => nodesById.has(e.source) && nodesById.has(e.target))
+    .sort((a, b) => Number(selectedEdges.has(a.id)) - 
Number(selectedEdges.has(b.id)));
+
+  // console.timeEnd("nodes");
+  if (diagram.overlays.enableNodeHierarchyHighlight) {
+    assignClassesToHighlightedHierarchyNodes(diagram._selectedNodes, 
nodesById, edgesById, swfEdges);
+  }
+
+  //clean up unused nodes position
+  if (nodesPosition) {
+    for (const id of nodeIds) {
+      if (!nodesById.get(id)) {
+        const i = nodeIds.indexOf(id);
+        if (i !== -1) {
+          nodesPosition.splice(1, i);
+          nodeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  //clean up unused edges waypoits
+  if (edgeWaypoints) {
+    for (const id of edgeIds) {
+      if (!edgesById.get(id)) {
+        const i = edgeIds.indexOf(id);
+        if (i !== -1) {
+          edgeWaypoints.splice(1, i);
+          edgeIds.splice(1, i);
+        }
+      }
+    }
+  }
+
+  return {
+    swfEdges,
+    swfAdjacencyList,
+    nodes: nodes,
+    edges: sortedEdges,
+    edgesById,
+    nodesById,
+    selectedNodeTypes,
+    selectedNodesById,
+    selectedEdgesById,
+  };
+}
+
+function ackTransitionEdges(states: Specification.States, ackEdge: AckEdge) {
+  for (let i = 0; i < states.length; i++) {
+    const state = states[i];
+
+    getEdgeArgsForNode(state, i).forEach((edge) => {
+      ackEdge(edge);
+    });
+  }
+}
+
+function getEdgeArgsForNode(node: Unpacked<Specification.States>, index: 
number): EdgeArgs[] {
+  const edges: EdgeArgs[] = [];
+
+  //compensation
+  if (node.compensatedBy) {
+    edges.push(getCompensationTrasitionArgs(index, node));
+  }
+
+  switch (node.type) {
+    case "sleep": {
+      const state: Specification.ISleepstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "event": {
+      const state: Specification.IEventstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "operation": {
+      const state: Specification.IOperationstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "parallel": {
+      const state: Specification.IParallelstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "switch": {
+      const state: Specification.Switchstate = node;
+
+      if ("dataConditions" in state) {
+        const switchData: Specification.IDatabasedswitchstate = state;
+        if (switchData.dataConditions) {
+          getConditionTrasitionsArgs(index, node, 
switchData.dataConditions).forEach((dataConditions) =>
+            edges.push(dataConditions)
+          );
+        }
+      } else {
+        const switchEvent: Specification.IEventbasedswitchstate = state;
+        if (switchEvent.eventConditions) {
+          getConditionTrasitionsArgs(index, node, 
switchEvent.eventConditions).forEach((eventConditions) =>
+            edges.push(eventConditions)
+          );
+        }
+      }
+
+      if (state.defaultCondition!.transition) {
+        edges.push(getDefaultTransitionArgs(index, state, 
state.defaultCondition.transition));
+      }
+
+      if (state.onErrors) {
+        getErrorTrasitionsArgs(index, state, 
state.onErrors).forEach((errorargs) => edges.push(errorargs));
+      }
+
+      break;
+    }
+    case "inject": {
+      const state: Specification.IInjectstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    case "foreach": {
+      const state: Specification.IForeachstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    case "callback": {
+      const state: Specification.ICallbackstate = node;
+
+      if (state.transition) {
+        edges.push(getTransitionArgs(index, state, state.transition));
+      }
+
+      break;
+    }
+    default: {
+      break;
+    }
+  }
+
+  return edges;
+}
+
+function getCompensationTrasitionArgs(index: number, node: 
Unpacked<Specification.States>): EdgeArgs {
+  return buildEdgeArgs(index, node, node.compensatedBy!, "edge_compensation", 
"compensationTransition");
+}
+
+function getTransitionArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  transition: string | Specification.ITransition
+): EdgeArgs {
+  let transitionStr: string | undefined = undefined;
+  if (typeof transition === "object") {
+    transitionStr = transition.nextState;
+  } else {
+    transitionStr = transition;
+  }
+
+  return buildEdgeArgs(index, node, transitionStr, "edge_transition", 
"transition");
+}
+
+function getErrorTrasitionsArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  errors: Specification.IError[]
+): EdgeArgs[] {
+  const edgeArgs: EdgeArgs[] = [];
+
+  errors.forEach((error) => {
+    let transitionStr: string | undefined = undefined;
+    if (typeof error.transition === "object") {
+      transitionStr = error.transition.nextState;
+    } else {
+      transitionStr = error.transition;
+    }
+
+    edgeArgs.push(buildEdgeArgs(index, node, transitionStr, "edge_error", 
"errorTransition"));
+  });
+
+  return edgeArgs;
+}
+
+function getDefaultTransitionArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  transition: string | Specification.ITransition
+): EdgeArgs {
+  let transitionStr: string | undefined = undefined;
+  if (typeof transition === "object") {
+    transitionStr = transition.nextState;
+  } else {
+    transitionStr = transition;
+  }
+
+  return buildEdgeArgs(index, node, transitionStr, "edge_defaultCondition", 
"defaultConditionTransition");
+}
+
+function getConditionTrasitionsArgs(
+  index: number,
+  node: Unpacked<Specification.States>,
+  conditions: Specification.Datacondition[] | Specification.Eventcondition[]
+): EdgeArgs[] {
+  const conditionTransitions: EdgeArgs[] = [];
+
+  conditions.forEach((condition) => {
+    // Specification.Enddeventcondition won't be created for now
+
+    if (condition instanceof Specification.Transitioneventcondition) {
+      const transitionEventCondition = condition as 
Specification.ITransitioneventcondition;
+
+      let transitionStr: string | undefined = undefined;
+      if (typeof transitionEventCondition.transition === "object") {
+        transitionStr = transitionEventCondition.transition.nextState;
+      } else {
+        transitionStr = transitionEventCondition.transition;
+      }
+
+      conditionTransitions.push(
+        buildEdgeArgs(index, node, transitionStr, "edge_eventCondition", 
"eventConditionTransition")
+      );
+    } else {
+      // Specification.Enddatacondition won't be created for now

Review Comment:
   I wonder if we should create a GH Issue not to forget this.
   You can skip this suggestion if not necessary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to