Skip to content

Commit 42bcd55

Browse files
committed
WIP: build direct nodes
1 parent 79884cf commit 42bcd55

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

Diff for: src/lib/components/workflow/workflow-relationships.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
2727
$: rootWorkflowId = workflow.rootExecution.workflowId;
2828
$: rootRunId = workflow.rootExecution.runId;
29-
$: parentWorkflowId = workflow.parent.workflowId;
30-
$: parentRunId = workflow.parent.runId;
29+
$: parentWorkflowId = workflow?.parent?.workflowId;
30+
$: parentRunId = workflow?.parent?.runId;
3131
3232
$: workflowRelationships = getWorkflowRelationships(
3333
workflow,
@@ -66,7 +66,7 @@
6666
</div>
6767
</div>
6868
{:else if intCount > FULL_TREE_LIMIT}
69-
{#await fetchAllDirectWorkflows( { namespace, workflowId, runId, parentWorkflowId, parentRunId }, )}
69+
{#await fetchAllDirectWorkflows( { namespace, parentWorkflowId, parentRunId, workflow }, )}
7070
<Loading />
7171
{:then root}
7272
{#if root && !!root.children.length}

Diff for: src/lib/services/workflow-service.ts

+44-11
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,44 @@ const buildRoots = (
792792
return buildNode(root, []);
793793
};
794794

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+
795833
export async function fetchAllRootWorkflowsCount(
796834
namespace: string,
797835
rootWorkflowId: string,
@@ -831,31 +869,26 @@ export async function fetchAllRootWorkflows(
831869

832870
type DirectWorkflowInputs = {
833871
namespace: string;
834-
workflowId: string;
835-
runId?: string;
836872
parentWorkflowId: string;
837873
parentRunId?: string;
874+
workflow: WorkflowExecution;
838875
};
839876

840877
export async function fetchAllDirectWorkflows({
841878
namespace,
842-
workflowId,
843-
runId,
844879
parentWorkflowId,
845880
parentRunId,
881+
workflow,
846882
}: DirectWorkflowInputs): Promise<RootNode | undefined> {
847-
let query = `ParentWorkflowId = "${workflowId}"`;
848-
if (runId) {
849-
query += ` AND ParentRunId = "${runId}"`;
850-
}
851-
852883
const parent = await fetchWorkflow({
853884
namespace,
854885
workflowId: parentWorkflowId,
855886
runId: parentRunId,
856887
});
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 });
859892
}
860893

861894
export const fetchAllPaginatedWorkflows = async (

0 commit comments

Comments
 (0)