@@ -12,15 +12,20 @@ interface UsePackageGraphProps {
1212
1313export function usePackageGraph ( { packageName, purl, nodeType } : UsePackageGraphProps ) {
1414 const [ graph , setGraph ] = useState < GraphResponse > ( ( ) => {
15+ const props : any = {
16+ name : packageName ,
17+ }
18+
19+ if ( nodeType !== 'RequirementFile' ) {
20+ props . purl = purl
21+ }
22+
1523 return {
1624 nodes : [ {
1725 id : purl ,
1826 label : packageName ,
1927 type : nodeType ,
20- props : {
21- name : packageName ,
22- purl : purl
23- }
28+ props : props
2429 } ] ,
2530 edges : [ ]
2631 }
@@ -46,6 +51,10 @@ export function usePackageGraph({ packageName, purl, nodeType }: UsePackageGraph
4651 response = await depexAPI . graph . expandVersion ( {
4752 version_purl : node . props ?. purl || nodeId
4853 } )
54+ } else if ( node . type === 'RequirementFile' ) {
55+ response = await depexAPI . graph . expandReqFile ( {
56+ requirement_file_id : nodeId
57+ } )
4958 } else {
5059 // Find the REQUIRE edge that points to this package to get constraints
5160 const requireEdge = graph . edges . find (
@@ -72,14 +81,29 @@ export function usePackageGraph({ packageName, purl, nodeType }: UsePackageGraph
7281
7382 const currentIds = new Set ( current . nodes . map ( n => n . id ) )
7483 const addedNodeIds : string [ ] = [ ]
84+
85+ // Filter out nodes with null id and process valid nodes
7586 expandData . nodes . forEach ( ( n : GraphNode ) => {
87+ // Skip nodes with null or undefined id
88+ if ( n . id == null ) {
89+ console . warn ( 'Skipping node with null id:' , n )
90+ return
91+ }
92+
7693 if ( ! currentIds . has ( n . id ) ) addedNodeIds . push ( n . id )
7794 nodesById [ n . id ] = { ...nodesById [ n . id ] , ...n }
7895 } )
7996
8097 const edgesById : Record < string , GraphEdge > = { }
8198 current . edges . forEach ( ( e : GraphEdge ) => ( edgesById [ e . id ] = e ) )
99+
100+ // Filter out edges with null source or target
82101 expandData . edges . forEach ( ( e : GraphEdge ) => {
102+ // Skip edges with null id, source, or target
103+ if ( e . id == null || e . source == null || e . target == null ) {
104+ console . warn ( 'Skipping edge with null values:' , e )
105+ return
106+ }
83107 edgesById [ e . id ] = e
84108 } )
85109
@@ -96,7 +120,7 @@ export function usePackageGraph({ packageName, purl, nodeType }: UsePackageGraph
96120 } finally {
97121 setLoadingNodes ( ( s : Record < string , boolean > ) => ( { ...s , [ nodeId ] : false } ) )
98122 }
99- } , [ fetched , graph . nodes ] )
123+ } , [ fetched , graph ] )
100124
101125 const collapseNode = useCallback ( ( nodeId : string ) => {
102126 const toRemove : string [ ] = [ ]
@@ -142,15 +166,21 @@ export function usePackageGraph({ packageName, purl, nodeType }: UsePackageGraph
142166 } , [ expansions ] )
143167
144168 const reload = useCallback ( ( ) => {
169+ // Para RequirementFile, no incluir purl en props
170+ const props : any = {
171+ name : packageName ,
172+ }
173+
174+ if ( nodeType !== 'RequirementFile' ) {
175+ props . purl = purl
176+ }
177+
145178 setGraph ( {
146179 nodes : [ {
147180 id : purl ,
148181 label : packageName ,
149182 type : nodeType ,
150- props : {
151- name : packageName ,
152- purl : purl
153- }
183+ props : props
154184 } ] ,
155185 edges : [ ]
156186 } )
0 commit comments