1- import React , { useMemo , useState } from 'react' ;
2- import { ReactFlow , Background , Controls , MarkerType } from '@xyflow/react' ;
1+ import React , { useState , useCallback , useMemo } from 'react' ;
2+ import { ReactFlow , Background , Controls , MarkerType , Node } from '@xyflow/react' ;
33import type { NodeProps } from '@xyflow/react' ;
44import { RadioButton , FlexBox , FlexBoxAlignItems } from '@ui5/webcomponents-react' ;
55import styles from './Graph.module.css' ;
66import '@xyflow/react/dist/style.css' ;
7- import { ManagedResourceItem } from './types' ;
7+ import { ManagedResourceItem , NodeData } from './types' ;
88import CustomNode from './CustomNode' ;
99import { Legend , LegendItem } from './Legend' ;
1010import { YamlViewDialog } from '../Yaml/YamlViewDialog' ;
@@ -14,34 +14,35 @@ import { removeManagedFieldsProperty } from '../../utils/removeManagedFieldsProp
1414import { useTranslation } from 'react-i18next' ;
1515import { useGraph } from './useGraph' ;
1616
17+ const nodeTypes = {
18+ custom : ( props : NodeProps < Node < NodeData , 'custom' > > ) => (
19+ < CustomNode
20+ label = { props . data . label }
21+ type = { props . data . type }
22+ status = { props . data . status }
23+ onYamlClick = { ( ) => props . data . onYamlClick ( props . data . item ) }
24+ />
25+ ) ,
26+ } ;
27+
1728const Graph : React . FC = ( ) => {
1829 const { t } = useTranslation ( ) ;
1930 const [ colorBy , setColorBy ] = useState < 'provider' | 'source' > ( 'provider' ) ;
20- const { nodes, edges, colorMap, treeData, loading, error } = useGraph ( colorBy ) ;
21-
2231 const [ yamlDialogOpen , setYamlDialogOpen ] = useState ( false ) ;
2332 const [ yamlResource , setYamlResource ] = useState < ManagedResourceItem | null > ( null ) ;
2433
25- const handleYamlClick = ( item : ManagedResourceItem ) => {
34+ const handleYamlClick = useCallback ( ( item : ManagedResourceItem ) => {
2635 setYamlResource ( item ) ;
2736 setYamlDialogOpen ( true ) ;
28- } ;
37+ } , [ ] ) ;
2938
30- const nodeTypes = {
31- custom : ( props : NodeProps ) => (
32- < CustomNode
33- label = { props . data . label as string }
34- type = { props . data . type as string }
35- status = { props . data . status as string }
36- onYamlClick = { ( ) => handleYamlClick ( props . data . item as ManagedResourceItem ) }
37- />
38- ) ,
39- } ;
39+ const { nodes, edges, colorMap, treeData, loading, error } = useGraph ( colorBy , handleYamlClick ) ;
4040
4141 const yamlString = useMemo (
4242 ( ) => ( yamlResource ? stringify ( removeManagedFieldsProperty ( yamlResource ) ) : '' ) ,
4343 [ yamlResource ] ,
4444 ) ;
45+
4546 const yamlFilename = useMemo ( ( ) => {
4647 if ( ! yamlResource ) return '' ;
4748 const { kind, metadata } = yamlResource ;
0 commit comments