Apply code review + add comments

Co-authored-by: Nick O'Leary <nick.oleary@gmail.com>
This commit is contained in:
GogoVega 2024-10-08 18:10:28 +02:00
parent 32540dd0e6
commit 49a3eded59
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

View File

@ -591,6 +591,7 @@ RED.deploy = (function() {
const flowsToLock = new Set()
// Node's properties cannot be modified if its workspace is locked.
function ensureUnlocked(id) {
// TODO: `RED.nodes.subflow` is useless
const flow = id && (RED.nodes.workspace(id) || RED.nodes.subflow(id) || null);
const isLocked = flow ? flow.locked : false;
if (flow && isLocked) {
@ -643,27 +644,27 @@ RED.deploy = (function() {
delete confNode.credentials;
}
});
// Subflow cannot be locked
RED.nodes.eachSubflow(function (subflow) {
if (subflow.changed) {
subflow.changed = false;
if (flowsToLock.has(subflow)) {
subflow.locked = true;
}
RED.events.emit("subflows:change", subflow);
}
});
RED.nodes.eachWorkspace(function (ws) {
if (ws.changed || ws.added) {
ensureUnlocked(ws.z)
// Ensure the Workspace is unlocked to modify its properties.
ensureUnlocked(ws.id);
ws.changed = false;
delete ws.added
if (flowsToLock.has(ws)) {
ws.locked = true;
flowsToLock.delete(ws);
}
RED.events.emit("flows:change", ws)
}
});
// Ensures all workspaces/subflows to be locked have been locked.
// Ensures all workspaces to be locked have been locked.
flowsToLock.forEach(flow => {
flow.locked = true
})