Apply suggestions from code review

This commit is contained in:
Nick O'Leary 2024-04-04 16:08:59 +01:00 committed by GitHub
parent 6e7fa6f921
commit affa8ea42b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -341,8 +341,8 @@ RED.editor = (function() {
nodeValue = node[property] nodeValue = node[property]
} }
const addBtnId = `${prefix}-add-${property}`; const addBtnId = `${prefix}-btn-${property}-add`;
const editBtnId = `${prefix}-lookup-${property}`; const editBtnId = `${prefix}-btn-${property}-edit`;
const selectId = prefix + '-' + property; const selectId = prefix + '-' + property;
const input = $(`#${selectId}`); const input = $(`#${selectId}`);
if (input.length === 0) { if (input.length === 0) {
@ -374,10 +374,13 @@ RED.editor = (function() {
.css({ "margin-left": "10px" }) .css({ "margin-left": "10px" })
.appendTo(outerWrap); .appendTo(outerWrap);
RED.popover.tooltip(editButton, RED._('editor.editConfig', { type }));
// create the add button // create the add button
const addButton = $('<a id="' + addBtnId + '-add" class="red-ui-button"><i class="fa fa-plus"></i></a>') const addButton = $('<a id="' + addBtnId + '" class="red-ui-button"><i class="fa fa-plus"></i></a>')
.css({ "margin-left": "10px" }) .css({ "margin-left": "10px" })
.appendTo(outerWrap); .appendTo(outerWrap);
RED.popover.tooltip(addButton, RED._('editor.addNewConfig', { type }));
const disableButton = function(button, disabled) { const disableButton = function(button, disabled) {
$(button).prop("disabled", !!disabled) $(button).prop("disabled", !!disabled)
@ -409,6 +412,9 @@ RED.editor = (function() {
} else if (optionsLength === 1 && selectedOpt.val() === "_ADD_") { } else if (optionsLength === 1 && selectedOpt.val() === "_ADD_") {
disableButton(addButton, false); disableButton(addButton, false);
disableButton(editButton, true); disableButton(editButton, true);
} else if (selectedOpt.val() === "") {
disableButton(addButton, false);
disableButton(editButton, true);
} else { } else {
disableButton(addButton, false); disableButton(addButton, false);
disableButton(editButton, false); disableButton(editButton, false);
@ -917,6 +923,8 @@ RED.editor = (function() {
if (!configNodes.length) { if (!configNodes.length) {
select.append('<option value="_ADD_" selected>' + RED._("editor.addNewType", { type: label }) + '</option>'); select.append('<option value="_ADD_" selected>' + RED._("editor.addNewType", { type: label }) + '</option>');
} else {
select.append('<option value="">' + RED._("editor.inputs.none") + '</option>');
} }
window.setTimeout(function() { select.trigger("change");},50); window.setTimeout(function() { select.trigger("change");},50);