@@ -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 ( ) ;
0 commit comments