From 0caa3087574363cb6efda1bcfef9fcb805fd4122 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 12 Sep 2022 20:53:46 +0100 Subject: [PATCH] Add core:copy-item-link action and expose in info sidebar --- .../editor-client/locales/en-US/editor.json | 3 ++- .../editor-client/src/js/ui/tab-info.js | 22 ++++++++++++--- .../editor-client/src/js/ui/view-tools.js | 27 +++++++++++++++++++ 3 files changed, 48 insertions(+), 4 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 c8abada3e..1cc571200 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 @@ -683,7 +683,8 @@ "empty": "empty", "globalConfig": "Global Configuration Nodes", "triggerAction": "Trigger action", - "find": "Find in workspace" + "find": "Find in workspace", + "copyItemUrl": "Copy item url" }, "help": { "name": "Help", diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js b/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js index dfd4b1e43..c46aa97e8 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/tab-info.js @@ -25,6 +25,7 @@ RED.sidebar.info = (function() { var propertiesPanelHeaderLabel; var propertiesPanelHeaderReveal; var propertiesPanelHeaderHelp; + var propertiesPanelHeaderCopyLink; var selectedObject; @@ -67,10 +68,20 @@ RED.sidebar.info = (function() { propertiesPanelHeaderIcon = $("").appendTo(propertiesPanelHeader); propertiesPanelHeaderLabel = $("").appendTo(propertiesPanelHeader); - propertiesPanelHeaderHelp = $('').css({ + + propertiesPanelHeaderCopyLink = $('').css({ position: 'absolute', top: '12px', right: '32px' + }).on("click", function(evt) { + RED.actions.invoke('core:copy-item-url',selectedObject) + }).appendTo(propertiesPanelHeader); + RED.popover.tooltip(propertiesPanelHeaderCopyLink,RED._("sidebar.info.copyItemUrl")); + + propertiesPanelHeaderHelp = $('').css({ + position: 'absolute', + top: '12px', + right: '56px' }).on("click", function(evt) { evt.preventDefault(); evt.stopPropagation(); @@ -80,8 +91,7 @@ RED.sidebar.info = (function() { }).appendTo(propertiesPanelHeader); RED.popover.tooltip(propertiesPanelHeaderHelp,RED._("sidebar.help.showHelp")); - - propertiesPanelHeaderReveal = $('').css({ + propertiesPanelHeaderReveal = $('').css({ position: 'absolute', top: '12px', right: '8px' @@ -185,6 +195,7 @@ RED.sidebar.info = (function() { propertiesPanelHeaderLabel.text(""); propertiesPanelHeaderReveal.hide(); propertiesPanelHeaderHelp.hide(); + propertiesPanelHeaderCopyLink.hide(); return; } else if (Array.isArray(node)) { // Multiple things selected @@ -196,6 +207,7 @@ RED.sidebar.info = (function() { propertiesPanelHeaderLabel.text("Selection"); propertiesPanelHeaderReveal.hide(); propertiesPanelHeaderHelp.hide(); + propertiesPanelHeaderCopyLink.hide(); selectedObject = null; var types = { @@ -277,9 +289,11 @@ RED.sidebar.info = (function() { if (node.type === "tab" || node.type === "subflow") { // If nothing is selected, but we're on a flow or subflow tab. propertiesPanelHeaderHelp.hide(); + propertiesPanelHeaderCopyLink.show(); } else if (node.type === "group") { propertiesPanelHeaderHelp.hide(); + propertiesPanelHeaderCopyLink.show(); propRow = $(' ').appendTo(tableBody); @@ -304,8 +318,10 @@ RED.sidebar.info = (function() { } } else if (node.type === 'junction') { propertiesPanelHeaderHelp.hide(); + propertiesPanelHeaderCopyLink.hide(); } else { propertiesPanelHeaderHelp.show(); + propertiesPanelHeaderCopyLink.show(); if (!subflowRegex) { propRow = $(''+RED._("sidebar.info.type")+'').appendTo(tableBody); diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js b/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js index bc81d4a43..1ed5791a6 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/view-tools.js @@ -1192,6 +1192,30 @@ RED.view.tools = (function() { RED.view.redraw(true); } + function copyItemUrl(node, isEdit) { + if (!node) { + const selection = RED.view.selection(); + if (selection.nodes && selection.nodes.length > 0) { + node = selection.nodes[0] + } + } + if (node) { + let thingType = 'node' + if (node.type === 'group') { + thingType = 'group' + } else if (node.type === 'tab' || node.type === 'subflow') { + thingType = 'flow' + } + let url = `${window.location.origin}${window.location.pathname}#${thingType}/${node.id}` + if (isEdit) { + url += '/edit' + } + if (RED.clipboard.copyText(url)) { + RED.notify('Copied url to clipboard', { timeout: 2000 }) + } + } + } + return { init: function() { RED.actions.add("core:show-selected-node-labels", function() { setSelectedNodeLabelState(true); }) @@ -1258,6 +1282,9 @@ RED.view.tools = (function() { RED.actions.add("core:generate-node-names", generateNodeNames ) + RED.actions.add("core:copy-item-url", function (node) { copyItemUrl(node) }) + RED.actions.add("core:copy-item-edit-url", function (node) { copyItemUrl(node, true) }) + // RED.actions.add("core:add-node", function() { addNode() }) }, /**