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

Better handling of multiple flow merges

Fixes #2039

Keeps better track of what was merged so a subsequent merge
properly identifies new-vs-old and doesn't remove thinks by mistake
This commit is contained in:
Nick O'Leary 2019-01-30 15:12:01 +00:00
parent 85de227003
commit efe8fbbd11
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -687,7 +687,7 @@ RED.diff = (function() {
diff: remoteDiff diff: remoteDiff
} }
} }
var selectState = ""; var selectState = "";
if (conflicted) { if (conflicted) {
@ -1158,19 +1158,19 @@ RED.diff = (function() {
} }
}); });
return { var diff = {
currentConfig: currentConfig, currentConfig: currentConfig,
newConfig: newConfig, newConfig: newConfig,
added: added, added: added,
deleted: deleted, deleted: deleted,
changed: changed, changed: changed,
moved: moved moved: moved
} };
return diff;
} }
function resolveDiffs(localDiff,remoteDiff) { function resolveDiffs(localDiff,remoteDiff) {
var conflicted = {}; var conflicted = {};
var resolutions = {}; var resolutions = {};
var diff = { var diff = {
localDiff: localDiff, localDiff: localDiff,
remoteDiff: remoteDiff, remoteDiff: remoteDiff,
@ -1348,7 +1348,7 @@ RED.diff = (function() {
if (node) { if (node) {
nodeChangedStates[id] = node.changed; nodeChangedStates[id] = node.changed;
} }
localChangedStates[id] = true; localChangedStates[id] = 1;
newConfig.push(remoteDiff.newConfig.all[id]); newConfig.push(remoteDiff.newConfig.all[id]);
} }
} else { } else {
@ -1363,7 +1363,7 @@ RED.diff = (function() {
nodeChangedStates[id] = node.changed; nodeChangedStates[id] = node.changed;
} }
if (!localDiff.added.hasOwnProperty(id)) { if (!localDiff.added.hasOwnProperty(id)) {
localChangedStates[id] = true; localChangedStates[id] = 2;
newConfig.push(remoteDiff.newConfig.all[id]); newConfig.push(remoteDiff.newConfig.all[id]);
} }
} }
@ -1376,24 +1376,42 @@ RED.diff = (function() {
} }
function mergeDiff(diff) { function mergeDiff(diff) {
//console.log(diff);
var appliedDiff = applyDiff(diff); var appliedDiff = applyDiff(diff);
var newConfig = appliedDiff.config; var newConfig = appliedDiff.config;
var nodeChangedStates = appliedDiff.nodeChangedStates; var nodeChangedStates = appliedDiff.nodeChangedStates;
var localChangedStates = appliedDiff.localChangedStates; var localChangedStates = appliedDiff.localChangedStates;
var isDirty = RED.nodes.dirty();
var historyEvent = { var historyEvent = {
t:"replace", t:"replace",
config: RED.nodes.createCompleteNodeSet(), config: RED.nodes.createCompleteNodeSet(),
changed: nodeChangedStates, changed: nodeChangedStates,
dirty: RED.nodes.dirty(), dirty: isDirty,
rev: RED.nodes.version() rev: RED.nodes.version()
} }
RED.history.push(historyEvent); RED.history.push(historyEvent);
var originalFlow = RED.nodes.originalFlow();
// originalFlow is what the editor things it loaded
// - add any newly added nodes from remote diff as they are now part of the record
for (var id in diff.remoteDiff.added) {
if (diff.remoteDiff.added.hasOwnProperty(id)) {
if (diff.remoteDiff.newConfig.all.hasOwnProperty(id)) {
originalFlow.push(JSON.parse(JSON.stringify(diff.remoteDiff.newConfig.all[id])));
}
}
}
RED.nodes.clear(); RED.nodes.clear();
var imported = RED.nodes.import(newConfig); var imported = RED.nodes.import(newConfig);
// Restore the original flow so subsequent merge resolutions can properly
// identify new-vs-old
RED.nodes.originalFlow(originalFlow);
imported[0].forEach(function(n) { imported[0].forEach(function(n) {
if (nodeChangedStates[n.id] || localChangedStates[n.id]) { if (nodeChangedStates[n.id] || localChangedStates[n.id]) {
n.changed = true; n.changed = true;
@ -1402,11 +1420,16 @@ RED.diff = (function() {
RED.nodes.version(diff.remoteDiff.rev); RED.nodes.version(diff.remoteDiff.rev);
if (isDirty) {
RED.nodes.dirty(true);
}
RED.view.redraw(true); RED.view.redraw(true);
RED.palette.refresh(); RED.palette.refresh();
RED.workspaces.refresh(); RED.workspaces.refresh();
RED.sidebar.config.refresh(); RED.sidebar.config.refresh();
} }
function showTestFlowDiff(index) { function showTestFlowDiff(index) {
if (index === 1) { if (index === 1) {
var localFlow = RED.nodes.createCompleteNodeSet(); var localFlow = RED.nodes.createCompleteNodeSet();