11import {
2- LineageRelationResponseV1 ,
32 OutputRelationLineageResponseV1 ,
43 SymlinkRelationLineageResponseV1 ,
54 InputRelationLineageResponseV1 ,
65 ParentRelationLineageResponseV1 ,
76 BaseRelationLineageResponseV1 ,
87 LineageResponseV1 ,
8+ RelationEndpointLineageResponseV1 ,
99} from "@/dataProvider/types" ;
1010import { Edge , MarkerType } from "@xyflow/react" ;
11- import { getNodeId } from "./getGraphNodes" ;
1211
1312const STOKE_THICK = 3 ;
1413const STOKE_THIN = 1 ;
1514
16- export const getEdgeId = ( relation : BaseRelationLineageResponseV1 ) : string => {
15+ const getNodeId = ( node : RelationEndpointLineageResponseV1 ) : string => {
16+ return node . kind + "-" + node . id ;
17+ } ;
18+
19+ const getEdgeId = ( relation : BaseRelationLineageResponseV1 ) : string => {
1720 // @ts -expect-error Type field may be present in some relation types
1821 const type = relation . type ?? "" ;
1922 return `${ getNodeId ( relation . from ) } -${ type } ->${ getNodeId ( relation . to ) } ` ;
@@ -25,8 +28,6 @@ const getMinimalEdge = (relation: BaseRelationLineageResponseV1): Edge => {
2528 source : getNodeId ( relation . from ) ,
2629 target : getNodeId ( relation . to ) ,
2730 type : "baseEdge" ,
28- // @ts -expect-error For some reason, TS thinks that BaseRelation does not satisfy Record
29- data : relation ,
3031 markerEnd : {
3132 type : MarkerType . ArrowClosed ,
3233 } ,
@@ -40,9 +41,13 @@ const getMinimalEdge = (relation: BaseRelationLineageResponseV1): Edge => {
4041const getParentEdge = ( relation : ParentRelationLineageResponseV1 ) : Edge => {
4142 return {
4243 ...getMinimalEdge ( relation ) ,
44+ label : "PARENT" ,
45+ data : {
46+ ...relation ,
47+ kind : "PARENT" ,
48+ } ,
4349 sourceHandle : "bottom" ,
4450 targetHandle : "top" ,
45- label : "PARENT" ,
4651 } ;
4752} ;
4853
@@ -64,6 +69,10 @@ const getOutputEdge = (relation: OutputRelationLineageResponseV1): Edge => {
6469 return {
6570 ...getMinimalEdge ( relation ) ,
6671 type : "ioEdge" ,
72+ data : {
73+ ...relation ,
74+ kind : "OUTPUT" ,
75+ } ,
6776 animated : true ,
6877 markerEnd : {
6978 type : MarkerType . ArrowClosed ,
@@ -84,6 +93,10 @@ const getInputEdge = (relation: InputRelationLineageResponseV1): Edge => {
8493 return {
8594 ...getMinimalEdge ( relation ) ,
8695 type : "ioEdge" ,
96+ data : {
97+ ...relation ,
98+ kind : "INPUT" ,
99+ } ,
87100 animated : true ,
88101 markerEnd : {
89102 type : MarkerType . ArrowClosed ,
@@ -128,12 +141,17 @@ const getSymlinkEdge = (
128141 // with more simple graphs, like these:
129142 //
130143 // HDFS <-> Hive -> Job
131- const targetRelations = raw_response . relations . filter (
132- ( r ) => r . to . id == relation . to . id || r . from . id == relation . to . id ,
144+ const anyTargetInput = raw_response . relations . inputs . find (
145+ ( r ) => r . from . id == relation . to . id ,
133146 ) ;
134- const targetHasOnlyOutputs = targetRelations . every (
135- ( r ) => r . kind == "OUTPUT" || r . kind == "SYMLINK" ,
147+ const anyTargetOutput = raw_response . relations . outputs . find (
148+ ( r ) => r . to . id == relation . to . id ,
149+ ) ;
150+ const anyTargetSymlink = raw_response . relations . symlinks . find (
151+ ( r ) => r . to . id == relation . to . id || r . from . id == relation . to . id ,
136152 ) ;
153+ const targetHasOnlyOutputs =
154+ ( ! ! anyTargetOutput || ! ! anyTargetSymlink ) && ! anyTargetInput ;
137155
138156 const color = "purple" ;
139157
@@ -146,6 +164,10 @@ const getSymlinkEdge = (
146164 target : targetHasOnlyOutputs
147165 ? getNodeId ( relation . from )
148166 : getNodeId ( relation . to ) ,
167+ data : {
168+ ...relation ,
169+ kind : "SYMLINK" ,
170+ } ,
149171 markerStart : {
150172 type : MarkerType . ArrowClosed ,
151173 color : color ,
@@ -164,35 +186,15 @@ const getSymlinkEdge = (
164186 } ;
165187} ;
166188
167- const getGraphEdge = (
168- relation : LineageRelationResponseV1 ,
169- raw_response : LineageResponseV1 ,
170- ) : Edge | null => {
171- switch ( relation . kind ) {
172- case "PARENT" :
173- return getParentEdge ( relation ) ;
174- case "OUTPUT" :
175- return getOutputEdge ( relation ) ;
176- case "INPUT" :
177- return getInputEdge ( relation ) ;
178- case "SYMLINK" :
179- return getSymlinkEdge ( relation , raw_response ) ;
180- default :
181- return getMinimalEdge ( relation ) ;
182- }
183- } ;
184-
185189const getGraphEdges = ( raw_response : LineageResponseV1 ) : Edge [ ] => {
186- const result : Edge [ ] = [ ] ;
187-
188- raw_response . relations . forEach ( ( relation ) => {
189- const edge = getGraphEdge ( relation , raw_response ) ;
190- if ( edge ) {
191- result . push ( edge ) ;
192- }
193- } ) ;
194-
195- return result ;
190+ return [
191+ ...raw_response . relations . parents . map ( getParentEdge ) ,
192+ ...raw_response . relations . inputs . map ( getInputEdge ) ,
193+ ...raw_response . relations . outputs . map ( getOutputEdge ) ,
194+ ...raw_response . relations . symlinks
195+ . map ( ( relation ) => getSymlinkEdge ( relation , raw_response ) )
196+ . filter ( ( edge ) => edge !== null ) ,
197+ ] ;
196198} ;
197199
198200export default getGraphEdges ;
0 commit comments