Ensure the order matches the flow file order

pull/5322/head
GogoVega 2025-10-30 17:25:16 +01:00
parent f380744483
commit a4875bf5f6
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B
1 changed files with 38 additions and 12 deletions

View File

@ -233,6 +233,35 @@ var RED = (function() {
});
}
/**
* The result of [A,C,B,D,E] and [B,C] is [A,B,C,D,E].
*
* @param {string[]} storedOrder
* @param {string[]} currentOrder
* @returns {string[]}
*/
function mergeTabOrder(storedOrder, currentOrder) {
const result = [...storedOrder];
for (let i = 0; i < currentOrder.length; i++) {
const current = currentOrder[i];
const currentIndex = result.indexOf(current);
for (let j = i + 1; j < currentOrder.length; j++) {
const next = currentOrder[j];
const nextIndex = result.indexOf(next);
if (nextIndex < currentIndex) {
result.splice(nextIndex, 1);
const newIndex = result.indexOf(current) + 1;
result.splice(newIndex, 0, next);
}
}
}
return result;
}
function loadFlows(done) {
loader.reportProgress(RED._("event.loadFlows"),80 )
$.ajax({
@ -288,20 +317,17 @@ var RED = (function() {
const tabOrder = JSON.parse(RED.settings.getLocal("tabOrder") || "[]");
if (tabOrder.length) {
// Checks that the last session order contains all current flows
// Otherwise, ignore the reorder
const currentOrder = RED.nodes.getWorkspaceOrder();
const orderNotUpToDate = currentOrder.some((t) => !tabOrder.includes(t));
if (!orderNotUpToDate) {
for (const tab of tabOrder) {
// Add missing tabs
RED.workspaces.show(tab, true);
}
// Restore the order from the last session
RED.workspaces.order(tabOrder);
// Select the active workspace again because adding missing tab has changed it
RED.workspaces.show(activeWorkspace, true);
// Ensure the order from last session matches the current order
const newOrder = mergeTabOrder(tabOrder, currentOrder);
for (const tab of newOrder) {
// Add missing tabs
RED.workspaces.show(tab, true);
}
// Restore the order from the last session
RED.workspaces.order(newOrder);
// Select the active workspace again because adding missing tab has changed it
RED.workspaces.show(activeWorkspace, true);
}
const hiddenTabs = JSON.parse(RED.settings.getLocal("hiddenTabs")||"{}");