Hello everyone. I have a requirement of opening only the flow whose ID is specified in the URL while opening Node-RED. After spending some time, I was able to achieve the desired results. I was wondering if I could make a pull request and make this an official feature. Since I am done developing it, I will share my code snippet as well. Following is the new loadFlows
function along with all the changes. I have also added comments (line 20 & line 24). Let me know what do you think. Thank you.
function loadFlows(done) {
loader.reportProgress(RED._("event.loadFlows"), 80)
$.ajax({
headers: {
"Accept": "application/json",
},
cache: false,
url: 'flows',
success: function (nodes) {
if (nodes) {
var currentHash = window.location.hash;
RED.nodes.version(nodes.rev);
loader.reportProgress(RED._("event.importFlows"), 90)
try {
RED.nodes.import(nodes.flows);
RED.nodes.dirty(false);
RED.view.redraw(true);
if (/^#(flow|node|group)\/.+$/.test(currentHash)) {
const hashParts = currentHash.split('/');
// check if "hideOtherFlows" parameter is passed
const hideOtherFlows = hashParts.length > 2 && (hashParts[2] === 'hideOtherFlows' || hashParts[3] === 'hideOtherFlows');
const showEditDialog = hashParts.length > 2 && hashParts[2] === 'edit';
if (hashParts[0] === '#flow') {
// if parameter is passed, hide all flows initially
// the flow having id specified in url will be made visible later
if (hideOtherFlows) {
const workspaces = RED.nodes.getWorkspaceOrder();
for (let index = 0; index < workspaces.length; index++) {
RED.workspaces.hide(workspaces[index])
}
}
RED.workspaces.show(hashParts[1], true);
if (showEditDialog) {
RED.workspaces.edit()
}
} else if (hashParts[0] === '#node') {
const nodeToShow = RED.nodes.node(hashParts[1])
if (nodeToShow) {
setTimeout(() => {
RED.view.reveal(nodeToShow.id)
window.location.hash = currentHash
RED.view.select(nodeToShow.id)
if (showEditDialog) {
RED.editor.edit(nodeToShow)
}
}, 50)
}
} else if (hashParts[0] === '#group') {
const nodeToShow = RED.nodes.group(hashParts[1])
if (nodeToShow) {
RED.view.reveal(nodeToShow.id)
window.location.hash = currentHash
RED.view.select(nodeToShow.id)
if (showEditDialog) {
RED.editor.editGroup(nodeToShow)
}
}
}
}
if (RED.workspaces.count() > 0) {
const hiddenTabs = JSON.parse(RED.settings.getLocal("hiddenTabs") || "{}");
const workspaces = RED.nodes.getWorkspaceOrder();
if (RED.workspaces.active() === 0) {
for (let index = 0; index < workspaces.length; index++) {
const ws = workspaces[index];
if (!hiddenTabs[ws]) {
RED.workspaces.show(ws);
break;
}
}
}
if (RED.workspaces.active() === 0) {
RED.workspaces.show(workspaces[0]);
}
}
} catch (err) {
console.warn(err);
RED.notify(
RED._("event.importError", { message: err.message }),
{
fixed: true,
type: 'error'
}
);
}
}
done();
}
});
}