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

Merge pull request #3752 from Steve-Mcl/fix-global-path-popover

Ensure global-config and flow-config have info in the hierarchy popover
This commit is contained in:
Nick O'Leary 2022-07-11 20:28:58 +01:00 committed by GitHub
commit e3b1f058cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -245,47 +245,37 @@
// complete parentage of the node that generated this message. // complete parentage of the node that generated this message.
// flow-id/subflow-A-instance/subflow-B-instance // flow-id/subflow-A-instance/subflow-B-instance
// If it has one id, that is a top level flow // If it has one id, that is a top level flow or config node/global
// each subsequent id is the instance id of a subflow node // each subsequent id is the instance id of a subflow node
// //
pathParts = o.path.split("/"); pathParts = o.path.split("/");
if (pathParts.length === 1) { if (pathParts.length === 1) {
// The source node is on a flow - so can use its id to find // The source node is on a flow or is a global/config - so can use its id to find
sourceNode = RED.nodes.node(o.id); sourceNode = RED.nodes.node(o.id);
if (pathParts[0] === "global") {
pathParts = [];
}
} else if (pathParts.length > 1) { } else if (pathParts.length > 1) {
// Highlight the subflow instance node. // Highlight the subflow instance node.
sourceNode = RED.nodes.node(pathParts[1]); sourceNode = RED.nodes.node(pathParts[1]);
} }
const getNodeLabel = (n) => n.name || (typeof n.label === "function" && n.label()) || (typeof n.label === "string" && n.label) || (n.type + ":" + n.id);
pathHierarchy = pathParts.map((id,index) => { pathHierarchy = pathParts.map((id,index) => {
if (index === 0) { if (index === 0) {
return { if (id === "global") {
id: id, return { id: sourceNode.id, label: getNodeLabel(sourceNode) }
label: RED.nodes.workspace(id).label }
} return { id: id, label: RED.nodes.workspace(id).label } //flow id + name
} else { } else {
var instanceNode = RED.nodes.node(id) const instanceNode = RED.nodes.node(id)
return { const pathLabel = (instanceNode.name || RED.nodes.subflow(instanceNode.type.substring(8)).name)
id: id, return { id: id, label: pathLabel }
label: (instanceNode.name || RED.nodes.subflow(instanceNode.type.substring(8)).name)
}
} }
}) })
if (pathParts.length === 1) { if (pathParts.length === 1 && pathParts[0] !== "global") {
pathHierarchy.push({ pathHierarchy.push({ id: o.id, label: getNodeLabel(sourceNode) })
id: o.id,
label: sourceNode.name || sourceNode.type+":"+sourceNode.id
})
} }
if (o._alias) { if (o._alias) {
let aliasNode = RED.nodes.node(o._alias) let aliasNode = RED.nodes.node(o._alias)
if (aliasNode) { if (aliasNode) {
pathHierarchy.push({ pathHierarchy.push({ id: o._alias, label: getNodeLabel(aliasNode) })
id: o._alias,
label: aliasNode.name || aliasNode.type+":"+aliasNode.id
})
} }
} }
} else { } else {