Merge pull request #3718 from Steve-Mcl/fix-async-node-type-reg

Add option flag `reimport` to `importNodes`
This commit is contained in:
Nick O'Leary 2022-06-29 20:22:48 +01:00 committed by GitHub
commit d37da58e87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 12 deletions

View File

@ -1654,21 +1654,19 @@ RED.nodes = (function() {
* Options: * Options:
* - generateIds - whether to replace all node ids * - generateIds - whether to replace all node ids
* - addFlow - whether to import nodes to a new tab * - addFlow - whether to import nodes to a new tab
* - importToCurrent * - reimport - if node has a .z property, dont overwrite it
* Only applicible when `generateIds` is false
* - importMap - how to resolve any conflicts. * - importMap - how to resolve any conflicts.
* - id:import - import as-is * - id:import - import as-is
* - id:copy - import with new id * - id:copy - import with new id
* - id:replace - import over the top of existing * - id:replace - import over the top of existing
*/ */
function importNodes(newNodesObj,options) { // createNewIds,createMissingWorkspace) { function importNodes(newNodesObj,options) { // createNewIds,createMissingWorkspace) {
options = options || { const defOpts = { generateIds: false, addFlow: false, reimport: false, importMap: {} }
generateIds: false, options = Object.assign({}, defOpts, options)
addFlow: false, const createNewIds = options.generateIds;
} const reimport = (!createNewIds && !!options.reimport)
options.importMap = options.importMap || {}; const createMissingWorkspace = options.addFlow;
var createNewIds = options.generateIds;
var createMissingWorkspace = options.addFlow;
var i; var i;
var n; var n;
var newNodes; var newNodes;
@ -1969,7 +1967,8 @@ RED.nodes = (function() {
} }
} }
} else { } else {
if (n.z && !workspace_map[n.z] && !subflow_map[n.z]) { const keepNodesCurrentZ = reimport && n.z && RED.workspaces.contains(n.z)
if (!keepNodesCurrentZ && n.z && !workspace_map[n.z] && !subflow_map[n.z]) {
n.z = activeWorkspace; n.z = activeWorkspace;
} }
} }
@ -2070,7 +2069,8 @@ RED.nodes = (function() {
node.id = getID(); node.id = getID();
} else { } else {
node.id = n.id; node.id = n.id;
if (node.z == null || (!workspace_map[node.z] && !subflow_map[node.z])) { const keepNodesCurrentZ = reimport && node.z && RED.workspaces.contains(node.z)
if (!keepNodesCurrentZ && (node.z == null || (!workspace_map[node.z] && !subflow_map[node.z]))) {
if (createMissingWorkspace) { if (createMissingWorkspace) {
if (missingWorkspace === null) { if (missingWorkspace === null) {
missingWorkspace = RED.workspaces.add(null,true); missingWorkspace = RED.workspaces.add(null,true);
@ -2769,7 +2769,7 @@ RED.nodes = (function() {
// Force the redraw to be synchronous so the view updates // Force the redraw to be synchronous so the view updates
// *now* and removes the unknown node // *now* and removes the unknown node
RED.view.redraw(true, true); RED.view.redraw(true, true);
var result = importNodes(reimportList,{generateIds:false}); var result = importNodes(reimportList,{generateIds:false, reimport: true});
var newNodeMap = {}; var newNodeMap = {};
result.nodes.forEach(function(n) { result.nodes.forEach(function(n) {
newNodeMap[n.id] = n; newNodeMap[n.id] = n;