Skip to content

Commit

Permalink
[4451] Keep using the same node after a refresh if possible
Browse files Browse the repository at this point in the history
Bug: #4451
Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi authored and sbegaudeau committed Mar 6, 2025
1 parent 51a1cf0 commit b4665bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Except for the specific case where `cause === 'refresh'` in `DiagramRenderer` (w
- https://github.com/eclipse-sirius/sirius-web/issues/4641[#4641] [form] Remove front dependency between form and table
- https://github.com/eclipse-sirius/sirius-web/issues/4635[#4635] [sirius-web] Derive the project semantic data from the project id
- https://github.com/eclipse-sirius/sirius-web/issues/4469[#4469] [table] Remove useless mutations send at the table opening
- https://github.com/eclipse-sirius/sirius-web/issues/4451[#4451] [diagram] Keep using the same node after a refresh if possible in order to avoid rerendering all the nodes after converting the diagram



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ReactFlow,
ReactFlowProps,
applyNodeChanges,
useReactFlow,
useStoreApi,
} from '@xyflow/react';
import React, { MouseEvent as ReactMouseEvent, memo, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
Expand Down Expand Up @@ -123,11 +124,31 @@ export const DiagramRenderer = memo(({ diagramRefreshedEventPayload }: DiagramRe

useInitialFitToScreen();

const { getNode } = useReactFlow<Node<NodeData>, Edge<EdgeData>>();
const store = useStoreApi<Node<NodeData>, Edge<EdgeData>>();

useEffect(() => {
const { diagram, cause } = diagramRefreshedEventPayload;
const convertedDiagram: Diagram = convertDiagram(diagram, nodeConverters, diagramDescription, edgeType);

convertedDiagram.nodes = convertedDiagram.nodes.map((convertedNode) => {
const currentNode = getNode(convertedNode.id);
if (
currentNode &&
(convertedNode.position.x !== currentNode.position.x ||
convertedNode.position.y !== currentNode.position.y ||
convertedNode.width !== currentNode.width ||
convertedNode.height !== currentNode.height ||
(currentNode && JSON.stringify(convertedNode.data) !== JSON.stringify(currentNode.data)))
) {
return convertedNode;
} else if (currentNode) {
return currentNode;
} else {
return convertedNode;
}
});

if (cause === 'layout') {
const diagramElementIds: string[] = [
...getNodes().map((node) => node.data.targetObjectId),
Expand Down

0 comments on commit b4665bb

Please sign in to comment.