Update sf instance env vars when removed from template

This commit is contained in:
Nick O'Leary 2025-01-22 10:25:24 +00:00
parent 479b7e756d
commit daa76e6e5f
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -1836,8 +1836,18 @@ RED.editor = (function() {
} }
}); });
} }
let envToRemove = new Set()
if (!isSameObj(old_env, new_env)) { if (!isSameObj(old_env, new_env)) {
// Get a list of env properties that have been removed
// by comparing old_env and new_env
if (old_env) {
old_env.forEach(env => { envToRemove.add(env.name) })
}
if (new_env) {
new_env.forEach(env => {
envToRemove.delete(env.name)
})
}
editState.changes.env = editing_node.env; editState.changes.env = editing_node.env;
editing_node.env = new_env; editing_node.env = new_env;
editState.changed = true; editState.changed = true;
@ -1846,10 +1856,11 @@ RED.editor = (function() {
if (editState.changed) { if (editState.changed) {
var wasChanged = editing_node.changed; let wasChanged = editing_node.changed;
editing_node.changed = true; editing_node.changed = true;
validateNode(editing_node); validateNode(editing_node);
var subflowInstances = []; let subflowInstances = [];
let instanceHistoryEvents = []
RED.nodes.eachNode(function(n) { RED.nodes.eachNode(function(n) {
if (n.type == "subflow:"+editing_node.id) { if (n.type == "subflow:"+editing_node.id) {
subflowInstances.push({ subflowInstances.push({
@ -1859,13 +1870,35 @@ RED.editor = (function() {
n._def.color = editing_node.color; n._def.color = editing_node.color;
n.changed = true; n.changed = true;
n.dirty = true; n.dirty = true;
if (n.env) {
const oldEnv = n.env
const newEnv = []
let envChanged = false
n.env.forEach((env, index) => {
if (envToRemove.has(env.name)) {
envChanged = true
} else {
newEnv.push(env)
}
})
if (envChanged) {
instanceHistoryEvents.push({
t: 'edit',
node: n,
changes: { env: oldEnv },
dirty: n.dirty,
changed: n.changed
})
n.env = newEnv
}
}
updateNodeProperties(n); updateNodeProperties(n);
validateNode(n); validateNode(n);
} }
}); });
RED.events.emit("subflows:change",editing_node); RED.events.emit("subflows:change",editing_node);
RED.nodes.dirty(true); RED.nodes.dirty(true);
var historyEvent = { let historyEvent = {
t:'edit', t:'edit',
node:editing_node, node:editing_node,
changes:editState.changes, changes:editState.changes,
@ -1875,7 +1908,13 @@ RED.editor = (function() {
instances:subflowInstances instances:subflowInstances
} }
}; };
if (instanceHistoryEvents.length > 0) {
historyEvent = {
t: 'multi',
events: [ historyEvent, ...instanceHistoryEvents ],
dirty: wasDirty
}
}
RED.history.push(historyEvent); RED.history.push(historyEvent);
} }
editing_node.dirty = true; editing_node.dirty = true;