From bb4b252401336a27326961425857fbc7daaa56a2 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Thu, 28 Jan 2021 23:08:47 +0000 Subject: [PATCH] Add confirm dialog when deleting subflow with instances in use --- .../editor-client/locales/en-US/editor.json | 1 + .../editor-client/src/js/ui/subflow.js | 41 ++++++++++++++++--- 2 files changed, 37 insertions(+), 5 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 7cdfde99d..881e9897c 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 @@ -338,6 +338,7 @@ "output": "outputs:", "status": "status node", "deleteSubflow": "delete subflow", + "confirmDelete": "Are you sure you want to delete this subflow?", "info": "Description", "category": "Category", "module": "Module", diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js b/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js index b4cf4be08..6227ef37b 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/subflow.js @@ -464,12 +464,43 @@ RED.subflow = (function() { $("#red-ui-subflow-delete").on("click", function(event) { event.preventDefault(); - var startDirty = RED.nodes.dirty(); - var historyEvent = removeSubflow(RED.workspaces.active()); - historyEvent.t = 'delete'; - historyEvent.dirty = startDirty; + var subflow = RED.nodes.subflow(RED.workspaces.active()); + if (subflow.instances.length > 0) { + var msg = $('
') + $('

').text(RED._("subflow.subflowInstances",{count: subflow.instances.length})).appendTo(msg); + $('

').text(RED._("subflow.confirmDelete")).appendTo(msg); + var confirmDeleteNotification = RED.notify(msg, { + modal: true, + fixed: true, + buttons: [ + { + text: RED._('common.label.cancel'), + click: function() { + confirmDeleteNotification.close(); + } + }, + { + text: RED._('workspace.confirmDelete'), + class: "primary", + click: function() { + confirmDeleteNotification.close(); + completeDelete(); + } + } + ] + }); - RED.history.push(historyEvent); + return; + } else { + completeDelete(); + } + function completeDelete() { + var startDirty = RED.nodes.dirty(); + var historyEvent = removeSubflow(RED.workspaces.active()); + historyEvent.t = 'delete'; + historyEvent.dirty = startDirty; + RED.history.push(historyEvent); + } });