Skip to content

Commit

Permalink
Merge pull request #4692 from node-red/improve-conflict-handling
Browse files Browse the repository at this point in the history
Improve background-deploy notification handling
  • Loading branch information
knolleary committed May 14, 2024
2 parents d520cde + 14dfb9a commit a977b87
Show file tree
Hide file tree
Showing 5 changed files with 264 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
"deleted": "deleted",
"flowDeleted": "flow deleted",
"flowAdded": "flow added",
"moved": "moved",
"movedTo": "moved to __id__",
"movedFrom": "moved from __id__"
},
Expand Down
41 changes: 38 additions & 3 deletions packages/node_modules/@node-red/editor-client/src/js/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ RED.history = (function() {
}
return RED.nodes.junction(id);
}

function ensureUnlocked(id, flowsToLock) {
const flow = id && (RED.nodes.workspace(id) || RED.nodes.subflow(id) || null);
const isLocked = flow ? flow.locked : false;
if (flow && isLocked) {
flow.locked = false;
flowsToLock.add(flow)
}
}
function undoEvent(ev) {
var i;
var len;
Expand Down Expand Up @@ -59,18 +66,46 @@ RED.history = (function() {
t: 'replace',
config: RED.nodes.createCompleteNodeSet(),
changed: {},
rev: RED.nodes.version()
moved: {},
complete: true,
rev: RED.nodes.version(),
dirty: RED.nodes.dirty()
};
var selectedTab = RED.workspaces.active();
inverseEv.config.forEach(n => {
const node = RED.nodes.node(n.id)
if (node) {
inverseEv.changed[n.id] = node.changed
inverseEv.moved[n.id] = node.moved
}
})
RED.nodes.clear();
var imported = RED.nodes.import(ev.config);
// Clear all change flags from the import
RED.nodes.dirty(false);

const flowsToLock = new Set()

imported.nodes.forEach(function(n) {
if (ev.changed[n.id]) {
ensureUnlocked(n.z, flowsToLock)
n.changed = true;
inverseEv.changed[n.id] = true;
}
if (ev.moved[n.id]) {
ensureUnlocked(n.z, flowsToLock)
n.moved = true;
}
})
flowsToLock.forEach(flow => {
flow.locked = true
})

RED.nodes.version(ev.rev);
RED.view.redraw(true);
RED.palette.refresh();
RED.workspaces.refresh();
RED.workspaces.show(selectedTab, true);
RED.sidebar.config.refresh();
} else {
var importMap = {};
ev.config.forEach(function(n) {
Expand Down
91 changes: 48 additions & 43 deletions packages/node_modules/@node-red/editor-client/src/js/ui/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ RED.deploy = (function() {

var currentDiff = null;

var activeBackgroundDeployNotification;

function changeDeploymentType(type) {
deploymentType = type;
$("#red-ui-header-button-deploy-icon").attr("src",deploymentTypes[type].img);
Expand Down Expand Up @@ -133,37 +135,38 @@ RED.deploy = (function() {
}
});

var activeNotifyMessage;
RED.comms.subscribe("notification/runtime-deploy",function(topic,msg) {
if (!activeNotifyMessage) {
var currentRev = RED.nodes.version();
if (currentRev === null || deployInflight || currentRev === msg.revision) {
return;
}
var message = $('<p>').text(RED._('deploy.confirm.backgroundUpdate'));
activeNotifyMessage = RED.notify(message,{
modal: true,
fixed: true,
buttons: [
{
text: RED._('deploy.confirm.button.ignore'),
click: function() {
activeNotifyMessage.close();
activeNotifyMessage = null;
}
},
{
text: RED._('deploy.confirm.button.review'),
class: "primary",
click: function() {
activeNotifyMessage.close();
var nns = RED.nodes.createCompleteNodeSet();
resolveConflict(nns,false);
activeNotifyMessage = null;
}
var currentRev = RED.nodes.version();
if (currentRev === null || deployInflight || currentRev === msg.revision) {
return;
}
if (activeBackgroundDeployNotification?.hidden && !activeBackgroundDeployNotification?.closed) {
activeBackgroundDeployNotification.showNotification()
return
}
const message = $('<p>').text(RED._('deploy.confirm.backgroundUpdate'));
const options = {
id: 'background-update',
type: 'compact',
modal: false,
fixed: true,
timeout: 10000,
buttons: [
{
text: RED._('deploy.confirm.button.review'),
class: "primary",
click: function() {
activeBackgroundDeployNotification.hideNotification();
var nns = RED.nodes.createCompleteNodeSet();
resolveConflict(nns,false);
}
]
});
}
]
}
if (!activeBackgroundDeployNotification || activeBackgroundDeployNotification.closed) {
activeBackgroundDeployNotification = RED.notify(message, options)
} else {
activeBackgroundDeployNotification.update(message, options)
}
});
}
Expand Down Expand Up @@ -220,7 +223,11 @@ RED.deploy = (function() {
class: "primary disabled",
click: function() {
if (!$("#red-ui-deploy-dialog-confirm-deploy-review").hasClass('disabled')) {
RED.diff.showRemoteDiff();
RED.diff.showRemoteDiff(null, {
onmerge: function () {
activeBackgroundDeployNotification.close()
}
});
conflictNotification.close();
}
}
Expand All @@ -233,6 +240,7 @@ RED.deploy = (function() {
if (!$("#red-ui-deploy-dialog-confirm-deploy-merge").hasClass('disabled')) {
RED.diff.mergeDiff(currentDiff);
conflictNotification.close();
activeBackgroundDeployNotification.close()
}
}
}
Expand All @@ -245,6 +253,7 @@ RED.deploy = (function() {
click: function() {
save(true,activeDeploy);
conflictNotification.close();
activeBackgroundDeployNotification.close()
}
})
}
Expand All @@ -255,21 +264,17 @@ RED.deploy = (function() {
buttons: buttons
});

var now = Date.now();
RED.diff.getRemoteDiff(function(diff) {
var ellapsed = Math.max(1000 - (Date.now()-now), 0);
currentDiff = diff;
setTimeout(function() {
conflictCheck.hide();
var d = Object.keys(diff.conflicts);
if (d.length === 0) {
conflictAutoMerge.show();
$("#red-ui-deploy-dialog-confirm-deploy-merge").removeClass('disabled')
} else {
conflictManualMerge.show();
}
$("#red-ui-deploy-dialog-confirm-deploy-review").removeClass('disabled')
},ellapsed);
conflictCheck.hide();
var d = Object.keys(diff.conflicts);
if (d.length === 0) {
conflictAutoMerge.show();
$("#red-ui-deploy-dialog-confirm-deploy-merge").removeClass('disabled')
} else {
conflictManualMerge.show();
}
$("#red-ui-deploy-dialog-confirm-deploy-review").removeClass('disabled')
})
}
function cropList(list) {
Expand Down

0 comments on commit a977b87

Please sign in to comment.