ljmotta commented on code in PR #2254:
URL: 
https://github.com/apache/incubator-kie-tools/pull/2254#discussion_r1578043764


##########
packages/dmn-editor/src/propertiesPanel/ShapeOptions.tsx:
##########
@@ -238,8 +289,22 @@ export function ShapeOptions({
     };
   }, [setShapeStyles, temporaryFillColor]);
 
+  useEffect(() => {
+    const timeout = setTimeout(() => {
+      if (currentlyReShapedNodeId !== nodeIds[0]) {
+        setWidth(boundWidth);
+        setHeight(boundHeight);
+        setCurrentlyReShapedNodeId(nodeIds[0]);
+      }
+    }, 0);
+
+    return () => {
+      clearTimeout(timeout);
+    };
+  }, [boundWidth, boundHeight, currentlyReShapedNodeId, nodeIds]);

Review Comment:
   Why we need the `setTimeout` here? One important concept of the `useEffect` 
is it runs everytime a value of the dependency array change. Meaning if the 
`boundWidth` change, it will re-run, calling the `setHeight` and 
`setCurrentlyReShapedNodeId`. To avoid this, we need to break this useEffect 
into multiple ones.
   
   ```ts
   useEffect(() => {
     setWidth(boundWidth);
   }, [boundWidth])
   ```



##########
packages/dmn-editor/src/propertiesPanel/ShapeOptions.tsx:
##########
@@ -63,6 +68,12 @@ export function ShapeOptions({
   const boundPositionX = useMemo(() => +(shapeBound?.["@_x"]?.toFixed(2) ?? 
""), [shapeBound]);
   const boundPositionY = useMemo(() => +(shapeBound?.["@_y"]?.toFixed(2) ?? 
""), [shapeBound]);
 
+  // this variable was introduced because of scenarios, when user switches 
between nodes without closing and reopening the properties panel
+  const [currentlyReShapedNodeId, setCurrentlyReShapedNodeId] = 
useState<string>(nodeIds[0]);

Review Comment:
   I'm not sure we need this, could you share which valeus are not updated when 
we select another node? Changing the selected node should update all the 
`bound*` constants.



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