Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4038] Select new diagram elements if the corresponding semantic element is selected #4039

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The new option ALWAYS allows the separator to be displayed in every case.
- https://github.com/eclipse-sirius/sirius-web/issues/4008[#4008] [diagram] Prevent `detailsEvent` to be triggered twice when selecting a multi-represented element in the diagram
- https://github.com/eclipse-sirius/sirius-web/issues/4032[#4032] [diagram] Fix an issue where separator list compartment is missing
- https://github.com/eclipse-sirius/sirius-web/issues/4028[#4028] [trees] Fixed an issue where special characters (e.g. #) could not be used in the treeId due to URL parsing limitations.
- https://github.com/eclipse-sirius/sirius-web/issues/4038[#4038] [diagram] Diagram elements which represent a _selected_ semantic element are now automatically selected when they appear

=== New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,47 +122,41 @@ export const DiagramRenderer = memo(({ diagramRefreshedEventPayload }: DiagramRe

const { nodeConverters } = useContext<NodeTypeContextValue>(NodeTypeContext);
const { fitToScreen } = useInitialFitToScreen();
const { setSelection } = useSelection();
const { selection, setSelection } = useSelection();
const { edgeType, setEdgeType } = useEdgeType();

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

const selectedNodeIds = nodes.filter((node) => node.selected).map((node) => node.id);
const selectedEdgeIds = edges.filter((edge) => edge.selected).map((edge) => edge.id);
const updateReactFlowDiagram = (diagram: Diagram) => {
const selectedSemanticElements = new Set(selection.entries.map((entry) => entry.id));
diagram.nodes.forEach((node) => (node.selected = selectedSemanticElements.has(node.data.targetObjectId)));
diagram.edges.forEach(
(edge) => (edge.selected = edge.data && selectedSemanticElements.has(edge.data.targetObjectId))
);
setEdges(diagram.edges);
setNodes(diagram.nodes);
};

if (cause === 'layout') {
convertedDiagram.nodes
.filter((node) => selectedNodeIds.includes(node.id))
.forEach((node) => (node.selected = true));
convertedDiagram.edges
.filter((edge) => selectedEdgeIds.includes(edge.id))
.forEach((edge) => (edge.selected = true));

setNodes(convertedDiagram.nodes);
setEdges(convertedDiagram.edges);
// Accept the new layout received from the backend
updateReactFlowDiagram(convertedDiagram);
fitToScreen();
} else if (cause === 'refresh') {
// Compute a new layout ourselves, use it and publish it to be applied by others
const previousDiagram: RawDiagram = {
nodes: nodes as Node<NodeData, DiagramNodeType>[],
edges,
};

layout(previousDiagram, convertedDiagram, diagramRefreshedEventPayload.referencePosition, (laidOutDiagram) => {
laidOutDiagram.nodes
.filter((node) => selectedNodeIds.includes(node.id))
.forEach((node) => (node.selected = true));
laidOutDiagram.edges
.filter((edge) => selectedEdgeIds.includes(edge.id))
.forEach((edge) => (edge.selected = true));

setNodes(laidOutDiagram.nodes);
setEdges(laidOutDiagram.edges);
updateReactFlowDiagram(laidOutDiagram);
closeAllPalettes();

synchronizeLayoutData(diagramRefreshedEventPayload.id, laidOutDiagram);
});
}
}, [diagramRefreshedEventPayload, diagramDescription, edgeType]);
}, [diagramRefreshedEventPayload, diagramDescription, edgeType, selection]);

useEffect(() => {
setEdges((oldEdges) => oldEdges.map((edge) => ({ ...edge, updatable: !!edge.selected })));
Expand Down
Loading