-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: master
Are you sure you want to change the base?
Conversation
|
Failed to generate code suggestions for PR |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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>( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
This PR include:
Fixes #418
Screen.Recording.2024-07-16.at.18.37.42.mov
Screen.Recording.2024-07-18.at.12.34.02.mov