Merge pull request #4793 from GogoVega/fix-creds-props-pane

Fix save and history of credentials for panes
This commit is contained in:
Nick O'Leary 2024-12-03 14:56:02 +00:00 committed by GitHub
commit 50e821d5d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -131,9 +131,16 @@
}
}
if (node._def.credentials) {
var credDefinition = node._def.credentials;
var credsChanged = updateNodeCredentials(node,credDefinition,this.inputClass);
editState.changed = editState.changed || credsChanged;
const credDefinition = node._def.credentials;
const credChanges = updateNodeCredentials(node, credDefinition, this.inputClass);
if (Object.keys(credChanges).length) {
editState.changed = true;
editState.changes.credentials = {
...(editState.changes.credentials || {}),
...credChanges
};
}
}
}
}
@ -161,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._) {
@ -177,22 +185,32 @@
if (input.length > 0) {
var value = input.val();
if (credDefinition[cred].type == 'password') {
node.credentials['has_' + cred] = (value !== "");
if (value == '__PWRD__') {
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;
}
})();