1- import { addManuallyAddedArtifacts } from "@/components/dag-visualizer/add-manual-artifacts" ;
2- import {
3- extractExistingNodes ,
4- extractPlaceholderLayout ,
5- StepDict
6- } from "@/components/dag-visualizer/extract-layout" ;
71import { getLayoutedNodes } from "@/components/dag-visualizer/layout" ;
2+ import { mergeRealAndPlacehodlerData } from "@/components/dag-visualizer/layout/helper" ;
3+ import { extractPlaceholderLayout } from "@/components/dag-visualizer/layout/placeholder" ;
4+ import { extractExistingNodes } from "@/components/dag-visualizer/layout/real-data" ;
85import { pipelineDeploymentQueries } from "@/data/pipeline-deployments" ;
96import { usePipelineRun } from "@/data/pipeline-runs/pipeline-run-detail-query" ;
107import { StepOutput } from "@/types/pipeline-deployments" ;
8+ import { StepDict } from "@/types/steps" ;
119import { useQuery } from "@tanstack/react-query" ;
1210import { useCallback , useEffect , useLayoutEffect , useMemo } from "react" ;
1311import { useParams } from "react-router-dom" ;
14- import { Edge , useEdgesState , useNodesState , useReactFlow , useStore } from "reactflow" ;
12+ import { useEdgesState , useNodesState , useReactFlow , useStore } from "reactflow" ;
1513
1614export function useDag ( ) {
1715 const { runId } = useParams ( ) as { runId : string } ;
@@ -22,7 +20,7 @@ export function useDag() {
2220 }
2321 ) ;
2422 const pipelineDeployment = useQuery ( {
25- ...pipelineDeploymentQueries . detail ( pipelineRun . data ?. body ?. deployment_id ! ) ,
23+ ...pipelineDeploymentQueries . detail ( pipelineRun . data ?. body ?. deployment_id || "" ) ,
2624 enabled : ! ! pipelineRun . data ?. body ?. deployment_id
2725 } ) ;
2826
@@ -44,31 +42,13 @@ export function useDag() {
4442
4543 const onDagreLayout = useCallback ( ( ) => {
4644 // replayed layouted with nodes from readNodes, in case the id is the same
47- const nodes = placeholderData . nodes . map ( ( node ) => {
48- const realNode = realNodes . find ( ( n ) => n . id === node . id ) ;
49- if ( realNode ) {
50- return { ...node , ...realNode } ;
51- }
52- return {
53- ...node ,
54- data : { ...node . data , status : pipelineRun . data ?. body ?. status ?? "running" }
55- } ;
56- } ) ;
57-
58- addManuallyAddedArtifacts (
59- nodes ,
60- realNodes ,
61- pipelineRun . data ?. metadata ?. steps as StepDict ,
62- placeholderData . edges
63- ) ;
6445
65- // add a custom styling to edges that have a real node as the target
66- const edges : Edge [ ] = placeholderData . edges . map ( ( edge ) => {
67- const realNode = realNodes . find ( ( n ) => n . id === edge . target ) ;
68- return {
69- ...edge ,
70- style : { stroke : realNode ? "#9CA3AF" : "#D1D5DB" , strokeWidth : 2 }
71- } ;
46+ const { nodes, edges } = mergeRealAndPlacehodlerData ( {
47+ placeholderEdges : placeholderData . edges ,
48+ placeholderNodes : placeholderData . nodes ,
49+ realEdges : realNodes . edges ,
50+ realNodes : realNodes . nodes ,
51+ runStatus : pipelineRun . data ?. body ?. status ?? "running"
7252 } ) ;
7353
7454 const layouted = getLayoutedNodes ( nodes , edges ) ;
@@ -83,7 +63,7 @@ export function useDag() {
8363
8464 useEffect ( ( ) => {
8565 fitView ( ) ; // Keep an eye on performance here
86- } , [ width , height ] ) ;
66+ } , [ width , height , fitView ] ) ;
8767
8868 useEffect ( ( ) => {
8969 const timeout = setTimeout ( ( ) => {
@@ -92,7 +72,7 @@ export function useDag() {
9272 return ( ) => {
9373 clearTimeout ( timeout ) ;
9474 } ;
95- } , [ pipelineDeployment . data , pipelineRun . data ] ) ;
75+ } , [ pipelineDeployment . data , pipelineRun . data , fitView ] ) ;
9676
9777 useLayoutEffect ( ( ) => {
9878 onDagreLayout ( ) ;
0 commit comments