@@ -80,15 +80,19 @@ const customLayoutFactory: LayoutFactory = (type: string, graph: Graph): Layout
8080 } ) ;
8181} ;
8282
83+ interface ApplicationContextMenuParams {
84+ application : ApplicationKind ;
85+ navigate : NavigateFunction ;
86+ launchLabelsModal : ( ) => void ;
87+ launchAnnotationsModal : ( ) => void ;
88+ launchDeleteModal : ( ) => void ;
89+ setGroupNodeStates : React . Dispatch < React . SetStateAction < string [ ] > > ;
90+ }
91+
8392const customComponentFactory =
8493 (
8594 hrefRef : React . MutableRefObject < string > ,
86- application : ApplicationKind ,
87- navigate : NavigateFunction ,
88- launchLabelsModal : ( ) => void ,
89- launchAnnotationsModal : ( ) => void ,
90- launchDeleteModal : ( ) => void ,
91- setGroupNodeStates : React . Dispatch < React . SetStateAction < string [ ] > > ,
95+ paramsRef : React . RefObject < ApplicationContextMenuParams > ,
9296 ) : ComponentFactory =>
9397 ( kind : ModelKind , type : string ) => {
9498 const createContextMenuItems = (
@@ -132,11 +136,15 @@ const customComponentFactory =
132136 < ContextMenuItem
133137 key = { label }
134138 onClick = { ( ) => {
139+ const params = paramsRef . current ;
140+ if ( ! params ) {
141+ return ;
142+ }
135143 if ( label === t ( 'View in Argo CD' ) ) {
136144 window . open ( hrefRef . current , '_blank' ) ;
137145 }
138146 if ( label === t ( 'View Details' ) ) {
139- navigate ( graphElement . getData ( ) . resourcePath ) ;
147+ params . navigate ( graphElement . getData ( ) . resourcePath ) ;
140148 }
141149 } }
142150 >
@@ -180,6 +188,18 @@ const customComponentFactory =
180188 < ContextMenuItem
181189 key = { label }
182190 onClick = { async ( ) => {
191+ const params = paramsRef . current ;
192+ if ( ! params ) {
193+ return ;
194+ }
195+ const {
196+ application,
197+ navigate,
198+ launchLabelsModal,
199+ launchAnnotationsModal,
200+ launchDeleteModal,
201+ setGroupNodeStates,
202+ } = params ;
183203 if ( label === t ( 'View in Argo CD' ) ) {
184204 window . open ( hrefRef . current , '_blank' ) ;
185205 } else if ( label === t ( 'Edit labels' ) ) {
@@ -339,22 +359,34 @@ export const ApplicationGraphView: React.FC<{
339359 const launchDeleteModal = useDeleteModal ( application ) ;
340360 const navigate = useNavigate ( ) ;
341361
362+ const contextMenuParamsRef = React . useRef < ApplicationContextMenuParams > ( {
363+ application,
364+ navigate,
365+ launchLabelsModal,
366+ launchAnnotationsModal,
367+ launchDeleteModal,
368+ setGroupNodeStates,
369+ } ) ;
370+
371+ React . useEffect ( ( ) => {
372+ contextMenuParamsRef . current = {
373+ application,
374+ navigate,
375+ launchLabelsModal,
376+ launchAnnotationsModal,
377+ launchDeleteModal,
378+ setGroupNodeStates,
379+ } ;
380+ } , [ application , navigate , launchLabelsModal , launchAnnotationsModal , launchDeleteModal ] ) ;
381+
342382 const controller = React . useMemo ( ( ) => {
343383 const newController = new Visualization ( ) ;
344384 newController . registerLayoutFactory ( customLayoutFactory ) ;
345- newController . registerComponentFactory (
346- customComponentFactory (
347- hrefRef ,
348- application ,
349- navigate ,
350- launchLabelsModal ,
351- launchAnnotationsModal ,
352- launchDeleteModal ,
353- setGroupNodeStates ,
354- ) ,
355- ) ;
385+ newController . registerComponentFactory ( customComponentFactory ( hrefRef , contextMenuParamsRef ) ) ;
356386 newController . addEventListener ( SELECTION_EVENT , setSelectedIds ) ;
357387 return newController ;
388+ // Controller is created once; context menu handlers read latest params via ref.
389+ // eslint-disable-next-line react-hooks/exhaustive-deps
358390 } , [ ] ) ;
359391
360392 const resourcePaths = React . useMemo ( ( ) => {
0 commit comments