-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Refactoring the RED.nodes.import()
function
#4757
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for your answers.
// No conflict resolution for this node | ||
var existing = allNodes.getNode(id) || configNodes[id] || workspaces[id] || subflows[id] || groups[id] || junctions[id]; | ||
if (existing) { | ||
existingNodes.push({existing:existing, imported:n}); | ||
// TODO: Sure? |
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.
Is the comment correct? There is a conflict because it's an existing node.
} | ||
|
||
// TODO: Right place? | ||
RED.workspaces.refresh(); |
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.
Right place?
if (activeWorkspace === 0) { // TODO: Why? | ||
activeWorkspace = 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.
In which case?
This function is so central to the editor, I am wary of anyone else doing a large refactoring of it. It contains 10 years of built up logic, and in many cases there are good reasons for the order things are done in. We are also trying to get 4.0 shipped. I simply don't have bandwidth to give this work the attention it needs any time soon given there is no compelling reason to do it. I will try to take a look at some point, but I can't say when. |
No worries, focus on v4 and for my part I'll continue here - It's going to take me a while, then test it thoroughly. Given all that this involves, I had not planned to bring it in for v4. So come back here as soon as you can but without pressure. Thanks 😉 |
Do we still have to handle the import of singleton config node? If so, the only currently unhandled case would be that multiple nodes use the same config node - this config node will need to be copied and re-associated with each 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.
Hi Nick,
These points remain to be discussed.
Tell me if you want me to target the code for fixes to help you review this very long PR?
} | ||
if (n.z == id) { | ||
if (n.z === id || !keepInstanceNodes && n.type === "subflow:" + id) { | ||
RED.nodes.updateConfigNodeUsers(n, { emitEvent: false, action: "remove" }); |
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.
The event must (should) be triggered.
RED.nodes.updateConfigNodeUsers(n, { emitEvent: false, action: "remove" }); | |
RED.nodes.updateConfigNodeUsers(n, { action: "remove" }); |
// If 'wires' is longer than outputs, clip wires | ||
console.log("Warning: node.wires longer than node.outputs - trimming wires:", node.id, " wires:", node.wires.length, " outputs:", node.outputs); | ||
// TODO: Pas dans l'autre sens ? | ||
newNode.wires = newNode.wires.slice(0, newNode.outputs); |
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 would remove the last elements instead of the first.
addWorkspace(recoveryWorkspace); | ||
RED.workspaces.add(recoveryWorkspace); | ||
// Put the recovery workspace at the first position | ||
newWorkspaces.splice(0, 1, recoveryWorkspace, newWorkspaces[0]); |
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.
Can be improved by:
newWorkspaces.splice(0, 1, recoveryWorkspace, newWorkspaces[0]); | |
newWorkspaces.unshift(recoveryWorkspace); |
let def = registry.getNodeType(node.type); | ||
|
||
// Update the Node definition for Subflow instance | ||
// TODO: A thing with `node.i` |
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.
See what node.i
is still used for
node.outputs = 1 | ||
node.w = 0; | ||
node.h = 0; | ||
// TODO: Group Node has config as category - why? |
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.
The group def is really strange - should is in the types like the others but that's not the point of this PR.
To be absolutely direct - as I was in an earlier comment - I'm not sure how to move forward with this PR. It is massive and changes such an important part of the editor code base. The PR not only moves code around, but also changes the logic in different places due to the various fixes you've identified. So not only do I have to understand how you've moved the code around, I need to understand why you've changed any particular bits of logic - which could be a bug you've fixed or a bug you've introduced. I simply don't know when I will have the time needed to focus on this. |
Proposed changes
Refactoring the
importNodes
function.Resolves also:
Bad number of
node.users
for Config Node:A Node that has an invalid number of inputs/outputs (dynamic number) is not correctly handled.
When copying a Subflow (tab), the name is not updated (addition of the copy count)
When importing a Subflow:
Ensure
activeWorkspace
can no longer be equal to 0.Other functions modified:
updateConfigNodeUsers
- for either add or remove and either trigger the eventRED.view.importNodes()
- overwrite importMap to undefinedChecklist
npm run test
to verify the unit tests pass