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

Save groups in the graph #455

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Save groups in the graph #455

wants to merge 4 commits into from

Conversation

georgebuciuman
Copy link
Contributor

@georgebuciuman georgebuciuman commented Jul 16, 2024

This PR include:

  • saving the groups in the graph
  • fixing duplicate for groups
  • fixing create subgraph from a selection that contains a group

Fixes #418

Screen.Recording.2024-07-16.at.18.37.42.mov
Screen.Recording.2024-07-18.at.12.34.02.mov

@georgebuciuman georgebuciuman requested a review from SorsOps July 16, 2024 15:42
Copy link

changeset-bot bot commented Jul 16, 2024

⚠️ No Changeset found

Latest commit: 2648a32

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

Failed to generate code suggestions for PR

Copy link
Collaborator

@roppazvan roppazvan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a comment: Do we really need a group node ? Maybe we could just save the ids in the annotations an recreate the group nodes on load.

graphNode.annotations[ypos] = node.position.y - parentPosition.y + GROUP_NODE_PADDING;
graphNode.annotations[width] = reactFlowNodesMap.get(node.id)?.width || 200;
graphNode.annotations[height] = reactFlowNodesMap.get(node.id)?.height || 100;
graphNode.annotations['parentId'] = flowNode.id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be scoped to indicate its for the UI

nodes.forEach((node) => {
const graphNode = graph.getNode(node.id);
if (graphNode) {
graphNode.annotations[xpos] = node.position.x - parentPosition.x + GROUP_NODE_PADDING;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would these persist if they are changed afterwards ? We don't seem to ever recompute these on changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed. After group creation you don't need to update this. If you move the node inside the group it will automatically change it's xpos and ypos. If you move the group, xpos and ypos of nodes inside should still be the same

const selectedNodeIds = selectedNodes
.reduce((acc, node) => {
if (node.type !== GROUP) {
return [...acc, node.id];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wouldn't need to spread each time, this would create a new array, since its bound to the reduce, just push the new node and return the accumulator

});
});

const reactFlowNodesMap = new Map<string, Node>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be called each render which will hamper performance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inside the onGroup callback. Will be called only once when you group nodes

@@ -294,9 +336,11 @@ export const SelectionContextMenu = ({ id, nodes }: INodeContextMenuProps) => {
duplicateNodes(selectedNodeIds);
};

const hasGroup = selectedNodes.some((node) => node.type === GROUP);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memoized

@@ -0,0 +1,8 @@
import { Node } from '../../programmatic/node.js';

export default class NodeDefinition extends Node {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add all this. This node does nothing, we've cluttered a lot of the code and we're likely going to get inconsistencies from the annotations not being updated correctly between reactflow. We should rather just use the finalizers for serialization and deserialization and store the group info as annotations until we make a more concrete construct that actually does stuff.

return [...acc, nodeId];
}, [] as string[]);

console.log('duplicate');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@SorsOps SorsOps changed the base branch from master to next July 30, 2024 09:33
Base automatically changed from next to master October 31, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating a subgraph of a group causing a crash
3 participants