@@ -792,6 +792,44 @@ const buildRoots = (
792
792
return buildNode ( root , [ ] ) ;
793
793
} ;
794
794
795
+ const buildDirectRoots = ( {
796
+ parent,
797
+ workflow,
798
+ children,
799
+ } : {
800
+ parent : WorkflowExecution ;
801
+ workflow : WorkflowExecution ;
802
+ children : WorkflowExecution [ ] ;
803
+ } ) => {
804
+ const childNodes = children . map ( ( child ) => {
805
+ return {
806
+ workflow : child ,
807
+ children : [ ] ,
808
+ rootPaths : [
809
+ ...currentNode . rootPaths ,
810
+ { runId : child . runId , workflowId : child . id } ,
811
+ ] ,
812
+ } ;
813
+ } ) ;
814
+
815
+ const currentNode = {
816
+ workflow,
817
+ children : childNodes ,
818
+ rootPaths : [
819
+ { runId : parent . runId , workflowId : parent . id } ,
820
+ { runId : workflow . runId , workflowId : workflow . id } ,
821
+ ] ,
822
+ } ;
823
+
824
+ const parentNode = {
825
+ workflow : parent ,
826
+ children : currentNode ,
827
+ rootPaths : [ { runId : parent . runId , workflowId : parent . id } ] ,
828
+ } ;
829
+
830
+ return parentNode ;
831
+ } ;
832
+
795
833
export async function fetchAllRootWorkflowsCount (
796
834
namespace : string ,
797
835
rootWorkflowId : string ,
@@ -831,31 +869,26 @@ export async function fetchAllRootWorkflows(
831
869
832
870
type DirectWorkflowInputs = {
833
871
namespace : string ;
834
- workflowId : string ;
835
- runId ?: string ;
836
872
parentWorkflowId : string ;
837
873
parentRunId ?: string ;
874
+ workflow : WorkflowExecution ;
838
875
} ;
839
876
840
877
export async function fetchAllDirectWorkflows ( {
841
878
namespace,
842
- workflowId,
843
- runId,
844
879
parentWorkflowId,
845
880
parentRunId,
881
+ workflow,
846
882
} : DirectWorkflowInputs ) : Promise < RootNode | undefined > {
847
- let query = `ParentWorkflowId = "${ workflowId } "` ;
848
- if ( runId ) {
849
- query += ` AND ParentRunId = "${ runId } "` ;
850
- }
851
-
852
883
const parent = await fetchWorkflow ( {
853
884
namespace,
854
885
workflowId : parentWorkflowId ,
855
886
runId : parentRunId ,
856
887
} ) ;
857
- const childWorkflows = await fetchAllPaginatedWorkflows ( namespace , { query } ) ;
858
- return buildRoots ( parent ?. workflow , childWorkflows ) ;
888
+
889
+ const query = `ParentWorkflowId = "${ workflow . id } " AND ParentRunId = "${ workflow . runId } "` ;
890
+ const children = await fetchAllPaginatedWorkflows ( namespace , { query } ) ;
891
+ return buildDirectRoots ( { parent, workflow, children } ) ;
859
892
}
860
893
861
894
export const fetchAllPaginatedWorkflows = async (
0 commit comments