1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #4148 from GerwinvBeek/Bugs/not-loading-missing-subflow

Handle missing subflow when loading flows into the editor
This commit is contained in:
Nick O'Leary 2023-04-28 18:47:10 +01:00 committed by GitHub
commit e9a08af73b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 14 deletions

View File

@ -2095,6 +2095,16 @@ RED.nodes = (function() {
} else if (n.type.substring(0,7) === "subflow") { } else if (n.type.substring(0,7) === "subflow") {
var parentId = n.type.split(":")[1]; var parentId = n.type.split(":")[1];
var subflow = subflow_denylist[parentId]||subflow_map[parentId]||getSubflow(parentId); var subflow = subflow_denylist[parentId]||subflow_map[parentId]||getSubflow(parentId);
if (!subflow){
node._def = {
color:"#fee",
defaults: {},
label: "unknown: "+n.type,
labelStyle: "red-ui-flow-node-label-italic",
outputs: n.outputs|| (n.wires && n.wires.length) || 0,
set: registry.getNodeSet("node-red/unknown")
}
} else {
if (createNewIds || options.importMap[n.id] === "copy") { if (createNewIds || options.importMap[n.id] === "copy") {
parentId = subflow.id; parentId = subflow.id;
node.type = "subflow:"+parentId; node.type = "subflow:"+parentId;
@ -2105,6 +2115,7 @@ RED.nodes = (function() {
node.outputs = subflow.out.length; node.outputs = subflow.out.length;
node.inputs = subflow.in.length; node.inputs = subflow.in.length;
node.env = n.env; node.env = n.env;
}
} else if (n.type === 'junction') { } else if (n.type === 'junction') {
node._def = {defaults:{}} node._def = {defaults:{}}
node._config.x = node.x node._config.x = node.x

View File

@ -45,12 +45,14 @@ RED.editor = (function() {
var hasChanged; var hasChanged;
if (node.type.indexOf("subflow:")===0) { if (node.type.indexOf("subflow:")===0) {
subflow = RED.nodes.subflow(node.type.substring(8)); subflow = RED.nodes.subflow(node.type.substring(8));
if (subflow){
isValid = subflow.valid; isValid = subflow.valid;
hasChanged = subflow.changed; hasChanged = subflow.changed;
if (isValid === undefined) { if (isValid === undefined) {
isValid = validateNode(subflow); isValid = validateNode(subflow);
hasChanged = subflow.changed; hasChanged = subflow.changed;
} }
}
validationErrors = validateNodeProperties(node, node._def.defaults, node); validationErrors = validateNodeProperties(node, node._def.defaults, node);
node.valid = isValid && validationErrors.length === 0; node.valid = isValid && validationErrors.length === 0;
node.changed = node.changed || hasChanged; node.changed = node.changed || hasChanged;

View File

@ -199,8 +199,10 @@ function parseConfig(config) {
if (subflowDetails) { if (subflowDetails) {
var subflowType = subflowDetails[1] var subflowType = subflowDetails[1]
n.subflow = subflowType; n.subflow = subflowType;
if (flow.subflows[subflowType]) {
flow.subflows[subflowType].instances.push(n) flow.subflows[subflowType].instances.push(n)
} }
}
if (container) { if (container) {
container.nodes[n.id] = n; container.nodes[n.id] = n;
} }