diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js index b1c6e18b7..5561541fc 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editor.js @@ -242,7 +242,7 @@ RED.editor = (function() { * @param property - the name of the field * @param type - the type of the config-node */ - function prepareConfigNodeSelect(node,property,type,prefix) { + function prepareConfigNodeSelect(node,property,type,prefix,filter) { var input = $("#"+prefix+"-"+property); if (input.length === 0 ) { return; @@ -265,12 +265,12 @@ RED.editor = (function() { select.css({ 'flex-grow': 1 }); - updateConfigNodeSelect(property,type,node[property],prefix); + updateConfigNodeSelect(property,type,node[property],prefix,filter); $('') .css({"margin-left":"10px"}) .appendTo(outerWrap); $('#'+prefix+'-lookup-'+property).on("click", function(e) { - showEditConfigNodeDialog(property,type,select.find(":selected").val(),prefix); + showEditConfigNodeDialog(property,type,select.find(":selected").val(),prefix,node); e.preventDefault(); }); var label = ""; @@ -304,7 +304,7 @@ RED.editor = (function() { } button.on("click", function(e) { - showEditConfigNodeDialog(property,type,input.val()||"_ADD_",prefix); + showEditConfigNodeDialog(property,type,input.val()||"_ADD_",prefix,node); e.preventDefault(); }); } @@ -476,7 +476,7 @@ RED.editor = (function() { if (configTypeDef.exclusive) { prepareConfigNodeButton(node,d,definition.defaults[d].type,prefix); } else { - prepareConfigNodeSelect(node,d,definition.defaults[d].type,prefix); + prepareConfigNodeSelect(node,d,definition.defaults[d].type,prefix,definition.defaults[d].filter); } } else { console.log("Unknown type:", definition.defaults[d].type); @@ -694,7 +694,7 @@ RED.editor = (function() { return 0; } - function updateConfigNodeSelect(name,type,value,prefix) { + function updateConfigNodeSelect(name,type,value,prefix,filter) { // if prefix is null, there is no config select to update if (prefix) { var button = $("#"+prefix+"-edit-"+name); @@ -717,12 +717,16 @@ RED.editor = (function() { } var configNodes = []; - + if (typeof filter !== 'function') { + filter = null; + } RED.nodes.eachConfig(function(config) { if (config.type == type && (!config.z || config.z === activeWorkspace.id)) { - var label = RED.utils.getNodeLabel(config,config.id); - config.__label__ = label+(config.d?" ["+RED._("workspace.disabled")+"]":""); - configNodes.push(config); + if (!filter || filter.call(null,config)) { + var label = RED.utils.getNodeLabel(config,config.id); + config.__label__ = label+(config.d?" ["+RED._("workspace.disabled")+"]":""); + configNodes.push(config); + } } }); var configSortFn = defaultConfigNodeSort; @@ -1038,8 +1042,9 @@ RED.editor = (function() { * type - type of config node * id - id of config node to edit. _ADD_ for a new one * prefix - the input prefix of the parent property + * editContext - the node that was being edited that triggered editing this node */ - function showEditConfigNodeDialog(name,type,id,prefix) { + function showEditConfigNodeDialog(name,type,id,prefix,editContext) { if (buildingEditDialog) { return } buildingEditDialog = true; var adding = (id == "_ADD_"); @@ -1342,7 +1347,13 @@ RED.editor = (function() { RED.events.emit("nodes:change",editing_config_node); } RED.tray.close(function() { - updateConfigNodeSelect(configProperty,configType,editing_config_node.id,prefix); + var filter = null; + if (editContext && typeof editContext._def.defaults[configProperty].filter === 'function') { + filter = function(n) { + return editContext._def.defaults[configProperty].filter.call(editContext,n); + } + } + updateConfigNodeSelect(configProperty,configType,editing_config_node.id,prefix,filter); }); } } @@ -1399,7 +1410,13 @@ RED.editor = (function() { RED.view.redraw(true); RED.history.push(historyEvent); RED.tray.close(function() { - updateConfigNodeSelect(configProperty,configType,"",prefix); + var filter = null; + if (editContext && typeof editContext._def.defaults[configProperty].filter === 'function') { + filter = function(n) { + return editContext._def.defaults[configProperty].filter.call(editContext,n); + } + } + updateConfigNodeSelect(configProperty,configType,"",prefix,filter); }); } });