From 2c6cda1f27b5b5bab538f2f605209768e2d6b3ef Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 2 Nov 2020 21:13:52 +0000 Subject: [PATCH] Handle import errors on initial load and report to user --- .../editor-client/locales/en-US/editor.json | 7 +++++-- .../@node-red/editor-client/src/js/nodes.js | 21 ++++++++++++++++--- .../@node-red/editor-client/src/js/red.js | 20 +++++++++++++----- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json index e68fe32f9..a26717b2f 100755 --- a/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json +++ b/packages/node_modules/@node-red/editor-client/locales/en-US/editor.json @@ -42,7 +42,8 @@ "loadNodeCatalogs": "Loading Node catalogs", "loadNodes": "Loading Nodes __count__", "loadFlows": "Loading Flows", - "importFlows": "Adding Flows to workspace" + "importFlows": "Adding Flows to workspace", + "importError": "

Error adding flows

__message__

" }, "workspace": { "defaultName": "Flow __number__", @@ -207,6 +208,8 @@ "download": "Download", "importUnrecognised": "Imported unrecognised type:", "importUnrecognised_plural": "Imported unrecognised types:", + "importDuplicate": "Imported duplicate node:", + "importDuplicate_plural": "Imported duplicate nodes:", "nodesExported": "Nodes exported to clipboard", "nodesImported": "Imported:", "nodeCopied": "__count__ node copied", @@ -545,7 +548,7 @@ "sortRecent": "recent", "more": "+ __count__ more", "upload": "Upload module tgz file", - "refresh": "Refresh module list", + "refresh": "Refresh module list", "errors": { "catalogLoadFailed": "

Failed to load node catalogue.

Check the browser console for more information

", "installFailed": "

Failed to install: __module__

__message__

Check the log for more information

", 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 1055c20ad..0d620e70a 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 @@ -1107,8 +1107,9 @@ RED.nodes = (function() { if (!options.generateIds) { if (!options.importMap[id]) { // No conflict resolution for this node - if (nodes[id] || configNodes[id] || workspaces[id] || subflows[id] || groups[id]) { - existingNodes.push(id); + var existing = nodes[id] || configNodes[id] || workspaces[id] || subflows[id] || groups[id]; + if (existing) { + existingNodes.push({existing:existing, imported:n}); } } else if (options.importMap[id] === "replace") { nodesToReplace.push(n); @@ -1120,7 +1121,21 @@ RED.nodes = (function() { }) if (existingNodes.length > 0) { - var existingNodesError = new Error(); + var errorMessage = RED._("clipboard.importDuplicate",{count:existingNodes.length}); + var nodeList = $("