tiagobento commented on code in PR #3162:
URL: 
https://github.com/apache/incubator-kie-tools/pull/3162#discussion_r2116115745


##########
packages/dmn-editor/src/diagram/Diagram.tsx:
##########
@@ -813,6 +813,119 @@ export const Diagram = React.forwardRef<DiagramRef, { 
container: React.RefObject
                         }
                       }
                     }
+                    if (node.type === NODE_TYPES.decisionService) {
+                      const drds = 
state.dmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"] ?? [];
+                      const drgElements = 
state.dmn.model.definitions.drgElement!;
+                      for (let i = 0; i < drds.length; i++) {
+                        if (i === state.computed(state).getDrdIndex()) {
+                          continue;
+                        }
+                        const _indexedDrd = computeIndexedDrd(
+                          state.dmn.model.definitions["@_namespace"],
+                          state.dmn.model.definitions,
+                          i
+                        );
+                        const dsShape = 
_indexedDrd.dmnShapesByHref.get(node.id);
+                        if (dsShape && dsShape["dc:Bounds"] && 
!node.data.shape["@_isCollapsed"]) {
+                          dsShape["dc:Bounds"]["@_width"] = 
change.dimensions?.width ?? 0;
+                          dsShape["dc:Bounds"]["@_height"] = 
change.dimensions?.height ?? 0;
+                        }
+
+                        // Apply delta shift to neighbouring nodes in other DRD
+                        const decisionService = node.data.dmnObject as 
Normalized<DMN15__tDecisionService>;
+                        const { containedDecisionHrefsRelativeToThisDmn } =
+                          getDecisionServicePropertiesRelativeToThisDmn({
+                            thisDmnsNamespace: 
state.dmn.model.definitions["@_namespace"],
+                            decisionService,
+                            decisionServiceNamespace:
+                              node.data.dmnObjectNamespace ?? 
state.dmn.model.definitions["@_namespace"],
+                          });
+
+                        const decisionsInDecisionServiceInDrd: string[] = [];
+                        for (const elem of drgElements) {
+                          if (elem.__$$element === "decisionService") {
+                            decisionsInDecisionServiceInDrd.push(
+                              ...(elem.outputDecision ?? []).map((od) => 
od["@_href"]),
+                              ...(elem.encapsulatedDecision ?? []).map((od) => 
od["@_href"])
+                            );
+                          }
+                        }
+
+                        for (const [key] of 
_indexedDrd.dmnShapesByHref.entries()) {
+                          if (key !== node.id && 
!containedDecisionHrefsRelativeToThisDmn.includes(key)) {
+                            const nodeShape = 
_indexedDrd.dmnShapesByHref.get(key);
+                            if (nodeShape && nodeShape["dc:Bounds"] && dsShape 
&& !node.data.shape["@_isCollapsed"]) {
+                              const nodeShapeWidth =
+                                nodeShape["dc:Bounds"]!["@_x"] + 
nodeShape["dc:Bounds"]!["@_width"];
+                              const nodeShapeHeight =
+                                nodeShape["dc:Bounds"]!["@_y"] + 
nodeShape["dc:Bounds"]!["@_height"];
+                              const dsShapeWidth =
+                                dsShape["dc:Bounds"]!["@_x"] + 
dsShape["dc:Bounds"]!["@_width"] - deltaWidth;
+                              const dsShapeHeight =
+                                dsShape["dc:Bounds"]!["@_y"] + 
dsShape["dc:Bounds"]!["@_height"] - deltaHeight;
+
+                              const drgElem = drgElements.filter(
+                                (item) => item["@_id"] === 
nodeShape["@_dmnElementRef"]
+                              );
+
+                              const shiftXPosition =
+                                nodeShape["dc:Bounds"]["@_x"] >= dsShapeWidth 
&&
+                                (nodeShapeHeight >= 
dsShape["dc:Bounds"]!["@_y"] ||
+                                  nodeShape["dc:Bounds"]["@_y"] <= 
dsShapeHeight);
+
+                              const shiftYPosition =
+                                nodeShape["dc:Bounds"]["@_y"] >= dsShapeHeight 
&&
+                                (dsShapeWidth <= nodeShapeWidth || 
nodeShape["dc:Bounds"]!["@_x"] <= nodeShapeWidth);
+
+                              const bounds = nodeShape["dc:Bounds"];
+
+                              if (drgElem[0].__$$element === 
"decisionService") {
+                                const containedDecisions = [
+                                  ...(drgElem[0].outputDecision ?? 
[]).map((od) => od["@_href"]),
+                                  ...(drgElem[0].encapsulatedDecision ?? 
[]).map((od) => od["@_href"]),
+                                ];
+
+                                if (shiftXPosition || shiftYPosition) {
+                                  const divider = 
nodeShape["dmndi:DMNDecisionServiceDividerLine"];
+                                  const waypoints = divider?.["di:waypoint"];
+                                  // Handles position shift of decision service
+                                  if (shiftXPosition) {
+                                    bounds["@_x"] += deltaWidth;
+                                    waypoints![0]["@_x"] += deltaWidth;
+                                    waypoints![1]["@_x"] += bounds["@_width"] 
+ deltaWidth;

Review Comment:
   I'm afraid this can lead to problems, as there can be multiple waypoints on 
edges. 



##########
packages/dmn-editor/src/diagram/nodes/Nodes.tsx:
##########
@@ -1161,10 +1161,34 @@ export const DecisionServiceNode = React.memo(
         });
 
       selection.call(dragHandler);
+
+      dmnEditorStoreApi.setState((state) => {
+        const dividerLineLocalY = getDecisionServiceDividerLineLocalY(shape);
+        const drds = 
state.dmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"] ?? [];
+        for (let i = 0; i < drds.length; i++) {
+          if (i === state.computed(state).getDrdIndex()) {
+            continue;
+          }
+          const _indexedDrd = computeIndexedDrd(
+            state.dmn.model.definitions["@_namespace"],
+            state.dmn.model.definitions,
+            i
+          );
+          const dsShape = _indexedDrd.dmnShapesByHref.get(id);
+          const dsShapeYPosition = dsShape?.["dc:Bounds"]?.["@_y"];
+          if (dsShape && dsShape["dmndi:DMNDecisionServiceDividerLine"]) {
+            
dsShape["dmndi:DMNDecisionServiceDividerLine"]!["di:waypoint"]![0]["@_y"] =
+              dsShapeYPosition! + dividerLineLocalY;
+            
dsShape["dmndi:DMNDecisionServiceDividerLine"]!["di:waypoint"]![1]["@_y"] =
+              dsShapeYPosition! + dividerLineLocalY;

Review Comment:
   Same comment here on multiple waypoints.



##########
packages/dmn-editor/src/diagram/Diagram.tsx:
##########
@@ -813,6 +813,119 @@ export const Diagram = React.forwardRef<DiagramRef, { 
container: React.RefObject
                         }
                       }
                     }
+                    if (node.type === NODE_TYPES.decisionService) {

Review Comment:
   Can you add a comment here saying that this is done due to the multiple DRDs 
strategy we have for Decision Services? It would also be nice to add such a 
comment on other places that you changed recently that add extra logic to 
account for the fact that we want to keep the depiction of Decision Services 
consistent across all DRDs. Thank you!



##########
packages/dmn-editor/src/diagram/nodes/Nodes.tsx:
##########
@@ -1161,10 +1161,34 @@ export const DecisionServiceNode = React.memo(
         });
 
       selection.call(dragHandler);
+
+      dmnEditorStoreApi.setState((state) => {
+        const dividerLineLocalY = getDecisionServiceDividerLineLocalY(shape);
+        const drds = 
state.dmn.model.definitions["dmndi:DMNDI"]?.["dmndi:DMNDiagram"] ?? [];
+        for (let i = 0; i < drds.length; i++) {
+          if (i === state.computed(state).getDrdIndex()) {
+            continue;
+          }
+          const _indexedDrd = computeIndexedDrd(
+            state.dmn.model.definitions["@_namespace"],
+            state.dmn.model.definitions,
+            i
+          );
+          const dsShape = _indexedDrd.dmnShapesByHref.get(id);
+          const dsShapeYPosition = dsShape?.["dc:Bounds"]?.["@_y"];
+          if (dsShape && dsShape["dmndi:DMNDecisionServiceDividerLine"]) {
+            
dsShape["dmndi:DMNDecisionServiceDividerLine"]!["di:waypoint"]![0]["@_y"] =
+              dsShapeYPosition! + dividerLineLocalY;
+            
dsShape["dmndi:DMNDecisionServiceDividerLine"]!["di:waypoint"]![1]["@_y"] =
+              dsShapeYPosition! + dividerLineLocalY;
+          }
+        }
+      });

Review Comment:
   Why use a separate `setState` call?



-- 
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