Skip to content

Commit 34a7223

Browse files
committed
pass also ui patches
1 parent 4b77b78 commit 34a7223

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

services/static-webserver/client/source/class/osparc/data/model/Workbench.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,11 +817,17 @@ qx.Class.define("osparc.data.model.Workbench", {
817817
return Promise.all(promises);
818818
},
819819

820-
updateWorkbenchFromPatches: function(workbenchPatches) {
820+
/**
821+
* Update the workbench from the given patches.
822+
* @param workbenchPatches {Array} Array of workbench patches.
823+
* @param uiPatches {Array} Array of UI patches. They might contain info (position) about new nodes.
824+
*/
825+
updateWorkbenchFromPatches: function(workbenchPatches, uiPatches) {
821826
// group the patches by nodeId
822827
const nodesAdded = [];
823828
const nodesRemoved = [];
824829
const workbenchPatchesByNode = {};
830+
const workbenchUiPatchesByNode = {};
825831
workbenchPatches.forEach(workbenchPatch => {
826832
const nodeId = workbenchPatch.path.split("/")[2];
827833

@@ -846,10 +852,20 @@ qx.Class.define("osparc.data.model.Workbench", {
846852
if (nodesRemoved.length) {
847853
this.__removeNodesFromPatches(nodesRemoved, workbenchPatchesByNode);
848854
}
855+
849856
// second, add nodes if any
850857
if (nodesAdded.length) {
851858
// this will call update nodes once finished
852-
this.__addNodesFromPatches(nodesAdded, workbenchPatchesByNode);
859+
nodesAdded.forEach(nodeId => {
860+
const uiPatchFound = uiPatches.find(uiPatch => {
861+
const pathParts = uiPatch.path.split("/");
862+
return uiPatch.op === "add" && pathParts.length === 4 && pathParts[3] === nodeId;
863+
});
864+
if (uiPatchFound) {
865+
workbenchUiPatchesByNode[nodeId] = uiPatchFound;
866+
}
867+
});
868+
this.__addNodesFromPatches(nodesAdded, workbenchPatchesByNode, workbenchUiPatchesByNode);
853869
} else {
854870
// third, update nodes
855871
this.__updateNodesFromPatches(workbenchPatchesByNode);
@@ -873,7 +889,7 @@ qx.Class.define("osparc.data.model.Workbench", {
873889
});
874890
},
875891

876-
__addNodesFromPatches: function(nodesAdded, workbenchPatchesByNode) {
892+
__addNodesFromPatches: function(nodesAdded, workbenchPatchesByNode, workbenchUiPatchesByNode = {}) {
877893
nodesAdded.forEach(nodeId => {
878894
const addNodePatch = workbenchPatchesByNode[nodeId].find(workbenchPatch => {
879895
const pathParts = workbenchPatch.path.split("/");
@@ -885,8 +901,11 @@ qx.Class.define("osparc.data.model.Workbench", {
885901
if (index > -1) {
886902
workbenchPatchesByNode[nodeId].splice(index, 1);
887903
}
904+
905+
const nodeUiData = workbenchUiPatchesByNode[nodeId] && workbenchUiPatchesByNode[nodeId]["value"] ? workbenchUiPatchesByNode[nodeId]["value"] : {};
906+
888907
const node = this.__createNode(nodeData["key"], nodeData["version"], nodeId);
889-
node.fetchMetadataAndPopulate(nodeData, null)
908+
node.fetchMetadataAndPopulate(nodeData, nodeUiData)
890909
.then(() => {
891910
this.fireDataEvent("nodeAdded", node);
892911
node.checkState();

services/static-webserver/client/source/class/osparc/desktop/StudyEditor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
409409
}
410410
}
411411
if (workbenchPatches.length > 0) {
412-
this.getStudy().getWorkbench().updateWorkbenchFromPatches(workbenchPatches);
412+
this.getStudy().getWorkbench().updateWorkbenchFromPatches(workbenchPatches, uiPatches);
413413
}
414414
if (uiPatches.length > 0) {
415415
this.getStudy().getUi().updateUiFromPatches(uiPatches);

0 commit comments

Comments
 (0)