1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3372 from Steve-Mcl/use-paletteLabel-in-help

Use a nodes palette label in help tree
This commit is contained in:
Nick O'Leary 2022-01-26 11:00:53 +00:00 committed by GitHub
commit 42a7165596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,15 +64,17 @@ RED.sidebar.help = (function() {
style: "compact", style: "compact",
delay: 100, delay: 100,
change: function() { change: function() {
var val = $(this).val().toLowerCase(); const searchFor = $(this).val().toLowerCase();
if (val) { if (searchFor) {
showTOC(); showTOC();
var c = treeList.treeList('filter',function(item) { treeList.treeList('filter',function(item) {
if (item.depth === 0) { if (item.depth === 0) {
return true; return true;
} }
return (item.nodeType && item.nodeType.indexOf(val) > -1) || let found = item.nodeType && item.nodeType.toLowerCase().indexOf(searchFor) > -1;
(item.subflowLabel && item.subflowLabel.indexOf(val) > -1) found = found || item.subflowLabel && item.subflowLabel.toLowerCase().indexOf(searchFor) > -1;
found = found || item.palleteLabel && item.palleteLabel.toLowerCase().indexOf(searchFor) > -1;
return found;
},true) },true)
} else { } else {
treeList.treeList('filter',null); treeList.treeList('filter',null);
@ -224,17 +226,21 @@ RED.sidebar.help = (function() {
moduleNames.forEach(function(moduleName) { moduleNames.forEach(function(moduleName) {
var module = modules[moduleName]; const module = modules[moduleName];
var nodeTypes = []; const nodeTypes = [];
const moduleSets = module.sets;
var setNames = Object.keys(module.sets); const setNames = Object.keys(moduleSets);
setNames.forEach(function(setName) { setNames.forEach(function(setName) {
module.sets[setName].types.forEach(function(nodeType) { const moduleSet = moduleSets[setName];
moduleSet.types.forEach(function(nodeType) {
if ($("script[data-help-name='"+nodeType+"']").length) { if ($("script[data-help-name='"+nodeType+"']").length) {
const n = {_def:RED.nodes.getType(nodeType),type:nodeType}
n.name = getNodePaletteLabel(n);
nodeTypes.push({ nodeTypes.push({
id: "node-type:"+nodeType, id: "node-type:"+nodeType,
nodeType: nodeType, nodeType: nodeType,
element:getNodeLabel({_def:RED.nodes.getType(nodeType),type:nodeType}) palleteLabel: n.name,
element: getNodeLabel(n)
}) })
} }
}) })
@ -254,18 +260,21 @@ RED.sidebar.help = (function() {
treeList.treeList("data",helpData); treeList.treeList("data",helpData);
} }
function getNodeLabel(n) { function getNodePaletteLabel(n) {
var div = $('<div>',{class:"red-ui-node-list-item"}); let label = n.name;
var icon = RED.utils.createNodeIcon(n).appendTo(div);
var label = n.name;
if (!label && n._def && n._def.paletteLabel) { if (!label && n._def && n._def.paletteLabel) {
try { try {
label = (typeof n._def.paletteLabel === "function" ? n._def.paletteLabel.call(n._def) : n._def.paletteLabel)||""; label = (typeof n._def.paletteLabel === "function" ? n._def.paletteLabel.call(n._def) : n._def.paletteLabel)||"";
} catch (err) { } catch (err) {
} }
} }
label = label || n.type; return label || n.type;
$('<div>',{class:"red-ui-node-label"}).text(n.name||n.type).appendTo(icon); }
function getNodeLabel(n) {
const div = $('<div>',{class:"red-ui-node-list-item"});
const icon = RED.utils.createNodeIcon(n).appendTo(div);
$('<div>',{class:"red-ui-node-label"}).text(getNodePaletteLabel(n)).appendTo(icon);
return div; return div;
} }