Skip to content

✨ Frontend: wait for backend's confirmation before removing a node #4639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original file line number Diff line number Diff line change
Expand Up @@ -578,18 +578,6 @@ qx.Class.define("osparc.data.model.Node", {
});
},

__deleteInBackend: function() {
// remove node in the backend
const params = {
url: {
studyId: this.getStudy().getUuid(),
nodeId: this.getNodeId()
}
};
osparc.data.Resources.fetch("studies", "deleteNode", params)
.catch(err => console.error(err));
},

__applyPropsForm: function() {
const checkIsPipelineRunning = () => {
const isPipelineRunning = this.getStudy().isPipelineRunning();
Expand Down Expand Up @@ -1503,8 +1491,28 @@ qx.Class.define("osparc.data.model.Node", {
},

removeNode: function() {
this.__deleteInBackend();
this.removeIFrame();
return new Promise(resolve => {
this.__deleteInBackend()
.then(() => {
resolve(true);
this.removeIFrame();
})
.catch(err => {
console.error(err);
resolve(false);
});
});
},

__deleteInBackend: function() {
// remove node in the backend
const params = {
url: {
studyId: this.getStudy().getUuid(),
nodeId: this.getNodeId()
}
};
return osparc.data.Resources.fetch("studies", "deleteNode", params);
},

stopRequestingStatus: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,34 +503,35 @@ qx.Class.define("osparc.data.model.Workbench", {
this.fireEvent("pipelineChanged");
},

removeNode: function(nodeId) {
removeNode: async function(nodeId) {
if (!osparc.data.Permissions.getInstance().canDo("study.node.delete", true)) {
return false;
}

// remove first the connected edges
const connectedEdges = this.getConnectedEdges(nodeId);
connectedEdges.forEach(connectedEdgeId => {
this.removeEdge(connectedEdgeId);
});

let node = this.getNode(nodeId);
if (node) {
node.removeNode();
const removed = await node.removeNode();
if (removed) {
// remove first the connected edges
const connectedEdges = this.getConnectedEdges(nodeId);
connectedEdges.forEach(connectedEdgeId => {
this.removeEdge(connectedEdgeId);
});

const isTopLevel = Object.prototype.hasOwnProperty.call(this.__rootNodes, nodeId);
if (isTopLevel) {
delete this.__rootNodes[nodeId];
}
const isTopLevel = Object.prototype.hasOwnProperty.call(this.__rootNodes, nodeId);
if (isTopLevel) {
delete this.__rootNodes[nodeId];
}

// remove it from slideshow
if (this.getStudy()) {
this.getStudy().getUi().getSlideshow()
.removeNode(nodeId);
}
// remove it from slideshow
if (this.getStudy()) {
this.getStudy().getUi().getSlideshow()
.removeNode(nodeId);
}

this.fireEvent("pipelineChanged");
return true;
this.fireEvent("pipelineChanged");
return true;
}
}
return false;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1276,10 +1276,11 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
}
},

__doRemoveNode: function(nodeId) {
__doRemoveNode: async function(nodeId) {
const workbench = this.getStudy().getWorkbench();
const connectedEdges = workbench.getConnectedEdges(nodeId);
if (workbench.removeNode(nodeId)) {
const removed = await workbench.removeNode(nodeId);
if (removed) {
// remove first the connected edges
for (let i = 0; i < connectedEdges.length; i++) {
const edgeId = connectedEdges[i];
Expand Down