From eab512ef22191f3dc6418c4c2da0313bf9419170 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Mon, 24 Jun 2024 17:55:23 +0200 Subject: [PATCH 1/2] Fix save and history of credentials for panes --- .../src/js/ui/editors/panes/properties.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js index cfa72be10..9b18ec35e 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js @@ -131,9 +131,13 @@ } } if (node._def.credentials) { - var credDefinition = node._def.credentials; - var credsChanged = updateNodeCredentials(node,credDefinition,this.inputClass); - editState.changed = editState.changed || credsChanged; + const credsDefinition = node._def.credentials; + const credsChanged = updateNodeCredentials(node, credsDefinition, this.inputClass); + + if (credsChanged) { + editState.changed = true; + editState.changes.credentials = node.credentials._; + } } } } @@ -178,11 +182,14 @@ var value = input.val(); if (credDefinition[cred].type == 'password') { node.credentials['has_' + cred] = (value !== ""); - if (value == '__PWRD__') { + + // Skip if the credential has not changed + if ((value === '__PWRD__' && node.credentials._['has_' + cred] === true) || + (value === "" && node.credentials._['has_' + cred] === false)) { continue; } - changed = true; + changed = true; } node.credentials[cred] = value; if (value != node.credentials._[cred]) { @@ -193,6 +200,4 @@ } return changed; } - - })(); From 83696abf9db7f433c38dec5f9deb5092f696bb71 Mon Sep 17 00:00:00 2001 From: GogoVega <92022724+GogoVega@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:34:51 +0200 Subject: [PATCH 2/2] Fixes and improvements with comments --- .../src/js/ui/editors/panes/properties.js | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js index 9b18ec35e..8f78b0a9a 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/editors/panes/properties.js @@ -131,12 +131,15 @@ } } if (node._def.credentials) { - const credsDefinition = node._def.credentials; - const credsChanged = updateNodeCredentials(node, credsDefinition, this.inputClass); + const credDefinition = node._def.credentials; + const credChanges = updateNodeCredentials(node, credDefinition, this.inputClass); - if (credsChanged) { + if (Object.keys(credChanges).length) { editState.changed = true; - editState.changes.credentials = node.credentials._; + editState.changes.credentials = { + ...(editState.changes.credentials || {}), + ...credChanges + }; } } } @@ -165,10 +168,11 @@ * @param node - the node containing the credentials * @param credDefinition - definition of the credentials * @param prefix - prefix of the input fields - * @return {boolean} whether anything has changed + * @return {object} an object containing the modified properties */ function updateNodeCredentials(node, credDefinition, prefix) { - var changed = false; + const changes = {}; + if (!node.credentials) { node.credentials = {_:{}}; } else if (!node.credentials._) { @@ -181,23 +185,32 @@ if (input.length > 0) { var value = input.val(); if (credDefinition[cred].type == 'password') { - node.credentials['has_' + cred] = (value !== ""); - - // Skip if the credential has not changed - if ((value === '__PWRD__' && node.credentials._['has_' + cred] === true) || - (value === "" && node.credentials._['has_' + cred] === false)) { - continue; + if (value === '__PWRD__') { + // A cred value exists - no changes + } else if (value === '' && node.credentials['has_' + cred] === false) { + // Empty cred value exists - no changes + } else if (value === node.credentials[cred]) { + // A cred value exists locally in the editor - no changes + // Like the user sets a value, saves the config, + // reopens the config and save the config again + } else { + changes[cred] = node.credentials[cred]; + node.credentials[cred] = value; } - changed = true; - } - node.credentials[cred] = value; - if (value != node.credentials._[cred]) { - changed = true; + node.credentials['has_' + cred] = (value !== ''); + } else { + // Since these creds are loaded by the editor, + // values can be directly compared + if (value !== node.credentials[cred]) { + changes[cred] = node.credentials[cred]; + node.credentials[cred] = value; + } } } } } - return changed; + + return changes; } })();