From c120dffbf07fbc49b642d6d0cdf9ac10d2503945 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Tue, 28 Jun 2022 16:22:24 +0100 Subject: [PATCH] Add option flag `reimport` to `importNodes` fixes #3699 --- .../@node-red/editor-client/src/js/nodes.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/nodes.js b/packages/node_modules/@node-red/editor-client/src/js/nodes.js index 052fad558..45804c29e 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/nodes.js +++ b/packages/node_modules/@node-red/editor-client/src/js/nodes.js @@ -1654,21 +1654,19 @@ RED.nodes = (function() { * Options: * - generateIds - whether to replace all node ids * - 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. * - id:import - import as-is * - id:copy - import with new id * - id:replace - import over the top of existing */ function importNodes(newNodesObj,options) { // createNewIds,createMissingWorkspace) { - options = options || { - generateIds: false, - addFlow: false, - } - options.importMap = options.importMap || {}; - - var createNewIds = options.generateIds; - var createMissingWorkspace = options.addFlow; + const defOpts = { generateIds: false, addFlow: false, reimport: false, importMap: {} } + options = Object.assign({}, defOpts, options) + const createNewIds = options.generateIds; + const reimport = (!createNewIds && !!options.reimport) + const createMissingWorkspace = options.addFlow; var i; var n; var newNodes; @@ -1969,7 +1967,8 @@ RED.nodes = (function() { } } } 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; } } @@ -2070,7 +2069,8 @@ RED.nodes = (function() { node.id = getID(); } else { 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 (missingWorkspace === null) { missingWorkspace = RED.workspaces.add(null,true); @@ -2769,7 +2769,7 @@ RED.nodes = (function() { // Force the redraw to be synchronous so the view updates // *now* and removes the unknown node RED.view.redraw(true, true); - var result = importNodes(reimportList,{generateIds:false}); + var result = importNodes(reimportList,{generateIds:false, reimport: true}); var newNodeMap = {}; result.nodes.forEach(function(n) { newNodeMap[n.id] = n;