@@ -483,7 +483,24 @@ const mutations = {
483483 localStorage . setItem ( 'topologyServicesInstanceDependency' , JSON . stringify ( state . topoServicesInstanceDependency ) ) ;
484484 } ,
485485 [ types . SET_ENDPOINT_DEPENDENCY ] ( state : State , data : { calls : Call [ ] ; nodes : Node [ ] } ) {
486- state . endpointDependency = data ;
486+ const obj = { } as any ;
487+ let nodes = [ ] ;
488+ let calls = [ ] ;
489+ nodes = data . nodes . reduce ( ( prev : Node [ ] , next : Node ) => {
490+ if ( ! obj [ next . id ] ) {
491+ obj [ next . id ] = true ;
492+ prev . push ( next ) ;
493+ }
494+ return prev ;
495+ } , [ ] ) ;
496+ calls = data . calls . reduce ( ( prev : Call [ ] , next : Call ) => {
497+ if ( ! obj [ next . id ] ) {
498+ obj [ next . id ] = true ;
499+ prev . push ( next ) ;
500+ }
501+ return prev ;
502+ } , [ ] ) ;
503+ state . endpointDependency = { nodes, calls } ;
487504 state . selectedEndpointCall = null ;
488505 } ,
489506 [ types . SET_ENDPOINT_DEPTH ] ( state : State , data : { key : number ; label : string } ) {
@@ -709,18 +726,31 @@ const actions: ActionTree<State, any> = {
709726 const endpointIds = res . nodes
710727 . map ( ( item : Node ) => item . id )
711728 . filter ( ( d : string ) => ! params . endpointIds . includes ( d ) ) ;
712-
729+ if ( ! endpointIds . length ) {
730+ context . commit ( types . SET_ENDPOINT_DEPENDENCY , res ) ;
731+ return ;
732+ }
713733 context . dispatch ( 'GET_ENDPOINT_TOPO' , { endpointIds, duration : params . duration } ) . then ( ( json ) => {
714734 if ( context . state . currentEndpointDepth . key > 2 ) {
715735 const ids = json . nodes
716736 . map ( ( item : Node ) => item . id )
717737 . filter ( ( d : string ) => ! [ ...endpointIds , ...params . endpointIds ] . includes ( d ) ) ;
718-
738+ if ( ! ids . length ) {
739+ const nodes = [ ...res . nodes , ...json . nodes ] ;
740+ const calls = [ ...res . calls , ...json . calls ] ;
741+ context . commit ( types . SET_ENDPOINT_DEPENDENCY , { nodes, calls } ) ;
742+ return ;
743+ }
719744 context . dispatch ( 'GET_ENDPOINT_TOPO' , { endpointIds : ids , duration : params . duration } ) . then ( ( topo ) => {
720745 if ( context . state . currentEndpointDepth . key > 3 ) {
721746 const endpoints = topo . nodes
722747 . map ( ( item : Node ) => item . id )
723748 . filter ( ( d : string ) => ! [ ...ids , ...endpointIds , ...params . endpointIds ] . includes ( d ) ) ;
749+ if ( ! endpoints . length ) {
750+ const nodes = [ ...res . nodes , ...json . nodes , ...topo . nodes ] ;
751+ const calls = [ ...res . calls , ...json . calls , ...topo . calls ] ;
752+ context . commit ( types . SET_ENDPOINT_DEPENDENCY , { nodes, calls } ) ;
753+ }
724754 context
725755 . dispatch ( 'GET_ENDPOINT_TOPO' , { endpointIds : endpoints , duration : params . duration } )
726756 . then ( ( data ) => {
@@ -730,21 +760,35 @@ const actions: ActionTree<State, any> = {
730760 . filter (
731761 ( d : string ) => ! [ ...endpoints , ...ids , ...endpointIds , ...params . endpointIds ] . includes ( d ) ,
732762 ) ;
763+ if ( ! nodeIds . length ) {
764+ const nodes = [ ...res . nodes , ...json . nodes , ...topo . nodes , ...data . nodes ] ;
765+ const calls = [ ...res . calls , ...json . calls , ...topo . calls , ...data . calls ] ;
766+ context . commit ( types . SET_ENDPOINT_DEPENDENCY , { nodes, calls } ) ;
767+ return ;
768+ }
733769 context
734770 . dispatch ( 'GET_ENDPOINT_TOPO' , { endpointIds : nodeIds , duration : params . duration } )
735771 . then ( ( toposObj ) => {
736- context . commit ( types . SET_ENDPOINT_DEPENDENCY , toposObj ) ;
772+ const nodes = [ ...res . nodes , ...json . nodes , ...topo . nodes , ...data . nodes , ...toposObj . nodes ] ;
773+ const calls = [ ...res . calls , ...json . calls , ...topo . calls , ...data . calls , ...toposObj . calls ] ;
774+ context . commit ( types . SET_ENDPOINT_DEPENDENCY , { nodes, calls } ) ;
737775 } ) ;
738776 } else {
739- context . commit ( types . SET_ENDPOINT_DEPENDENCY , data ) ;
777+ const nodes = [ ...res . nodes , ...json . nodes , ...topo . nodes , ...data . nodes ] ;
778+ const calls = [ ...res . calls , ...json . calls , ...topo . calls , ...data . calls ] ;
779+ context . commit ( types . SET_ENDPOINT_DEPENDENCY , { nodes, calls } ) ;
740780 }
741781 } ) ;
742782 } else {
743- context . commit ( types . SET_ENDPOINT_DEPENDENCY , topo ) ;
783+ const nodes = [ ...res . nodes , ...json . nodes , ...topo . nodes ] ;
784+ const calls = [ ...res . calls , ...json . calls , ...topo . calls ] ;
785+ context . commit ( types . SET_ENDPOINT_DEPENDENCY , { nodes, calls } ) ;
744786 }
745787 } ) ;
746788 } else {
747- context . commit ( types . SET_ENDPOINT_DEPENDENCY , json ) ;
789+ const nodes = [ ...res . nodes , ...json . nodes ] ;
790+ const calls = [ ...res . calls , ...json . calls ] ;
791+ context . commit ( types . SET_ENDPOINT_DEPENDENCY , { nodes, calls } ) ;
748792 }
749793 } ) ;
750794 } else {
0 commit comments