Merge pull request #3390 from node-red/copy-node-props

Copy node props
This commit is contained in:
Nick O'Leary 2022-03-03 21:57:00 +00:00 committed by GitHub
commit c75bebfc90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 15 deletions

View File

@ -280,15 +280,18 @@ RED.sidebar.info.outliner = (function() {
data:getFlowData() data:getFlowData()
}) })
treeList.on('treelistselect', function(e,item) { treeList.on('treelistselect', function(e,item) {
var node = RED.nodes.node(item.id) || RED.nodes.group(item.id); var node = RED.nodes.node(item.id) || RED.nodes.group(item.id) || RED.nodes.workspace(item.id) || RED.nodes.subflow(item.id);
if (node) { if (node) {
if (node.type === 'group' || node._def.category !== "config") { RED.sidebar.info.refresh(node);
// RED.view.select({nodes:[node]}) // if (node.type === 'group' || node._def.category !== "config") {
} else if (node._def.category === "config") { // // RED.view.select({nodes:[node]})
RED.sidebar.info.refresh(node); // } else if (node._def.category === "config") {
} else { // RED.sidebar.info.refresh(node);
// RED.view.select({nodes:[]}) // } else {
} // // RED.view.select({nodes:[]})
// }
} else {
RED.sidebar.info.refresh(null);
} }
}) })
treeList.on('treelistconfirm', function(e,item) { treeList.on('treelistconfirm', function(e,item) {

View File

@ -163,6 +163,7 @@ RED.sidebar.info = (function() {
}); });
return el; return el;
} }
function refresh(node) { function refresh(node) {
if (node === undefined) { if (node === undefined) {
refreshSelection(); refreshSelection();
@ -271,7 +272,7 @@ RED.sidebar.info = (function() {
objectType = "group"; objectType = "group";
} }
$(propRow.children()[0]).text(RED._("sidebar.info."+objectType)) $(propRow.children()[0]).text(RED._("sidebar.info."+objectType))
RED.utils.createObjectElement(node.id).appendTo(propRow.children()[1]); RED.utils.createObjectElement(node.id,{sourceId: node.id}).appendTo(propRow.children()[1]);
if (node.type === "tab" || node.type === "subflow") { if (node.type === "tab" || node.type === "subflow") {
// If nothing is selected, but we're on a flow or subflow tab. // If nothing is selected, but we're on a flow or subflow tab.
@ -365,7 +366,7 @@ RED.sidebar.info = (function() {
} }
} else { } else {
RED.utils.createObjectElement(val).appendTo(propRow.children()[1]); RED.utils.createObjectElement(val,{sourceId: node.id}).appendTo(propRow.children()[1]);
} }
} }
} }
@ -431,6 +432,7 @@ RED.sidebar.info = (function() {
} }
function setInfoText(infoText,target) { function setInfoText(infoText,target) {
var info = addTargetToExternalLinks($('<div class="red-ui-help"><span class="red-ui-text-bidi-aware" dir=\"'+RED.text.bidi.resolveBaseTextDir(infoText)+'">'+infoText+'</span></div>')).appendTo(target); var info = addTargetToExternalLinks($('<div class="red-ui-help"><span class="red-ui-text-bidi-aware" dir=\"'+RED.text.bidi.resolveBaseTextDir(infoText)+'">'+infoText+'</span></div>')).appendTo(target);
info.find(".red-ui-text-bidi-aware").contents().filter(function() { return this.nodeType === 3 && this.textContent.trim() !== "" }).wrap( "<span></span>" ); info.find(".red-ui-text-bidi-aware").contents().filter(function() { return this.nodeType === 3 && this.textContent.trim() !== "" }).wrap( "<span></span>" );
@ -447,6 +449,7 @@ RED.sidebar.info = (function() {
$(this).toggleClass('expanded',!isExpanded); $(this).toggleClass('expanded',!isExpanded);
}) })
} }
var tips = (function() { var tips = (function() {
var enabled = true; var enabled = true;
var startDelay = 1000; var startDelay = 1000;

View File

@ -365,7 +365,16 @@ RED.utils = (function() {
} }
} }
function buildMessageElement(obj,options) { /**
* Create a DOM element representation of obj - as used by Debug sidebar etc
*
* @params obj - the data to display
* @params options - a bag of options
*
* - If you want the Copy Value button, then set `sourceId`
* - If you want the Copy Path button, also set `path` to the value to be copied
*/
function createObjectElement(obj,options) {
options = options || {}; options = options || {};
var key = options.key; var key = options.key;
var typeHint = options.typeHint; var typeHint = options.typeHint;
@ -555,7 +564,7 @@ RED.utils = (function() {
if (fullLength <= 10) { if (fullLength <= 10) {
for (i=0;i<fullLength;i++) { for (i=0;i<fullLength;i++) {
row = $('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(arrayRows); row = $('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(arrayRows);
subElements[path+"["+i+"]"] = buildMessageElement( subElements[path+"["+i+"]"] = createObjectElement(
data[i], data[i],
{ {
key: ""+i, key: ""+i,
@ -585,7 +594,7 @@ RED.utils = (function() {
return function() { return function() {
for (var i=min;i<=max;i++) { for (var i=min;i<=max;i++) {
var row = $('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(parent); var row = $('<div class="red-ui-debug-msg-object-entry collapsed"></div>').appendTo(parent);
subElements[path+"["+i+"]"] = buildMessageElement( subElements[path+"["+i+"]"] = createObjectElement(
data[i], data[i],
{ {
key: ""+i, key: ""+i,
@ -641,7 +650,7 @@ RED.utils = (function() {
newPath += "[\""+keys[i].replace(/"/,"\\\"")+"\"]" newPath += "[\""+keys[i].replace(/"/,"\\\"")+"\"]"
} }
} }
subElements[newPath] = buildMessageElement( subElements[newPath] = createObjectElement(
data[keys[i]], data[keys[i]],
{ {
key: keys[i], key: keys[i],
@ -1369,7 +1378,7 @@ RED.utils = (function() {
} }
return { return {
createObjectElement: buildMessageElement, createObjectElement: createObjectElement,
getMessageProperty: getMessageProperty, getMessageProperty: getMessageProperty,
setMessageProperty: setMessageProperty, setMessageProperty: setMessageProperty,
normalisePropertyExpression: normalisePropertyExpression, normalisePropertyExpression: normalisePropertyExpression,