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

Refactoring the RED.nodes.import() function #4757

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

GogoVega
Copy link
Contributor

@GogoVega GogoVega commented Jun 11, 2024

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

Refactoring the importNodes function.

Resolves also:

  • Bad number of node.users for Config Node:

    • Deleting a Node inside a Subflow does not update the number of users.
    • Replacing a Config Node overwrites the user list to empty.
  • 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:

    • If the definition is missing, the Node will be marked as unknown - which allows to double click and have dialog box and be able to export this Node.
    • When adding the definition, existing instances into the workspace are updated.
    • A Node missing into the Subflow import is now handled (to avoid create link)
  • Ensure activeWorkspace can no longer be equal to 0.

Other functions modified:

  • updateConfigNodeUsers - for either add or remove and either trigger the event
  • RED.view.importNodes() - overwrite importMap to undefined

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

Copy link
Contributor Author

@GogoVega GogoVega left a 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.

Comment on lines 2041 to +2042
// 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?
Copy link
Contributor Author

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();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right place?

Comment on lines 2182 to 2184
if (activeWorkspace === 0) { // TODO: Why?
activeWorkspace = node.id;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In which case?

@knolleary
Copy link
Member

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.

@GogoVega
Copy link
Contributor Author

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 😉

@GogoVega
Copy link
Contributor Author

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.

Copy link
Contributor Author

@GogoVega GogoVega left a 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" });
Copy link
Contributor Author

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.

Suggested change
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);
Copy link
Contributor Author

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]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can be improved by:

Suggested change
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`
Copy link
Contributor Author

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?
Copy link
Contributor Author

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.

@knolleary
Copy link
Member

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.

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.

None yet

2 participants